/// <summary> /// 根据服务编号获取频道编号 /// </summary> /// <param name="ServiceID"></param> /// <returns></returns> public string GetChannelIDByServiceID(string ServiceID, DBEntities db = null) { var cacheKey_ConversationRoomID = new StringCacheKey(StringCacheKeyType.MAP_GetChannelIDByServiceID, ServiceID); string ConversationRoomID = cacheKey_ConversationRoomID.FromCache <string>(); if (string.IsNullOrEmpty(ConversationRoomID)) { bool dbPrivateFlag = false; if (db == null) { db = CreateDb(); dbPrivateFlag = true; } var model = db.ConversationRooms.Where(a => a.ServiceID == ServiceID).Select(a => new { a.ConversationRoomID }).FirstOrDefault(); if (dbPrivateFlag) { db.Dispose(); } if (model != null) { ConversationRoomID = model.ConversationRoomID; ConversationRoomID.ToCache(cacheKey_ConversationRoomID, TimeSpan.FromHours(1)); } else { return(null); } } return(ConversationRoomID); }
/// <summary> /// 获取房间信息 /// </summary> /// <param name="ConversationRoomID"></param> /// <returns></returns> public ResponseConversationRoomDTO GetChannelInfo(string ConversationRoomID, DBEntities db = null) { var cacheKey = new StringCacheKey(StringCacheKeyType.Channel, ConversationRoomID); ResponseConversationRoomDTO room = cacheKey.FromCache <ResponseConversationRoomDTO>(); if (room == null) { bool dbPrivateFlag = false; if (db == null) { db = CreateDb(); dbPrivateFlag = true; } var model = db.ConversationRooms.Where(a => a.ConversationRoomID == ConversationRoomID).FirstOrDefault(); if (dbPrivateFlag) { db.Dispose(); } if (model != null) { room = model.Map <ConversationRoom, ResponseConversationRoomDTO>(); room.ToCache(cacheKey, TimeSpan.FromHours(1)); } } return(room); }
/// <summary> /// 检查验证码 /// </summary> /// <param name="Mobile"></param> /// <param name="MsgType"></param> /// <param name="Title"></param> /// <returns></returns> public bool CheckVerifyCode(string Mobile, string MsgType, string Title) { var cacheKey = new StringCacheKey(StringCacheKeyType.SYS_SMSVerifyCode, $"{Mobile}/{MsgType}/{Title}"); UserShortMessageLog model = cacheKey.FromCache <UserShortMessageLog>(); return(model != null); }
List <RequestMessageExtrasConfigDTO> GetAllExtrasConfig() { var cacheKey = new StringCacheKey(StringCacheKeyType.Sys_NoticeMessageExtrasConfig, ""); ////从缓存中取 var list = cacheKey.FromCache <List <RequestMessageExtrasConfigDTO> >(); if (list == null) { using (DBEntities db = new DBEntities()) { list = db.MessageExtrasConfigs.Where(a => !a.IsDeleted).Select(a => new RequestMessageExtrasConfigDTO() { ExtrasConfigID = a.ExtrasConfigID, MsgTitle = a.MsgTitle, MsgType = a.MsgType, PageArgs = "", PageTarget = a.PageTarget, PageType = a.PageType, PageUrl = a.PageUrl, TerminalType = a.TerminalType }).ToList(); } list.ToCache(cacheKey); } return(list); }
public bool Handle(Dto.EventBus.ChannelNewMsgEvent evt) { if (evt == null) { return(true); } //是通过客户端发送的 if (evt.OptPlatform != "RESTAPI" && IsEnable()) { #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.AlreadyVisit) { // { "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"]; } } else { //医生已经回答 "disabled".ToCache(cacheKey_Channel_DrKangState, TimeSpan.FromHours(24)); } } } return(true); }
/// <summary> /// 检查是否已存在 时代,蒙发利,掌上医院 用外部唯一ID;健康档案 一体机 用身份证号 /// </summary> /// <param name="idNumber"></param> /// <param name="outID"></param> /// <param name="orgID"></param> /// <param name="checkType">1-外部唯一ID;2-身份证号</param> /// <returns></returns> public string ExistUserByCreateID(string outID, string orgID, int checkType) { StringCacheKey GetUserIDByCreateUserID_CacheKey = null; string UserID = null; switch (checkType) { case 1: GetUserIDByCreateUserID_CacheKey = new StringCacheKey(StringCacheKeyType.MAP_GetUserIDByCreateUserIDAndOrgID, $"{orgID}&{outID}"); UserID = GetUserIDByCreateUserID_CacheKey.FromCache <string>(); if (string.IsNullOrEmpty(UserID)) { using (DBEntities db = new DBEntities()) { //康美时代会员,蒙发利会员,掌上医院 //判断 outID 和orgID UserID = (from aa in db.Users where aa.CreateUserID == outID && aa.OrgCode == orgID && !aa.IsDeleted select aa.UserID).FirstOrDefault(); if (!string.IsNullOrEmpty(UserID)) { UserID.ToCache(GetUserIDByCreateUserID_CacheKey, TimeSpan.FromMinutes(_GetUserInfoExpireMinutes())); } } } break; case 2: GetUserIDByCreateUserID_CacheKey = new StringCacheKey(StringCacheKeyType.MAP_GetUserIDByCreateUserID, outID); UserID = GetUserIDByCreateUserID_CacheKey.FromCache <string>(); if (string.IsNullOrEmpty(UserID)) { using (DBEntities db = new DBEntities()) { //双佳一体机,健康档案 //双佳一体机 调用,判断 身份证号 UserID = (from aa in db.Users where aa.CreateUserID == outID && !aa.IsDeleted select aa.UserID).FirstOrDefault(); UserID.ToCache(GetUserIDByCreateUserID_CacheKey, TimeSpan.FromMinutes(_GetUserInfoExpireMinutes())); } } break; } return(UserID); }
/// <summary> /// 获取医生的通信唯一标识 /// </summary> /// <param name="doctorIDList"></param> /// <returns></returns> public int GetUserIMUid(string userID) { var cacheKey = new StringCacheKey(StringCacheKeyType.MAP_GetIMUidByUserID, userID); int?uid = cacheKey.FromCache <int?>(); if (uid == null || !uid.HasValue || uid.Value == 0) { uid = GetUserIMUids(userID).FirstOrDefault(); uid.ToCache(cacheKey); } return(uid.Value); }
public bool Handle(Dto.EventBus.ChannelCreatedEvent evt) { if (evt != null && (evt.ServiceType == EnumDoctorServiceType.AudServiceType || evt.ServiceType == EnumDoctorServiceType.VidServiceType)) { var lockName = $"{nameof(IfVideoOrAudioConsultSendConsultContent)}:{evt.ChannelID}"; var lockValue = Guid.NewGuid().ToString("N"); if (lockName.Lock(lockValue, TimeSpan.FromSeconds(5))) { try { var CacheKey_Derep = new StringCacheKey(StringCacheKeyType.SysDerep_ChannelConsultContentMsg, evt.ChannelID.ToString()); //订单续费去重复 if (!CacheKey_Derep.FromCache <bool>()) { if (service.SendConsultContent(evt.ChannelID, evt.ServiceID)) { true.ToCache(CacheKey_Derep, TimeSpan.FromMinutes(5)); } else { return(false); } } } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex); return(false); } finally { lockName.UnLock(lockValue); } } else { return(false); } } return(true); }
public static string GetPublicKey(uint SdkAppid) { var cacheKey = new StringCacheKey(StringCacheKeyType.KEY_IM_PublicKey, SdkAppid.ToString()); var key = cacheKey.FromCache <string>(); if (string.IsNullOrEmpty(key)) { var basedir = System.AppDomain.CurrentDomain.BaseDirectory; var pri_key_path = System.IO.Path.Combine(basedir, "App_Data/Key/IM", SdkAppid.ToString(), "public_key"); FileStream f = new FileStream(pri_key_path, FileMode.Open, FileAccess.Read); BinaryReader reader = new BinaryReader(f); byte[] b = new byte[f.Length]; reader.Read(b, 0, b.Length); key = Encoding.Default.GetString(b); key.ToCache(cacheKey); } return(key); }
/// <summary> /// 获取所有模板 /// </summary> /// <returns></returns> List <SysShortMessageTemplate> GetAllTemplates() { StringCacheKey shortMsgTemplatesKey = new StringCacheKey(StringCacheKeyType.Sys_ShortMsgTemplates); var shortMsgTemplates = shortMsgTemplatesKey.FromCache <List <SysShortMessageTemplate> >(); if (shortMsgTemplates == null) { using (DBEntities db = new DBEntities()) { shortMsgTemplates = db.SysShortMessageTemplates.ToList(); if (shortMsgTemplates == null) { shortMsgTemplates = new List <SysShortMessageTemplate>(); } shortMsgTemplates.ToCache(shortMsgTemplatesKey); } } return(shortMsgTemplates); }
/// <summary> /// 根据手机号码查询用户编号 /// </summary> /// <param name="UserID"></param> /// <returns></returns> public string GetUserIDByOpenID(string openid) { var GetUserIDByOpenID_CacheKey = new StringCacheKey(StringCacheKeyType.MAP_GetUserIDByOpenID, $"{openid}"); var UserID = GetUserIDByOpenID_CacheKey.FromCache <string>(); //缓存没有命中,则查询数据库获取医生编号并设置缓存(缓存不过期) if (string.IsNullOrEmpty(UserID)) { using (var db = new DBEntities()) { UserID = db.UserWechatMaps.Where(p => p.IsDeleted == false && p.OpenID == openid). Select(t => t.UserID).FirstOrDefault(); if (!string.IsNullOrEmpty(UserID)) { UserID.ToCache(GetUserIDByOpenID_CacheKey, TimeSpan.FromMinutes(_GetUserInfoExpireMinutes())); } } } return(UserID); }
/// <summary> /// 获取房间用户信息 /// </summary> /// <param name="ConversationRoomID"></param> /// <returns></returns> public List <ResponseConversationRoomMemberDTO> GetChannelUsersInfo(string ConversationRoomID, DBEntities db = null) { var cacheKey = new StringCacheKey(StringCacheKeyType.Channel_Member, ConversationRoomID); var result = cacheKey.FromCache <List <ResponseConversationRoomMemberDTO> >(); if (result == null) { bool dbPrivateFlag = false; if (db == null) { db = CreateDb(); dbPrivateFlag = true; } result = ( from roomMember in db.ConversationRoomUids join room in db.ConversationRooms on roomMember.ConversationRoomID equals room.ConversationRoomID where room.ConversationRoomID == ConversationRoomID select new ResponseConversationRoomMemberDTO { identifier = roomMember.Identifier, UserCNName = roomMember.UserCNName, UserENName = roomMember.UserENName, PhotoUrl = roomMember.PhotoUrl, UserType = roomMember.UserType, UserID = roomMember.UserID, }).ToList(); if (dbPrivateFlag) { db.Dispose(); } result.ToCache(cacheKey, TimeSpan.FromHours(2)); } return(result); }
/// <summary> /// 获取医生状态配置 /// </summary> /// <param name="room"></param> /// <returns></returns> public List <ResponseConversationRoomDocConfDTO> GetDoctorConfigs(string DoctorID, DBEntities db = null) { #region 获取医生配置 var CacheKey = new StringCacheKey(StringCacheKeyType.Doctor_Configs, DoctorID); var doctorConfigs = CacheKey.FromCache <List <ResponseConversationRoomDocConfDTO> >(); if (doctorConfigs == null) { bool dbPrivateFlag = false; if (db == null) { db = CreateDb(); dbPrivateFlag = true; } doctorConfigs = db.DoctorConfigs.Where(x => !x.IsDeleted && x.DoctorID == DoctorID).Select(x => new ResponseConversationRoomDocConfDTO { DoctorID = DoctorID, ConfigType = x.ConfigType, ConfigContent = x.ConfigContent }).ToList(); if (dbPrivateFlag) { db.Dispose(); } if (doctorConfigs != null) { doctorConfigs.ToCache(CacheKey); } } return(doctorConfigs); #endregion }
static void SetVideoConsultTaskList() { var cacheKey = new StringCacheKey(StringCacheKeyType.Sys_TaskListResetTime, "Video"); //补库存需要小心前面任务没有处理的情况 if (!cacheKey.FromCache <DateTime?>().HasValue) { var LockName = $"{nameof(SetVideoConsultTaskList)}"; var lockValue = Guid.NewGuid().ToString("N"); if (LockName.Lock(lockValue, TimeSpan.FromSeconds(10))) { try { //医生分组会比较多 var allDoctorGroups = userOPDRegisterRepository.GetDoctorGroupIdList(); //获取所有医生分组的任务状态 var taskGroupQueueStatus = grabOPDService.TaskListEmpty(allDoctorGroups); //查询出所有待处理的图文咨询记录编号和对应的优先级 var allList = userOPDRegisterRepository.GetWaitVideoList(); //循环处理医生分组的情况 foreach (var groupTaskStatus in taskGroupQueueStatus) { var taskGroupID = groupTaskStatus.Key; var taskQueueStatus = groupTaskStatus.Value; //如果其中一个队列是空的 if (taskQueueStatus.Any(a => !a.Value)) { foreach (var taskQueue in taskQueueStatus) { //当前任务列表没有初始化 if (!taskQueue.Value) { //根据队列的优先级匹配相关的咨询记录 var list = allList.Where(opd => ( opd.DoctorGroupID.ToUpper() == taskGroupID.ToUpper()) && opd.Priority == taskQueue.Key).ToList(); foreach (var opd in list) { grabOPDService.DispatchTask(opd.ServiceID, opd.Priority, opd.DoctorGroupID); } } } } } DateTime.Now.ToCache(cacheKey); } catch (Exception ex) { LogHelper.DefaultLogger.Error(ex.Message, ex); } finally { LockName.UnLock(lockValue); } } } }
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); }
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); }
/// <summary> /// 依据角色,系统标识 获取菜单功能权限 /// </summary> /// <param name="roletypes"></param> /// <param name="topModuleID"></param> /// <param name="type">0 菜单 1 功能</param> /// <returns></returns> public List <ResponseSysModuleForDocDTO> GetRoleMenus(List <EnumRoleType> roletypes, string topModuleID, int type = -1) { StringCacheKey SysModuleskey = new StringCacheKey(StringCacheKeyType.Sys_SysModules); var sysModules = SysModuleskey.FromCache <List <ResponseRoleSysModuleDTO> >(); if (sysModules == null) { using (var db = new DBEntities()) { sysModules = (from sys in db.SysModules join sysmap in db.UserRolePrevileges on sys.ModuleID equals sysmap.ModuleID join role in db.UserRoles on sysmap.RoleID equals role.RoleID where !sys.IsDeleted select new ResponseRoleSysModuleDTO() { CSSClass = sys.CSSClass, Level = sys.Level, ModuleID = sys.ModuleID, ModuleName = sys.ModuleName, ModuleType = sys.ModuleType, ModuleUrl = sys.ModuleUrl, ParentModuleID = sys.ParentModuleID, Sort = sys.Sort, Target = sys.Target, TopModuleID = sys.TopModuleID, RoleID = role.RoleID, RoleType = (int)role.RoleType }).ToList(); sysModules.ToCache(SysModuleskey); } } if (sysModules == null) { return(new List <ResponseSysModuleForDocDTO>()); } else { var query = (from sys in sysModules join role in roletypes on sys.RoleType equals(int) role where sys.TopModuleID == topModuleID && !string.IsNullOrEmpty(sys.ModuleUrl) group new { sys.CSSClass, sys.ModuleUrl, sys.Target, sys.ModuleName, sys.Sort, sys.ModuleType } by new { sys.CSSClass, sys.ModuleUrl, sys.Target, sys.ModuleName, sys.Sort, sys.ModuleType } into gro select new ResponseSysModuleForDocDTO() { cssClass = gro.Key.CSSClass, href = gro.Key.ModuleUrl, target = gro.Key.Target, title = gro.Key.ModuleName, Sort = gro.Key.Sort, ModuleType = gro.Key.ModuleType, id = gro.Key.ModuleUrl }); if (type >= 0) { query = query.Where(t => t.ModuleType == type); } return(query.OrderBy(t => t.Sort).ToList()); } }
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(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); }