LiveConsultationService.Sync.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using WingInterfaceLibrary.Enum;
  2. using WingServerCommon.Log;
  3. using WingServerCommon.Service;
  4. using WingInterfaceLibrary.Internal.Request;
  5. using WingInterfaceLibrary.Internal.Interface;
  6. using WingServerCommon.Config;
  7. using WingServerCommon.Config.Parameters;
  8. using WingInterfaceLibrary.Enum.NotificationEnum;
  9. using WingInterfaceLibrary.Interface;
  10. using WingServerCommon.Interfaces.Cache;
  11. using WingInterfaceLibrary.LiveConsultation;
  12. using WingServerCommon.Mapper;
  13. namespace WingLiveConsultationService
  14. {
  15. public partial class LiveConsultationService : JsonRpcService, ISyncLiveConsultationService
  16. {
  17. /// <summary>转发请求给主服务器</summary>
  18. /// <param name="syncType"></param>
  19. /// <param name="roomId"></param>
  20. /// <param name="roomId"></param>
  21. /// <param name="message"></param>
  22. /// <returns></returns>
  23. private async Task SyncToMasterAsync(SyncTypeEnum syncType, string roomId, string patientName, BaseLiveConsultationJson message)
  24. {
  25. try
  26. {
  27. if (ConfigurationManager.IsDistributed)
  28. {
  29. var syncRequest = new SyncReceiveServiceDataRequest
  30. {
  31. SyncService = SyncServiceEnum.LiveConsultation,
  32. SyncType = syncType,
  33. SourceUrl = EnvironmentConfigManager.GetParammeter<StringParameter>("Gateway", "Domains").Value,
  34. ServerID = _serverID,
  35. ServiceDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(message),
  36. };
  37. Logger.WriteLineWarn($"LiveConsultationService SyncToMasterAsync, roomId:{roomId}, syncType:{syncType.ToString()}, {syncRequest.ServiceDataJson}");
  38. _masterInteractionCenterService.SyncReceiveSlaveServiceDataAsync(syncRequest);
  39. }
  40. }
  41. catch (Exception ex)
  42. {
  43. Logger.WriteLineWarn($"LiveConsultationService SyncToMasterAsync err, roomId:{roomId}, syncType:{syncType.ToString()}, err: {ex}");
  44. }
  45. }
  46. /// <summary>
  47. /// 服务器间会诊通知
  48. /// </summary>
  49. /// <param name="request">The request</param>
  50. /// <returns></returns>
  51. public async Task<bool> SyncServerMessageAsync(SyncReceiveServiceDataRequest request)
  52. {
  53. try
  54. {
  55. Logger.WriteLineInfo($"LiveConsultationService SyncServerMeaasge, source url:{request.SourceUrl}, syncType:{request.SyncType.ToString()}");
  56. switch (request.SyncType)
  57. {
  58. case SyncTypeEnum.UploadData:
  59. var message = Newtonsoft.Json.JsonConvert.DeserializeObject<BaseLiveConsultationJson>(request.ServiceDataJson);
  60. var userCode = message.OperatorCode;
  61. //获取房间缓存
  62. var roomId = message.ConsultationRecordCode;
  63. var room = await _rtcService.GetLiveRoomAsync(new GetLiveRoomRequest { LiveRoomCode = roomId });
  64. if (room != null)
  65. {
  66. try
  67. {
  68. var members = await _rtcService.GetLiveMemberInfosAsync(new GetLiveMemberInfosRequest { LiveRoomCode = roomId });
  69. var otherJoinMembers = members.Where(x => x.MemberType == LiveMemberEnum.User && x.Status == LiveConsultationMemberStatus.Joined && x.Id != userCode)?.ToList() ?? new List<LiveConsultationMember>();
  70. if (otherJoinMembers?.Count > 0)
  71. {
  72. //同时转发给其他用户
  73. var sendMessage = new UploadConsultationDataNotification
  74. {
  75. ConsultationCode = roomId,
  76. UserCode = userCode
  77. };
  78. var openNotifyQueueRequest = new WingInterfaceLibrary.Request.Notification.OpenNotifyQueueRequest { Module = roomId };
  79. var clientIds = otherJoinMembers.Select(x => x.Id).ToList();
  80. var tokenInfos = CacheMaintenance.Instance.Get<ITokensManager>().Where(x => clientIds.Contains(x.ClientId));
  81. if (tokenInfos != null && tokenInfos.Any())
  82. {
  83. Logger.WriteLineInfo($"UpdateConsultationFilesInfoAsync PushMessage, roomId:{roomId}, type:{sendMessage.NotificationType.ToString()}, receivers:{string.Join(";", tokenInfos.Select(x => x.AccountName).Distinct())}");
  84. var notificationRequest = new BroadcastNotificationRequest
  85. {
  86. ClientIds = clientIds,
  87. Tokens = tokenInfos.MappingTo<List<TokenDTO>>() ,
  88. Message = sendMessage,
  89. JsonMessage = Newtonsoft.Json.JsonConvert.SerializeObject(sendMessage),
  90. NotificationType = sendMessage.NotificationType,
  91. TransactionType = TransactionTypeEnum.Consultion,
  92. RelevanceCode = roomId,
  93. ReceiverType = ApplicantTypeEnum.Client,
  94. WSConnectType = WSConnectTypeEnum.ConsultationSecondWindow,
  95. IsNeedSyn = false
  96. };
  97. var res = await _notificationService.BroadcastMessageAsync(notificationRequest);
  98. }
  99. }
  100. }
  101. catch (Exception ex)
  102. {
  103. Logger.WriteLineError($"UpdateConsultationFilesInfoAsync send message error:{ex.ToString()}");
  104. }
  105. }
  106. break;
  107. default:
  108. return false;
  109. }
  110. return await Task.FromResult(true);
  111. }
  112. catch (Exception ex)
  113. {
  114. Logger.WriteLineWarn($"LiveConsultationService SyncServerMessageAsync err, {ex}");
  115. return false;
  116. }
  117. return false;
  118. }
  119. }
  120. }