DeviceService.cs 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using WingInterfaceLibrary.DTO.Device;
  6. using WingInterfaceLibrary.Interface;
  7. using WingInterfaceLibrary.Request.Device;
  8. using WingInterfaceLibrary.DTO.Dictionary;
  9. using WingServerCommon.Log;
  10. using WingServerCommon.Service;
  11. using WingInterfaceLibrary.Interface.DBInterface;
  12. using WingInterfaceLibrary.DB.Request;
  13. using WingServerCommon.Mapper;
  14. using WingInterfaceLibrary.Request;
  15. using WingInterfaceLibrary.Request.Authentication;
  16. using WingInterfaceLibrary.DTO.User;
  17. using WingInterfaceLibrary.DTO.Management;
  18. using WingServerCommon.Config;
  19. using WingDeviceService.Common;
  20. using WingInterfaceLibrary.Request.User;
  21. using WingInterfaceLibrary.Enum;
  22. using WingInterfaceLibrary.DTO.Organization;
  23. using WingInterfaceLibrary.DTO.DiagnosisModule;
  24. using WingServerCommon.Config.Parameters;
  25. using WingServerCommon.Interfaces.Cache;
  26. using WingInterfaceLibrary.LiveConsultation;
  27. using WingInterfaceLibrary.Result.Languge;
  28. using WingInterfaceLibrary.Internal.Interface;
  29. using WingInterfaceLibrary.Notifications;
  30. using WingInterfaceLibrary.Internal.Request;
  31. using WingInterfaceLibrary.Rtc;
  32. using WingInterfaceLibrary.Enum.CommentEnum;
  33. using WingInterfaceLibrary.DTO.RTC;
  34. using Newtonsoft.Json;
  35. using WingInterfaceLibrary.Notifications.Live;
  36. using WingInterfaceLibrary.Enum.NotificationEnum;
  37. using WingInterfaceLibrary.DTO.LiveRoom;
  38. namespace WingDeviceService.Service
  39. {
  40. /// <summary>
  41. /// 设备管理服务
  42. /// </summary>
  43. public partial class DeviceService : JsonRpcService, IDeviceService
  44. {
  45. private IUserDBService _userServiceProxy;
  46. private IDeviceInfoDBService _deviceInfoDBServiceProxy;
  47. private IAuthenticationService _authenticationService;
  48. private IOrganizationDBService _organizationDBService;
  49. private INotificationService _notificationService;
  50. private IRecordsInfoDBService _recordsInfoDBService;
  51. private IPatientInfoDBService _patientInfoDBService;
  52. private IDiagnosisModuleDBService _diagnosisModuleService;
  53. private IRemedicalService _remedicalService;
  54. private IWingRtcService _rtcService;
  55. private int _heartRateSeconds;
  56. private DeviceHeartRateManager _deviceHeartRateManager;
  57. private string _webSocketUrl = string.Empty;
  58. private int _liveConsultationRateSeconds = 0;
  59. private bool _isRTCSelf = false;
  60. private int _sdkAppId = 0;
  61. private int _remoteControlAskTimeoutSec = 0;
  62. private int _reportStateIntervalSeconds = 0;
  63. private int _reportStateTimeout = 0;
  64. private ILiveConsultationService _liveConsultationService;
  65. /// <summary>
  66. /// Init service
  67. /// </summary>
  68. public override void Load(JsonRpcClientPool jsonRpcClientPool)
  69. {
  70. base.Load(jsonRpcClientPool);
  71. _userServiceProxy = GetProxy<IUserDBService>();
  72. _authenticationService = GetProxy<IAuthenticationService>();
  73. _deviceInfoDBServiceProxy = GetProxy<IDeviceInfoDBService>();
  74. _organizationDBService = GetProxy<IOrganizationDBService>();
  75. _notificationService = GetProxy<INotificationService>();
  76. _recordsInfoDBService = GetProxy<IRecordsInfoDBService>();
  77. _patientInfoDBService = GetProxy<IPatientInfoDBService>();
  78. _diagnosisModuleService = GetProxy<IDiagnosisModuleDBService>();
  79. _remedicalService = GetProxy<IRemedicalService>();
  80. _rtcService = GetProxy<IWingRtcService>();
  81. _liveConsultationService = GetProxy<ILiveConsultationService>();
  82. _heartRateSeconds = ConfigurationManager.GetParammeter<IntParameter>("Device", "HeartRateSeconds").Value;
  83. _deviceHeartRateManager = new DeviceHeartRateManager(SetOnlineState);
  84. _webSocketUrl = ConfigurationManager.GetParammeter<StringParameter>("Notification", "WebSocketUrl").Value;
  85. _liveConsultationRateSeconds = ConfigurationManager.GetParammeter<IntParameter>("Live", "HeartRateSeconds").Value;
  86. _isRTCSelf = ConfigurationManager.GetParammeter<BoolParameter>("Rtc", "IsSelf").Value;
  87. var sdkAppIdString = ConfigurationManager.GetParammeter<StringParameter>("Rtc", "RTCAppId").Value;
  88. if (int.TryParse(sdkAppIdString, out int sdkAppId))
  89. {
  90. _sdkAppId = sdkAppId;
  91. }
  92. _remoteControlAskTimeoutSec = ConfigurationManager.GetParammeter<IntParameter>("Device", "RemoteControlAskTimeoutSec").Value;
  93. var _reportStateIntervalSeconds = ConfigurationManager.GetParammeter<IntParameter>("Live", "ReportStateIntervalSeconds").Value;
  94. var _reportStateTimeout = ConfigurationManager.GetParammeter<IntParameter>("Live", "ReportStateTimeout").Value;
  95. }
  96. /// <summary>
  97. /// 设备心跳
  98. /// </summary>
  99. /// <param name="request"></param>
  100. /// <returns></returns>
  101. public async Task<bool> HeartRateAsync(TokenRequest request)
  102. {
  103. _deviceHeartRateManager.AddOrUpdate(request.Token);
  104. var result = SetOnlineState(request.Token, true);
  105. return result;
  106. }
  107. private bool SetOnlineState(string token, bool isOnline)
  108. {
  109. return _authenticationService.SetOnlineStateAsync(new SetOnlineStateRequest { Token = token, IsOnline = isOnline }).Result;
  110. }
  111. /// <summary>
  112. /// 添加分享设备关联用户请求
  113. /// </summary>
  114. /// <param name="request"></param>
  115. /// <returns></returns>
  116. public async Task<bool> CreateShareDeviceToUserAsync(CreateShareDeviceToUserRequest request)
  117. {
  118. var userCodes = request.UserCodes;
  119. var deviceCode = request.DeviceCode;
  120. //检查设备编码不为空
  121. if (string.IsNullOrWhiteSpace(request.DeviceCode))
  122. {
  123. ThrowCustomerException(CustomerRpcCode.DeviceCodeIsEmpty, "Required parameter:DeviceCode cannot be empty");
  124. }
  125. if (userCodes == null || userCodes.Count <= 0)
  126. {
  127. ThrowCustomerException(CustomerRpcCode.UserCodeEmptyError, "Required parameter:UserCodes cannot be empty");
  128. }
  129. //查询设备对象
  130. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
  131. if (deviceDb == null)
  132. {
  133. ThrowCustomerException(CustomerRpcCode.NoExistDevice, "Device does not exist");
  134. }
  135. foreach (var userCode in userCodes)
  136. {
  137. var existUser = await _userServiceProxy.FindUserByCodeAsync(userCode);
  138. if (existUser == null)
  139. {
  140. ThrowCustomerException(CustomerRpcCode.UserNotExistError, "User does not exist");
  141. }
  142. }
  143. await _userServiceProxy.BingDevicesToUsersAsync(new BingDevicesToUsersRequest
  144. {
  145. DeviceCodes = new List<string> { deviceCode },
  146. UserCodes = userCodes.ToList()
  147. });
  148. return true;
  149. }
  150. /// <summary>
  151. /// 根据设备code获取设备信息
  152. /// </summary>
  153. /// <param name="request">设备code请求实体</param>
  154. /// <returns>返回查询到的设备对象信息</returns>
  155. public async Task<DeviceExtendInfoDTO> GetDeviceInfoAsync(GetDeviceRequest request)
  156. {
  157. //验证
  158. if (string.IsNullOrWhiteSpace(request.DeviceCode))
  159. {
  160. ThrowCustomerException(CustomerRpcCode.DeviceCodeEmpty, "DeviceCode empty error");
  161. }
  162. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
  163. if (deviceDb == null || deviceDb.DeviceCode != request.DeviceCode)
  164. {
  165. ThrowCustomerException(CustomerRpcCode.NoExistDevice, "Device does not exist");
  166. }
  167. //根据机构编号查询机构名称
  168. var organizationName = "";
  169. if (!string.IsNullOrEmpty(deviceDb.OrganizationCode))
  170. {
  171. var organization = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = deviceDb.OrganizationCode });
  172. organizationName = organization?.OrganizationName ?? string.Empty;
  173. }
  174. //根据机构编号查询科室名称
  175. var departmentName = "";
  176. if (!string.IsNullOrEmpty(deviceDb.DepartmentCode))
  177. {
  178. var department = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = deviceDb.DepartmentCode });
  179. departmentName = department?.OrganizationName ?? string.Empty;
  180. }
  181. //是否在线 todo
  182. var deviceTypeModel = await _deviceInfoDBServiceProxy.FindDictionaryByCodeAsync(deviceDb.DeviceType);
  183. var result = new DeviceExtendInfoDTO()
  184. {
  185. DepartmentName = departmentName,
  186. OrganizationName = organizationName,
  187. IsOnline = await GetDeviceOnlineState(deviceDb.DeviceCode),
  188. DeviceCode = deviceDb.DeviceCode,
  189. SerialNumber = deviceDb.SerialNumber,
  190. Name = deviceDb.Name,
  191. Description = deviceDb.Description,
  192. DeviceModel = deviceDb.DeviceModel,
  193. DeviceType = deviceDb.DeviceType,
  194. HeadPicUrl = deviceDb.HeadPicUrl,
  195. DeviceSoftwareVersion = deviceDb.DeviceSoftwareVersion,
  196. SDKSoftwareVersion = deviceDb.SDKSoftwareVersion,
  197. OrganizationCode = deviceDb.OrganizationCode,
  198. DepartmentCode = deviceDb.DepartmentCode,
  199. ShortCode = deviceDb.ShortCode,
  200. LanguageConfigs = deviceTypeModel.LanguageConfigs
  201. };
  202. return result;
  203. }
  204. /// <summary>
  205. /// 根据设备动态唯一码获取设备信息
  206. /// </summary>
  207. /// <param name="request"></param>
  208. /// <returns></returns>
  209. public async Task<DeviceExtendInfoDTO> GetDeviceByShortCodeAsync(GetDeviceByShortCodeRequest request)
  210. {
  211. //验证
  212. if (string.IsNullOrWhiteSpace(request.ShortCode))
  213. {
  214. ThrowCustomerException(CustomerRpcCode.ShortCodeEmpty, "ShortCode empty error");
  215. }
  216. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(request.ShortCode);
  217. if (deviceDb == null || deviceDb.ShortCode != request.ShortCode)
  218. {
  219. ThrowCustomerException(CustomerRpcCode.NoExistDevice, "Device does not exist");
  220. }
  221. return await MapToExtendDTO(deviceDb);
  222. }
  223. public async Task<PageCollection<DeviceInfoDTO>> GetDeviceInfoPageAsync(PageFilterRequest request)
  224. {
  225. throw new System.NotImplementedException();
  226. }
  227. public async Task<bool> DeleteShareDeviceToUserAsync(DeleteShareDeviceToUserRequest request)
  228. {
  229. var userCodes = request.UserCodes;
  230. var deviceCode = request.DeviceCode;
  231. //检查设备编码不为空
  232. if (string.IsNullOrWhiteSpace(request.DeviceCode))
  233. {
  234. ThrowCustomerException(CustomerRpcCode.DeviceCodeIsEmpty, "Required parameter:DeviceCode cannot be empty");
  235. }
  236. //用户编码集合检查
  237. if (userCodes == null || userCodes.Count <= 0)
  238. {
  239. ThrowCustomerException(CustomerRpcCode.UserCodeEmptyError, "Required parameter:UserCodes cannot be empty");
  240. }
  241. //查询设备对象
  242. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
  243. if (deviceDb == null)
  244. {
  245. ThrowCustomerException(CustomerRpcCode.NoExistDevice, "Device does not exist");
  246. }
  247. var updateUsers = new List<TableDataItem<UserPasswordDTO>>();
  248. foreach (var userCode in userCodes)
  249. {
  250. var user = await _userServiceProxy.FindUserByCodeAsync(userCode);
  251. if (user != null)
  252. {
  253. if (user.BindDevices.Contains(deviceCode))
  254. {
  255. user.BindDevices.Remove(deviceCode);
  256. updateUsers.Add(new TableDataItem<UserPasswordDTO>()
  257. {
  258. Data = user.MappingTo<UserPasswordDTO>(),
  259. });
  260. }
  261. }
  262. }
  263. if (updateUsers.Count > 0)
  264. {
  265. var updateUsersDBRequest = new UpdateUsersDBRequest() { Users = updateUsers };
  266. await _userServiceProxy.UpdateUsersAsync(updateUsersDBRequest);
  267. }
  268. return true;
  269. }
  270. /// <summary>
  271. /// 机构设备移除-根据机构code和设备code解除其绑定关系
  272. /// </summary>
  273. /// <param name="request">移除设备请求实体</param>
  274. /// <returns>移除是否成功:true-成功;false-失败</returns>
  275. public async Task<bool> RemoveDeviceRelevancyAsync(RemoveDeviceRelevancyRequest request)
  276. {
  277. //验证
  278. if (string.IsNullOrWhiteSpace(request.DeviceCode) || string.IsNullOrWhiteSpace(request.OrganizationCode))
  279. {
  280. ThrowCustomerException(CustomerRpcCode.DeviceCodeOrOrganizationCodeEmpty, "DeviceCode Or OrganizationCode empty error");
  281. }
  282. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
  283. if (deviceDb == null || deviceDb.OrganizationCode != request.OrganizationCode || deviceDb.DepartmentCode != request.DepartmentCode)
  284. {
  285. ThrowCustomerException(CustomerRpcCode.DeviceNotExist, "DeviceInfo not exist error");
  286. }
  287. //根据设备code和机构code查询相关数据,查到则删除关联
  288. if (!string.IsNullOrEmpty(deviceDb.DepartmentCode))
  289. {
  290. deviceDb.DepartmentCode = "";
  291. deviceDb.OrganizationCode = "";
  292. }
  293. else
  294. {
  295. deviceDb.OrganizationCode = "";
  296. }
  297. bool removeDeviceResult = await _deviceInfoDBServiceProxy.UpdateDeviceInfoByCodeAsync(deviceDb.DeviceCode, deviceDb, string.Empty, true);
  298. return removeDeviceResult;
  299. }
  300. private async Task<string> GetClientIdByTokenAsync(string token)
  301. {
  302. var request = new TokenRequest() { Token = token };
  303. var result = await _authenticationService.GetTokenAsync(request);
  304. return result.ClientId; //return User code
  305. }
  306. /// <summary>
  307. /// 查询个人名下所有设备列表接口
  308. /// </summary>
  309. /// <param name="request">查询个人名下所有设备列表请求实体</param>
  310. /// <returns>返回设备信息列表</returns>
  311. public async Task<PageCollection<DeviceExtendInfoDTO>> GetPersonDeviceListAsync(GetPersonDeviceRequest request)
  312. {
  313. //验证
  314. var userCode = await GetClientIdByTokenAsync(request.Token);
  315. //查询用户是否存在
  316. var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(userCode);
  317. if (userInfoDO == null)
  318. {
  319. ThrowCustomerException(CustomerRpcCode.UserNotExistError, "User does not exist");
  320. }
  321. //查询用户的医院是否存在
  322. if (string.IsNullOrWhiteSpace(userInfoDO.OrganizationCode))
  323. {
  324. ThrowCustomerException(CustomerRpcCode.OrganizationNotExist, "Org does not exist");
  325. }
  326. var deviceInfoDOList = new List<DeviceInfoDTO>();
  327. if (!userInfoDO.IsDirector)
  328. {
  329. //普通用户,查询用户绑定的设备
  330. if (userInfoDO.BindDevices != null && userInfoDO.BindDevices.Any())
  331. {
  332. deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByCodeListAsync(userInfoDO.BindDevices);
  333. }
  334. }
  335. else
  336. {
  337. //机构负责人
  338. deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByOrganizationCodeAsync(userInfoDO.RootOrganizationCode);
  339. }
  340. if (!deviceInfoDOList.Any())
  341. {
  342. return new PageCollection<DeviceExtendInfoDTO>() { CurrentPage = request.PageIndex, PageSize = request.PageSize, DataCount = 0, PageData = new List<DeviceExtendInfoDTO>() };
  343. }
  344. var deviceList = await MapToExtendDTO(deviceInfoDOList);
  345. //条件筛选
  346. if (!string.IsNullOrWhiteSpace(request.DeviceType))
  347. {
  348. deviceList = deviceList.Where(d => d.DeviceType == request.DeviceType)?.ToList() ?? new List<DeviceExtendInfoDTO>();
  349. }
  350. if (!string.IsNullOrWhiteSpace(request.DeviceModel))
  351. {
  352. deviceList = deviceList.Where(d => d.DeviceModel == request.DeviceModel)?.ToList() ?? new List<DeviceExtendInfoDTO>();
  353. }
  354. if (!string.IsNullOrWhiteSpace(request.KeyWord))
  355. {
  356. var keyword = request.KeyWord.Trim().ToLower();
  357. deviceList = deviceList.Where(d => d.Name.ToLower().Contains(keyword) || d.ShortCode.ToLower().Contains(keyword))?.ToList() ?? new List<DeviceExtendInfoDTO>();
  358. }
  359. if (request.IsOnline != null)
  360. {
  361. deviceList = deviceList.Where(d => d.IsOnline == request.IsOnline)?.ToList() ?? new List<DeviceExtendInfoDTO>();
  362. }
  363. var pagedResult = new PageCollection<DeviceExtendInfoDTO>
  364. {
  365. CurrentPage = request.PageIndex,
  366. PageSize = request.PageSize,
  367. DataCount = deviceList.Count,
  368. PageData = deviceList.Skip(request.PageSize * (request.PageIndex - 1)).Take(request.PageSize)?.ToList() ?? new List<DeviceExtendInfoDTO>()
  369. };
  370. return pagedResult;
  371. }
  372. /// <summary>
  373. /// 绑定设备
  374. /// </summary>
  375. /// <param name="request"></param>
  376. /// <returns></returns>
  377. public async Task<bool> BindDeviceAsync(BindDeviceRequest request)
  378. {
  379. //验证
  380. var userCode = await GetClientIdByTokenAsync(request.Token);
  381. //查询用户是否存在
  382. var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(userCode);
  383. if (userInfoDO == null)
  384. {
  385. ThrowCustomerException(CustomerRpcCode.UserNotExistError, "User does not exist");
  386. }
  387. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(request.ShortCode);
  388. if (deviceDb == null)
  389. {
  390. ThrowCustomerException(CustomerRpcCode.DeviceNotExist, "Not find device");
  391. }
  392. if (userInfoDO.BindDevices != null && userInfoDO.BindDevices.Contains(deviceDb.DeviceCode))
  393. {
  394. ThrowCustomerException(CustomerRpcCode.HasAddedDevice, "The device has been Added");
  395. }
  396. try
  397. {
  398. var isInvented = (string.IsNullOrWhiteSpace(deviceDb.OrganizationCode) || deviceDb.OrganizationCode == $"invented_{deviceDb.ShortCode}") ? true : false;
  399. deviceDb.Name = request.Name;
  400. deviceDb.SerialNumber = request.SerialNumber;
  401. deviceDb.Description = request.Description;
  402. if (!string.IsNullOrEmpty(request.HeadPicUrl))
  403. {
  404. deviceDb.HeadPicUrl = request.HeadPicUrl.ToUrlToken();
  405. }
  406. deviceDb.DepartmentCode = request.DepartmentCode;
  407. deviceDb.IsAutoShared = request.IsAutoShared;
  408. deviceDb.OrganizationCode = request.OrganizationCode;
  409. await _deviceInfoDBServiceProxy.UpdateDeviceInfoByCodeAsync(deviceDb.DeviceCode, deviceDb, string.Empty);
  410. if (isInvented && !string.IsNullOrWhiteSpace(request.OrganizationCode)) //虚拟机构改为正常机构
  411. {
  412. var newOrgCode = string.IsNullOrWhiteSpace(request.DepartmentCode) ? request.OrganizationCode : request.DepartmentCode;
  413. //迁移数据超声机上传检查记录
  414. await _recordsInfoDBService.UpdateRecordsWithOrgCodeAsync(new List<string>() { deviceDb.DeviceCode }, newOrgCode);
  415. //迁移数据超声机上传病人
  416. await _patientInfoDBService.UpdatePatientWithOrgCodeAsync(new List<string>() { deviceDb.DeviceCode }, newOrgCode);
  417. }
  418. if (deviceDb.IsAutoShared)
  419. {
  420. var users = new List<UserDTO>();
  421. if (!string.IsNullOrEmpty(deviceDb.DepartmentCode))
  422. {
  423. users = await _userServiceProxy.FindUserListByOrganizationCodesAsync(new List<string> { deviceDb.DepartmentCode });
  424. }
  425. else
  426. {
  427. users = await _userServiceProxy.GetUserListAsync(new GetUserListDBRequest { OrganizationQueryType = OrganizationQueryTypeEnum.All, OrganizationCode = deviceDb.OrganizationCode });
  428. }
  429. var userCodes = users.Select(f => f.UserCode).ToList();
  430. await _userServiceProxy.BingDevicesToUsersAsync(new BingDevicesToUsersRequest
  431. {
  432. DeviceCodes = new List<string> { deviceDb.DeviceCode.ToString() },
  433. UserCodes = userCodes.Select(f => f.ToString()).ToList()
  434. });
  435. }
  436. return true;
  437. }
  438. catch (Exception ex)
  439. {
  440. Logger.WriteLineError($"BindDeviceAsync error {ex}");
  441. }
  442. return false;
  443. }
  444. /// <summary>
  445. /// 修改设备
  446. /// </summary>
  447. /// <param name="request"></param>
  448. /// <returns></returns>
  449. public async Task<bool> ModifyDeviceAsync(ModifyDeviceRequest request)
  450. {
  451. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
  452. if (deviceDb == null)
  453. {
  454. ThrowCustomerException(CustomerRpcCode.DeviceNotExist, "Not find device");
  455. }
  456. if (string.IsNullOrWhiteSpace(request.Name))
  457. {
  458. ThrowCustomerException(CustomerRpcCode.DeviceNameEmpty, "Device name cannot be empty");
  459. }
  460. deviceDb.Name = request.Name;
  461. if (!string.IsNullOrWhiteSpace(request.HeadPicUrl))
  462. {
  463. deviceDb.HeadPicUrl = request.HeadPicUrl.ToUrlToken();
  464. }
  465. else
  466. {
  467. deviceDb.HeadPicUrl = string.Empty;
  468. }
  469. deviceDb.DepartmentCode = request.DepartmentCode;
  470. //修改自动分享
  471. deviceDb.IsAutoShared = request.IsAutoShared;
  472. if (deviceDb.IsAutoShared)
  473. {
  474. var users = new List<UserDTO>();
  475. if (!string.IsNullOrEmpty(deviceDb.DepartmentCode))
  476. {
  477. users = await _userServiceProxy.FindUserListByOrganizationCodesAsync(new List<string> { deviceDb.DepartmentCode });
  478. }
  479. else
  480. {
  481. users = await _userServiceProxy.GetUserListAsync(new GetUserListDBRequest { OrganizationQueryType = OrganizationQueryTypeEnum.All, OrganizationCode = deviceDb.OrganizationCode });
  482. }
  483. var userCodes = users.Select(f => f.UserCode).ToList();
  484. //先解绑,再绑定,避免绑定重复设备code
  485. var updateUsers = new List<TableDataItem<UserPasswordDTO>>();
  486. foreach (var user in users)
  487. {
  488. var userPasswordDTO = user.MappingTo<UserPasswordDTO>();
  489. user.BindDevices?.Remove(deviceDb.DeviceCode);
  490. await _userServiceProxy.UpdateUserAsync(userPasswordDTO.UserCode, userPasswordDTO, string.Empty);
  491. }
  492. await _userServiceProxy.BingDevicesToUsersAsync(new BingDevicesToUsersRequest
  493. {
  494. DeviceCodes = new List<string> { deviceDb.DeviceCode.ToString() },
  495. UserCodes = userCodes.Select(f => f.ToString()).ToList()
  496. });
  497. }
  498. return await _deviceInfoDBServiceProxy.UpdateDeviceInfoByCodeAsync(deviceDb.DeviceCode, deviceDb, string.Empty, true);
  499. }
  500. /// <summary>
  501. /// 创建字典
  502. /// </summary>
  503. /// <param name="request"></param>
  504. /// <returns></returns>
  505. public async Task<string> CreateDictionaryItemAsync(CreateDictionaryItemRequest request)
  506. {
  507. return await _deviceInfoDBServiceProxy.CreateDictionaryItemAsync(new CreateDictionaryItemDBRequest
  508. {
  509. Data = new DictionaryDTO { DictionaryType = request.DictionaryType, Value = request.DictionaryItemValue, ParentCode = request.ParentCode },
  510. ExtensionData = string.Empty
  511. });
  512. }
  513. /// <summary>
  514. /// 查找设备型号所有字典项
  515. /// </summary>
  516. /// <param name="request"></param>
  517. /// <returns></returns>
  518. public async Task<List<DictionaryDTO>> FindDeviceModelItemsAsync(FindDeviceModelItemsRequest request)
  519. {
  520. var dictionaryDOList = await _deviceInfoDBServiceProxy.FindDictionaryItemsAsync(new FindDictionaryItemsDBRequest
  521. {
  522. DictionaryType = (int)request.DictionaryType,
  523. ParentCode = request.DeviceTypeCode
  524. });
  525. return dictionaryDOList;
  526. }
  527. /// <summary>
  528. /// 查找设备类型所有字典项
  529. /// </summary>
  530. /// <param name="request"></param>
  531. /// <returns></returns>
  532. public async Task<List<DictionaryDTO>> FindDeviceTypeItemsAsync(FindDeviceTypeItemsRequest request)
  533. {
  534. var dictionaryDOList = await _deviceInfoDBServiceProxy.FindDictionaryItemsAsync(new FindDictionaryItemsDBRequest
  535. {
  536. DictionaryType = (int)request.DictionaryType
  537. });
  538. return dictionaryDOList;
  539. }
  540. /// <summary>
  541. /// 根据组织编码查询所属全部设备信息
  542. /// </summary>
  543. /// <param name="request"></param>
  544. /// <returns></returns>
  545. public async Task<List<DeviceExtendInfoDTO>> FindDevicesByOrganizationCodeAsync(FindDevicesByOrganizationCodeRequest request)
  546. {
  547. var result = new List<DeviceExtendInfoDTO>();
  548. var deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByOrganizationCodeAsync(request.OrganizationCode);
  549. if (deviceInfoDOList?.Count > 0)
  550. {
  551. //根据机构编号查询机构名称
  552. var organizationCode = deviceInfoDOList.FindAll(c => !string.IsNullOrEmpty(c.OrganizationCode)).Select(c => c.OrganizationCode).FirstOrDefault() ?? string.Empty;
  553. var organization = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = organizationCode });
  554. var organizationName = organization?.OrganizationName ?? string.Empty;
  555. //根据机构编号查询科室名称
  556. var organizationFilter = new Dictionary<string, string>();
  557. organizationFilter.Add("RootCode", organizationCode);
  558. var organizations = await _organizationDBService.GetOrganizationPageAsync((new PageFilterRequest { CurrentPage = 1, PageSize = 999999, Filter = organizationFilter, IsFuzzy = false }));
  559. var deviceCodes = deviceInfoDOList.Select(x => x.DeviceCode).ToList();
  560. var deviceTokens = await _authenticationService.GetTokenWithClientIdsAsync(new GetTokenWithClientIdsRequest { ClientIds = deviceCodes });
  561. var deviceTypeList = await _deviceInfoDBServiceProxy.FindDictionaryItemsAsync(new FindDictionaryItemsDBRequest { DictionaryType = (int)DictionaryTypeEnum.DeviceType });
  562. foreach (var c in deviceInfoDOList)
  563. {
  564. var deviceTypeModel = deviceTypeList.FirstOrDefault(t => t.DictionaryCode == c.DeviceType);
  565. result.Add(new DeviceExtendInfoDTO
  566. {
  567. DepartmentName = organizations.PageData.FirstOrDefault(o => o.OrganizationCode == c.DepartmentCode)?.OrganizationName,
  568. OrganizationName = organizationName,
  569. IsOnline = deviceTokens.FirstOrDefault(x => x.ClientId == c.DeviceCode)?.IsOnline ?? false,
  570. DeviceCode = c.DeviceCode,
  571. SerialNumber = c.SerialNumber,
  572. Name = c.Name,
  573. Description = c.Description,
  574. DeviceModel = c.DeviceModel,
  575. DeviceType = c.DeviceType,
  576. HeadPicUrl = c.HeadPicUrl,
  577. DeviceSoftwareVersion = c.DeviceSoftwareVersion,
  578. SDKSoftwareVersion = c.SDKSoftwareVersion,
  579. OrganizationCode = c.OrganizationCode,
  580. DepartmentCode = c.DepartmentCode,
  581. ShortCode = c.ShortCode,
  582. LanguageConfigs = deviceTypeModel?.LanguageConfigs
  583. });
  584. }
  585. }
  586. return result;
  587. }
  588. public Task<DeviceInfoDTO> CreateDeviceInfoAsync(CreateDeviceRequest request)
  589. {
  590. throw new NotImplementedException();
  591. }
  592. public async Task<List<SelectItemDTO>> GetPersonDeviceDropdownListAsync(TokenRequest request)
  593. {
  594. //验证
  595. var userCode = await GetClientIdByTokenAsync(request.Token);
  596. //查询用户是否存在
  597. var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(userCode);
  598. if (userInfoDO == null)
  599. {
  600. ThrowCustomerException(CustomerRpcCode.UserNotExistError, "User does not exist");
  601. }
  602. var result = new List<SelectItemDTO>();
  603. //查询用户的医院是否存在
  604. if (string.IsNullOrEmpty(userInfoDO.OrganizationCode))
  605. {
  606. ThrowCustomerException(CustomerRpcCode.OrganizationNotExist, "Org does not exist");
  607. }
  608. var deviceInfoDOList = new List<DeviceInfoDTO>();
  609. if (userInfoDO.IsDirector)
  610. {
  611. deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByOrganizationCodeAsync(userInfoDO.RootOrganizationCode);
  612. }
  613. else if (!userInfoDO.RoleCodes.Contains("Role_ExpertAssistant"))
  614. {
  615. //查询用户绑定的设备
  616. if (userInfoDO.BindDevices == null || userInfoDO.BindDevices.Count <= 0)
  617. {
  618. return result;
  619. }
  620. //根据用户名下的设备id查询所有的设备信息
  621. deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByCodeListAsync(userInfoDO.BindDevices);
  622. }
  623. else
  624. {
  625. var experts = await _userServiceProxy.GetBindExpertsAsync(userCode);
  626. if (experts.Any())
  627. {
  628. var bindDeviceCodes = experts.SelectMany(x => x.BindDevices ?? new List<string>()).Distinct().ToList();
  629. if (bindDeviceCodes.Any())
  630. {
  631. deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByCodeListAsync(bindDeviceCodes);
  632. }
  633. }
  634. else
  635. {
  636. deviceInfoDOList = await _deviceInfoDBServiceProxy.FindDeviceInfoListByOrganizationCodeAsync(userInfoDO.RootOrganizationCode);
  637. }
  638. }
  639. if (deviceInfoDOList?.Count > 0)
  640. {
  641. result = deviceInfoDOList.Select(c => new SelectItemDTO()
  642. {
  643. Key = c.DeviceCode,
  644. Value = c.Name
  645. }).ToList();
  646. }
  647. return result;
  648. }
  649. /// <summary>
  650. /// 设备端调用,查询获取服务器配置信息接口
  651. /// </summary>
  652. /// <param name="request">Token验证</param>
  653. /// <returns>服务器配置信息结果:key:字段,value:数据值,复杂类型可为json</returns>
  654. public async Task<DeviceServerSettingResult> QueryServerConfigAsync(TokenRequest request)
  655. {
  656. var deviceCode = await GetClientIdByTokenAsync(request.Token);
  657. var deviceInfo = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
  658. if (deviceInfo == null || string.IsNullOrWhiteSpace(deviceInfo.DeviceCode))
  659. {
  660. ThrowCustomerException(CustomerRpcCode.NoExistDevice, "Device does not exist");
  661. }
  662. var org = new OrganizationDTO();
  663. if (!string.IsNullOrWhiteSpace(deviceInfo.OrganizationCode))
  664. {
  665. org = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = deviceInfo.OrganizationCode });
  666. if (org == null)
  667. {
  668. org = new OrganizationDTO();
  669. }
  670. }
  671. var dictionary = new Dictionary<string, string>();
  672. //定义配置字段 并扩充字段,返回数据可持续更新接口文档,如果数据是复杂类型可以转成json
  673. //TODO 配置信息: 直播配置、存储配置、
  674. //存储上传图像或者视频是 是否本地上传缩略图
  675. var isUploadThumbnail = ConfigurationManager.RemedicalSettings.IsUploadThumbnail;
  676. dictionary.Add("IsUploadThumbnail", isUploadThumbnail.ToString());
  677. dictionary.Add("PatientType", org.PatientType.ToString());
  678. dictionary.Add("HeartRateSeconds", _heartRateSeconds.ToString());
  679. dictionary.Add("NotificationUrl", _webSocketUrl);
  680. dictionary.Add("MergedChannel", deviceInfo.MergedChannel.ToString());
  681. dictionary.Add("LiveConsultationRateSeconds", _liveConsultationRateSeconds.ToString());
  682. var result = new DeviceServerSettingResult()
  683. {
  684. ServerConfigList = dictionary,
  685. IsUploadThumbnail = isUploadThumbnail,
  686. PatientType = org.PatientType,
  687. HeartRateSeconds = _heartRateSeconds,
  688. NotificationUrl = _webSocketUrl,
  689. LiveConsultationRateSeconds = _liveConsultationRateSeconds,
  690. MergedChannel = deviceInfo.MergedChannel,
  691. MergedVideoOutputWidth = deviceInfo.MergedVideoOutputWidth,
  692. MergedVideoOutputHeight = deviceInfo.MergedVideoOutputHeight,
  693. IsSelfRtcService = _isRTCSelf,
  694. RemoteControlAskTimeoutSec = _remoteControlAskTimeoutSec
  695. };
  696. return result;
  697. }
  698. /// <summary>
  699. /// 添加或迁移设备到医院请求
  700. /// </summary>
  701. /// <param name="request"></param>
  702. /// <returns></returns>
  703. public async Task<bool> AddDeviceToOrgAsync(AddDeviceToOrgRequest request)
  704. {
  705. var shortCode = request.UniqueCode;
  706. #region Params Check
  707. var userCode = await GetClientIdByTokenAsync(request.Token);
  708. if (string.IsNullOrEmpty(shortCode))
  709. {
  710. ThrowCustomerException(CustomerRpcCode.UniqueCodeIsEmpty, "UniqueCode is empty");
  711. }
  712. var device = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(shortCode);
  713. if (device == null)
  714. {
  715. ThrowCustomerException(CustomerRpcCode.NoExistDevice, "Device does not exist");
  716. }
  717. var oldOrg = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = device.OrganizationCode });
  718. if (oldOrg == null || string.IsNullOrWhiteSpace(oldOrg.OrganizationCode))
  719. {
  720. ThrowCustomerException(CustomerRpcCode.OrganizationNotExist, "Org does not exist");
  721. }
  722. //用户
  723. var userDTO = await _userServiceProxy.FindUserByCodeAsync(userCode);
  724. if (userDTO == null)
  725. {
  726. ThrowCustomerException(CustomerRpcCode.UserNotExistError, "User does not exist");
  727. }
  728. if (!userDTO.IsDirector)
  729. {
  730. ThrowCustomerException(CustomerRpcCode.NotOrgAdmin, "not org admin");
  731. }
  732. var org = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = userDTO.OrganizationCode });
  733. if (org == null || string.IsNullOrWhiteSpace(org.OrganizationCode))
  734. {
  735. ThrowCustomerException(CustomerRpcCode.OrganizationNotExist, "Org does not exist");
  736. }
  737. #endregion
  738. try
  739. {
  740. var newOrgode = org.OrganizationCode;
  741. //设备更新医院
  742. if (!string.IsNullOrEmpty(device.DepartmentCode))
  743. {
  744. device.DepartmentCode = "";
  745. }
  746. if (!string.IsNullOrEmpty(device.Name))
  747. {
  748. device.Name = "";
  749. }
  750. device.HeadPicUrl = "";
  751. device.Description = "";
  752. device.IsAutoShared = false;
  753. device.OrganizationCode = newOrgode;
  754. bool success = await _deviceInfoDBServiceProxy.UpdateDeviceInfoByCodeAsync(device.DeviceCode, device, string.Empty, true);
  755. if (success)
  756. {
  757. // 删除已知绑定的用户
  758. var users = await _userServiceProxy.GetUsersByDeviceAsync(device.DeviceCode);
  759. var updateUsers = new List<TableDataItem<UserPasswordDTO>>();
  760. foreach (var user in users)
  761. {
  762. user.BindDevices.Remove(device.DeviceCode);
  763. updateUsers.Add(new TableDataItem<UserPasswordDTO>()
  764. {
  765. Data = user.MappingTo<UserPasswordDTO>(),
  766. });
  767. }
  768. if (updateUsers.Count > 0)
  769. {
  770. var updateUsersDBRequest = new UpdateUsersDBRequest() { Users = updateUsers };
  771. await _userServiceProxy.UpdateUsersAsync(updateUsersDBRequest);
  772. }
  773. if (oldOrg.Isinvented) // 虚拟医院
  774. {
  775. //迁移数据超声机上传检查记录
  776. await _recordsInfoDBService.UpdateRecordsWithOrgCodeAsync(new List<string>() { device.DeviceCode }, newOrgode);
  777. //迁移数据超声机上传病人
  778. await _patientInfoDBService.UpdatePatientWithOrgCodeAsync(new List<string>() { device.DeviceCode }, newOrgode);
  779. }
  780. }
  781. return success;
  782. }
  783. catch (System.Exception ex)
  784. {
  785. Logger.WriteLineError($"AddDeviceToOrgAsync error {ex}");
  786. }
  787. return false;
  788. }
  789. /// <summary>
  790. /// 补齐设备扩展信息
  791. /// </summary>
  792. /// <param name="deviceInfoDOList"></param>
  793. /// <returns></returns>
  794. private async Task<List<DeviceExtendInfoDTO>> MapToExtendDTO(List<DeviceInfoDTO> deviceInfoDOList)
  795. {
  796. var deviceList = new List<DeviceExtendInfoDTO>();
  797. if (deviceInfoDOList != null && deviceInfoDOList.Any())
  798. {
  799. //查询机构
  800. var orgCodes = deviceInfoDOList.Select(x => x.OrganizationCode).ToList();
  801. orgCodes.AddRange(deviceInfoDOList.Select(x => x.DepartmentCode));
  802. var organizations = await _organizationDBService.FindOrganizationListByCodesAsync(orgCodes.Distinct().ToList());
  803. //查询机构负责人
  804. var organizationDirectorCodes = new List<string>();
  805. foreach (var org in organizations)
  806. {
  807. if (org.Directors != null && org.Directors.Any())
  808. {
  809. organizationDirectorCodes.AddRange(org.Directors);
  810. }
  811. }
  812. var organizationDirectors = await _userServiceProxy.FindUserListByUserCodesAsync(organizationDirectorCodes);
  813. var deviceCodes = deviceInfoDOList.Select(x => x.DeviceCode).ToList();
  814. var deviceTokens = await _authenticationService.GetTokenWithClientIdsAsync(new GetTokenWithClientIdsRequest { ClientIds = deviceCodes });
  815. var deviceTypeList = await _deviceInfoDBServiceProxy.FindDictionaryItemsAsync(new FindDictionaryItemsDBRequest { DictionaryType = (int)DictionaryTypeEnum.DeviceType });
  816. foreach (var dto in deviceInfoDOList)
  817. {
  818. var device = dto.MappingTo<DeviceExtendInfoDTO>();
  819. device.IsOnline = deviceTokens.FirstOrDefault(x => x.ClientId == dto.DeviceCode)?.IsOnline ?? false;
  820. device.DepartmentName = organizations.FirstOrDefault(x => x.OrganizationCode == dto.DepartmentCode)?.OrganizationName;
  821. device.LanguageConfigs = deviceTypeList.FirstOrDefault(t => t.DictionaryCode == device.DeviceType)?.LanguageConfigs;
  822. var organization = organizations.FirstOrDefault(x => x.OrganizationCode == dto.OrganizationCode);
  823. if (organization != null)
  824. {
  825. device.OrganizationName = organization.OrganizationName;
  826. if (organization.Directors != null && organization.Directors.Any())
  827. {
  828. var director = organizationDirectors.FirstOrDefault(x => x.UserCode == organization.Directors.FirstOrDefault());
  829. device.OrganizationDirectorCode = director?.UserCode;
  830. device.OrganizationDirectorUserName = director?.UserName;
  831. device.OrganizationDirectorFullName = director?.FullName;
  832. }
  833. }
  834. deviceList.Add(device);
  835. }
  836. }
  837. return deviceList;
  838. }
  839. /// <summary>
  840. /// 补齐设备扩展信息
  841. /// </summary>
  842. /// <param name="deviceInfoDOList"></param>
  843. /// <returns></returns>
  844. private async Task<DeviceExtendInfoDTO> MapToExtendDTO(DeviceInfoDTO deviceInfoDO)
  845. {
  846. var deviceList = await MapToExtendDTO(new List<DeviceInfoDTO> { deviceInfoDO });
  847. return deviceList.FirstOrDefault();
  848. }
  849. /// <summary>
  850. /// 获取设备绑定用户codes
  851. /// </summary>
  852. /// <param name="request">获取设备绑定用户codes请求实体</param>
  853. /// <returns>test01,test02</returns>
  854. public async Task<List<string>> GetDeviceBindUsersCodesAsync(GetDeviceRequest request)
  855. {
  856. //检查设备编码不为空
  857. if (string.IsNullOrWhiteSpace(request.DeviceCode))
  858. {
  859. ThrowCustomerException(CustomerRpcCode.DeviceCodeIsEmpty, "Required parameter:DeviceCode cannot be empty");
  860. }
  861. //查询设备对象
  862. var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
  863. if (deviceDb == null)
  864. {
  865. ThrowCustomerException(CustomerRpcCode.NoExistDevice, "Device does not exist");
  866. }
  867. var userListResult = await _userServiceProxy.GetUsersByDeviceAsync(request.DeviceCode);
  868. if (userListResult != null && userListResult.Count > 0)
  869. {
  870. return userListResult.Select(u => u.UserCode).ToList();
  871. }
  872. return new List<string>();
  873. }
  874. /// <summary>
  875. /// 查询设备AI应用的状态
  876. /// </summary>
  877. /// <param name="request">请求参数</param>
  878. /// <returns>AI应用集合</returns>
  879. public async Task<List<DiagnosisModuleDTO>> FindDeviceDiagnosisModulesAsync(FindDeviceDiagnosisModulesRequest request)
  880. {
  881. //检查设备编码不为空
  882. if (string.IsNullOrWhiteSpace(request.DeviceCode))
  883. {
  884. ThrowCustomerException(CustomerRpcCode.DeviceCodeIsEmpty, "Required parameter:DeviceCode cannot be empty");
  885. }
  886. return await _diagnosisModuleService.GetDeviceDiagnosisModulesAsync(new GetDeviceDiagnosisModulesDBRequest { DeviceCode = request.DeviceCode });
  887. }
  888. /// <summary>
  889. /// 修改设备AI应用启用状态
  890. /// </summary>
  891. /// <param name="request">修改设备AI应用启用状态请求实体</param>
  892. /// <returns>是否成功</returns>
  893. /// <para>DeviceErrorCodeEnum</para>
  894. public async Task<bool> ModifyDeviceDiagnosisModuleStateAsync(ModifyDeviceDiagnosisModuleStateRequest request)
  895. {
  896. //检查设备编码不为空
  897. if (string.IsNullOrWhiteSpace(request.DeviceCode))
  898. {
  899. ThrowCustomerException(CustomerRpcCode.DeviceCodeIsEmpty, "Required parameter:DeviceCode cannot be empty");
  900. }
  901. if (string.IsNullOrWhiteSpace(request.DiagnosisModule))
  902. {
  903. ThrowCustomerException(CustomerRpcCode.DeviceAIDiagnosisModule, "Required parameter:DeviceCode cannot be empty");
  904. }
  905. var result = await _diagnosisModuleService.UpdateDeviceDiagnosisModuleStateAsync(new UpdateDeviceDiagnosisModuleStateDBRequest
  906. {
  907. DeviceCode = request.DeviceCode,
  908. DiagnosisModule = request.DiagnosisModule,
  909. Enabled = request.Enabled
  910. });
  911. CacheMaintenance.Instance.Get<IDeviceInfosManager>().Remove(request.DeviceCode);
  912. return result;
  913. }
  914. /// <summary>
  915. /// 设备离开会诊房间
  916. /// </summary>
  917. /// <param name="request">设备离开会诊房间请求实体</param>
  918. /// <returns></returns>
  919. public async Task<DeviceLeaveLiveConsultationResult> DeviceLeaveLiveConsultationAsync(DeviceLeaveLiveConsultationRequest request)
  920. {
  921. var deviceCode = await GetClientIdByTokenAsync(request.Token);
  922. var result = new DeviceLeaveLiveConsultationResult
  923. {
  924. Success = false,
  925. };
  926. return result;
  927. }
  928. /// <summary>
  929. /// 通用异常处理方法
  930. /// </summary>
  931. /// <param name="customerRpcCodeEnum">异常标识码</param>
  932. /// <param name="msg">异常信息</param>
  933. /// <param name="internalMessage">内部异常信息,非必填</param>
  934. private void ThrowCustomerException(CustomerRpcCode customerRpcCodeEnum, string msg, string internalMessage = null)
  935. {
  936. ThrowRpcException((int)customerRpcCodeEnum, msg, internalMessage);
  937. }
  938. /// <summary>
  939. /// 上报设备画面尺寸相关信息
  940. /// </summary>
  941. /// <param name="request"></param>
  942. /// <docFirstDirectory>设备端API</docFirstDirectory>
  943. /// <docSecondDirectory>实时会诊服务接口</docSecondDirectory>
  944. /// <docThirdDirectory>会诊</docThirdDirectory>
  945. /// <returns></returns>
  946. public async Task<ReportVideoDeviceInfoResult> ReportVideoDeviceInfoAsync(ReportVideoDeviceInfoRequest request)
  947. {
  948. var result = new ReportVideoDeviceInfoResult();
  949. if (request.VideoDeviceInfos == null || request.VideoDeviceInfos.Count == 0)
  950. {
  951. //视屏设备画面信息为空
  952. ThrowCustomerException(CustomerRpcCode.VideoDeviceInfosEmpty, "VideoDeviceInfosEmpty");
  953. }
  954. if (request.VideoDeviceInfos.Any(x => string.IsNullOrWhiteSpace(x.VideoDeviceId)))
  955. {
  956. //视屏设备ID为空
  957. ThrowCustomerException(CustomerRpcCode.VideoDeviceIdEmpty, "VideoDeviceIdEmpty");
  958. }
  959. var videoDeviceIdCount = request.VideoDeviceInfos.Select(x => x.VideoDeviceId).Distinct().Count();
  960. if (videoDeviceIdCount < request.VideoDeviceInfos.Count)
  961. {
  962. //视屏设备ID重复
  963. ThrowCustomerException(CustomerRpcCode.VideoDeviceIdRepeatError, "VideoDeviceIdRepeatError");
  964. }
  965. var deviceCode = await GetClientIdByTokenAsync(request.Token);
  966. var deviceDTO = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
  967. var videoDeviceInfos = new List<VideoDeviceDTO>();
  968. foreach (var video in request.VideoDeviceInfos)
  969. {
  970. var videoDeviceInfo = new VideoDeviceDTO
  971. {
  972. VideoDeviceId = video.VideoDeviceId,
  973. VideoDeviceSourceType = video.VideoDeviceSourceType,
  974. Width = video.Width,
  975. Height = video.Height,
  976. OutputWidth = video.Width,
  977. OutputHeight = video.Height
  978. };
  979. if (deviceDTO.VideoDeviceInfos != null && deviceDTO.VideoDeviceInfos.Any(x => x.VideoDeviceId == video.VideoDeviceId))
  980. {
  981. var oldVideo = deviceDTO.VideoDeviceInfos.FirstOrDefault(x => x.VideoDeviceId == video.VideoDeviceId);
  982. videoDeviceInfo.OutputWidth = oldVideo.OutputWidth;
  983. videoDeviceInfo.OutputHeight = oldVideo.OutputHeight;
  984. videoDeviceInfo.VideoFps = oldVideo.VideoFps;
  985. videoDeviceInfo.VideoBitrate = oldVideo.VideoBitrate;
  986. videoDeviceInfo.MinVideoBitrate = oldVideo.MinVideoBitrate;
  987. }
  988. videoDeviceInfos.Add(videoDeviceInfo);
  989. }
  990. deviceDTO.VideoDeviceInfos = videoDeviceInfos;
  991. var updateVideoDeviceInfosDBRequest = new UpdateVideoDeviceInfosDBRequest
  992. {
  993. DeviceCode = deviceDTO.DeviceCode,
  994. LiveOpened = request.LiveOpened,
  995. VideoDeviceInfos = videoDeviceInfos
  996. };
  997. await _deviceInfoDBServiceProxy.UpdateVideoDeviceInfosAsync(updateVideoDeviceInfosDBRequest);
  998. CacheMaintenance.Instance.Get<IDeviceInfosManager>().Remove(deviceDTO.DeviceCode);
  999. result.Success = true;
  1000. return result;
  1001. }
  1002. /// <summary>
  1003. /// 查找有效设备总数量
  1004. /// </summary>
  1005. /// <returns></returns>
  1006. public async Task<long> GetActiveDeviceCount()
  1007. {
  1008. return await _deviceInfoDBServiceProxy.GetActiveDeviceCount();
  1009. }
  1010. /// <summary>
  1011. /// 设备发送调参初始化数据
  1012. /// </summary>
  1013. /// <param name="request">调参数据请求</param>
  1014. /// <returns></returns>
  1015. public async Task<bool> SendControlParameterByDeviceAsync(SendControlParameterByDeviceRequest request)
  1016. {
  1017. var deviceCode = await GetClientIdByTokenAsync(request.Token);
  1018. var userCode = request.ControlUserCode;
  1019. //发送控制人通知
  1020. if (string.IsNullOrWhiteSpace(userCode))
  1021. {
  1022. ThrowCustomerException(CustomerRpcCode.UsercodeIsEmpty, "User code is empty");
  1023. }
  1024. var userDTO = await _userServiceProxy.FindUserByCodeAsync(userCode);
  1025. if (userDTO == null)
  1026. {
  1027. ThrowCustomerException(CustomerRpcCode.UserNotExistError, "User does not exist");
  1028. }
  1029. var notify = new DeviceParametersNotification()
  1030. {
  1031. DeviceCode = deviceCode,
  1032. ProbeApplication = request.ProbeApplication,
  1033. Parameter = request.Parameter,
  1034. IsResponse = true
  1035. };
  1036. var notificationRequest = new SendNotificationRequest()
  1037. {
  1038. ClientId = userCode,
  1039. Message = notify,
  1040. JsonMessage = Newtonsoft.Json.JsonConvert.SerializeObject(notify),
  1041. NotificationType = notify.NotificationType,
  1042. TransactionType = TransactionTypeEnum.ControlParameter,
  1043. RelevanceCode = userCode,
  1044. ReceiverType = ApplicantTypeEnum.Client
  1045. };
  1046. await _notificationService.PostMessageAsync(notificationRequest);
  1047. return true;
  1048. }
  1049. /// <summary>
  1050. /// 用户进入设备直播房间
  1051. /// </summary>
  1052. /// <param name="request">用户进入设备直播房间请求实体</param>
  1053. /// <returns></returns>
  1054. public async Task<JoinDeviceLiveRoomResult> JoinDeviceLiveRoomAsync(JoinDeviceLiveRoomRequest request)
  1055. {
  1056. var userInfo = await _authenticationService.GetTokenAsync(request);
  1057. var deviceCode = request.DeviceCode;
  1058. var liveRooms = await _rtcService.GetLiveRoomsByDeviceCodeAsync(new GetLiveRoomsByDeviceCodeRequest
  1059. {
  1060. DeviceCode = deviceCode
  1061. });
  1062. var liveRoom = liveRooms?.FirstOrDefault(x => x.Status == LiveRoomStatus.Initiating);
  1063. LiveMemberDTO deviceMemberInfo;
  1064. if (liveRoom != null)
  1065. {
  1066. //设备正在推流
  1067. deviceMemberInfo = liveRoom.Members.FirstOrDefault(x => x.Code == deviceCode);
  1068. if (deviceMemberInfo?.Status == LiveMemberStatus.Joined)
  1069. {
  1070. return new JoinDeviceLiveRoomResult
  1071. {
  1072. RoomNo = liveRoom.RoomNo,
  1073. RtmpUrl = deviceMemberInfo.LiveData.RtmpPullUrl,
  1074. };
  1075. }
  1076. }
  1077. //新增或更新设备直播间 TODO
  1078. var rtcRoomResult = await _rtcService.GetRoomIdAsync(new GetRoomIdRequest
  1079. {
  1080. UniqueId = deviceCode,
  1081. });
  1082. var rtcRoomId = (int)rtcRoomResult.RoomId;
  1083. var initiateResult = await _rtcService.InitiateLiveAsync(new InitiateLiveRequest
  1084. {
  1085. RoomId = deviceCode,
  1086. InitiatorCode = deviceCode,
  1087. IntegerRoomId = rtcRoomId
  1088. });
  1089. //添加观众
  1090. var addOrUpdateViewerResult = await _rtcService.SaveViewerAsync(new SaveViewerRequest
  1091. {
  1092. LiveRoomCode = initiateResult.RoomId,
  1093. UserCode = userInfo.ClientId,
  1094. UserName = userInfo.AccountName,
  1095. });
  1096. //通知设备推流
  1097. deviceMemberInfo = initiateResult.Members.FirstOrDefault(x => x.Code == deviceCode);
  1098. var message = new StartLiveToDeviceNotification
  1099. {
  1100. LiveRoomCode = initiateResult.RoomId,
  1101. RoomNo = initiateResult.RoomNo,
  1102. AppId = _sdkAppId,
  1103. // MergedChannel = deviceMemberInfo.MergedChannel,
  1104. // MergedVideoOutputWidth = deviceMemberInfo.MergedVideoOutputWidth,
  1105. // MergedVideoOutputHeight = deviceMemberInfo.MergedVideoOutputHeight,
  1106. // VideoDeviceOutputList = deviceMemberInfo.VideoDeviceInfos.ToList(),
  1107. };
  1108. await BroadcastNotificationAsync(liveRoom.RoomId, new List<string> { deviceCode }, message);
  1109. return new JoinDeviceLiveRoomResult
  1110. {
  1111. RoomNo = initiateResult.RoomNo,
  1112. RtmpUrl = deviceMemberInfo.LiveData.RtmpPullUrl,
  1113. ReportStateIntervalSeconds = _reportStateIntervalSeconds,
  1114. };
  1115. }
  1116. /// <summary>
  1117. /// 用户离开设备直播房间
  1118. /// </summary>
  1119. /// <param name="request">用户离开设备直播房间请求实体</param>
  1120. /// <returns></returns>
  1121. public async Task<bool> LeaveDeviceLiveRoomAsync(LeaveDeviceLiveRoomRequest request)
  1122. {
  1123. var userInfo = await _authenticationService.GetTokenAsync(request);
  1124. var userCode = userInfo.ClientId;
  1125. var rtcRoomId = request.RoomNo;
  1126. var liveRooms = await _rtcService.GetLiveRoomsByRtcRoomIdAsync(new GetLiveRoomsByRtcRoomIdRequest
  1127. {
  1128. RtcRoomId = rtcRoomId
  1129. });
  1130. var liveRoom = liveRooms?.FirstOrDefault(x => x.Status == LiveRoomStatus.Initiating);
  1131. if (liveRoom != null)
  1132. {
  1133. var deviceCode = liveRoom.DeviceInfos?.FirstOrDefault()?.Code;
  1134. //移除观众
  1135. var removeViewerResult = await _rtcService.RemoveViewerAsync(new RemoveViewerRequest
  1136. {
  1137. LiveRoomCode = liveRoom.RoomId,
  1138. UserCode = userInfo.ClientId,
  1139. });
  1140. var expireTime = DateTime.UtcNow.AddSeconds(_reportStateTimeout * -1);
  1141. if (!liveRoom.ViewerInfos.Any(x => x.UserCode != userCode && x.LastReportTime >= expireTime) && !string.IsNullOrWhiteSpace(deviceCode))
  1142. {
  1143. //关闭直播 to device
  1144. var message = new CloseLiveToDeviceNotification
  1145. {
  1146. LiveRoomCode = liveRoom.RoomId,
  1147. };
  1148. await BroadcastNotificationAsync(liveRoom.RoomId, new List<string> { deviceCode }, message);
  1149. }
  1150. }
  1151. return true;
  1152. }
  1153. /// <summary>
  1154. /// 上报观看直播状态
  1155. /// </summary>
  1156. /// <param name="request">上报观看直播状态请求实体</param>
  1157. /// <returns></returns>
  1158. public async Task<bool> ReportLiveViewStateAsync(ReportLiveViewStateRequest request)
  1159. {
  1160. var userInfo = await _authenticationService.GetTokenAsync(request);
  1161. var rtcRoomId = request.RoomNo;
  1162. var liveRooms = await _rtcService.GetLiveRoomsByRtcRoomIdAsync(new GetLiveRoomsByRtcRoomIdRequest
  1163. {
  1164. RtcRoomId = rtcRoomId
  1165. });
  1166. var liveRoom = liveRooms?.FirstOrDefault(x => x.Status == LiveRoomStatus.Initiating);
  1167. if (liveRoom != null)
  1168. {
  1169. //添加观众
  1170. var addOrUpdateViewerResult = await _rtcService.SaveViewerAsync(new SaveViewerRequest
  1171. {
  1172. LiveRoomCode = liveRoom.RoomId,
  1173. UserCode = userInfo.ClientId,
  1174. UserName = userInfo.AccountName,
  1175. });
  1176. }
  1177. return true;
  1178. }
  1179. /// <summary>
  1180. /// 上报直播状态
  1181. /// </summary>
  1182. /// <param name="request">上报直播状态请求实体</param>
  1183. /// <returns></returns>
  1184. public async Task<bool> ReportLiveStateAsync(ReportLiveStateRequest request)
  1185. {
  1186. var tokenInfo = await _authenticationService.GetTokenAsync(request);
  1187. var deviceCode = tokenInfo.ClientId;
  1188. switch (request.LiveState)
  1189. {
  1190. case DeviceLiveStateEnum.Error:
  1191. case DeviceLiveStateEnum.Warning:
  1192. Logger.WriteLineWarn($"DeviceService ReportLiveStateAsync, [{tokenInfo.AccountType.ToString()}]{tokenInfo.AccountName}, state:{request.LiveState.ToString()}, message:{request.Message}");
  1193. break;
  1194. default:
  1195. Logger.WriteLineInfo($"DeviceService ReportLiveStateAsync, [{tokenInfo.AccountType.ToString()}]{tokenInfo.AccountName}, state:{request.LiveState.ToString()}, message:{request.Message}");
  1196. break;
  1197. }
  1198. if (request.LiveState == DeviceLiveStateEnum.Pushing || request.LiveState == DeviceLiveStateEnum.Closed)
  1199. {
  1200. var rtcRoomId = request.RoomNo;
  1201. var liveRooms = await _rtcService.GetLiveRoomsByRtcRoomIdAsync(new GetLiveRoomsByRtcRoomIdRequest
  1202. {
  1203. RtcRoomId = rtcRoomId
  1204. });
  1205. var liveRoom = liveRooms?.FirstOrDefault(x => x.Status == LiveRoomStatus.Initiating);
  1206. if (liveRoom != null)
  1207. {
  1208. var expireTime = DateTime.UtcNow.AddSeconds(_reportStateTimeout * -1);
  1209. var validViewers = liveRoom.ViewerInfos.Where(x => x.LastReportTime >= expireTime)?.ToList() ?? new List<LiveViewerDTO>();
  1210. if (request.LiveState == DeviceLiveStateEnum.Closed && validViewers.Any())
  1211. {
  1212. //关闭直播 to users
  1213. var message = new DeviceLiveFinishedNotification
  1214. {
  1215. LiveRoomCode = liveRoom.RoomId,
  1216. };
  1217. await BroadcastNotificationAsync(liveRoom.RoomId, validViewers.Select(x => x.UserCode).ToList(), message);
  1218. }
  1219. if (request.LiveState == DeviceLiveStateEnum.Pushing && !validViewers.Any())
  1220. {
  1221. //关闭直播 to device
  1222. var message = new CloseLiveToDeviceNotification
  1223. {
  1224. LiveRoomCode = liveRoom.RoomId,
  1225. };
  1226. await BroadcastNotificationAsync(liveRoom.RoomId, new List<string> { deviceCode }, message);
  1227. }
  1228. }
  1229. }
  1230. return await Task.FromResult(true);
  1231. }
  1232. /// <summary>
  1233. /// 获取实时音视频参数
  1234. /// </summary>
  1235. /// <param name="request">获取实时音视频参数请求实体</param>
  1236. /// <returns></returns>
  1237. public async Task<CreateLiveRoomInfoResult> CreateLiveRoomInfoAsync(CreateLiveRoomInfoRequest request)
  1238. {
  1239. Logger.WriteLineInfo($"DeviceService CreateLiveRoomInfoAsync, DeviceUniqueCode:{request.DeviceUniqueCode}, DeviceType:{request.DeviceType}, DeviceModel:{request.DeviceModel}, SoftwareVersion:{request.SoftwareVersion}");
  1240. var userCode = Guid.NewGuid().ToString("N");
  1241. var getUserSignRequest = new GetUserSignRequest
  1242. {
  1243. UserId = userCode,
  1244. };
  1245. var getUserSignResult = await _rtcService.GetUserSignAsync(getUserSignRequest);
  1246. var userSign = getUserSignResult.UserSign;
  1247. var getRoomIdRequest = new GetRoomIdRequest
  1248. {
  1249. UniqueId = userCode,
  1250. };
  1251. var getRoomIdResult = await _rtcService.GetRoomIdAsync(getRoomIdRequest);
  1252. var intRoomNo = (int)getRoomIdResult.RoomId;
  1253. Logger.WriteLineInfo($"DeviceService CreateLiveRoomInfoAsync, DeviceUniqueCode:{request.DeviceUniqueCode}, UserCode:{userCode}, roomNo:{intRoomNo}");
  1254. return new CreateLiveRoomInfoResult
  1255. {
  1256. IsTrtc = !_isRTCSelf,
  1257. UserCode = userCode,
  1258. UserSign = userSign,
  1259. AppId = _sdkAppId,
  1260. RoomNo = intRoomNo,
  1261. };
  1262. }
  1263. private async Task<bool> BroadcastNotificationAsync(string roomId, IList<string> clientIds, NotificationDTO message)
  1264. {
  1265. var broadcastNotificationRequest = new BroadcastRoomNotificationRequest
  1266. {
  1267. RoomId = roomId,
  1268. ClientIds = clientIds,
  1269. Message = message,
  1270. TransactionType = TransactionTypeEnum.Live,
  1271. RelevanceCode = roomId,
  1272. ReceiverType = ApplicantTypeEnum.Client,
  1273. WSConnectType = WSConnectTypeEnum.Default
  1274. };
  1275. return await _rtcService.BroadcastRoomNotificationAsync(broadcastNotificationRequest);
  1276. }
  1277. /// <summary>
  1278. /// 拒绝远程控制
  1279. /// </summary>
  1280. /// <param name="request"></param>
  1281. /// <returns></returns>
  1282. public async Task<bool> RejectRemoteControl(RemoteControlRequest request)
  1283. {
  1284. string deviceCode = await GetClientIdByTokenAsync(request.Token);
  1285. string userCode = request.ControlUserCode;
  1286. //发送控制人通知
  1287. if (string.IsNullOrWhiteSpace(userCode))
  1288. {
  1289. ThrowCustomerException(CustomerRpcCode.UsercodeIsEmpty, "User code is empty");
  1290. }
  1291. var userDTO = await _userServiceProxy.FindUserByCodeAsync(userCode);
  1292. if (userDTO == null)
  1293. {
  1294. ThrowCustomerException(CustomerRpcCode.UserNotExistError, "User does not exist");
  1295. }
  1296. var notify = new DeviceRejectRemoteControlNotification()
  1297. {
  1298. DeviceCode = deviceCode,
  1299. };
  1300. var notificationRequest = new SendNotificationRequest()
  1301. {
  1302. ClientId = userCode,
  1303. Message = notify,
  1304. JsonMessage = Newtonsoft.Json.JsonConvert.SerializeObject(notify),
  1305. NotificationType = notify.NotificationType,
  1306. TransactionType = TransactionTypeEnum.RemoteControl,
  1307. RelevanceCode = userCode,
  1308. ReceiverType = ApplicantTypeEnum.Client
  1309. };
  1310. await _notificationService.PostMessageAsync(notificationRequest);
  1311. //更改房间调参状态
  1312. // var getRoomRequest = new FindRoomByCodeRequest { DeviceCode = deviceCode, UserCode = userCode };
  1313. // var room = await _rtcService.GetLiveRoomByCodeAsync(getRoomRequest);
  1314. // if (room != null && !string.IsNullOrWhiteSpace(room.RoomId))
  1315. // {
  1316. // var changeControllingParameterStateRequest = new SetLiveParamsRequest { UserCode = userCode, RoomId = room.RoomId, IsControllingParameter = false };
  1317. // await _rtcService.ChangeControllingParameterStateAsync(changeControllingParameterStateRequest);
  1318. // }
  1319. var roomRequest = new ChangeConsultationControllingStateRequest { DeviceCode = deviceCode, UserCode = userCode, IsControllingParameter = false };
  1320. await _liveConsultationService.ChangeConsultationControllingStateAsync(roomRequest);
  1321. return true;
  1322. }
  1323. /// <summary>
  1324. /// 断开远程控制
  1325. /// </summary>
  1326. /// <param name="request"></param>
  1327. /// <returns></returns>
  1328. public async Task<bool> DisconnectRemoteControl(RemoteControlRequest request)
  1329. {
  1330. string deviceCode = await GetClientIdByTokenAsync(request.Token);
  1331. string userCode = request.ControlUserCode;
  1332. //发送控制人通知
  1333. if (string.IsNullOrWhiteSpace(userCode))
  1334. {
  1335. ThrowCustomerException(CustomerRpcCode.UsercodeIsEmpty, "User code is empty");
  1336. }
  1337. var userDTO = await _userServiceProxy.FindUserByCodeAsync(userCode);
  1338. if (userDTO == null)
  1339. {
  1340. ThrowCustomerException(CustomerRpcCode.UserNotExistError, "User does not exist");
  1341. }
  1342. var notify = new DeviceDisconnectRemoteControlNotification()
  1343. {
  1344. DeviceCode = deviceCode,
  1345. };
  1346. var notificationRequest = new SendNotificationRequest()
  1347. {
  1348. ClientId = userCode,
  1349. Message = notify,
  1350. JsonMessage = Newtonsoft.Json.JsonConvert.SerializeObject(notify),
  1351. NotificationType = notify.NotificationType,
  1352. TransactionType = TransactionTypeEnum.RemoteControl,
  1353. RelevanceCode = userCode,
  1354. ReceiverType = ApplicantTypeEnum.Client
  1355. };
  1356. await _notificationService.PostMessageAsync(notificationRequest);
  1357. //更改房间调参状态
  1358. // var getRoomRequest = new FindRoomByCodeRequest { DeviceCode = deviceCode, UserCode = userCode };
  1359. // var room = await _rtcService.GetLiveRoomByCodeAsync(getRoomRequest);
  1360. // if (room != null && !string.IsNullOrWhiteSpace(room.RoomId))
  1361. // {
  1362. // var changeControllingParameterStateRequest = new SetLiveParamsRequest { UserCode = userCode, RoomId = room.RoomId, IsControllingParameter = false };
  1363. // await _rtcService.ChangeControllingParameterStateAsync(changeControllingParameterStateRequest);
  1364. // }
  1365. var roomRequest = new ChangeConsultationControllingStateRequest { DeviceCode = deviceCode, UserCode = userCode, IsControllingParameter = false };
  1366. await _liveConsultationService.ChangeConsultationControllingStateAsync(roomRequest);
  1367. return true;
  1368. }
  1369. }
  1370. }