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> /// 暂停计时 /// </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); }
/// <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.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.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(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); }