Przeglądaj źródła

根据唯一码查询设备信息,分页查询用户设备列表

Jeremy 2 lat temu
rodzic
commit
3ac49959be
2 zmienionych plików z 128 dodań i 38 usunięć
  1. 1 0
      AutoMapperProfile.cs
  2. 127 38
      Service/DeviceService.cs

+ 1 - 0
AutoMapperProfile.cs

@@ -10,6 +10,7 @@ namespace WingDeviceService
          {
             CreateMap<UserDTO, UserPasswordDTO>().ReverseMap();
             CreateMap<DeviceInfoDTO, CacheDeviceDTO>().ReverseMap();
+            CreateMap<DeviceInfoDTO, DeviceExtendInfoDTO>().ReverseMap();
          }
     }
 }

+ 127 - 38
Service/DeviceService.cs

@@ -165,6 +165,30 @@ namespace WingDeviceService.Service
             return result;
         }
 
+        /// <summary>
+        /// 根据设备动态唯一码获取设备信息
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<DeviceExtendInfoDTO> GetDeviceByShortCodeAsync(GetDeviceByShortCodeRequest request)
+        {
+            //验证
+            if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
+            {
+                throw new RpcException(1002, "Permission validation error", "Permission validation error");
+            }
+            if (string.IsNullOrWhiteSpace(request.ShortCode))
+            {
+                throw new RpcException(1001, "ShortCode empty error", "ShortCode empty error");
+            }
+            var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(request.ShortCode);
+            if (deviceDb == null || deviceDb.ShortCode != request.ShortCode)
+            {
+                throw new RpcException(1001, "DeviceInfo not exist error", "DeviceInfo not exist error");
+            }
+            return await MapToExtendDTO(deviceDb);
+        }
+
         public async Task<PageCollection<DeviceInfoDTO>> GetDeviceInfoPageAsync(PageFilterRequest request)
         {
             throw new System.NotImplementedException();
@@ -270,9 +294,9 @@ namespace WingDeviceService.Service
         /// <summary>
         /// 查询个人名下所有设备列表接口
         /// </summary>
-        /// <param name="request">签名令牌请求信息</param>
+        /// <param name="request">查询个人名下所有设备列表请求实体</param>
         /// <returns>返回设备信息列表</returns>
-        public async Task<List<DeviceExtendInfoDTO>> GetPersonDeviceListAsync(WingInterfaceLibrary.Request.TokenRequest request)
+        public async Task<PageCollection<DeviceExtendInfoDTO>> GetPersonDeviceListAsync(GetPersonDeviceRequest request)
         {
             //验证
             var tokenInfo = await _authenticationServiceProxy.GetTokenInfoAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token });
@@ -286,49 +310,51 @@ namespace WingDeviceService.Service
             {
                 throw new RpcException(1007, "User not exist.", "User not exist.");
             }
-            var result = new List<DeviceExtendInfoDTO>();
             //查询用户的医院是否存在
-            if (string.IsNullOrEmpty(userInfoDO.OrganizationCode))
+            if (string.IsNullOrWhiteSpace(userInfoDO.OrganizationCode))
             {
                 throw new RpcException(1007, "User's organization not exist.", "User's organization not exist.");
             }
-            //查询用户绑定的设备
-            if (userInfoDO.BindDevices == null || userInfoDO.BindDevices.Count <= 0)
+            var deviceInfoDOList = new List<DeviceInfoDTO>();
+            if (!userInfoDO.IsDirector)
             {
-                return result;
+                //普通用户,查询用户绑定的设备
+                if (userInfoDO.BindDevices != null || userInfoDO.BindDevices.Any())
+                {
+                    deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByCodeListAsync(userInfoDO.BindDevices);
+                }
             }
-            //根据用户名下的设备id查询所有的设备信息
-            var deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByCodeListAsync(userInfoDO.BindDevices);
-            if (deviceInfoDOList?.Count > 0)
+            else
             {
-                //根据机构编号查询机构名称
-                var organizationCode = deviceInfoDOList.FindAll(c => !string.IsNullOrEmpty(c.OrganizationCode)).Select(c => c.OrganizationCode).FirstOrDefault() ?? string.Empty;
-                var organization = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = organizationCode });
-                var organizationName = organization?.OrganizationName ?? string.Empty;
-                //根据机构编号查询科室名称
-                var department = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = userInfoDO.OrganizationCode });
-                var departmentName = department?.OrganizationName ?? string.Empty;
-                //是否在线 todo
-                result = deviceInfoDOList.Select(c => new DeviceExtendInfoDTO()
-                {
-                    DepartmentName = departmentName,
-                    OrganizationName = organizationName,
-                    IsOnline = GetOnline(c.DeviceCode),
-                    DeviceCode = c.DeviceCode,
-                    SerialNumber = c.SerialNumber,
-                    Name = c.Name,
-                    Description = c.Description,
-                    DeviceModel = c.DeviceModel,
-                    DeviceType = c.DeviceType,
-                    HeadPicUrl = c.HeadPicUrl,
-                    DeviceSoftwareVersion = c.DeviceSoftwareVersion,
-                    SDKSoftwareVersion = c.SDKSoftwareVersion,
-                    OrganizationCode = c.OrganizationCode,
-                    DepartmentCode = c.DepartmentCode,
-                    ShortCode = c.ShortCode
-                }).ToList();
+                //机构负责人
+                deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByOrganizationCodeAsync(userInfoDO.OrganizationCode);
             }
