Beispiel #1
0
        public bool Handle(Dto.EventBus.DoctorAcceptEvent evt)
        {
            try
            {
                if (evt == null || string.IsNullOrEmpty(evt.DoctorID))
                {
                    return(true);
                }

                DoctorTaskService bll = new DoctorTaskService();

                if (evt.ServiceType == EnumDoctorServiceType.VidServiceType || evt.ServiceType == EnumDoctorServiceType.AudServiceType)
                {
                    if (!bll.AcceptVideoCompleted(evt))
                    {
                        return(false);
                    }
                }
                else if (evt.ServiceType == EnumDoctorServiceType.PicServiceType)
                {
                    if (!bll.AcceptTextConsultCompletd(evt))
                    {
                        return(false);
                    }
                }

                #region 更新监控指标(记录处理订单的医生)

                SysMonitorIndexService service = new SysMonitorIndexService();
                var values = new Dictionary <string, string>();
                values.Add("DoctorID", evt.DoctorID);
                values.Add("DoctorName", evt.DoctorName);
                if (!service.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO()
                {
                    Category = "UserConsult",
                    OutID = evt.ServiceID,
                    Values = values
                }))
                {
                    return(false);
                }
                #endregion

                return(true);
            }
            catch (Dto.Exceptions.TaskConcurrentTakeException ex)
            {
                return(true);
            }
            catch (Exception E)
            {
                LogHelper.DefaultLogger.Error(E.Message, E);
            }

            return(false);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        public bool Handle(EventBus.Events.OrderPayCompletedEvent evt)
        {
            if (evt == null || evt.OrderNo == "")
            {
                return(true);
            }

            var opd = opdService.Single(evt.OrderOutID);

            if (opd != null)
            {
                #region 需分诊的订单,等分诊后再处理
                if (opd.DoctorTriage.IsToGuidance == true)
                {
                    return(true);
                }
                #endregion

                var user = userService.GetUserInfoByUserId(opd.UserID);

                if (user != null)
                {
                    var DoctorName = "-";
                    var DoctorID   = "";

                    //正常预约的记录
                    if (opd.DoctorID != "")
                    {
                        var doctor = doctorService.GetDoctorDetail(opd.DoctorID);
                        DoctorID   = doctor.DoctorID;
                        DoctorName = doctor.DoctorName;
                    }

                    SysMonitorIndexService service = new SysMonitorIndexService();
                    var values = new Dictionary <string, string>();
                    values.Add("UserID", opd.UserID + "");
                    values.Add("UserName", user.UserCNName + "");
                    values.Add("UserSource", user.OrgID + "");
                    values.Add("UserLevel", user.UserLevel.ToString());

                    values.Add("DoctorID", DoctorID);                  //医生编号 DoctorAcceptEvent  中维护
                    values.Add("DoctorName", DoctorName);              //医生名称 DoctorAcceptEvent  中维护

                    values.Add("WaitingElapsedSeconds", "-");          //候诊消耗时长 ChannelStateChangedEvent  中维护

                    values.Add("VisitingRoomState", "-");              //就诊结束标志 ChannelChargingEvent/ChannelStateChangedEvent  中维护
                    values.Add("VisitingServiceChargingState", "-");   //服务计费标志 ChannelChargingEvent 中维护
                    values.Add("VisitingServiceDurationSeconds", "-"); //就诊服务时长 ChannelChargingEvent 中维护
                    values.Add("VisitingServiceElapsedSeconds", "-");  //就诊消耗时长 ChannelChargingEvent 中维护

                    values.Add("RecipeTotalCount", "-");               //处方总数量 RecipeSignSubmitEvent 中维护
                    values.Add("RecipeSignedCount", "-");              //处方签名数量 RecipeSignCallbackEvent 中维护
                    values.Add("FallbackRemark", "-");
                    values.Add("FallbackFlag", "-");
                    values.Add("DrKangState", "-");//康博士问诊状态
                    service.InsertAndUpdate(new RequestSysMonitorIndexUpdateDTO()
                    {
                        Category = "UserConsult",
                        OutID    = evt.OrderNo,
                        Values   = values
                    });
                }
            }

            return(true);
        }
Beispiel #7
0
        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);
        }