public bool Handle(Dto.EventBus.ChannelSendGroupMsgEvent <RequestCustomMsgRoomDurationChanged> evt) { try { return(imservice.SendGroupCustomMsg(evt.ChannelID, evt.FromAccount, evt.Msg)); } catch (InvalidGroupException) { //自动修正房间不存在的问题 using (MQChannel mq = new MQChannel()) { var room = roomService.GetChannelInfo(evt.ChannelID); if (roomService.UpdateRoomEable(evt.ChannelID, false)) { mq.Publish(new Dto.EventBus.ChannelCreateEvent() { ChannelID = evt.ChannelID, ServiceID = room.ServiceID, ServiceType = room.ServiceType, }); } return(false); } } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex); return(false); } }
public bool Handle(EventBus.Events.OrderCancelingEvent evt) { try { if (evt == null) { return(true); } var service = new XuHos.BLL.OrderService(evt.UserID); var result = service.Cancel(evt.OrderNo, evt.CancelReason, evt.RefundFee); //发布通知 if (result == true) { using (XuHos.EventBus.MQChannel mqChannel = new MQChannel()) { mqChannel.Publish <EventBus.Events.UserNoticeEvent>(new EventBus.Events.UserNoticeEvent() { ServiceID = evt.OrderNo, NoticeType = EnumNoticeSecondType.DoctorStopDiagnosisCancelOrderNotice }); } } return(result); } catch (Exception E) { XuHos.Common.LogHelper.WriteError(E); return(false); } }
public bool Handle(ChannelSendGroupMsgEvent <RequestIMCustomMsgSurvey> evt) { try { return(imservice.SendGroupCustomMsg(evt.ChannelID, evt.FromAccount, evt.Msg)); } catch (XuHos.Integration.QQCloudy.InvalidGroupException) { //自动修正房间不存在的问题 using (XuHos.EventBus.MQChannel mq = new MQChannel()) { var room = roomService.GetChannelInfo(evt.ChannelID); room.Enable = false; if (roomService.CompareAndSetChannelInfo(room)) { mq.Publish <XuHos.EventBus.Events.ChannelCreateEvent>(new ChannelCreateEvent() { ChannelID = evt.ChannelID, ServiceID = room.ServiceID, ServiceType = room.ServiceType, }); } return(false); } } catch (Exception Ex) { XuHos.Common.LogHelper.WriteError(Ex); return(false); } }
public bool Handle(EventBus.Events.OrderPayCompletedEvent evt) { try { if (evt != null && evt.OrderNo != "") { XuHos.BLL.OrderService orderService = new BLL.OrderService(""); ConversationRoomService roomService = new ConversationRoomService(); if (evt.OrderType == EnumProductType.ImageText || evt.OrderType == EnumProductType.video || evt.OrderType == EnumProductType.Phone || evt.OrderType == EnumProductType.Consultation) { if (string.IsNullOrEmpty(evt.OrderOutID)) { var order = orderService.GetOrder(evt.OrderNo); evt.OrderOutID = order.OrderOutID; } var room = roomService.GetChannelInfo(evt.OrderOutID); if (room != null) { using (XuHos.EventBus.MQChannel mqChannel = new MQChannel()) { return(mqChannel.Publish(new EventBus.Events.ChannelCreateEvent() { ServiceID = room.ServiceID, ServiceType = room.ServiceType, ChannelID = room.ChannelID })); } } else { var order = orderService.GetOrder("", evt.OrderOutID); if (order.OrderState == EnumOrderState.Canceled) { return(true); } else { return(false); } } } } } catch (Exception E) { LogHelper.WriteError(E); return(false); } return(true); }
public bool Handle(Dto.EventBus.ChannelSendGroupMsgEvent <ResponseUserFileDTO> evt) { try { //发送图片消息 if (evt.Msg.FileType == 0) { return(imservice.SendGroupImageMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileUrl)); } //发送图片消息 else if (evt.Msg.FileType == 1) { return(imservice.SendGroupFileMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileSize, evt.Msg.FileName)); } //发送音频消息 //else if (evt.Msg.FileType == 2) //{ // using (var filestream = KMEHosp.Common.Storage.Manager.Instance.OpenFile("Audios", evt.Msg.FileUrl)) // { // Task.WaitAll(filestream); // var Second = Convert.ToInt32(KMEHosp.Common.Utility.AudioHelper.TotalSeconds(filestream.Result)); // return imservice.SendGroupAudioMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileSize, Second); // } //} else { return(true); } } catch (InvalidGroupException) { //自动修正房间不存在的问题 using (MQChannel mq = new MQChannel()) { var room = roomService.GetChannelInfo(evt.ChannelID); room.Enable = false; if (roomService.UpdateRoomEable(evt.ChannelID, false)) { mq.Publish(new ChannelCreateEvent() { ChannelID = evt.ChannelID, ServiceID = room.ServiceID, ServiceType = room.ServiceType, }); } return(false); } } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex); return(false); } }
public bool Handle(ChannelSendGroupMsgEvent <ResponseUserFileDTO> evt) { try { //发送图片消息 if (evt.Msg.FileType == 0) { return(imservice.SendGroupImageMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileUrl)); } //发送图片消息 else if (evt.Msg.FileType == 1) { return(imservice.SendGroupFileMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileSize, evt.Msg.FileName)); } //发送音频消息 else if (evt.Msg.FileType == 2) { using (var filestream = XuHos.Common.Storage.Manager.Instance.OpenFile("Audios", evt.Msg.FileUrl)) { Task.WaitAll(filestream); var Second = Convert.ToInt32(XuHos.Common.Utility.AudioHelper.TotalSeconds(filestream.Result)); return(imservice.SendGroupAudioMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileSize, Second)); } } else { return(true); } } catch (XuHos.Integration.QQCloudy.InvalidGroupException) { //自动修正房间不存在的问题 using (XuHos.EventBus.MQChannel mq = new MQChannel()) { var room = roomService.GetChannelInfo(evt.ChannelID); room.Enable = false; if (roomService.CompareAndSetChannelInfo(room)) { mq.Publish <XuHos.EventBus.Events.ChannelCreateEvent>(new ChannelCreateEvent() { ChannelID = evt.ChannelID, ServiceID = room.ServiceID, ServiceType = room.ServiceType, }); } return(false); } } catch (Exception ex) { XuHos.Common.LogHelper.WriteError(ex); return(false); } }
public ApiResult Triage([FromBody] RequestConversationRoomTriageDTO request) { using (MQChannel mqChannel = new MQChannel()) { return(mqChannel.Publish(new Dto.EventBus.ChannelTriageChangeEvent() { ChannelID = request.ChannelID, DoctorID = request.CurrentOperatorDoctorID, TriageID = HealthCloud.Common.Utility.SeqIDHelper.GetSeqId().ToString() }).ToApiResultForBoolean()); } }
/// <summary> /// 领取问题(盲领) /// </summary> /// <param name="AcceptDoctorID"></param> /// <returns></returns> public ApiResult AcceptTextConsult(string AcceptDoctorID, List <string> groupList) { if (string.IsNullOrEmpty(AcceptDoctorID)) { return(EnumApiStatus.BizError.ToApiResultForApiStatus()); } //初始化已经领取列表 SetTextConsultDoingList(AcceptDoctorID); SetTextConsultFinishedList(AcceptDoctorID); var UserConsultID = ""; //获取医生分组 //var groupList = doctorService.GetDoctorGroupIdListByDoctorID(AcceptDoctorID); var takeResult = grabConsultService.TakeTask(AcceptDoctorID, out UserConsultID, groupList); //领取了任务 if (!string.IsNullOrEmpty(UserConsultID)) { var task = userOPDRegisterRepository.GetTask(UserConsultID); if (task != null) { using (MQChannel mqChannel = new MQChannel()) { if (mqChannel.Publish(new DoctorAcceptEvent() { DoctorID = AcceptDoctorID, ServiceID = task.OPDRegisterID, ServiceType = task.OPDType, ChannelID = task.ChannelID, UserID = task.UserID, UserMemberID = task.MemberID })) { return(task.ToApiResultForObject(takeResult)); } } } } return(takeResult.ToApiResultForApiStatus()); }
public bool Handle(EventBus.Events.OrderCanceledEvent evt) { try { if (evt == null) { return(true); } //查询出所有交易日志 var logs = service.QueryOrderTradeLogs(evt.OrderNo); using (XuHos.EventBus.MQChannel mqChannel = new MQChannel()) { mqChannel.BeginTransaction(); //循环所哟交易日志 foreach (var trade in logs) { //如果不是线下付款的方式,并且已经交易成功了则开始退款 if (trade.PayType != EnumPayType.OfflinePay && trade.TradeStatus != EnumTradeState.TRADE_NOT_EXIST && trade.TradeStatus != EnumTradeState.WAIT_BUYER_PAY) { mqChannel.Publish <EventBus.Events.OrderRefundEvent>(new EventBus.Events.OrderRefundEvent() { OrderNo = trade.OrderNo, PayType = trade.PayType, TradeNo = trade.TradeNo }); } } mqChannel.Commit(); return(true); } } catch (Exception E) { XuHos.Common.LogHelper.WriteError(E); } return(false); }
/// <summary> /// 领取问题(盲领) /// 作者:郭明 /// 日期:2017年5月18日 /// </summary> /// <param name="AcceptDoctorID"></param> /// <returns></returns> public ApiResult AcceptVideo(string DoctorID, List <string> groupList) { if (string.IsNullOrEmpty(DoctorID)) { return(EnumApiStatus.BizError.ToApiResultForApiStatus()); } //设置识破正在处理的列表 SetVideoConsultDoingList(DoctorID); //设置视频已经完成列表 SetVideoConsultFinishedList(DoctorID); var OPDRegisterID = ""; //获取医生分组 var takeResult = grabOPDService.TakeTask(DoctorID, out OPDRegisterID, groupList); if (!string.IsNullOrEmpty(OPDRegisterID)) { var task = userOPDRegisterRepository.GetTask(OPDRegisterID); if (task != null) { using (MQChannel mqChannel = new MQChannel()) { if (mqChannel.Publish <DoctorAcceptEvent>(new DoctorAcceptEvent() { DoctorID = DoctorID, ServiceID = task.OPDRegisterID, ServiceType = task.OPDType, ChannelID = task.ChannelID, UserID = task.UserID, UserMemberID = task.MemberID })) { return(task.ToApiResultForObject(takeResult)); } } } } return(takeResult.ToApiResultForApiStatus()); }
public bool Handle(Dto.EventBus.ChannelSendGroupMsgEvent <string> evt) { try { if (string.IsNullOrWhiteSpace(evt.Msg)) { return(true); } else { return(imservice.SendGroupTextMsg(evt.ChannelID, evt.FromAccount, evt.Msg)); } } catch (InvalidGroupException) { //自动修正房间不存在的问题 using (MQChannel mq = new MQChannel()) { var room = roomService.GetChannelInfo(evt.ChannelID); if (roomService.UpdateRoomEable(evt.ChannelID, false)) { mq.Publish(new Dto.EventBus.ChannelCreateEvent() { ChannelID = evt.ChannelID, ServiceID = room.ServiceID, ServiceType = room.ServiceType, }); } return(false); } } catch (Exception Ex) { LogHelper.DefaultLogger.Error(Ex); return(false); } }
/// <summary> /// 插入消息表并推送消息 /// </summary> /// <param name="model">消息</param> /// <param name="ToUserList">接收消息的用户</param> /// <param name="pageArgs">扩展参数,该参数会一起推给客户端</param> /// <param name="silence">是否静默推送</param> /// <returns></returns> public bool SendNotice( RequestNoticeMessageDTO model, List <string> ToUserList = null, bool silence = false, string ServiceID = "", string FromUserID = "", EnumTargetUserCodeType ToUserListType = EnumTargetUserCodeType.UserID) { if (ToUserList == null) { ToUserList = new List <string>(); } var extrasIOS = _GetJMessageExtras(EnumTerminalType.IOS, model, model.PageArgs); var extrasAndroid = _GetJMessageExtras(EnumTerminalType.Android, model, model.PageArgs); using (MQChannel mqChanne = new MQChannel()) { return(mqChanne.Publish(new Dto.EventBus.UserNoticeSendEvent() { MessageID = model.MessageID, Content = model.Content, Title = model.Title, Summary = model.Summary, PageArgs = model.PageArgs, ClientName = model.ClientName, NoticeDate = model.NoticeDate, NoticeSecondType = model.NoticeSecondType, FromUserID = FromUserID, ToUserList = ToUserList, ToUserListType = ToUserListType, extrasAndroid = extrasAndroid, extrasIOS = extrasIOS, serviceID = ServiceID, silence = silence })); } }
/// <summary> /// 重新开始计时 /// </summary> /// <param name="ChannelID"></param> /// <returns></returns> public bool RestartCharging(string ConversationRoomID) { try { //获取房间信息 var room = GetChannelInfo(ConversationRoomID); var doctorUser = GetChannelUsersInfo(ConversationRoomID).Find(a => a.UserType == EnumUserType.Doctor); #region 房间不存在或医生不存在则忽略 if (room == null && doctorUser == null) { return(true); } #endregion #region 更新房间计费状态 if (room.ChargingState != EnumRoomChargingState.Started) { room.ChargingState = EnumRoomChargingState.Started; if (!conversationRoomRepository.UpdateChannelChargeState(room.ConversationRoomID, room.ChargingState)) { return(false); } } #endregion using (MQChannel mqChannel = new MQChannel()) { mqChannel.BeginTransaction(); #region 发布延时消息,15秒为一个周期。消费端收到消息后重新计算房间已通话时间。 if (!mqChannel.Publish <ChannelChargingEvent>(new ChannelChargingEvent() { ChannelID = ConversationRoomID, Seq = room.ChargingSeq + 1, ChargingTime = room.ChargingTime, Interval = room.ChargingInterval })) { return(false); } #endregion #region 发送服务时长变更消息 if (!mqChannel.Publish(new ChannelSendGroupMsgEvent <RequestCustomMsgRoomDurationChanged>() { Msg = new RequestCustomMsgRoomDurationChanged() { Data = new RequestConversationRoomStatusDTO() { ChannelID = room.ConversationRoomID, State = room.RoomState, ServiceID = room.ServiceID, ServiceType = room.ServiceType, DisableWebSdkInteroperability = room.DisableWebSdkInteroperability, ChargingState = EnumRoomChargingState.Started, Duration = room.Duration, //总时长 TotalTime = room.TotalTime // 消耗 }, Desc = $"服务计时已启动,总时长{Format(room.Duration)}, 剩余{Format(room.Duration - room.TotalTime)}" }, ChannelID = room.ConversationRoomID, FromAccount = doctorUser.identifier })) { return(false); } #endregion mqChannel.Commit(); return(true); } } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex.Message, ex); return(false); } }
/// <summary> /// 比较并设置房间状态 /// </summary> /// <param name="ChannelID"></param> /// <param name="FromUserID"></param> /// <param name="State"></param> /// <param name="DisableWebSdkInteroperability"></param> /// <param name="ExpectedState"> 返回值</param> /// <returns></returns> public EnumApiStatus CompareAndSetChannelState(string ConversationRoomID, string FromUserID, EnumRoomState State, bool DisableWebSdkInteroperability, ref EnumRoomState ExpectedState) { try { var room = GetChannelInfo(ConversationRoomID); #region 校验:房间已标记为失效的,不可设置房间状态 if (room.Close) { return(EnumApiStatus.BizChannelSetStateIfClose); } #endregion #region 校验:房间状态未启用 if (!room.Enable) { //频道未就绪(客户端重试) return(EnumApiStatus.BizChannelNotReady); } #endregion #region 校验:当前房间状态和预期的房间状态一致才允许设置 #region 处理特殊状态情况 客户端没有WaitAgain 状态需要统一 if (ExpectedState == EnumRoomState.Waiting && room.RoomState == EnumRoomState.WaitAgain) { ExpectedState = room.RoomState; } #endregion if (room.RoomState != ExpectedState) { //返回新的状态给客户端,客户端需要同步 ExpectedState = room.RoomState; //前端用户只需要知道有候诊状态即可,不需要知道有重复候诊的状态 if (ExpectedState == EnumRoomState.WaitAgain) { ExpectedState = EnumRoomState.Waiting; } //当前状态不是预期状态 return(EnumApiStatus.BizChannelRejectSetStateIfNotExpectedState); } #endregion #region 校验:只能在预约时间内进入诊室或提前30分钟进入诊室 if ((State == EnumRoomState.WaitAgain || State == EnumRoomState.Waiting)) { if (DateTime.Now <= room.BeginTime.AddMinutes(-30)) { return(EnumApiStatus.BizChannelRejectConnectIfNoReservationTime); } } #endregion #region 校验:医生在休诊状态下不可进入诊室 if ((State == EnumRoomState.WaitAgain || State == EnumRoomState.Waiting)) { if (IsChannelDiagnoseOff(room)) { return(EnumApiStatus.BizChannelRejectConnectIfDiagnoseOff); } } #endregion #region 房间状态切换的规则 switch (room.RoomState) { case EnumRoomState.AlreadyVisit: { //就诊已经结束不能在设置状态 return(EnumApiStatus.BizOK); } case EnumRoomState.NoTreatment: { if (State == EnumRoomState.NoTreatment) { State = EnumRoomState.NoTreatment; } else if (State == EnumRoomState.InMedicalTreatment) { State = EnumRoomState.InMedicalTreatment; } else { State = EnumRoomState.Waiting; } break; } case EnumRoomState.Waiting: { //重试 if (State == EnumRoomState.Waiting || State == EnumRoomState.WaitAgain) { State = EnumRoomState.Waiting; } //医生呼叫 else if (State == EnumRoomState.Calling) { State = EnumRoomState.Calling; } //接听 else if (State == EnumRoomState.InMedicalTreatment) { State = EnumRoomState.InMedicalTreatment; } //候诊界面,用户点击离开或者异常断开都是未就诊 else { State = EnumRoomState.NoTreatment; } break; } case EnumRoomState.Calling: { //重试 if (State == EnumRoomState.Calling) { State = EnumRoomState.Calling; } //接听 else if (State == EnumRoomState.InMedicalTreatment) { State = EnumRoomState.InMedicalTreatment; } //取消呼叫 或者拒绝 else if (State == EnumRoomState.Waiting || State == EnumRoomState.WaitAgain) { State = EnumRoomState.WaitAgain; } else { State = EnumRoomState.Disconnection; } break; } case EnumRoomState.InMedicalTreatment: { //重试 if (State == EnumRoomState.InMedicalTreatment) { State = EnumRoomState.InMedicalTreatment; } //医生挂断 else if (State == EnumRoomState.AlreadyVisit) { State = EnumRoomState.AlreadyVisit; } //重试候诊 else if (State == EnumRoomState.Waiting || State == EnumRoomState.WaitAgain) { State = EnumRoomState.WaitAgain; } //患者离开,一会再来 else { State = EnumRoomState.Disconnection; } break; } case EnumRoomState.Disconnection: { //医生挂断 if (State == EnumRoomState.AlreadyVisit) { State = EnumRoomState.AlreadyVisit; } //取消呼叫 或者拒绝 else if (State == EnumRoomState.Waiting || State == EnumRoomState.WaitAgain) { State = EnumRoomState.WaitAgain; } else { State = EnumRoomState.Disconnection; } break; } case EnumRoomState.WaitAgain: { //医生呼叫 if (State == EnumRoomState.Calling) { State = EnumRoomState.Calling; } //取消呼叫 或者拒绝 else if (State == EnumRoomState.Waiting || State == EnumRoomState.WaitAgain) { State = EnumRoomState.WaitAgain; } else { State = EnumRoomState.Disconnection; } break; } } #endregion //默认高版本,当前禁用互通性(SDK直接可以互通的情况下) if (room.DisableWebSdkInteroperability) { room.DisableWebSdkInteroperability = DisableWebSdkInteroperability; } room.RoomState = State; #region 推送状态变更消息,并修改状态 using (MQChannel mqChannel = new MQChannel()) { mqChannel.BeginTransaction(); if (!mqChannel.Publish(new ChannelStateChangedEvent() { ChannelID = ConversationRoomID, FromUserID = FromUserID, State = State, ExpectedState = ExpectedState, DisableWebSdkInteroperability = room.DisableWebSdkInteroperability })) { return(EnumApiStatus.BizError); } if (conversationRoomRepository.UpdateChannelState(room.ConversationRoomID, room.RoomState)) { mqChannel.Commit(); return(EnumApiStatus.BizOK); } else { return(EnumApiStatus.BizError); } } #endregion } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex.Message, ex); //业务错误 return(EnumApiStatus.BizError); } }
/// <summary> /// 开始计时 /// </summary> /// <param name="ChannelID"></param> /// <param name="Duration"></param> /// <param name="ServiceID"></param> /// <param name="OrderNo"></param> /// <returns></returns> public bool StartCharging(string ConversationRoomID, int Duration, string ServiceID, string OrderNo) { try { var room = GetChannelInfo(ConversationRoomID); #region 修改房间开始时间和已经消耗的时间 //第一次进入诊室的时候 if (room.TotalTime < 1) { //room.BeginTime = DateTime.Now; //room.TotalTime = 1; if (!conversationRoomRepository.UpdateChannelChargeTime(ConversationRoomID, 1, DateTime.Now)) { return(false); } } #endregion using (MQChannel mqChannel = new MQChannel()) { mqChannel.BeginTransaction(); //存在重复的请求,消费端需要去重复 if (!mqChannel.Publish(new ChannelDurationChangeEvent() { Duration = Duration, //套餐里面的服务时长单位是分钟需要转换成秒 ServiceID = ServiceID, OrderNo = OrderNo, NewUpgradeOrderNo = OrderNo })) { return(false); } //存在重复的请求,消费端需要去重复 //发布延时消息,15秒为一个周期。消费端收到消息后重新计算房间已通话时间。 if (!mqChannel.Publish(new ChannelChargingEvent() { ChannelID = ConversationRoomID, Seq = 0, ChargingTime = room.BeginTime, Interval = 15 })) { return(false); } room.ChargingState = EnumRoomChargingState.Started; if (conversationRoomRepository.UpdateChannelChargeState(ConversationRoomID, EnumRoomChargingState.Started)) { mqChannel.Commit(); return(true); } else { return(false); } } } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex.Message, ex); return(false); } }
public bool Handle(EventBus.Events.OrderEvaluationEvent evt) { if (evt == null) { return(true); } try { var ProviderID = ""; var UserID = ""; #region 获取服务提供者的编号 var order = orderService.GetOrder("", evt.OuterID); if (order != null) { UserID = order.UserID; switch (order.OrderType) { case EnumProductType.video: { ProviderID = new XuHos.BLL.UserOPDRegisterService(order.UserID).Single <XuHos.DTO.UserOPDRegisterDTO>(order.OrderOutID).DoctorID; }; break; } } #endregion if (string.IsNullOrEmpty(ProviderID) || string.IsNullOrEmpty(UserID)) { return(true); } #region 写评论记录 ServiceEvaluation model = new ServiceEvaluation() { UserID = UserID, EvaluationTags = evt.EvaluationTags, ProviderID = ProviderID, Content = evt.Content, CreateTime = DateTime.Now, CreateUserID = string.IsNullOrEmpty(evt.CreateUserID) ? UserID : evt.CreateUserID, OuterID = evt.OuterID, Score = evt.Score, ServiceType = order.OrderType }; if (!doctorService.Evaluation(model)) { return(false); } #endregion #region 写领域消息,评论完成 using (XuHos.EventBus.MQChannel mqChannel = new MQChannel()) { if (!mqChannel.Publish <XuHos.EventBus.Events.OrderEvaluationCompletedEvent>(new EventBus.Events.OrderEvaluationCompletedEvent() { Content = evt.Content, CreateUserID = evt.CreateUserID, EvaluationTags = evt.EvaluationTags, OuterID = evt.OuterID, ProviderID = ProviderID, Score = evt.Score })) { return(false); } } #endregion } catch (Exception Ex) { XuHos.Common.LogHelper.WriteError(Ex); return(false); } return(true); }
public bool Handle(Dto.EventBus.ChannelNewMsgEvent evt) { if (evt == null) { return(true); } //已经启用了康博士 if (!string.IsNullOrEmpty(HealthCloud.Consultation.Services.DrKang.Configuration.Config.drKangEnable) && (HealthCloud.Consultation.Services.DrKang.Configuration.Config.drKangEnable == "1" || HealthCloud.Consultation.Services.DrKang.Configuration.Config.drKangEnable.ToUpper() == bool.TrueString.ToUpper()) ) { try { //是通过客户端发送的 if (evt.OptPlatform != "RESTAPI" && evt.ServiceType == EnumDoctorServiceType.PicServiceType) { #region 检查当前咨询中康博士回答情况,判断是否还需要继续使用康博士 var cacheKey_Channel_DrKangState = new StringCacheKey(StringCacheKeyType.Channel_DrKangState, evt.ChannelID.ToString()); var Channel_DrKangState = cacheKey_Channel_DrKangState.FromCache <string>(); switch (Channel_DrKangState) { //问答结束,没有匹配的疾病 case "nullMatchDisease": //问答结束,已有明确诊断 case "diagnosis": //无法响应回复 case "nullMatchResponse": //禁用(医生已回复) case "disabled": //出现异常 case "exception": return(true); } #endregion //文字内容才识别 if (evt.Messages.Length > 0 && evt.Messages[0].MessageContent.Contains("\"MsgType\":\"TIMTextElem\"")) { var room = roomService.GetChannelInfo(evt.ChannelID); //医生未接诊 if (room != null && room.RoomState == EnumRoomState.NoTreatment) { #region 医生未回答 //获取用户的信息 var userInfo = roomService.GetChannelUsersInfo(evt.ChannelID).Where(t => t.identifier == Convert.ToInt32(evt.FromAccount)).FirstOrDefault(); //获取医生信息 var sendMsgFromAccount = 0; //用户回复了 if (userInfo != null && userInfo.UserType == EnumUserType.User) { // { "MsgContent":{ "Text":"头疼"},"MsgType":"TIMTextElem"} var msg = JsonHelper.FromJson <Msg>(evt.Messages[0].MessageContent); if (msg != null && msg.MsgType == "TIMTextElem" && msg.MsgContent != null) { var text = msg.MsgContent["Text"]; try { #region 使用康博士,记录最后的处理状态,并返回康博士的回答 Services.DrKang.Model.ResponseResultDataDTO ret = null; //首次的时候没有设置基本信息,如果是通过一键呼叫或者其他服务转过来的则没有设置。 if (Channel_DrKangState == "notSetBaseMsg") { ret = drKangService.setBaseMsg(userInfo.MemberID, "", text, userInfo.Gender == EnumUserGender.Male ? "男" : "女", room.ServiceID); } else { //调用康博士导诊接口 ret = drKangService.drKangGuide(text, evt.ServiceID); } var QuestionTopic = ""; var QuestionAnswer = new List <string>(); var DrKangTrueSymptom = ""; var DrKangDisease = ""; //没有与症状匹配的模板 if (ret.type == "nullMatchSymptom") { QuestionTopic = "您的情况我已转达给了医生,请耐心等待医生的回复。"; //康博士无能为力,医生参与吧 } //没有与症状匹配的模板 else if (ret.type == "nullMatchTemplate") { //康博士无能为力,医生参与吧 QuestionTopic = "您的情况我已转达给了医生,请耐心等待医生的回复。"; } //匹配到多个模板需要跟用户确认() else if (ret.type == "confirmTemplate") { QuestionTopic = ret.body; //返回提示内容,需要在跟患者确认。 } //问答阶段 else if (ret.type == "acking") { QuestionTopic = ret.body; QuestionAnswer = ret.answer; //返回提示信息,正在问答阶段,医生这时候是否能够介入? } //问答结束,没有匹配的疾病 else if (ret.type == "nullMatchDisease") { QuestionTopic = "您的情况我已转达给了医生,请耐心等待医生的回复。"; //没有明确的诊断,需要医生参与 } //问答结束,已有明确诊断 else if (ret.type == "diagnosis") { var diagnosisRet = drKangService.getInterrogationRecord(evt.ServiceID); DrKangTrueSymptom = diagnosisRet.trueSymptom; DrKangDisease = diagnosisRet.disease; //QuestionTopic = $"您的症状为:{diagnosisRet.trueSymptom},可能患有{diagnosisRet.disease}疾病。该情况我已转达给了医生,请耐心等待医生的正式回复。"; QuestionTopic = $"您的症状为:{diagnosisRet.trueSymptom}。该情况我已转达给了医生,请耐心等待医生的正式回复。"; } //无法回答 else if (ret.type == "nullMatchResponse") { QuestionTopic = "您的情况我已转达给了医生,请耐心等待医生的回复。"; //康博士无法回答的问题,需人工介入 } //记录最后一次问答的状态 ret.type.ToCache(cacheKey_Channel_DrKangState); #endregion #region 更新监控指标 var values = new Dictionary <string, string>(); values.Add("DrKangState", ret.type);//康博士问诊状态 if (!string.IsNullOrEmpty(DrKangDisease)) { values.Add("DrKangDisease", DrKangDisease);//康博士问诊状态 } if (!string.IsNullOrEmpty(DrKangTrueSymptom)) { values.Add("DrKangTrueSymptom", DrKangTrueSymptom);//康博士问诊状态 } if (!moniorIndexService.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO() { Category = "UserConsult", OutID = evt.ServiceID, Values = values })) { return(false); } #endregion #region 使用非医生的身份,回答给用户 using (MQChannel channle = new MQChannel()) { if (QuestionAnswer.Count > 0) { return(channle.Publish(new Dto.EventBus.ChannelSendGroupMsgEvent <RequestIMCustomMsgSurvey>() { ChannelID = evt.ChannelID, FromAccount = sendMsgFromAccount, Msg = new RequestIMCustomMsgSurvey() { Desc = QuestionTopic, Data = new RadioTopic() { Answer = QuestionAnswer } } })); } else { return(channle.Publish(new Dto.EventBus.ChannelSendGroupMsgEvent <string>() { ChannelID = evt.ChannelID, FromAccount = sendMsgFromAccount, Msg = QuestionTopic })); } } #endregion } catch { #region 出现异常,则记录下来 var values = new Dictionary <string, string>(); values.Add("DrKangState", "exception");//康博士问诊状态 if (!moniorIndexService.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO() { Category = "UserConsult", OutID = evt.ServiceID, Values = values })) { return(false); } else { return(true); } #endregion } } } #endregion } else { //医生已经回答 "disabled".ToCache(cacheKey_Channel_DrKangState, TimeSpan.FromHours(24)); } } } } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex); return(false); } } else { return(true); } return(true); }
public bool Handle(EventBus.Events.ChannelStateChangedEvent evt) { DTO.ConversationRoomDTO room = null; try { if (evt == null) { return(true); } if (string.IsNullOrEmpty(evt.FromUserID)) { return(true); } //获取房间信息 room = roomService.GetChannelInfo(evt.ChannelID); #region 参数校验:房间不存在的则不允许修改 if (room == null) { return(true); } #endregion var userInfo = userService.GetUserInfoByUserId(evt.FromUserID); var CurrentOperatorUserIdentifier = userInfo.identifier; var RoomStateChangeMsgDesc = ""; var RoomOperatorType = ""; var RoomOperatorRemark = ""; //结束看诊 if (evt.State == EnumRoomState.AlreadyVisit) { if (userInfo.UserType == EnumUserType.Doctor) { #region 停止计费 if (room.ChargingState == EnumRoomChargingState.Started && !roomService.PauseCharging(evt.ChannelID)) { return(false); } #endregion #region 更新订单状态 if (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType || room.ServiceType == EnumDoctorServiceType.PicServiceType || room.ServiceType == EnumDoctorServiceType.Consultation) { //订单完成 if (!orderService.Complete("", room.ServiceID)) { XuHos.Common.LogHelper.WriteWarn($"订单完成失败,ServiceID={room.ServiceID}"); return(false); } } #endregion #region 更新监控指标(记录服务时长,总耗时,就诊是否结束标志) var order = orderService.GetOrder("", room.ServiceID); if (order != null) { SysMonitorIndexService service = new SysMonitorIndexService(); var values = new Dictionary <string, string>(); values.Add("VisitingServiceChargingState", room.ChargingState.ToString()); //就诊暂停标志 values.Add("VisitingServiceDurationSeconds", room.Duration.ToString()); //就诊服务时长 values.Add("VisitingServiceElapsedSeconds", room.TotalTime.ToString()); //就诊消耗时长 values.Add("VisitingRoomState", room.RoomState.ToString()); //就诊暂停标志 if (!service.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO() { Category = "UserConsult", OutID = order.OrderNo, Values = values })) { return(false); } } #endregion //语音、视频看诊 if (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType) { var DoctorID = ""; #region 获取医生编号 if (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType) { BLL.UserOPDRegisterService bllOPD = new UserOPDRegisterService(""); //获取预约信息 var opd = bllOPD.Single <UserOPDRegister>(room.ServiceID); if (opd != null) { DoctorID = opd.DoctorID; } else { XuHos.Common.LogHelper.WriteWarn("房间 " + room.ChannelID + " 对应的预约记录不存在"); } } #endregion var DoctorUid = uidService.GetDoctorIMUid(DoctorID); #region 发送候诊队列通知 roomService.SendWaitingQueueChangeNotice(DoctorID); #endregion } RoomOperatorRemark = $""; RoomOperatorType = "Hangup"; RoomStateChangeMsgDesc = "医生已结束看诊,请对本次服务作出评价"; } else { //无效请求 return(true); } } else if (evt.State == EnumRoomState.Waiting) { //取消呼叫 if (userInfo.UserType == EnumUserType.Doctor) { RoomStateChangeMsgDesc = "医生取消了呼叫"; RoomOperatorType = "Call_Cancel"; } else { RoomStateChangeMsgDesc = "患者正在候诊,等待医生呼叫"; RoomOperatorType = "Wait"; #region 修改状态并设置分诊编号 room.RoomState = evt.State; room.TriageID = XuHos.Common.Utility.SeqIDHelper.GetSeqId(); //修改就诊时间和开始就诊时间 if (!roomService.CompareAndSetChannelInfo(room)) { XuHos.Common.LogHelper.WriteWarn($"修改房间信息失败,ChannelID={room.ChannelID}"); return(false); } #endregion #region 发送患者进入诊室的通知 if (userInfo.UserType == EnumUserType.User || userInfo.UserType == EnumUserType.Drugstore) { using (XuHos.EventBus.MQChannel mqChannel = new MQChannel()) { if (!mqChannel.Publish <EventBus.Events.UserNoticeEvent>(new EventBus.Events.UserNoticeEvent() { NoticeType = EnumNoticeSecondType.DoctorVidUserEnterRoomNotice, ServiceID = room.ServiceID })) { XuHos.Common.LogHelper.WriteWarn($"Publis UserNoticeEvent失败,ServiceID={room.ServiceID}"); return(false); } } } #endregion } } else if (evt.State == EnumRoomState.Calling) { //医生呼叫患者 if (userInfo.UserType == EnumUserType.Doctor) { RoomOperatorType = "Calling"; RoomStateChangeMsgDesc = "医生正在呼叫,等待患者接听"; using (XuHos.EventBus.MQChannel mqChannel = new MQChannel()) { if (!mqChannel.Publish <EventBus.Events.UserNoticeEvent>(new EventBus.Events.UserNoticeEvent() { NoticeType = EnumNoticeSecondType.UserVidDoctorCallNotice, ServiceID = room.ServiceID })) { return(false); } } } else { //无效请求 return(true); } } else if (evt.State == EnumRoomState.InMedicalTreatment) { if (userInfo.UserType == EnumUserType.Doctor) { //无效请求 return(true); } //患者接听 else { RoomOperatorType = "Calling_Answer"; RoomStateChangeMsgDesc = "患者已进入诊室"; #region 修改订单状态,用户将不能够再取消订单 if (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType) { #region 语音/视频 修改订单状态(配送中) if (!orderService.LogisticWithDistributionIn(room.ServiceID)) { return(false); } #endregion } else if (room.ServiceType == EnumDoctorServiceType.PicServiceType) { #region 图文咨询 修改订单状态(配送中) BLL.OrderService bllOrder = new OrderService(evt.FromUserID); if (!bllOrder.LogisticWithDistributionIn(room.ServiceID)) { return(false); } #endregion } #endregion #region 计算候诊耗时并更新统计指标 var log = roomService.GetChannelLastLog(room.ConversationRoomID, "Wait"); var order = orderService.GetOrder("", room.ServiceID); if (log != null && order != null) { //候诊耗时 var WaitingElapsedSeconds = (DateTime.Now - log.OperationTime).TotalSeconds; RoomOperatorRemark = $"用户候诊用时{WaitingElapsedSeconds}秒"; SysMonitorIndexService service = new SysMonitorIndexService(); var values = new Dictionary <string, string>(); values.Add("WaitingElapsedSeconds", WaitingElapsedSeconds.ToString()); //更新候诊总耗时,指标=原指标+新指标 if (!service.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO() { Category = "UserConsult", OutID = order.OrderNo, Values = values }, true)) { return(false); } } #endregion } } else if (evt.State == EnumRoomState.NoTreatment) { if (userInfo.UserType == EnumUserType.Doctor) { RoomOperatorType = "Calling_Cancel"; RoomStateChangeMsgDesc = "医生取消了呼叫"; } else { RoomOperatorType = "Waiting_Cancel"; RoomStateChangeMsgDesc = "患者取消了候诊"; } //发送指令前状态是在就诊中 if (evt.ExpectedState == EnumRoomState.InMedicalTreatment) { #region 停止计费 if (room.ChargingState == EnumRoomChargingState.Started && !roomService.PauseCharging(evt.ChannelID)) { return(false); } #endregion } } else if (evt.State == EnumRoomState.Disconnection) { if (userInfo.UserType == EnumUserType.Doctor) { RoomOperatorType = "Leave"; RoomStateChangeMsgDesc = "医生已离开"; } else { RoomOperatorType = "Leave"; RoomStateChangeMsgDesc = "患者已离开"; } #region 停止计费 if (room.ChargingState == EnumRoomChargingState.Started && !roomService.PauseCharging(evt.ChannelID)) { return(false); } #endregion } else if (evt.State == EnumRoomState.WaitAgain) { RoomOperatorType = "Waiting"; RoomStateChangeMsgDesc = "患者正在候诊,等待医生呼叫"; } if (room.Enable) { var State = room.RoomState; //兼容移动端状态 if (State == EnumRoomState.WaitAgain) { State = EnumRoomState.Waiting; } ///写入日志 if (!roomService.InsertChannelLog(room.ConversationRoomID, userInfo.UserID, userInfo.UserCNName, RoomOperatorType, RoomStateChangeMsgDesc, RoomOperatorRemark)) { return(false); } if (!imService.SendGroupCustomMsg(evt.ChannelID, CurrentOperatorUserIdentifier, new BLL.Sys.DTOs.Request.RequestCustomMsgRoomStateChanged() { Data = new RequestConversationRoomStatusDTO() { ChannelID = evt.ChannelID, State = State, ServiceID = room.ServiceID, ServiceType = room.ServiceType, Duration = room.Duration, ChargingState = room.ChargingState, TotalTime = room.TotalTime, DisableWebSdkInteroperability = room.DisableWebSdkInteroperability }, Desc = RoomStateChangeMsgDesc })) { return(false); } } } catch (XuHos.Integration.QQCloudy.InvalidGroupException) { if (room != null) { room.Enable = false; if (roomService.CompareAndSetChannelInfo(room)) { new XuHos.Service.EventHandlers.ChanneCreateEvent.DefaultHandler().Handle(new EventBus.Events.ChannelCreateEvent() { ChannelID = evt.ChannelID, ServiceID = room.ServiceID, ServiceType = room.ServiceType }); } } return(false); } catch (Exception E) { LogHelper.WriteError(E); return(false); } return(true); }
/// <summary> /// 暂停计时 /// </summary> /// <param name="ChannelID"></param> /// <returns></returns> public bool PauseCharging(string ConversationRoomID) { try { //获取房间信息 var room = GetChannelInfo(ConversationRoomID); //房间存在且状态不是暂停的则执行暂停操作(去重复) if (room != null && room.RoomState != EnumRoomState.AlreadyVisit && (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType)) { var doctorUser = GetChannelUsersInfo(ConversationRoomID).Find(a => a.UserType == EnumUserType.Doctor); if (doctorUser != null) { using (MQChannel channel = new MQChannel()) { channel.BeginTransaction(); if (!channel.Publish(new ChannelSendGroupMsgEvent <RequestCustomMsgRoomDurationChanged>() { Msg = new RequestCustomMsgRoomDurationChanged() { Data = new RequestConversationRoomStatusDTO() { ChannelID = room.ConversationRoomID, State = room.RoomState, ServiceID = room.ServiceID, ServiceType = room.ServiceType, DisableWebSdkInteroperability = room.DisableWebSdkInteroperability, ChargingState = EnumRoomChargingState.Paused, Duration = room.Duration, //总时长 TotalTime = room.TotalTime // 消耗 }, Desc = $"服务计时已暂停,总时长{Format(room.Duration)}, 剩余{Format(room.Duration - room.TotalTime)}" }, ChannelID = room.ConversationRoomID, FromAccount = doctorUser.identifier })) { return(false); } room.ChargingState = EnumRoomChargingState.Paused; if (conversationRoomRepository.UpdateChannelChargeState(room.ConversationRoomID, room.ChargingState)) { channel.Commit(); return(true); } else { return(false); } } } } } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex.Message, ex); return(false); } return(true); }
public bool Handle(Dto.EventBus.ChannelStateChangedEvent evt) { ResponseConversationRoomDTO room = null; try { if (evt == null) { return(true); } if (string.IsNullOrEmpty(evt.FromUserID)) { return(true); } //获取房间信息 room = roomService.GetChannelInfo(evt.ChannelID); #region 参数校验:房间不存在的则不允许修改 if (room == null) { return(true); } #endregion var CurrentOperatorUserIdentifier = evt.FromUseridentifier; var RoomStateChangeMsgDesc = ""; var RoomOperatorType = ""; var RoomOperatorRemark = ""; //结束看诊 if (evt.State == EnumRoomState.AlreadyVisit) { if (evt.UserType == EnumUserType.Doctor) { #region 停止计费 if (room.ChargingState == EnumRoomChargingState.Started && !roomService.PauseCharging(evt.ChannelID)) { return(false); } #endregion #region 更新订单状态 if (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType || room.ServiceType == EnumDoctorServiceType.PicServiceType || room.ServiceType == EnumDoctorServiceType.Consultation) { //订单完成 throw new NotImplementedException("未实现订单完成"); //if (!orderService.Complete("", room.ServiceID)) //{ // KMEHosp.Common.LogHelper.WriteWarn($"订单完成失败,ServiceID={room.ServiceID}"); // return false; //} } #endregion #region 提交处方签名 using (MQChannel mqChannel = new MQChannel()) { if (!mqChannel.Publish(new Dto.EventBus.RecipeSignSubmitEvent() { ServiceID = room.ServiceID })) { LogHelper.DefaultLogger.Error($"发布RecipeSignSubmitEvent失败,ServiceID={room.ServiceID}"); return(false); } } #endregion #region 更新监控指标(记录服务时长,总耗时,就诊是否结束标志) SysMonitorIndexService service = new SysMonitorIndexService(); var values = new Dictionary <string, string>(); values.Add("VisitingServiceChargingState", room.ChargingState.ToString()); //就诊暂停标志 values.Add("VisitingServiceDurationSeconds", room.Duration.ToString()); //就诊服务时长 values.Add("VisitingServiceElapsedSeconds", room.TotalTime.ToString()); //就诊消耗时长 values.Add("VisitingRoomState", room.RoomState.ToString()); //就诊暂停标志 if (!service.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO() { Category = "UserConsult", OutID = room.ServiceID, Values = values })) { return(false); } #endregion //语音、视频看诊 if (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType) { var DoctorID = ""; #region 获取医生编号 if (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType) { UserOPDRegisterService bllOPD = new UserOPDRegisterService(); //获取预约信息 //var opd = bllOPD.Single<UserOPDRegister>(room.ServiceID); var triage = bllOPD.GetDoctorTriageDetail(room.ServiceID); if (triage != null) { DoctorID = triage.TriageDoctorID; } else { LogHelper.DefaultLogger.Error("房间 " + room.ConversationRoomID + " 对应的预约记录不存在"); } } #endregion var DoctorUid = uidService.GetUserIMUid(DoctorID); #region 发送候诊队列通知 roomService.SendWaitingQueueChangeNotice(DoctorID); #endregion } RoomOperatorRemark = $""; RoomOperatorType = "Hangup"; RoomStateChangeMsgDesc = "医生已结束看诊,请对本次服务作出评价"; } else { //无效请求 return(true); } } else if (evt.State == EnumRoomState.Waiting) { //取消呼叫 if (evt.UserType == EnumUserType.Doctor) { RoomStateChangeMsgDesc = "医生取消了呼叫"; RoomOperatorType = "Call_Cancel"; } else { RoomStateChangeMsgDesc = "患者正在候诊,等待医生呼叫"; RoomOperatorType = "Wait"; #region 修改状态并设置分诊编号 room.RoomState = evt.State; room.TriageID = SeqIDHelper.GetSeqId(); //修改就诊时间和开始就诊时间 if (!roomService.UpdateChannelState(room)) { LogHelper.DefaultLogger.Error($"修改房间信息失败,ConversationRoomID={room.ConversationRoomID}"); return(false); } #endregion #region 发送患者进入诊室的通知 if (evt.UserType == EnumUserType.User || evt.UserType == EnumUserType.Drugstore) { using (MQChannel mqChannel = new MQChannel()) { if (!mqChannel.Publish(new Dto.EventBus.UserNoticeEvent() { NoticeType = EnumNoticeSecondType.DoctorVidUserEnterRoomNotice, ServiceID = room.ServiceID })) { LogHelper.DefaultLogger.Error($"Publis UserNoticeEvent失败,ServiceID={room.ServiceID}"); return(false); } } } #endregion } } else if (evt.State == EnumRoomState.Calling) { //医生呼叫患者 if (evt.UserType == EnumUserType.Doctor) { RoomOperatorType = "Calling"; RoomStateChangeMsgDesc = "医生正在呼叫,等待患者接听"; using (MQChannel mqChannel = new MQChannel()) { if (!mqChannel.Publish(new Dto.EventBus.UserNoticeEvent() { NoticeType = EnumNoticeSecondType.UserVidDoctorCallNotice, ServiceID = room.ServiceID })) { return(false); } } } else { //无效请求 return(true); } } else if (evt.State == EnumRoomState.InMedicalTreatment) { if (evt.UserType == EnumUserType.Doctor) { //无效请求 return(true); } //患者接听 else { RoomOperatorType = "Calling_Answer"; RoomStateChangeMsgDesc = "患者已进入诊室"; #region 修改订单状态,用户将不能够再取消订单 if (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType) { #region 语音/视频 修改订单状态(配送中) //if (!orderService.LogisticWithDistributionIn(room.ServiceID)) // return false; #endregion } else if (room.ServiceType == EnumDoctorServiceType.PicServiceType) { #region 图文咨询 修改订单状态(配送中) //BLL.OrderService bllOrder = new OrderService(evt.FromUserID); //if (!bllOrder.LogisticWithDistributionIn(room.ServiceID)) // return false; #endregion } else if (room.ServiceType == EnumDoctorServiceType.Consultation) { #region 更改会诊状态 //var service = new BLL.RemoteConsultation.Implements.RemoteConsultationService(); //var res = service.Start(room.ServiceID, evt.FromUserID, ""); //if (res == EnumApiStatus.ConsultationNotExists || res == EnumApiStatus.ConsultationNotChangeProgress) // return true; //if (res == EnumApiStatus.BizError) // return false; #endregion #region 修改状态 room.RoomState = evt.State; //修改就诊时间和开始就诊时间 if (!roomService.UpdateChannelState(room)) { return(false); } #endregion } #endregion #region 计算候诊耗时并更新统计指标 var log = roomService.GetChannelLastLog(room.ConversationRoomID, "Wait"); if (log != null) { //候诊耗时 var WaitingElapsedSeconds = (DateTime.Now - log.OperationTime).TotalSeconds; RoomOperatorRemark = $"用户候诊用时{WaitingElapsedSeconds}秒"; SysMonitorIndexService service = new SysMonitorIndexService(); var values = new Dictionary <string, string>(); values.Add("WaitingElapsedSeconds", WaitingElapsedSeconds.ToString()); //更新候诊总耗时,指标=原指标+新指标 if (!service.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO() { Category = "UserConsult", OutID = room.ServiceID, Values = values }, true)) { return(false); } } #endregion } } else if (evt.State == EnumRoomState.NoTreatment) { if (evt.UserType == EnumUserType.Doctor) { RoomOperatorType = "Calling_Cancel"; RoomStateChangeMsgDesc = "医生取消了呼叫"; } else { RoomOperatorType = "Waiting_Cancel"; RoomStateChangeMsgDesc = "患者取消了候诊"; } //发送指令前状态是在就诊中 if (evt.ExpectedState == EnumRoomState.InMedicalTreatment) { #region 停止计费 if (room.ChargingState == EnumRoomChargingState.Started && !roomService.PauseCharging(evt.ChannelID)) { return(false); } #endregion } } else if (evt.State == EnumRoomState.Disconnection) { if (evt.UserType == EnumUserType.Doctor) { RoomOperatorType = "Leave"; RoomStateChangeMsgDesc = "医生已离开"; } else { RoomOperatorType = "Leave"; RoomStateChangeMsgDesc = "患者已离开"; } #region 停止计费 if (room.ChargingState == EnumRoomChargingState.Started && !roomService.PauseCharging(evt.ChannelID)) { return(false); } #endregion } else if (evt.State == EnumRoomState.WaitAgain) { RoomOperatorType = "Waiting"; RoomStateChangeMsgDesc = "患者正在候诊,等待医生呼叫"; } if (room.Enable) { var State = room.RoomState; //兼容移动端状态 if (State == EnumRoomState.WaitAgain) { State = EnumRoomState.Waiting; } ///写入日志 if (!roomService.InsertChannelLog(room.ConversationRoomID, room.UserID, room.MemberName, RoomOperatorType, RoomStateChangeMsgDesc, RoomOperatorRemark)) { return(false); } if (!imService.SendGroupCustomMsg(evt.ChannelID, CurrentOperatorUserIdentifier, new RequestCustomMsgRoomStateChanged() { Data = new RequestConversationRoomStatusDTO() { ChannelID = evt.ChannelID, State = State, ServiceID = room.ServiceID, ServiceType = room.ServiceType, Duration = room.Duration, ChargingState = room.ChargingState, TotalTime = room.TotalTime, DisableWebSdkInteroperability = room.DisableWebSdkInteroperability }, Desc = RoomStateChangeMsgDesc })) { return(false); } } } catch (Exception E) { LogHelper.DefaultLogger.Error(E.Message, E); return(false); } return(true); }
public bool Handle(Dto.EventBus.ChannelC2CCreateEvent evt) { try { if (evt == null) { return(true); } if (string.IsNullOrEmpty(evt.FromUserID)) { return(true); } if (evt.AddFriendItem == null || evt.AddFriendItem.Count <= 0) { return(true); } //创建房间请求参数 var createC2CChannelRequest = new RequestConversactionApplyAddFriendDTO() { FromUserIdentifier = evt.FromUserIdentifier, FromUserMemberID = evt.FromUserMemberID, FromUserType = evt.FromUserType, FromUserID = evt.FromUserID, FromUserName = evt.FromUserName, AddFriendItem = new List <AddFriendAccount>() }; //添加群组请求参数 var requestParamsCreateGroup = new List <int>() { evt.FromUserIdentifier }; //添加好友请求参数 var requestParamsApplyAddFriend = new List <Dto.IM.AddFriendAccount>(); //循环好友项 evt.AddFriendItem.ForEach(a => { //好友存在 createC2CChannelRequest.AddFriendItem.Add(new AddFriendAccount() { AddType = "Add_Type_Both", AddWording = a.AddWording, ForceAddFlags = 1, GroupName = a.GroupName, Remark = a.Remark, ToUserID = a.ToUserID, ToUserIdentifier = a.ToUserIdentifier, ToUserMemberID = a.ToUserMemberID, ToUserType = a.ToUserType, ToUserName = a.ToUserName }); requestParamsApplyAddFriend.Add(new Dto.IM.AddFriendAccount { AddWording = a.AddWording, AddSource = "AddSource_Type_WEB",//需要前缀AddSource_Type_ GroupName = a.GroupName, Remark = a.Remark, To_Account = a.ToUserIdentifier.ToString() }); requestParamsCreateGroup.Add(a.ToUserIdentifier); }); //写入数据库 var ChannelInfoList = roomService.ApplyAddFriend(createC2CChannelRequest); using (MQChannel mqChannel = new MQChannel()) { mqChannel.BeginTransaction(); foreach (var item in ChannelInfoList) { var room = item.Value; //根据Uid 获取好友信息 var friend = requestParamsApplyAddFriend.Find(a => a.To_Account == item.Key.ToString()); //如果房间还未启用才调用请求否则忽略 if (!room.Enable) { //发送好友附言消息 if (!mqChannel.Publish(new Dto.EventBus.ChannelSendGroupMsgEvent <string>() { ChannelID = room.ConversationRoomID, FromAccount = evt.FromUserIdentifier, Msg = friend.AddWording })) { return(false); } //发布房间创建完成的领域消息 if (!mqChannel.Publish(new Dto.EventBus.ChannelCreatedEvent() { ChannelID = room.ConversationRoomID, ServiceID = room.ServiceID, ServiceType = room.ServiceType })) { return(false); } //新增好友 if (!imService.ApplyAddFriend(evt.FromUserIdentifier.ToString(), requestParamsApplyAddFriend)) { return(false); } //创建群组 if (!imService.CreateGroup(room.ConversationRoomID, room.ConversationRoomID, room.ServiceType, requestParamsCreateGroup, "", "")) { return(false); } //设置房间已经启用 //room.Enable = true; //更新房间状态 if (!roomService.UpdateRoomEable(room.ConversationRoomID, true)) { return(false); } } } mqChannel.Commit(); } return(true); } catch (Exception E) { LogHelper.DefaultLogger.Error(E); } return(false); }
public bool Handle(Dto.EventBus.ChannelCreatedEvent evt) { if (evt == null) { return(true); } if (evt.ServiceType == EnumDoctorServiceType.PicServiceType) { var LockName = $"{typeof(IfTextConsultCallDrKangAnswer)}:{evt.ChannelID}"; var lockValue = Guid.NewGuid().ToString("N"); //获取分布式锁,获取锁失败时进行锁等待(锁超时时间2秒) if (LockName.Lock(lockValue, TimeSpan.FromSeconds(5))) { try { var room = roomService.GetChannelInfo(evt.ChannelID); #region 频道不可用则返回重试 if (!room.Enable) { return(false); } #endregion #region 发送用户的内容到聊天窗口 //避免重复,去重复 var CacheKey_Derep = new StringCacheKey(StringCacheKeyType.SysDerep_ChannelConsultContentMsg, evt.ChannelID.ToString()); if (!CacheKey_Derep.FromCache <bool>()) { if (!userOPDRegisterService.SendConsultContent(evt.ChannelID, evt.ServiceID)) { return(false); } else { true.ToCache(CacheKey_Derep, TimeSpan.FromMinutes(5)); } } #endregion #region 康博士处理 //已经启用了康博士 if (!string.IsNullOrEmpty(HealthCloud.Consultation.Services.DrKang.Configuration.Config.drKangEnable) && (HealthCloud.Consultation.Services.DrKang.Configuration.Config.drKangEnable == "1" || HealthCloud.Consultation.Services.DrKang.Configuration.Config.drKangEnable.ToUpper() == bool.TrueString.ToUpper()) ) { try { #region 检查当前咨询中康博士回答情况,判断是否还需要继续使用康博士 var cacheKey_Channel_DrKangState = new StringCacheKey(StringCacheKeyType.Channel_DrKangState, evt.ChannelID.ToString()); var Channel_DrKangState = cacheKey_Channel_DrKangState.FromCache <string>(); switch (Channel_DrKangState) { //问答结束,没有匹配的疾病 case "nullMatchDisease": //问答结束,已有明确诊断 case "diagnosis": //无法响应回复 case "nullMatchResponse": //禁用(医生已回复) case "disabled": //出现异常 case "exception": return(true); } #endregion var robotIdentifier = 0; var robotName = "医生助理"; var robotPhotoUrl = ""; //图文咨询记录 var consult = userOPDRegisterService.Single(evt.ServiceID); #region 图文咨询记录不存在、有医生处理、医生已经回复、咨询已完成、咨询已取消都直接忽略 if (consult == null || consult.OPDState == EnumOPDState.Replied || consult.OPDState == EnumOPDState.Completed || consult.OPDState == EnumOPDState.Canceled ) { //记录最后一次问答的状态 "disabled".ToCache(cacheKey_Channel_DrKangState); return(true); } #endregion #region 康博士加入到频道中 robotIdentifier = 0; //康博士加入群组 if (!imservice.AddGroupMember(room.ConversationRoomID, new List <int>() { robotIdentifier })) { return(false); } //新增群组成员 if (!roomService.InsertChannelMembers(room.ConversationRoomID, new List <RequestChannelMemberDTO>() { new RequestChannelMemberDTO() { Identifier = robotIdentifier, UserID = "", UserMemberID = "", UserType = EnumUserType.SysRobot, PhotoUrl = robotPhotoUrl, UserENName = robotName, UserCNName = robotName } })) { return(false); } #endregion if (consult != null) { //咨询内容不为空 if (!string.IsNullOrEmpty(consult.ConsultContent)) { if (consult.Member != null) { #region 使用康博士,记录最后的处理状态,并返回康博士的回答 var SayHello = ""; var QuestionTopic = ""; var QuestionAnswer = new List <string>(); var ret = drKangService.setBaseMsg( consult.Member.MemberName, "", consult.ConsultContent, consult.Member.Gender == EnumUserGender.Male ? "男" : "女", consult.OPDRegisterID); //没有与症状匹配的模板 if (ret.type == "nullMatchTemplate") { //康博士无能为力,医生参与吧 SayHello = "您好,我是医生的助理!为了更好的为您服务,需要了解您的病情"; QuestionTopic = "请详细描述您的症状"; } else if (ret.type == "nullMatchSymptom") { //康博士无能为力,医生参与吧 SayHello = "您好,我是医生的助理!为了更好的为您服务,需要了解您的病情"; QuestionTopic = "请详细描述您的症状"; } //匹配到多个模板需要跟用户确认() else if (ret.type == "confirmTemplate") { //返回提示内容,需要在跟患者确认。 SayHello = "您好,我是医生的助理!为了更好的为您服务,需要了解您的病情"; QuestionTopic = ret.body; } //问答阶段 else if (ret.type == "acking") { SayHello = "您好,我是医生的助理!为了更好的为您服务,需要了解您的病情"; QuestionTopic = ret.body; QuestionAnswer = ret.answer; //返回提示信息,正在问答阶段,医生这时候是否能够介入? } //问答结束,没有匹配的疾病 else if (ret.type == "nullMatchDisease") { //没有明确的诊断,需要医生参与 SayHello = "您好,我是医生的助理!您的情况我已转达给了医生,请耐心等待医生的回复。"; QuestionTopic = ""; } //问答结束,已有明确诊断 else if (ret.type == "diagnosis") { SayHello = "您好,我是医生的助理!您的情况我已转达给了医生,请耐心等待医生的回复。"; QuestionTopic = ret.body; //返回诊断给客户 } //无法回答 else if (ret.type == "nullMatchResponse") { //康博士无法回答的问题,需人工介入 SayHello = "您好,我是医生的助理!您的情况我已转达给了医生,请耐心等待医生的回复。"; QuestionTopic = ""; } //记录最后一次问答的状态 ret.type.ToCache(cacheKey_Channel_DrKangState); #endregion #region 更新监控指标 var values = new Dictionary <string, string>(); values.Add("DrKangState", ret.type);//康博士问诊状态 if (!moniorIndexService.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO() { Category = "UserConsult", OutID = consult.OPDRegisterID, Values = values })) { return(false); } #endregion #region 使用非医生的身份,回答给用户 //避免重复,去重复 var CacheKey_DerepCallDrKangAnswerMsg = new StringCacheKey(StringCacheKeyType.SysDerep_ChannelCallDrKangAnswerMsg, evt.ChannelID.ToString()); if (!CacheKey_DerepCallDrKangAnswerMsg.FromCache <bool>()) { using (MQChannel channle = new MQChannel()) { channle.BeginTransaction(); #region 发送欢迎语句 if (!string.IsNullOrEmpty(SayHello)) { channle.Publish(new Dto.EventBus.ChannelSendGroupMsgEvent <string>() { ChannelID = evt.ChannelID, FromAccount = robotIdentifier, Msg = SayHello }, 2); } #endregion #region 发送提问 //发送问题 if (!string.IsNullOrEmpty(QuestionTopic)) { if (QuestionAnswer.Count > 0) { //发送自定义消息,客户端需要解析。采用点选的方式选择问题 channle.Publish(new Dto.EventBus.ChannelSendGroupMsgEvent <RequestIMCustomMsgSurvey>() { ChannelID = evt.ChannelID, FromAccount = robotIdentifier, Msg = new RequestIMCustomMsgSurvey() { Desc = QuestionTopic, Data = new RadioTopic() { Answer = QuestionAnswer } } }, 4); } else { //发送文字消息 channle.Publish(new Dto.EventBus.ChannelSendGroupMsgEvent <string>() { ChannelID = evt.ChannelID, FromAccount = robotIdentifier, Msg = QuestionTopic }, 4); } } #endregion channle.Commit(); true.ToCache(CacheKey_DerepCallDrKangAnswerMsg, TimeSpan.FromMinutes(5)); return(true); } } #endregion } } else { //记录没有设置基本信息(用户第一次提问时重试) "notSetBaseMsg".ToCache(cacheKey_Channel_DrKangState); } } } catch (Exception ex) { #region 更新监控指标 var values = new Dictionary <string, string>(); values.Add("DrKangState", "exception");//康博士问诊状态 if (!moniorIndexService.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO() { Category = "UserConsult", OutID = room.ServiceID, Values = values })) { return(false); } else { return(true); } #endregion } } else { return(true); } #endregion } catch (Exception E) { HealthCloud.Common.Log.LogHelper.DefaultLogger.Error(E.Message, E); return(false); } finally { LockName.UnLock(lockValue); } } else { return(false); } } return(true); }
public bool Handle(EventBus.Events.OrderPayCompletedEvent evt) { if (evt != null && evt.OrderNo != "" && evt.OrderType == Common.Enum.EnumProductType.RenewUpgrade) { var LockName = $"{typeof(IfRenewUpgradePublishChannelDurationChangeEvent)}:{evt.OrderNo}"; var lockValue = Guid.NewGuid().ToString("N"); //获取分布式锁,获取锁失败时进行锁等待(锁超时时间5秒) if (LockName.Lock(lockValue, TimeSpan.FromSeconds(5))) { try { //当前续费订单外部订单编号,是原始订单的订单编号 var renewUpgradeOrder = orderService.GetOrder(evt.OrderNo); if (renewUpgradeOrder != null) { XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,需发布服务时长变更通知"); //当前续费订单外部订单编号,是原始订单的订单编号 var origOrder = orderService.GetOrder(renewUpgradeOrder.OrderOutID); if (origOrder != null) { var Duration = 0; #region 计算时长(如果续费订单是通过套餐购买则时长则按照套餐中定义的,如果不是则按照系统的时长计算) if (Duration <= 0) { if (origOrder.OrderType == Common.Enum.EnumProductType.video || origOrder.OrderType == Common.Enum.EnumProductType.Phone) { //30分钟 Duration = 60 * 30; } else { //一天 Duration = 60 * 60 * 24; } } #endregion var room = roomService.GetChannelInfo(origOrder.OrderOutID); if (room != null && room.RoomState == Common.Enum.EnumRoomState.AlreadyVisit) { XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,就诊已经结束,续费操作无效"); //忽略无效的续费 return(true); } //原订单已经完成,这时候续费无效。续费订单会进行退款处理 else if (origOrder.OrderState == Common.Enum.EnumOrderState.Finish) { XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,原订单{origOrder.OrderNo}已经完成,续费操作无效"); //忽略无效的续费 return(true); } else { XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,发送服务时长变更通知"); using (MQChannel channel = new MQChannel()) { return(channel.Publish <EventBus.Events.ChannelDurationChangeEvent>(new EventBus.Events.ChannelDurationChangeEvent() { Duration = Duration, ServiceID = origOrder.OrderOutID, OrderNo = evt.OrderNo, NewUpgradeOrderNo = evt.OrderOutID })); } } } else { XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,原订单不存在"); return(true); } } else { XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,订单不存在"); return(true); } } catch (Exception ex) { XuHos.Common.LogHelper.WriteError(ex); return(false); } finally { LockName.UnLock(lockValue); } } else { return(false); } } return(true); }
public bool Handle(EventBus.Events.ChannelEnteredEvent evt) { if (evt == null || string.IsNullOrEmpty(evt.UserID)) { return(true); } try { var service = new XuHos.BLL.Doctor.Implements.DoctorService(); string doctorID = service.GetDoctorIDByUserID(evt.UserID); if (string.IsNullOrEmpty(doctorID)) { return(true); } ConversationRoomService roomService = new ConversationRoomService(); var room = roomService.GetChannelInfo(evt.ChannelID); if (room == null) { return(true); } // 判断医生是否已经进入过诊室 var enteredStateCacheKey = new XuHos.Common.Cache.Keys.EntityListCacheKey <string>(Common.Cache.Keys.StringCacheKeyType.Channel_EnteredState, evt.ChannelID.ToString()); List <string> enteredStates = enteredStateCacheKey.FromCache(); if (enteredStates == null) { enteredStates = new List <string>(); } // 如果医生已进入过诊室 if (enteredStates.Exists(x => x == evt.UserID)) { return(true); } enteredStates.Add(evt.UserID); // 将机器人加入诊室 //int robotIdentifier = 0; //if (!AddRobotToChannel(evt.ChannelID, robotIdentifier)) // return false; int?doctorIdentifier = roomService.GetChannelUsersInfo(evt.ChannelID)?.Where(x => x.UserID == evt.UserID).Select(x => x.identifier).FirstOrDefault(); if (!doctorIdentifier.HasValue) { return(true); } using (MQChannel channle = new MQChannel()) { if (channle.Publish <EventBus.Events.ChannelSendGroupMsgEvent <string> >(new EventBus.Events.ChannelSendGroupMsgEvent <string>() { ChannelID = evt.ChannelID, FromAccount = doctorIdentifier.Value,//robotIdentifier, Msg = "您好,我是康美网络医院在线医生,很高兴为您服务!" })) { // 记录进入诊室状态 enteredStates.ToCache(enteredStateCacheKey); return(true); } else { return(false); } } } catch (Exception e) { LogHelper.WriteError(e); return(false); } }
public bool Handle(EventBus.Events.ChannelChargingEvent evt) { try { if (evt == null) { return(true); } var room = roomService.GetChannelInfo(evt.ChannelID); #region 校验:就诊已经结束则停止计费 if (room == null || room.RoomState == EnumRoomState.AlreadyVisit) { return(true); } #endregion #region 校验:计费已经停止则停止计费 if (room.ChargingState == EnumRoomChargingState.Stoped) { return(true); } #endregion #region 校验:计费已经暂停则停止计费 if (room.ChargingState == EnumRoomChargingState.Paused) { return(true); } #endregion #region 校验:计费没有开始则停止计费 if (room.ChargingState != EnumRoomChargingState.Started) { return(true); } #endregion using (MQChannel mqChannel = new MQChannel()) { room.TotalTime += evt.Interval;//总消耗 #region 更新监控指标(记录服务时长,总耗时,就诊是否结束标志) var order = orderService.GetOrder("", room.ServiceID); if (order != null) { SysMonitorIndexService service = new SysMonitorIndexService(); var values = new Dictionary <string, string>(); values.Add("VisitingServiceChargingState", room.ChargingState.ToString()); //就诊暂停标志 values.Add("VisitingServiceDurationSeconds", room.Duration.ToString()); //就诊服务时长 values.Add("VisitingServiceElapsedSeconds", room.TotalTime.ToString()); //就诊消耗时长 values.Add("VisitingRoomState", room.RoomState.ToString()); //就诊消耗时长 if (!service.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO() { Category = "UserConsult", OutID = order.OrderNo, Values = values })) { return(false); } } #endregion //使用逻辑时间,分布式系统下存在时钟不同步问题,通过上次计费的时间增加15秒得到当前时间 var Now = evt.ChargingTime.AddSeconds(evt.Interval); room.ChargingSeq = evt.Seq; //时钟序号 room.ChargingTime = Now; //计费时间 room.ChargingInterval = evt.Interval; //时钟周期 //计费结束 if ((room.TotalTime >= room.Duration && room.Duration > 0) || (room.Duration <= 0 && room.TotalTime > 60 * 30)) { #region 计费结束 room.RoomState = XuHos.Common.Enum.EnumRoomState.AlreadyVisit; room.EndTime = Now;//这里使用逻辑时间(不要使用系统时间) if (roomService.CompareAndSetChannelInfo(room)) { var DoctorUid = roomService.GetChannelUsersInfo(room.ChannelID).FirstOrDefault(a => a.UserType == EnumUserType.Doctor); if (DoctorUid == null) { return(false); } else { #region 更新订单状态 if (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType || room.ServiceType == EnumDoctorServiceType.PicServiceType || room.ServiceType == EnumDoctorServiceType.Consultation) { //订单完成 if (!orderService.Complete("", room.ServiceID)) { return(false); } } #endregion //语音、视频看诊 if (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType) { #region 发送频道房间挂断消息 if (!imService.SendGroupCustomMsg(evt.ChannelID, DoctorUid.identifier, new BLL.Sys.DTOs.Request.RequestIMCustomMsgRoomTurnOff() { Data = new RequestConversationRoomStatusDTO() { ChannelID = room.ChannelID, Duration = room.Duration, ServiceID = room.ServiceID, ServiceType = room.ServiceType, State = room.RoomState, TotalTime = room.TotalTime, DisableWebSdkInteroperability = room.DisableWebSdkInteroperability, }, Desc = "本次就诊已结束" })) { return(false); } #endregion } return(true); } } #endregion } //不限制时长,会长期占用服务端资源。现在计费之前都会设置默认时长。在没有设置默认时长的时候则是小于0的数据 else if (room.Duration <= 0) { #region 计费中 if (roomService.CompareAndSetChannelInfo(room)) { //发布延时消息,15秒为一个周期。消费端收到消息后重新计算房间已通话时间。 return(mqChannel.Publish <EventBus.Events.ChannelChargingEvent>(new EventBus.Events.ChannelChargingEvent() { ChannelID = evt.ChannelID, Seq = evt.Seq + 1, ChargingTime = Now, Interval = evt.Interval }, evt.Interval)); } else { return(false); } #endregion } //计费未结束,继续计费 else if (room.TotalTime < room.Duration) { #region 计费中 if (roomService.CompareAndSetChannelInfo(room)) { var Interval = room.Duration - room.TotalTime; mqChannel.BeginTransaction(); #region 检查:是否需要发送续费消息.接近一分钟时发送 var Duration = (room.Duration <= 0 ? 0 : room.Duration); var TotalTime = room.TotalTime > Duration ? Duration : room.TotalTime; if (room.ChargingSeq == (room.Duration / room.ChargingInterval) - (60 / room.ChargingInterval)) { //获取患者信息 var otherUser = roomService.GetChannelUsersInfo(room.ChannelID).Where(a => a.UserType != EnumUserType.Doctor); #region 药店不需要发送续费消息 if (!otherUser.Any(a => a.UserType == EnumUserType.Drugstore)) { if (!mqChannel.Publish <EventBus.Events.ChannelExpireEvent>(new EventBus.Events.ChannelExpireEvent() { ServiceID = room.ServiceID })) { return(false); } } #endregion } #endregion //剩余时间大于一个时钟周期,那么按照正常时钟15秒处理 if (Interval > evt.Interval) { //发布延时消息,15秒为一个周期。消费端收到消息后重新计算房间已通话时间。 if (!mqChannel.Publish <EventBus.Events.ChannelChargingEvent>(new EventBus.Events.ChannelChargingEvent() { ChannelID = evt.ChannelID, Seq = evt.Seq + 1, ChargingTime = Now, Interval = evt.Interval }, evt.Interval)) { return(false); } } //如果小于小于时钟周期那么,按照剩余时间执行 else { //发布延时消息,15秒为一个周期。消费端收到消息后重新计算房间已通话时间。 if (!mqChannel.Publish <EventBus.Events.ChannelChargingEvent>(new EventBus.Events.ChannelChargingEvent() { ChannelID = evt.ChannelID, Seq = evt.Seq + 1, ChargingTime = Now, Interval = evt.Interval }, evt.Interval)) { return(false); } } mqChannel.Commit(); return(true); } else { return(false); } #endregion } } } catch (Exception ex) { XuHos.Common.LogHelper.WriteError(ex); } return(false); }
public bool Handle(Dto.EventBus.ChannelNewMsgEvent evt) { try { if (evt.OptPlatform != "RESTAPI" && evt.ServiceType == EnumDoctorServiceType.PicServiceType) { //获取医生回复状态,已经回答的则忽略 var cacheKey_Channel_DoctorAnswerState = new StringCacheKey(StringCacheKeyType.Channel_DoctorAnswerState, evt.ChannelID.ToString()); var Channel_DoctorAnswerState = cacheKey_Channel_DoctorAnswerState.FromCache <bool?>(); if (Channel_DoctorAnswerState.HasValue && Channel_DoctorAnswerState.Value) { return(true); } var room = roomService.GetChannelInfo(evt.ChannelID); if (room != null && ( room.RoomState != EnumRoomState.AlreadyVisit && room.RoomState != EnumRoomState.InMedicalTreatment)) { var userInfo = roomService.GetChannelUsersInfo(evt.ChannelID).Where(t => t.identifier == Convert.ToInt32(evt.FromAccount)).FirstOrDefault(); //医生回复了 if (userInfo != null && userInfo.UserType == EnumUserType.Doctor) { //修改咨询状态为已回复 bllUserConsult.UpdateReplied(evt.ServiceID); var ExpectedState = room.RoomState; if (roomService.CompareAndSetChannelState( room.ConversationRoomID, userInfo.UserID, EnumRoomState.InMedicalTreatment, room.DisableWebSdkInteroperability, ref ExpectedState) != EnumApiStatus.BizOK) { return(false); } //设置医生回复状态 true.ToCache(cacheKey_Channel_DoctorAnswerState, TimeSpan.FromHours(24)); using (MQChannel mqChannel = new MQChannel()) { return(mqChannel.Publish(new Dto.EventBus.UserNoticeEvent() { NoticeType = EnumNoticeSecondType.UserPicDoctorReplyNotice, ServiceID = evt.ServiceID })); } } } } return(true); } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex); } return(false); }
public bool Handle(Dto.EventBus.ChannelDurationChangeEvent evt) { if (evt == null || string.IsNullOrEmpty(evt.OrderNo)) { return(true); } var LockName = $"{typeof(Default)}:{evt.OrderNo}:{evt.NewUpgradeOrderNo}"; var lockValue = Guid.NewGuid().ToString("N"); //获取分布式锁,获取锁失败时进行锁等待(锁超时时间5秒) if (LockName.Lock(lockValue, TimeSpan.FromSeconds(5))) { try { var room = roomService.GetChannelInfo(evt.ServiceID); #region 频道不存在,忽略无效消息 if (room == null || room.RoomState == EnumRoomState.AlreadyVisit) { // return(true); } #endregion #region 已经开始计费时才发送计费消息 if (room.ChargingState != EnumRoomChargingState.Started) { return(true); } #endregion #region 修改服务时长 if (!roomService.IncrementChannelDuration(room.ConversationRoomID, evt.ServiceID, evt.Duration, evt.OrderNo, evt.NewUpgradeOrderNo)) { return(false); } #endregion //重新获取房间信息 room = roomService.GetChannelInfo(evt.ServiceID); //获取医生信息 var doctorUser = roomService.GetChannelUsersInfo(room.ConversationRoomID).Find(a => a.UserType == EnumUserType.Doctor); var Duration = (room.Duration <= 0 ? 0 : room.Duration); var TotalTime = room.TotalTime > Duration ? Duration : room.TotalTime; using (MQChannel channel = new MQChannel()) { ///处方购买消息去重复 var CacheKey_Derep = new StringCacheKey(StringCacheKeyType.SysDerep_OrderNewupgrade, $"{evt.OrderNo}:{evt.NewUpgradeOrderNo}"); //订单续费去重复 if (!CacheKey_Derep.FromCache <bool>()) { #region 发送服务时长变更消息 if (!channel.Publish(new Dto.EventBus.ChannelSendGroupMsgEvent <RequestCustomMsgRoomDurationChanged>() { Msg = new RequestCustomMsgRoomDurationChanged() { Data = new RequestConversationRoomStatusDTO() { ChannelID = room.ConversationRoomID, State = room.RoomState, ServiceID = room.ServiceID, ServiceType = room.ServiceType, ChargingState = room.ChargingState, Duration = Duration, //总时长 TotalTime = TotalTime, // 消耗 DisableWebSdkInteroperability = room.DisableWebSdkInteroperability }, Desc = $"服务计时中,总时长{Format(Duration)}, 剩余{Format(Duration - TotalTime)}" }, ChannelID = room.ConversationRoomID, FromAccount = doctorUser.identifier })) { return(false); } #endregion true.ToCache(CacheKey_Derep, TimeSpan.FromMinutes(5)); } } } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex); return(false); } finally { LockName.UnLock(lockValue); } } else { return(false); } return(true); }