-            return result;
+            if (!deviceInfoDOList.Any())
+            {
+                return new PageCollection<DeviceExtendInfoDTO>() { CurrentPage = request.PageIndex, PageSize = request.PageSize, DataCount = 0, PageData = new List<DeviceExtendInfoDTO>() };
+            }
+            var deviceList = await MapToExtendDTO(deviceInfoDOList);
+            //条件筛选
+            if (!string.IsNullOrWhiteSpace(request.DeviceType))
+            {
+                deviceList = deviceList.Where(d => d.DeviceType == request.DeviceType)?.ToList() ?? new List<DeviceExtendInfoDTO>();
+            }
+            if (!string.IsNullOrWhiteSpace(request.DeviceModel))
+            {
+                deviceList = deviceList.Where(d => d.DeviceModel == request.DeviceModel)?.ToList() ?? new List<DeviceExtendInfoDTO>();
+            }
+            if (request.IsOnline != null)
+            {
+                deviceList = deviceList.Where(d => d.IsOnline == request.IsOnline)?.ToList() ?? new List<DeviceExtendInfoDTO>();
+            }
+            var pagedResult = new PageCollection<DeviceExtendInfoDTO>
+            {
+                CurrentPage = request.PageIndex,
+                PageSize = request.PageSize,
+                DataCount = deviceList.Count,
+                PageData = deviceList.Skip(request.PageSize * (request.PageIndex - 1)).Take(request.PageSize)?.ToList() ?? new List<DeviceExtendInfoDTO>()
+            };
+            return pagedResult;
         }
 
         /// <summary>
@@ -636,7 +662,7 @@ namespace WingDeviceService.Service
             {
                 throw new RpcException((int)DeviceErrorCodeEnum.DeviceNotExist, "Device not exist", "Device not exist");
             }
-             var oldOrg = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode =   device.OrganizationCode });
+            var oldOrg = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = device.OrganizationCode });
             if (oldOrg == null || string.IsNullOrWhiteSpace(oldOrg.OrganizationCode))
             {
                 throw new RpcException((int)DeviceErrorCodeEnum.OrganizationNotExist, "Not exist device's organization ", "Not exist device's organization ");
@@ -708,6 +734,69 @@ namespace WingDeviceService.Service
             }
             return false;
         }
+
+        /// <summary>
+        /// 补齐设备扩展信息
+        /// </summary>
+        /// <param name="deviceInfoDOList"></param>
+        /// <returns></returns>
+        private async Task<List<DeviceExtendInfoDTO>> MapToExtendDTO(List<DeviceInfoDTO> deviceInfoDOList)
+        {
+            var deviceList = new List<DeviceExtendInfoDTO>();
+            if (deviceInfoDOList != null && deviceInfoDOList.Any())
+            {
+                //查询机构
+                var orgCodes = deviceInfoDOList.Select(x => x.OrganizationCode).ToList();
+                orgCodes.AddRange(deviceInfoDOList.Select(x => x.DepartmentCode));
+                var organizations = await _organizationDBService.FindOrganizationListByCodesAsync(orgCodes.Distinct().ToList());
+                //查询机构负责人
+                var organizationDirectorCodes = new List<string>();
+                foreach (var org in organizations)
+                {
+                    if (org.Directors != null && org.Directors.Any())
+                    {
+                        organizationDirectorCodes.AddRange(org.Directors);
+                    }
+                }
+                var organizationDirectors = await _userServiceProxy.FindUserListByUserCodes(organizationDirectorCodes);
+                foreach (var dto in deviceInfoDOList)
+                {
+                    var device = dto.MappingTo<DeviceExtendInfoDTO>();
+                    device.IsOnline = GetOnline(device.DeviceCode);
+                    device.DepartmentName = organizations.FirstOrDefault(x => x.OrganizationCode == dto.DepartmentCode)?.OrganizationName;
+
+                    var organization = organizations.FirstOrDefault(x => x.OrganizationCode == dto.OrganizationCode);
+                    if (organization != null)
+                    {
+                        device.OrganizationName = organization.OrganizationName;
+                        if (organization.Directors != null && organization.Directors.Any())
+                        {
+                            var director = organizationDirectors.FirstOrDefault(x => x.UserCode == organization.Directors.FirstOrDefault());
+                            device.OrganizationDirectorCode = director?.UserCode;
+                            device.OrganizationDirectorUserName = director?.UserName;
+                            device.OrganizationDirectorFullName = director?.FullName;
+                        }
+                    }
+
+                    deviceList.Add(device);
+                }
+            }
+            return deviceList;
+        }
+
+        /// <summary>
+        /// 补齐设备扩展信息
+        /// </summary>
+        /// <param name="deviceInfoDOList"></param>
+        /// <returns></returns>
+        private async Task<DeviceExtendInfoDTO> MapToExtendDTO(DeviceInfoDTO deviceInfoDO)
+        {
+            var deviceList = await MapToExtendDTO(new List<DeviceInfoDTO> { deviceInfoDO });
+            return deviceList.FirstOrDefault();
+        }
+
+
+
     }
 
 }