DeviceService.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using WingInterfaceLibrary.Enum;
  5. using System.Threading.Tasks;
  6. using JsonRpcLite.Services;
  7. using WingInterfaceLibrary.DTO.Device;
  8. using WingInterfaceLibrary.Interface;
  9. using WingInterfaceLibrary.Request.Device;
  10. using WingInterfaceLibrary.DTO.Dictionary;
  11. using WingServerCommon.Log;
  12. using WingServerCommon.Service;
  13. using WingInterfaceLibrary.Interface.DBInterface;
  14. using WingInterfaceLibrary.DB.Request;
  15. using WingServerCommon.Mapper;
  16. using WingInterfaceLibrary.Request;
  17. using WingInterfaceLibrary.DTO.User;
  18. using System.IO;
  19. using WingInterfaceLibrary.DTO.Management;
  20. using WingServerCommon.Config;
  21. using WingDeviceService.Common;
  22. namespace WingDeviceService.Service
  23. {
  24. /// <summary>
  25. /// 设备管理服务
  26. /// </summary>
  27. public partial class DeviceService : JsonRpcService, IDeviceService
  28. {
  29. private IUserDBService _userServiceProxy;
  30. private IDeviceInfoDBService _deviceInfoDBServiceProxy;
  31. private IAuthenticationService _authenticationServiceProxy;
  32. private IOrganizationDBService _organizationDBService;
  33. private INotificationService _notificationService;
  34. private CacheManager<CacheDeviceDTO> _cacheDeviceManager
  35. {
  36. get
  37. {
  38. return CacheManagerSingle<CacheDeviceDTO>.Instance;
  39. }
  40. }
  41. /// <summary>
  42. /// Init service
  43. /// </summary>
  44. public override void Load(JsonRpcClientPool jsonRpcClientPool)
  45. {
  46. base.Load(jsonRpcClientPool);
  47. _userServiceProxy = GetProxy<IUserDBService>();
  48. _authenticationServiceProxy = GetProxy<IAuthenticationService>();
  49. _deviceInfoDBServiceProxy = GetProxy<IDeviceInfoDBService>();
  50. _organizationDBService = GetProxy<IOrganizationDBService>();
  51. _notificationService = GetProxy<INotificationService>();
  52. }
  53. /// <summary>
  54. /// 添加分享设备关联用户请求
  55. /// </summary>
  56. /// <param name="request"></param>
  57. /// <returns></returns>
  58. public async Task<bool> CreateShareDeviceToUserAsync(CreateShareDeviceToUserRequest request)
  59. {
  60. var userCodes = request.UserCodes;
  61. var deviceCode = request.DeviceCode;
  62. if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
  63. {
  64. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  65. }
  66. //检查设备编码不为空
  67. if (string.IsNullOrWhiteSpace(request.DeviceCode))
  68. {
  69. throw new RpcException(1004, "Required parameter:DeviceCode cannot be empty", "Required parameter:DeviceCode cannot be empty");
  70. }
  71. if (userCodes == null || userCodes.Count <= 0)
  72. {
  73. throw new RpcException(1004, "Required parameter:UserCodes cannot be empty", "Required parameter:UserCodes cannot be empty");
  74. }
  75. //查询设备对象
  76. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
  77. if (deviceDb == null)
  78. {
  79. throw new RpcException(1007, "Device not exist.", "Device not exist.");
  80. }
  81. foreach (var userCode in userCodes)
  82. {
  83. var existUser = await _userServiceProxy.FindUserByCodeAsync(userCode);
  84. if (existUser == null)
  85. {
  86. throw new RpcException(1007, " Users not exist.", " Users not exist.");
  87. }
  88. }
  89. await _userServiceProxy.BingDevicesToUsersAsync(new BingDevicesToUsersRequest
  90. {
  91. DeviceCodes = new List<string> { deviceCode },
  92. UserCodes = userCodes.ToList()
  93. });
  94. return true;
  95. }
  96. /// <summary>
  97. /// 根据设备code获取设备信息
  98. /// </summary>
  99. /// <param name="request">设备code请求实体</param>
  100. /// <returns>返回查询到的设备对象信息</returns>
  101. public async Task<DeviceExtendInfoDTO> GetDeviceInfoAsync(GetDeviceRequest request)
  102. {
  103. //验证
  104. if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
  105. {
  106. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  107. }
  108. if (string.IsNullOrWhiteSpace(request.DeviceCode))
  109. {
  110. throw new RpcException(1001, "DeviceCode empty error", "DeviceCode empty error");
  111. }
  112. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
  113. if (deviceDb == null || deviceDb.DeviceCode != request.DeviceCode)
  114. {
  115. throw new RpcException(1001, "DeviceInfo not exist error", "DeviceInfo not exist error");
  116. }
  117. //根据机构编号查询机构名称
  118. var organizationName = "";
  119. if (!string.IsNullOrEmpty(deviceDb.OrganizationCode))
  120. {
  121. var organization = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = deviceDb.OrganizationCode });
  122. organizationName = organization?.OrganizationName ?? string.Empty;
  123. }
  124. //根据机构编号查询科室名称
  125. var departmentName = "";
  126. if (!string.IsNullOrEmpty(deviceDb.DepartmentCode))
  127. {
  128. var department = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = deviceDb.DepartmentCode });
  129. departmentName = department?.OrganizationName ?? string.Empty;
  130. }
  131. //是否在线 todo
  132. var result = new DeviceExtendInfoDTO()
  133. {
  134. DepartmentName = departmentName,
  135. OrganizationName = organizationName,
  136. IsOnline = (deviceDb.Name == null ? false : ((deviceDb.Name.ToString().Length % 2 == 0) ? true : false)),
  137. DeviceCode = deviceDb.DeviceCode,
  138. SerialNumber = deviceDb.SerialNumber,
  139. Name = deviceDb.Name,
  140. Description = deviceDb.Description,
  141. DeviceModel = deviceDb.DeviceModel,
  142. DeviceType = deviceDb.DeviceType,
  143. HeadPicUrl = deviceDb.HeadPicUrl,
  144. DeviceSoftwareVersion = deviceDb.DeviceSoftwareVersion,
  145. SDKSoftwareVersion = deviceDb.SDKSoftwareVersion,
  146. OrganizationCode = deviceDb.OrganizationCode,
  147. DepartmentCode = deviceDb.DepartmentCode,
  148. ShortCode = deviceDb.ShortCode
  149. };
  150. return result;
  151. }
  152. public async Task<PageCollection<DeviceInfoDTO>> GetDeviceInfoPageAsync(PageFilterRequest request)
  153. {
  154. throw new System.NotImplementedException();
  155. }
  156. public async Task<bool> DeleteShareDeviceToUserAsync(DeleteShareDeviceToUserRequest request)
  157. {
  158. var userCodes = request.UserCodes;
  159. var deviceCode = request.DeviceCode;
  160. if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
  161. {
  162. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  163. }
  164. //检查设备编码不为空
  165. if (string.IsNullOrWhiteSpace(request.DeviceCode))
  166. {
  167. throw new RpcException(1004, "Required parameter:DeviceCode cannot be empty", "Required parameter:DeviceCode cannot be empty");
  168. }
  169. //用户编码集合检查
  170. if (userCodes == null || userCodes.Count <= 0)
  171. {
  172. throw new RpcException(1004, "Required parameter:UserCodes cannot be empty", "Required parameter:UserCodes cannot be empty");
  173. }
  174. //查询设备对象
  175. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
  176. if (deviceDb == null)
  177. {
  178. throw new RpcException(1007, "Device not exist.", "Device not exist.");
  179. }
  180. var updateUsers = new List<TableDataItem<UserPasswordDTO>>();
  181. foreach (var userCode in userCodes)
  182. {
  183. var user = await _userServiceProxy.FindUserByCodeAsync(userCode);
  184. if (user != null)
  185. {
  186. if (user.BindDevices.Contains(deviceCode))
  187. {
  188. user.BindDevices.Remove(deviceCode);
  189. updateUsers.Add(new TableDataItem<UserPasswordDTO>()
  190. {
  191. Data = user.MappingTo<UserPasswordDTO>(),
  192. });
  193. }
  194. }
  195. }
  196. if (updateUsers.Count > 0)
  197. {
  198. var updateUsersDBRequest = new UpdateUsersDBRequest() { Users = updateUsers };
  199. await _userServiceProxy.UpdateUsersAsync(updateUsersDBRequest);
  200. }
  201. return true;
  202. }
  203. /// <summary>
  204. /// 机构设备移除-根据机构code和设备code解除其绑定关系
  205. /// </summary>
  206. /// <param name="request">移除设备请求实体</param>
  207. /// <returns>移除是否成功:true-成功;false-失败</returns>
  208. public async Task<bool> RemoveDeviceRelevancyAsync(RemoveDeviceRelevancyRequest request)
  209. {
  210. //验证
  211. if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
  212. {
  213. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  214. }
  215. if (string.IsNullOrWhiteSpace(request.DeviceCode) || string.IsNullOrWhiteSpace(request.OrganizationCode))
  216. {
  217. throw new RpcException(1001, "DeviceCode Or OrganizationCode empty error", "DeviceCode Or OrganizationCode empty error");
  218. }
  219. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
  220. if (deviceDb == null || deviceDb.OrganizationCode != request.OrganizationCode || deviceDb.DepartmentCode != request.DepartmentCode)
  221. {
  222. throw new RpcException(1001, "DeviceInfo not exist error", "DeviceInfo not exist error");
  223. }
  224. // //根据机构code和设备code去用户表查询关联数据,如果有则返回异常,否则就解除绑定关系;
  225. // var isExistUserRelevancy = false;
  226. // //todo 到时候调用mike的关联用户接口
  227. // if (isExistUserRelevancy)
  228. // {
  229. // throw new RpcException(1001, "This Device Exist Share User error", "This Device Exist Share User error");
  230. // }
  231. //根据设备code和机构code查询相关数据,查到则删除关联
  232. if (!string.IsNullOrEmpty(deviceDb.DepartmentCode))
  233. {
  234. deviceDb.DepartmentCode = "";
  235. deviceDb.OrganizationCode = "";
  236. }
  237. else
  238. {
  239. deviceDb.OrganizationCode = "";
  240. }
  241. bool removeDeviceResult = await _deviceInfoDBServiceProxy.UpdateDeviceInfoByCodeAsync(deviceDb.DeviceCode, deviceDb, string.Empty, true);
  242. return removeDeviceResult;
  243. }
  244. /// <summary>
  245. /// 查询个人名下所有设备列表接口
  246. /// </summary>
  247. /// <param name="request">签名令牌请求信息</param>
  248. /// <returns>返回设备信息列表</returns>
  249. public async Task<List<DeviceExtendInfoDTO>> GetPersonDeviceListAsync(WingInterfaceLibrary.Request.TokenRequest request)
  250. {
  251. //验证
  252. var tokenInfo = await _authenticationServiceProxy.GetTokenInfoAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token });
  253. if (tokenInfo == null)
  254. {
  255. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  256. }
  257. //查询用户是否存在
  258. var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(tokenInfo.UserCode);
  259. if (userInfoDO == null)
  260. {
  261. throw new RpcException(1007, "User not exist.", "User not exist.");
  262. }
  263. var result = new List<DeviceExtendInfoDTO>();
  264. //查询用户的医院是否存在
  265. if (string.IsNullOrEmpty(userInfoDO.OrganizationCode))
  266. {
  267. throw new RpcException(1007, "User's organization not exist.", "User's organization not exist.");
  268. }
  269. //查询用户绑定的设备
  270. if (userInfoDO.BindDevices == null || userInfoDO.BindDevices.Count <= 0)
  271. {
  272. return result;
  273. }
  274. //根据用户名下的设备id查询所有的设备信息
  275. var deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByCodeListAsync(userInfoDO.BindDevices);
  276. if (deviceInfoDOList?.Count > 0)
  277. {
  278. //根据机构编号查询机构名称
  279. var organizationCode = deviceInfoDOList.FindAll(c => !string.IsNullOrEmpty(c.OrganizationCode)).Select(c => c.OrganizationCode).FirstOrDefault() ?? string.Empty;
  280. var organization = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = organizationCode });
  281. var organizationName = organization?.OrganizationName ?? string.Empty;
  282. //根据机构编号查询科室名称
  283. var department = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = userInfoDO.OrganizationCode });
  284. var departmentName = department?.OrganizationName ?? string.Empty;
  285. //是否在线 todo
  286. result = deviceInfoDOList.Select(c => new DeviceExtendInfoDTO()
  287. {
  288. DepartmentName = departmentName,
  289. OrganizationName = organizationName,
  290. IsOnline = (c.Name == null ? false : ((c.Name.ToString().Length % 2 == 0) ? true : false)),
  291. DeviceCode = c.DeviceCode,
  292. SerialNumber = c.SerialNumber,
  293. Name = c.Name,
  294. Description = c.Description,
  295. DeviceModel = c.DeviceModel,
  296. DeviceType = c.DeviceType,
  297. HeadPicUrl = c.HeadPicUrl,
  298. DeviceSoftwareVersion = c.DeviceSoftwareVersion,
  299. SDKSoftwareVersion = c.SDKSoftwareVersion,
  300. OrganizationCode = c.OrganizationCode,
  301. DepartmentCode = c.DepartmentCode,
  302. ShortCode = c.ShortCode
  303. }).ToList();
  304. }
  305. return result;
  306. }
  307. /// <summary>
  308. /// 绑定设备
  309. /// </summary>
  310. /// <param name="request"></param>
  311. /// <returns></returns>
  312. public async Task<bool> BindDeviceAsync(BindDeviceRequest request)
  313. {
  314. if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
  315. {
  316. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  317. }
  318. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(request.ShortCode);
  319. if (deviceDb == null)
  320. {
  321. throw new RpcException(1001, "Not find device", "Not find device");
  322. }
  323. try
  324. {
  325. deviceDb.Name = request.Name;
  326. deviceDb.SerialNumber = request.SerialNumber;
  327. deviceDb.Description = request.Description;
  328. if (!string.IsNullOrEmpty(request.HeadPicUrl))
  329. {
  330. // var fileName = Path.GetFileName(request.HeadPicUrl);
  331. // var fileExtension = Path.GetExtension(request.HeadPicUrl);
  332. // if (fileName.Contains("_"))
  333. // {
  334. // deviceDb.HeadPicUrl = fileName.Replace(fileExtension, "");
  335. // }
  336. // else
  337. // {
  338. // Enum.TryParse<UploadFileTypeEnum>(fileExtension.Replace(".", ""), out var type);
  339. // deviceDb.HeadPicUrl = fileName.Replace(fileExtension, "") + "_" + type.GetHashCode() + "_0";
  340. // }
  341. deviceDb.HeadPicUrl = request.HeadPicUrl.ToUrlToken();
  342. }
  343. deviceDb.OrganizationCode = request.OrganizationCode;
  344. deviceDb.DepartmentCode = request.DepartmentCode;
  345. deviceDb.IsAutoShared = request.IsAutoShared;
  346. if (deviceDb.IsAutoShared)
  347. {
  348. if (await _deviceInfoDBServiceProxy.UpdateDeviceInfoByCodeAsync(deviceDb.DeviceCode, deviceDb, string.Empty))
  349. {
  350. var users = new List<UserDTO>();
  351. if (!string.IsNullOrEmpty(deviceDb.DepartmentCode))
  352. {
  353. users = await _userServiceProxy.FindUserListByOrganizationCodesAsync(new List<string> { deviceDb.DepartmentCode });
  354. }
  355. else
  356. {
  357. users = await _userServiceProxy.FindUserListByOrganizationCodesAsync(new List<string> { deviceDb.OrganizationCode });
  358. }
  359. var userCodes = users.Select(f => f.UserCode).ToList();
  360. await _userServiceProxy.BingDevicesToUsersAsync(new BingDevicesToUsersRequest
  361. {
  362. DeviceCodes = new List<string> { deviceDb.DeviceCode.ToString() },
  363. UserCodes = userCodes.Select(f => f.ToString()).ToList()
  364. });
  365. }
  366. }
  367. return true;
  368. }
  369. catch (Exception ex)
  370. {
  371. Logger.WriteLineError($"BindDeviceAsync error {ex}");
  372. }
  373. return false;
  374. }
  375. /// <summary>
  376. /// 修改设备
  377. /// </summary>
  378. /// <param name="request"></param>
  379. /// <returns></returns>
  380. public async Task<bool> AlterDeviceAsync(AlterDeviceRequest request)
  381. {
  382. if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
  383. {
  384. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  385. }
  386. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
  387. if (deviceDb == null)
  388. {
  389. throw new RpcException(1001, "Not find device", "Not find device");
  390. }
  391. deviceDb.Name = request.Name;
  392. deviceDb.SerialNumber = request.SerialNumber;
  393. deviceDb.Description = request.Description;
  394. deviceDb.HeadPicUrl = request.HeadPicUrl.ToUrlToken();
  395. deviceDb.OrganizationCode = request.OrganizationCode;
  396. return await _deviceInfoDBServiceProxy.UpdateDeviceInfoByCodeAsync(deviceDb.DeviceCode, deviceDb, string.Empty);
  397. }
  398. /// <summary>
  399. /// 创建字典
  400. /// </summary>
  401. /// <param name="request"></param>
  402. /// <returns></returns>
  403. public async Task<string> CreateDictionaryItemAsync(CreateDictionaryItemRequest request)
  404. {
  405. if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
  406. {
  407. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  408. }
  409. var tokenInfo = await _authenticationServiceProxy.GetTokenInfoAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token });
  410. return await _deviceInfoDBServiceProxy.CreateDictionaryItemAsync(new CreateDictionaryItemDBRequest
  411. {
  412. Data = new DictionaryDTO { DictionaryType = request.DictionaryType, Value = request.DictionaryItemValue, ParentCode = request.ParentCode },
  413. PlatformDatas = tokenInfo.HeaderMap,
  414. ExtensionData = string.Empty
  415. });
  416. }
  417. /// <summary>
  418. /// 查找设备型号所有字典项
  419. /// </summary>
  420. /// <param name="request"></param>
  421. /// <returns></returns>
  422. public async Task<List<DictionaryDTO>> FindDeviceModelItemsAsync(FindDeviceModelItemsRequest request)
  423. {
  424. if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
  425. {
  426. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  427. }
  428. var dictionaryDOList = await _deviceInfoDBServiceProxy.FindDictionaryItemsAsync(new FindDictionaryItemsDBRequest
  429. {
  430. DictionaryType = (int)request.DictionaryType,
  431. ParentCode = request.DeviceTypeCode
  432. });
  433. return dictionaryDOList;
  434. }
  435. /// <summary>
  436. /// 查找设备类型所有字典项
  437. /// </summary>
  438. /// <param name="request"></param>
  439. /// <returns></returns>
  440. public async Task<List<DictionaryDTO>> FindDeviceTypeItemsAsync(FindDeviceTypeItemsRequest request)
  441. {
  442. if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
  443. {
  444. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  445. }
  446. var dictionaryDOList = await _deviceInfoDBServiceProxy.FindDictionaryItemsAsync(new FindDictionaryItemsDBRequest
  447. {
  448. DictionaryType = (int)request.DictionaryType
  449. });
  450. return dictionaryDOList;
  451. }
  452. /// <summary>
  453. /// 根据组织编码查询所属全部设备信息
  454. /// </summary>
  455. /// <param name="request"></param>
  456. /// <returns></returns>
  457. public async Task<List<DeviceInfoDTO>> FindDevicesByOrganizationCodeAsync(FindDevicesByOrganizationCodeRequest request)
  458. {
  459. if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
  460. {
  461. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  462. }
  463. var deviceInfosDO = await _deviceInfoDBServiceProxy.FindDeviceInfoListByOrganizationCodeAsync(request.OrganizationCode);
  464. return deviceInfosDO;
  465. }
  466. public Task<DeviceInfoDTO> CreateDeviceInfoAsync(CreateDeviceRequest request)
  467. {
  468. throw new NotImplementedException();
  469. }
  470. public async Task<List<SelectItemDTO>> GetPersonDeviceDropdownListAsync(TokenRequest request)
  471. {
  472. //验证
  473. var tokenInfo = await _authenticationServiceProxy.GetTokenInfoAsync(request);
  474. if (tokenInfo == null)
  475. {
  476. throw new RpcException(1002, "Permission validation error", "Permission validation error");
  477. }
  478. //查询用户是否存在
  479. var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(tokenInfo.UserCode);
  480. if (userInfoDO == null)
  481. {
  482. throw new RpcException(1007, "User not exist.", "User not exist.");
  483. }
  484. var result = new List<SelectItemDTO>();
  485. //查询用户的医院是否存在
  486. if (string.IsNullOrEmpty(userInfoDO.OrganizationCode))
  487. {
  488. throw new RpcException(1007, "User's organization not exist.", "User's organization not exist.");
  489. }
  490. //查询用户绑定的设备
  491. if (userInfoDO.BindDevices == null || userInfoDO.BindDevices.Count <= 0)
  492. {
  493. return result;
  494. }
  495. //根据用户名下的设备id查询所有的设备信息
  496. var deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByCodeListAsync(userInfoDO.BindDevices);
  497. if (deviceInfoDOList?.Count > 0)
  498. {
  499. result = deviceInfoDOList.Select(c => new SelectItemDTO()
  500. {
  501. Key = c.DeviceCode,
  502. Value = c.Name
  503. }).ToList();
  504. }
  505. return result;
  506. }
  507. /// <summary>
  508. /// 设备端调用,查询获取服务器配置信息接口
  509. /// </summary>
  510. /// <param name="request">Token验证</param>
  511. /// <returns>服务器配置信息结果:key:字段,value:数据值,复杂类型可为json</returns>
  512. public async Task<Dictionary<string, string>> QueryServerConfig(TokenRequest request)
  513. {
  514. var cacheDeviceDTO = await GetDeviceByToken(request);
  515. //设备Code编码
  516. var code = cacheDeviceDTO.DeviceCode;
  517. var dictionary = new Dictionary<string, string>();
  518. //定义配置字段 并扩充字段,返回数据可持续更新接口文档,如果数据是复杂类型可以转成json
  519. //TODO 配置信息: 直播配置、存储配置、
  520. //存储上传图像或者视频是 是否本地上传缩略图
  521. var isUploadThumbnail = ConfigurationManager.RemedicalSettings.IsUploadThumbnail;
  522. dictionary.Add("IsUploadThumbnail", isUploadThumbnail.ToString());
  523. return dictionary;
  524. }
  525. }
  526. }