123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using WingInterfaceLibrary.Enum;
- using WingServerCommon.Log;
- using WingServerCommon.Service;
- using WingInterfaceLibrary.Internal.Request;
- using WingInterfaceLibrary.Internal.Interface;
- using WingServerCommon.Config;
- using WingServerCommon.Config.Parameters;
- using WingInterfaceLibrary.Enum.NotificationEnum;
- using WingInterfaceLibrary.Interface;
- using WingServerCommon.Interfaces.Cache;
- using WingInterfaceLibrary.LiveConsultation;
- using WingServerCommon.Mapper;
- namespace WingLiveConsultationService
- {
- public partial class LiveConsultationService : JsonRpcService, ISyncLiveConsultationService
- {
- /// <summary>转发请求给主服务器</summary>
- /// <param name="syncType"></param>
- /// <param name="roomId"></param>
- /// <param name="roomId"></param>
- /// <param name="message"></param>
- /// <returns></returns>
- private async Task SyncToMasterAsync(SyncTypeEnum syncType, string roomId, string patientName, BaseLiveConsultationJson message)
- {
- try
- {
- if (ConfigurationManager.IsDistributed)
- {
- var syncRequest = new SyncReceiveServiceDataRequest
- {
- SyncService = SyncServiceEnum.LiveConsultation,
- SyncType = syncType,
- SourceUrl = EnvironmentConfigManager.GetParammeter<StringParameter>("Gateway", "Domains").Value,
- ServerID = _serverID,
- ServiceDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(message),
- };
- Logger.WriteLineWarn($"LiveConsultationService SyncToMasterAsync, roomId:{roomId}, syncType:{syncType.ToString()}, {syncRequest.ServiceDataJson}");
- _masterInteractionCenterService.SyncReceiveSlaveServiceDataAsync(syncRequest);
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineWarn($"LiveConsultationService SyncToMasterAsync err, roomId:{roomId}, syncType:{syncType.ToString()}, err: {ex}");
- }
- }
- /// <summary>
- /// 服务器间会诊通知
- /// </summary>
- /// <param name="request">The request</param>
- /// <returns></returns>
- public async Task<bool> SyncServerMessageAsync(SyncReceiveServiceDataRequest request)
- {
- try
- {
- Logger.WriteLineInfo($"LiveConsultationService SyncServerMeaasge, source url:{request.SourceUrl}, syncType:{request.SyncType.ToString()}");
- switch (request.SyncType)
- {
- case SyncTypeEnum.UploadData:
- var message = Newtonsoft.Json.JsonConvert.DeserializeObject<BaseLiveConsultationJson>(request.ServiceDataJson);
- var userCode = message.OperatorCode;
- //获取房间缓存
- var roomId = message.ConsultationRecordCode;
- var room = await _rtcService.GetLiveRoomAsync(new GetLiveRoomRequest { LiveRoomCode = roomId });
- if (room != null)
- {
- try
- {
- var members = await _rtcService.GetLiveMemberInfosAsync(new GetLiveMemberInfosRequest { LiveRoomCode = roomId });
- var otherJoinMembers = members.Where(x => x.MemberType == LiveMemberEnum.User && x.Status == LiveConsultationMemberStatus.Joined && x.Id != userCode)?.ToList() ?? new List<LiveConsultationMember>();
- if (otherJoinMembers?.Count > 0)
- {
- //同时转发给其他用户
- var sendMessage = new UploadConsultationDataNotification
- {
- ConsultationCode = roomId,
- UserCode = userCode
- };
- var openNotifyQueueRequest = new WingInterfaceLibrary.Request.Notification.OpenNotifyQueueRequest { Module = roomId };
- var clientIds = otherJoinMembers.Select(x => x.Id).ToList();
- var tokenInfos = CacheMaintenance.Instance.Get<ITokensManager>().Where(x => clientIds.Contains(x.ClientId));
- if (tokenInfos != null && tokenInfos.Any())
- {
- Logger.WriteLineInfo($"UpdateConsultationFilesInfoAsync PushMessage, roomId:{roomId}, type:{sendMessage.NotificationType.ToString()}, receivers:{string.Join(";", tokenInfos.Select(x => x.AccountName).Distinct())}");
- var notificationRequest = new BroadcastNotificationRequest
- {
- ClientIds = clientIds,
- Tokens = tokenInfos.MappingTo<List<TokenDTO>>() ,
- Message = sendMessage,
- JsonMessage = Newtonsoft.Json.JsonConvert.SerializeObject(sendMessage),
- NotificationType = sendMessage.NotificationType,
- TransactionType = TransactionTypeEnum.Consultion,
- RelevanceCode = roomId,
- ReceiverType = ApplicantTypeEnum.Client,
- WSConnectType = WSConnectTypeEnum.ConsultationSecondWindow,
- IsNeedSyn = false
- };
- var res = await _notificationService.BroadcastMessageAsync(notificationRequest);
- }
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"UpdateConsultationFilesInfoAsync send message error:{ex.ToString()}");
- }
- }
- break;
- default:
- return false;
- }
- return await Task.FromResult(true);
- }
- catch (Exception ex)
- {
- Logger.WriteLineWarn($"LiveConsultationService SyncServerMessageAsync err, {ex}");
- return false;
- }
- return false;
- }
- }
- }
|