Пример #1
0
        public bool Handle(ChannelSendGroupMsgEvent <RequestIMCustomMsgSurvey> evt)
        {
            try
            {
                return(imservice.SendGroupCustomMsg(evt.ChannelID, evt.FromAccount, evt.Msg));
            }
            catch (XuHos.Integration.QQCloudy.InvalidGroupException)
            {
                //自动修正房间不存在的问题
                using (XuHos.EventBus.MQChannel mq = new MQChannel())
                {
                    var room = roomService.GetChannelInfo(evt.ChannelID);
                    room.Enable = false;
                    if (roomService.CompareAndSetChannelInfo(room))
                    {
                        mq.Publish <XuHos.EventBus.Events.ChannelCreateEvent>(new ChannelCreateEvent()
                        {
                            ChannelID   = evt.ChannelID,
                            ServiceID   = room.ServiceID,
                            ServiceType = room.ServiceType,
                        });
                    }

                    return(false);
                }
            }
            catch (Exception Ex)
            {
                XuHos.Common.LogHelper.WriteError(Ex);
                return(false);
            }
        }
Пример #2
0
        public MQChannel CreateChannel(string queue, string routeKey, string exchangeType)
        {
            MQConnection conn    = new MQConnection(this.UserName, this.Password, this.Host, this.Port, this.vHost, this.logger);
            MQChannel    channel = conn.CreateReceiveChannel(exchangeType, this.Exchange, queue, routeKey);

            return(channel);
        }
        public bool Handle(Dto.EventBus.ChannelSendGroupMsgEvent <RequestCustomMsgRoomDurationChanged> evt)
        {
            try
            {
                return(imservice.SendGroupCustomMsg(evt.ChannelID, evt.FromAccount, evt.Msg));
            }
            catch (InvalidGroupException)
            {
                //自动修正房间不存在的问题
                using (MQChannel mq = new MQChannel())
                {
                    var room = roomService.GetChannelInfo(evt.ChannelID);
                    if (roomService.UpdateRoomEable(evt.ChannelID, false))
                    {
                        mq.Publish(new Dto.EventBus.ChannelCreateEvent()
                        {
                            ChannelID   = evt.ChannelID,
                            ServiceID   = room.ServiceID,
                            ServiceType = room.ServiceType,
                        });
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                LogHelper.DefaultLogger.Error(ex);
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// 手动获取一个空闲信道,如果获取失败返回null
        /// </summary>
        /// <returns></returns>
        public MQChannel DequeueChannel()
        {
            MQChannel Channel = null;

            bool TryDeq = false;

            int TryDeqCount = 0;

            while (true)
            {
                TryDeq = ChannelQueue.TryDequeue(out Channel);

                if (TryDeq && !Channel.IsDispose)
                {
                    break;
                }

                System.Threading.Thread.Sleep(50);
                TryDeqCount++;

                if (TryDeqCount > 100)
                {
                    return(null);
                }
            }

            return(Channel);
        }
Пример #5
0
        public bool Handle(EventBus.Events.OrderCancelingEvent evt)
        {
            try
            {
                if (evt == null)
                {
                    return(true);
                }

                var service = new XuHos.BLL.OrderService(evt.UserID);
                var result  = service.Cancel(evt.OrderNo, evt.CancelReason, evt.RefundFee);
                //发布通知
                if (result == true)
                {
                    using (XuHos.EventBus.MQChannel mqChannel = new MQChannel())
                    {
                        mqChannel.Publish <EventBus.Events.UserNoticeEvent>(new EventBus.Events.UserNoticeEvent()
                        {
                            ServiceID  = evt.OrderNo,
                            NoticeType = EnumNoticeSecondType.DoctorStopDiagnosisCancelOrderNotice
                        });
                    }
                }

                return(result);
            }
            catch (Exception E)
            {
                XuHos.Common.LogHelper.WriteError(E);
                return(false);
            }
        }
Пример #6
0
 /// <summary>
 /// 用到用完返回空闲信道池
 /// </summary>
 /// <param name="Channel"></param>
 public void EnqueueFreeChannel(MQChannel Channel)
 {
     if (this.ConnList.Contains(Channel.Conn))
     {
         ChannelQueue.Enqueue(Channel);
     }
 }
Пример #7
0
        public MQChannel CreateChannel(string queue, string routeKey, string exchangeType)
        {
            MQConnection     conn    = new MQConnection(this.Config, this.vHost);
            MQChannelManager cm      = new MQChannelManager(conn);
            MQChannel        channel = cm.CreateReceiveChannel(exchangeType, this.Exchange, queue, routeKey);

            return(channel);
        }
Пример #8
0
        public bool Handle(EventBus.Events.OrderPayCompletedEvent evt)
        {
            try
            {
                if (evt != null && evt.OrderNo != "")
                {
                    XuHos.BLL.OrderService  orderService = new BLL.OrderService("");
                    ConversationRoomService roomService  = new ConversationRoomService();


                    if (evt.OrderType == EnumProductType.ImageText ||
                        evt.OrderType == EnumProductType.video ||
                        evt.OrderType == EnumProductType.Phone ||
                        evt.OrderType == EnumProductType.Consultation)
                    {
                        if (string.IsNullOrEmpty(evt.OrderOutID))
                        {
                            var order = orderService.GetOrder(evt.OrderNo);
                            evt.OrderOutID = order.OrderOutID;
                        }

                        var room = roomService.GetChannelInfo(evt.OrderOutID);

                        if (room != null)
                        {
                            using (XuHos.EventBus.MQChannel mqChannel = new MQChannel())
                            {
                                return(mqChannel.Publish(new EventBus.Events.ChannelCreateEvent()
                                {
                                    ServiceID = room.ServiceID,
                                    ServiceType = room.ServiceType,
                                    ChannelID = room.ChannelID
                                }));
                            }
                        }
                        else
                        {
                            var order = orderService.GetOrder("", evt.OrderOutID);
                            if (order.OrderState == EnumOrderState.Canceled)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (Exception E)
            {
                LogHelper.WriteError(E);
                return(false);
            }

            return(true);
        }
Пример #9
0
        public bool Handle(Dto.EventBus.ChannelSendGroupMsgEvent <ResponseUserFileDTO> evt)
        {
            try
            {
                //发送图片消息
                if (evt.Msg.FileType == 0)
                {
                    return(imservice.SendGroupImageMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileUrl));
                }
                //发送图片消息
                else if (evt.Msg.FileType == 1)
                {
                    return(imservice.SendGroupFileMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileSize, evt.Msg.FileName));
                }
                //发送音频消息
                //else if (evt.Msg.FileType == 2)
                //{
                //    using (var filestream = KMEHosp.Common.Storage.Manager.Instance.OpenFile("Audios", evt.Msg.FileUrl))
                //    {
                //        Task.WaitAll(filestream);

                //        var Second = Convert.ToInt32(KMEHosp.Common.Utility.AudioHelper.TotalSeconds(filestream.Result));
                //        return imservice.SendGroupAudioMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileSize, Second);

                //    }
                //}
                else
                {
                    return(true);
                }
            }
            catch (InvalidGroupException)
            {
                //自动修正房间不存在的问题
                using (MQChannel mq = new MQChannel())
                {
                    var room = roomService.GetChannelInfo(evt.ChannelID);
                    room.Enable = false;
                    if (roomService.UpdateRoomEable(evt.ChannelID, false))
                    {
                        mq.Publish(new ChannelCreateEvent()
                        {
                            ChannelID   = evt.ChannelID,
                            ServiceID   = room.ServiceID,
                            ServiceType = room.ServiceType,
                        });
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                LogHelper.DefaultLogger.Error(ex);
                return(false);
            }
        }
Пример #10
0
        public bool Handle(ChannelSendGroupMsgEvent <ResponseUserFileDTO> evt)
        {
            try
            {
                //发送图片消息
                if (evt.Msg.FileType == 0)
                {
                    return(imservice.SendGroupImageMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileUrl));
                }
                //发送图片消息
                else if (evt.Msg.FileType == 1)
                {
                    return(imservice.SendGroupFileMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileSize, evt.Msg.FileName));
                }
                //发送音频消息
                else if (evt.Msg.FileType == 2)
                {
                    using (var filestream = XuHos.Common.Storage.Manager.Instance.OpenFile("Audios", evt.Msg.FileUrl))
                    {
                        Task.WaitAll(filestream);

                        var Second = Convert.ToInt32(XuHos.Common.Utility.AudioHelper.TotalSeconds(filestream.Result));
                        return(imservice.SendGroupAudioMsg(evt.ChannelID, evt.FromAccount, evt.Msg.FileID, evt.Msg.FileSize, Second));
                    }
                }
                else
                {
                    return(true);
                }
            }
            catch (XuHos.Integration.QQCloudy.InvalidGroupException)
            {
                //自动修正房间不存在的问题
                using (XuHos.EventBus.MQChannel mq = new MQChannel())
                {
                    var room = roomService.GetChannelInfo(evt.ChannelID);
                    room.Enable = false;
                    if (roomService.CompareAndSetChannelInfo(room))
                    {
                        mq.Publish <XuHos.EventBus.Events.ChannelCreateEvent>(new ChannelCreateEvent()
                        {
                            ChannelID   = evt.ChannelID,
                            ServiceID   = room.ServiceID,
                            ServiceType = room.ServiceType,
                        });
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                XuHos.Common.LogHelper.WriteError(ex);
                return(false);
            }
        }
Пример #11
0
 public ApiResult Triage([FromBody] RequestConversationRoomTriageDTO request)
 {
     using (MQChannel mqChannel = new MQChannel())
     {
         return(mqChannel.Publish(new Dto.EventBus.ChannelTriageChangeEvent()
         {
             ChannelID = request.ChannelID,
             DoctorID = request.CurrentOperatorDoctorID,
             TriageID = HealthCloud.Common.Utility.SeqIDHelper.GetSeqId().ToString()
         }).ToApiResultForBoolean());
     }
 }
Пример #12
0
 /// <summary>
 ///  启动订阅
 /// </summary>
 public void Start()
 {
     if (started)
     {
         Console.WriteLine("服务已经启动!");
         return;
     }
     foreach (var item in this.Binds)
     {
         Channel = CreateChannel(item.Queue, item.RouterKey, item.ExchangeType);
         Channel.OnReceivedCallback = item.OnReceived;
         this.List.Add(Channel);
     }
     started = true;
 }
Пример #13
0
        /// <summary>
        ///  启动订阅
        /// </summary>
        public void Start()
        {
            if (started)
            {
                return;
            }
            MQConnection     conn    = new MQConnection(this.Config, this.vHost);
            MQChannelManager manager = new MQChannelManager(conn);

            foreach (var item in this.Queue)
            {
                MQChannel channel = manager.CreateReceiveChannel(item.ExchangeType, this.Exchange, item.Queue, item.RouterKey);
                channel.OnReceivedCallBack = item.OnReceived;
                this.Channels.Add(channel);
            }
            started = true;
        }
        /// <summary>
        /// 领取问题(盲领)
        /// </summary>
        /// <param name="AcceptDoctorID"></param>
        /// <returns></returns>
        public ApiResult AcceptTextConsult(string AcceptDoctorID, List <string> groupList)
        {
            if (string.IsNullOrEmpty(AcceptDoctorID))
            {
                return(EnumApiStatus.BizError.ToApiResultForApiStatus());
            }

            //初始化已经领取列表
            SetTextConsultDoingList(AcceptDoctorID);
            SetTextConsultFinishedList(AcceptDoctorID);

            var UserConsultID = "";

            //获取医生分组
            //var groupList = doctorService.GetDoctorGroupIdListByDoctorID(AcceptDoctorID);

            var takeResult = grabConsultService.TakeTask(AcceptDoctorID, out UserConsultID, groupList);

            //领取了任务
            if (!string.IsNullOrEmpty(UserConsultID))
            {
                var task = userOPDRegisterRepository.GetTask(UserConsultID);

                if (task != null)
                {
                    using (MQChannel mqChannel = new MQChannel())
                    {
                        if (mqChannel.Publish(new DoctorAcceptEvent()
                        {
                            DoctorID = AcceptDoctorID,
                            ServiceID = task.OPDRegisterID,
                            ServiceType = task.OPDType,
                            ChannelID = task.ChannelID,
                            UserID = task.UserID,
                            UserMemberID = task.MemberID
                        }))
                        {
                            return(task.ToApiResultForObject(takeResult));
                        }
                    }
                }
            }

            return(takeResult.ToApiResultForApiStatus());
        }
Пример #15
0
        public bool Handle(EventBus.Events.OrderCanceledEvent evt)
        {
            try
            {
                if (evt == null)
                {
                    return(true);
                }

                //查询出所有交易日志
                var logs = service.QueryOrderTradeLogs(evt.OrderNo);

                using (XuHos.EventBus.MQChannel mqChannel = new MQChannel())
                {
                    mqChannel.BeginTransaction();

                    //循环所哟交易日志
                    foreach (var trade in logs)
                    {
                        //如果不是线下付款的方式,并且已经交易成功了则开始退款
                        if (trade.PayType != EnumPayType.OfflinePay &&
                            trade.TradeStatus != EnumTradeState.TRADE_NOT_EXIST &&
                            trade.TradeStatus != EnumTradeState.WAIT_BUYER_PAY)
                        {
                            mqChannel.Publish <EventBus.Events.OrderRefundEvent>(new EventBus.Events.OrderRefundEvent()
                            {
                                OrderNo = trade.OrderNo,
                                PayType = trade.PayType,
                                TradeNo = trade.TradeNo
                            });
                        }
                    }

                    mqChannel.Commit();
                    return(true);
                }
            }
            catch (Exception E)
            {
                XuHos.Common.LogHelper.WriteError(E);
            }

            return(false);
        }
        /// <summary>
        /// 领取问题(盲领)
        /// 作者:郭明
        /// 日期:2017年5月18日
        /// </summary>
        /// <param name="AcceptDoctorID"></param>
        /// <returns></returns>
        public ApiResult AcceptVideo(string DoctorID, List <string> groupList)
        {
            if (string.IsNullOrEmpty(DoctorID))
            {
                return(EnumApiStatus.BizError.ToApiResultForApiStatus());
            }

            //设置识破正在处理的列表
            SetVideoConsultDoingList(DoctorID);
            //设置视频已经完成列表
            SetVideoConsultFinishedList(DoctorID);

            var OPDRegisterID = "";

            //获取医生分组
            var takeResult = grabOPDService.TakeTask(DoctorID, out OPDRegisterID, groupList);

            if (!string.IsNullOrEmpty(OPDRegisterID))
            {
                var task = userOPDRegisterRepository.GetTask(OPDRegisterID);

                if (task != null)
                {
                    using (MQChannel mqChannel = new MQChannel())
                    {
                        if (mqChannel.Publish <DoctorAcceptEvent>(new DoctorAcceptEvent()
                        {
                            DoctorID = DoctorID,
                            ServiceID = task.OPDRegisterID,
                            ServiceType = task.OPDType,
                            ChannelID = task.ChannelID,
                            UserID = task.UserID,
                            UserMemberID = task.MemberID
                        }))
                        {
                            return(task.ToApiResultForObject(takeResult));
                        }
                    }
                }
            }

            return(takeResult.ToApiResultForApiStatus());
        }
Пример #17
0
        /// <summary>
        /// 动态创建地区监听队列
        /// </summary>
        /// <param name="mqManager"></param>
        /// <param name="config"></param>
        /// <param name="cityCode"></param>
        private static void DynamicAddMonitorCityCode(MQServcieManager mqManager, MQConfig config, string cityCode)
        {
            MQQueueInfo mQQueueInfo = new MQQueueInfo()
            {
                QueueName    = MQManufacturerCode + cityCode + "YunParkCameraQueue",
                RoutingKey   = cityCode,
                ExchangeType = RabbitMQ.Client.ExchangeType.Topic
            };

            IMQService mQService = new CreateMQService(config, mQQueueInfo);

            mQService.Exchange = MQYunCameraExchange.TopicFuJiCaYunCameraParkPushExchange;

            MQChannel m_MQChannel3 = new MQChannel(mQQueueInfo.ExchangeType, mQQueueInfo.ExchangeName, mQQueueInfo.QueueName, mQQueueInfo.RoutingKey);
            Dictionary <IMQService, MQChannel> IMQServiceAndMQChannel3 = new Dictionary <IMQService, MQChannel>();

            IMQServiceAndMQChannel3.Add(mQService, m_MQChannel3);

            mqManager.DynamicAddMQChannel.Enqueue(IMQServiceAndMQChannel3);
        }
Пример #18
0
        /// <summary>
        /// 自动调用信道执行方法
        /// </summary>
        /// <param name="Action"></param>
        /// <returns></returns>
        public bool AutoChannel(Action <MQChannel> Action)
        {
            MQChannel Channel = null;

            bool TryDeq      = false;
            int  TryDeqCount = 0;

            while (true)
            {
                TryDeq = ChannelQueue.TryDequeue(out Channel);

                if (TryDeq && !Channel.IsDispose)
                {
                    break;
                }

                System.Threading.Thread.Sleep(50);

                TryDeqCount++;

                if (TryDeqCount > 100)
                {
                    return(false);
                }
            }

            try
            {
                Action.Invoke(Channel);
            }
            catch (Exception)
            {
            }
            finally
            {
                ChannelQueue.Enqueue(Channel);
            }
            return(true);
        }
Пример #19
0
        public bool Handle(Dto.EventBus.ChannelSendGroupMsgEvent <string> evt)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(evt.Msg))
                {
                    return(true);
                }
                else
                {
                    return(imservice.SendGroupTextMsg(evt.ChannelID, evt.FromAccount, evt.Msg));
                }
            }
            catch (InvalidGroupException)
            {
                //自动修正房间不存在的问题
                using (MQChannel mq = new MQChannel())
                {
                    var room = roomService.GetChannelInfo(evt.ChannelID);
                    if (roomService.UpdateRoomEable(evt.ChannelID, false))
                    {
                        mq.Publish(new Dto.EventBus.ChannelCreateEvent()
                        {
                            ChannelID   = evt.ChannelID,
                            ServiceID   = room.ServiceID,
                            ServiceType = room.ServiceType,
                        });
                    }

                    return(false);
                }
            }
            catch (Exception Ex)
            {
                LogHelper.DefaultLogger.Error(Ex);
                return(false);
            }
        }
Пример #20
0
        /// <summary>
        /// 插入消息表并推送消息
        /// </summary>
        /// <param name="model">消息</param>
        /// <param name="ToUserList">接收消息的用户</param>
        /// <param name="pageArgs">扩展参数,该参数会一起推给客户端</param>
        /// <param name="silence">是否静默推送</param>
        /// <returns></returns>
        public bool SendNotice(
            RequestNoticeMessageDTO model,
            List <string> ToUserList = null,
            bool silence             = false,
            string ServiceID         = "",
            string FromUserID        = "",
            EnumTargetUserCodeType ToUserListType = EnumTargetUserCodeType.UserID)
        {
            if (ToUserList == null)
            {
                ToUserList = new List <string>();
            }

            var extrasIOS     = _GetJMessageExtras(EnumTerminalType.IOS, model, model.PageArgs);
            var extrasAndroid = _GetJMessageExtras(EnumTerminalType.Android, model, model.PageArgs);

            using (MQChannel mqChanne = new MQChannel())
            {
                return(mqChanne.Publish(new Dto.EventBus.UserNoticeSendEvent()
                {
                    MessageID = model.MessageID,
                    Content = model.Content,
                    Title = model.Title,
                    Summary = model.Summary,
                    PageArgs = model.PageArgs,
                    ClientName = model.ClientName,
                    NoticeDate = model.NoticeDate,
                    NoticeSecondType = model.NoticeSecondType,
                    FromUserID = FromUserID,
                    ToUserList = ToUserList,
                    ToUserListType = ToUserListType,
                    extrasAndroid = extrasAndroid,
                    extrasIOS = extrasIOS,
                    serviceID = ServiceID,
                    silence = silence
                }));
            }
        }
        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);
        }
Пример #22
0
        /// <summary>
        /// 暂停计时
        /// </summary>
        /// <param name="ChannelID"></param>
        /// <returns></returns>
        public bool PauseCharging(string ConversationRoomID)
        {
            try
            {
                //获取房间信息
                var room = GetChannelInfo(ConversationRoomID);

                //房间存在且状态不是暂停的则执行暂停操作(去重复)
                if (room != null && room.RoomState != EnumRoomState.AlreadyVisit && (room.ServiceType == EnumDoctorServiceType.AudServiceType || room.ServiceType == EnumDoctorServiceType.VidServiceType))
                {
                    var doctorUser = GetChannelUsersInfo(ConversationRoomID).Find(a => a.UserType == EnumUserType.Doctor);

                    if (doctorUser != null)
                    {
                        using (MQChannel channel = new MQChannel())
                        {
                            channel.BeginTransaction();

                            if (!channel.Publish(new ChannelSendGroupMsgEvent <RequestCustomMsgRoomDurationChanged>()
                            {
                                Msg = new RequestCustomMsgRoomDurationChanged()
                                {
                                    Data = new RequestConversationRoomStatusDTO()
                                    {
                                        ChannelID = room.ConversationRoomID,
                                        State = room.RoomState,
                                        ServiceID = room.ServiceID,
                                        ServiceType = room.ServiceType,
                                        DisableWebSdkInteroperability = room.DisableWebSdkInteroperability,
                                        ChargingState = EnumRoomChargingState.Paused,
                                        Duration = room.Duration,  //总时长
                                        TotalTime = room.TotalTime // 消耗
                                    },
                                    Desc = $"服务计时已暂停,总时长{Format(room.Duration)}, 剩余{Format(room.Duration - room.TotalTime)}"
                                },
                                ChannelID = room.ConversationRoomID,
                                FromAccount = doctorUser.identifier
                            }))
                            {
                                return(false);
                            }

                            room.ChargingState = EnumRoomChargingState.Paused;

                            if (conversationRoomRepository.UpdateChannelChargeState(room.ConversationRoomID, room.ChargingState))
                            {
                                channel.Commit();
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.DefaultLogger.Error(ex.Message, ex);
                return(false);
            }

            return(true);
        }
Пример #23
0
        /// <summary>
        /// 重新开始计时
        /// </summary>
        /// <param name="ChannelID"></param>
        /// <returns></returns>
        public bool RestartCharging(string ConversationRoomID)
        {
            try
            {
                //获取房间信息
                var room       = GetChannelInfo(ConversationRoomID);
                var doctorUser = GetChannelUsersInfo(ConversationRoomID).Find(a => a.UserType == EnumUserType.Doctor);

                #region 房间不存在或医生不存在则忽略
                if (room == null && doctorUser == null)
                {
                    return(true);
                }
                #endregion

                #region 更新房间计费状态
                if (room.ChargingState != EnumRoomChargingState.Started)
                {
                    room.ChargingState = EnumRoomChargingState.Started;

                    if (!conversationRoomRepository.UpdateChannelChargeState(room.ConversationRoomID, room.ChargingState))
                    {
                        return(false);
                    }
                }
                #endregion

                using (MQChannel mqChannel = new MQChannel())
                {
                    mqChannel.BeginTransaction();

                    #region 发布延时消息,15秒为一个周期。消费端收到消息后重新计算房间已通话时间。
                    if (!mqChannel.Publish <ChannelChargingEvent>(new ChannelChargingEvent()
                    {
                        ChannelID = ConversationRoomID,
                        Seq = room.ChargingSeq + 1,
                        ChargingTime = room.ChargingTime,
                        Interval = room.ChargingInterval
                    }))
                    {
                        return(false);
                    }
                    #endregion

                    #region 发送服务时长变更消息
                    if (!mqChannel.Publish(new ChannelSendGroupMsgEvent <RequestCustomMsgRoomDurationChanged>()
                    {
                        Msg = new RequestCustomMsgRoomDurationChanged()
                        {
                            Data = new RequestConversationRoomStatusDTO()
                            {
                                ChannelID = room.ConversationRoomID,
                                State = room.RoomState,
                                ServiceID = room.ServiceID,
                                ServiceType = room.ServiceType,
                                DisableWebSdkInteroperability = room.DisableWebSdkInteroperability,
                                ChargingState = EnumRoomChargingState.Started,
                                Duration = room.Duration,  //总时长
                                TotalTime = room.TotalTime // 消耗
                            },
                            Desc = $"服务计时已启动,总时长{Format(room.Duration)}, 剩余{Format(room.Duration - room.TotalTime)}"
                        },
                        ChannelID = room.ConversationRoomID,
                        FromAccount = doctorUser.identifier
                    }))
                    {
                        return(false);
                    }
                    #endregion

                    mqChannel.Commit();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogHelper.DefaultLogger.Error(ex.Message, ex);
                return(false);
            }
        }
Пример #24
0
        /// <summary>
        /// 比较并设置房间状态
        /// </summary>
        /// <param name="ChannelID"></param>
        /// <param name="FromUserID"></param>
        /// <param name="State"></param>
        /// <param name="DisableWebSdkInteroperability"></param>
        /// <param name="ExpectedState"> 返回值</param>
        /// <returns></returns>
        public EnumApiStatus CompareAndSetChannelState(string ConversationRoomID, string FromUserID, EnumRoomState State, bool DisableWebSdkInteroperability, ref EnumRoomState ExpectedState)
        {
            try
            {
                var room = GetChannelInfo(ConversationRoomID);

                #region 校验:房间已标记为失效的,不可设置房间状态
                if (room.Close)
                {
                    return(EnumApiStatus.BizChannelSetStateIfClose);
                }
                #endregion

                #region 校验:房间状态未启用
                if (!room.Enable)
                {
                    //频道未就绪(客户端重试)
                    return(EnumApiStatus.BizChannelNotReady);
                }
                #endregion

                #region 校验:当前房间状态和预期的房间状态一致才允许设置

                #region 处理特殊状态情况 客户端没有WaitAgain 状态需要统一
                if (ExpectedState == EnumRoomState.Waiting && room.RoomState == EnumRoomState.WaitAgain)
                {
                    ExpectedState = room.RoomState;
                }
                #endregion

                if (room.RoomState != ExpectedState)
                {
                    //返回新的状态给客户端,客户端需要同步
                    ExpectedState = room.RoomState;

                    //前端用户只需要知道有候诊状态即可,不需要知道有重复候诊的状态
                    if (ExpectedState == EnumRoomState.WaitAgain)
                    {
                        ExpectedState = EnumRoomState.Waiting;
                    }

                    //当前状态不是预期状态
                    return(EnumApiStatus.BizChannelRejectSetStateIfNotExpectedState);
                }
                #endregion

                #region 校验:只能在预约时间内进入诊室或提前30分钟进入诊室
                if ((State == EnumRoomState.WaitAgain || State == EnumRoomState.Waiting))
                {
                    if (DateTime.Now <= room.BeginTime.AddMinutes(-30))
                    {
                        return(EnumApiStatus.BizChannelRejectConnectIfNoReservationTime);
                    }
                }
                #endregion

                #region 校验:医生在休诊状态下不可进入诊室
                if ((State == EnumRoomState.WaitAgain || State == EnumRoomState.Waiting))
                {
                    if (IsChannelDiagnoseOff(room))
                    {
                        return(EnumApiStatus.BizChannelRejectConnectIfDiagnoseOff);
                    }
                }
                #endregion

                #region 房间状态切换的规则
                switch (room.RoomState)
                {
                case EnumRoomState.AlreadyVisit:
                {
                    //就诊已经结束不能在设置状态
                    return(EnumApiStatus.BizOK);
                }

                case EnumRoomState.NoTreatment:
                {
                    if (State == EnumRoomState.NoTreatment)
                    {
                        State = EnumRoomState.NoTreatment;
                    }
                    else if (State == EnumRoomState.InMedicalTreatment)
                    {
                        State = EnumRoomState.InMedicalTreatment;
                    }
                    else
                    {
                        State = EnumRoomState.Waiting;
                    }
                    break;
                }

                case EnumRoomState.Waiting:
                {
                    //重试
                    if (State == EnumRoomState.Waiting || State == EnumRoomState.WaitAgain)
                    {
                        State = EnumRoomState.Waiting;
                    }
                    //医生呼叫
                    else if (State == EnumRoomState.Calling)
                    {
                        State = EnumRoomState.Calling;
                    }
                    //接听
                    else if (State == EnumRoomState.InMedicalTreatment)
                    {
                        State = EnumRoomState.InMedicalTreatment;
                    }
                    //候诊界面,用户点击离开或者异常断开都是未就诊
                    else
                    {
                        State = EnumRoomState.NoTreatment;
                    }
                    break;
                }

                case EnumRoomState.Calling:
                {
                    //重试
                    if (State == EnumRoomState.Calling)
                    {
                        State = EnumRoomState.Calling;
                    }
                    //接听
                    else if (State == EnumRoomState.InMedicalTreatment)
                    {
                        State = EnumRoomState.InMedicalTreatment;
                    }
                    //取消呼叫 或者拒绝
                    else if (State == EnumRoomState.Waiting || State == EnumRoomState.WaitAgain)
                    {
                        State = EnumRoomState.WaitAgain;
                    }
                    else
                    {
                        State = EnumRoomState.Disconnection;
                    }
                    break;
                }

                case EnumRoomState.InMedicalTreatment:
                {
                    //重试
                    if (State == EnumRoomState.InMedicalTreatment)
                    {
                        State = EnumRoomState.InMedicalTreatment;
                    }
                    //医生挂断
                    else if (State == EnumRoomState.AlreadyVisit)
                    {
                        State = EnumRoomState.AlreadyVisit;
                    }
                    //重试候诊
                    else if (State == EnumRoomState.Waiting || State == EnumRoomState.WaitAgain)
                    {
                        State = EnumRoomState.WaitAgain;
                    }
                    //患者离开,一会再来
                    else
                    {
                        State = EnumRoomState.Disconnection;
                    }
                    break;
                }

                case EnumRoomState.Disconnection:
                {
                    //医生挂断
                    if (State == EnumRoomState.AlreadyVisit)
                    {
                        State = EnumRoomState.AlreadyVisit;
                    }
                    //取消呼叫 或者拒绝
                    else if (State == EnumRoomState.Waiting || State == EnumRoomState.WaitAgain)
                    {
                        State = EnumRoomState.WaitAgain;
                    }
                    else
                    {
                        State = EnumRoomState.Disconnection;
                    }
                    break;
                }

                case EnumRoomState.WaitAgain:
                {
                    //医生呼叫
                    if (State == EnumRoomState.Calling)
                    {
                        State = EnumRoomState.Calling;
                    }
                    //取消呼叫 或者拒绝
                    else if (State == EnumRoomState.Waiting || State == EnumRoomState.WaitAgain)
                    {
                        State = EnumRoomState.WaitAgain;
                    }
                    else
                    {
                        State = EnumRoomState.Disconnection;
                    }
                    break;
                }
                }
                #endregion

                //默认高版本,当前禁用互通性(SDK直接可以互通的情况下)
                if (room.DisableWebSdkInteroperability)
                {
                    room.DisableWebSdkInteroperability = DisableWebSdkInteroperability;
                }

                room.RoomState = State;

                #region 推送状态变更消息,并修改状态
                using (MQChannel mqChannel = new MQChannel())
                {
                    mqChannel.BeginTransaction();
                    if (!mqChannel.Publish(new ChannelStateChangedEvent()
                    {
                        ChannelID = ConversationRoomID,
                        FromUserID = FromUserID,
                        State = State,
                        ExpectedState = ExpectedState,
                        DisableWebSdkInteroperability = room.DisableWebSdkInteroperability
                    }))
                    {
                        return(EnumApiStatus.BizError);
                    }

                    if (conversationRoomRepository.UpdateChannelState(room.ConversationRoomID, room.RoomState))
                    {
                        mqChannel.Commit();
                        return(EnumApiStatus.BizOK);
                    }
                    else
                    {
                        return(EnumApiStatus.BizError);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.DefaultLogger.Error(ex.Message, ex);
                //业务错误
                return(EnumApiStatus.BizError);
            }
        }
Пример #25
0
        /// <summary>
        /// 开始计时
        /// </summary>
        /// <param name="ChannelID"></param>
        /// <param name="Duration"></param>
        /// <param name="ServiceID"></param>
        /// <param name="OrderNo"></param>
        /// <returns></returns>
        public bool StartCharging(string ConversationRoomID, int Duration, string ServiceID, string OrderNo)
        {
            try
            {
                var room = GetChannelInfo(ConversationRoomID);

                #region 修改房间开始时间和已经消耗的时间
                //第一次进入诊室的时候
                if (room.TotalTime < 1)
                {
                    //room.BeginTime = DateTime.Now;
                    //room.TotalTime = 1;

                    if (!conversationRoomRepository.UpdateChannelChargeTime(ConversationRoomID, 1, DateTime.Now))
                    {
                        return(false);
                    }
                }
                #endregion

                using (MQChannel mqChannel = new MQChannel())
                {
                    mqChannel.BeginTransaction();

                    //存在重复的请求,消费端需要去重复
                    if (!mqChannel.Publish(new ChannelDurationChangeEvent()
                    {
                        Duration = Duration, //套餐里面的服务时长单位是分钟需要转换成秒
                        ServiceID = ServiceID,
                        OrderNo = OrderNo,
                        NewUpgradeOrderNo = OrderNo
                    }))
                    {
                        return(false);
                    }

                    //存在重复的请求,消费端需要去重复
                    //发布延时消息,15秒为一个周期。消费端收到消息后重新计算房间已通话时间。
                    if (!mqChannel.Publish(new ChannelChargingEvent()
                    {
                        ChannelID = ConversationRoomID,
                        Seq = 0,
                        ChargingTime = room.BeginTime,
                        Interval = 15
                    }))
                    {
                        return(false);
                    }

                    room.ChargingState = EnumRoomChargingState.Started;

                    if (conversationRoomRepository.UpdateChannelChargeState(ConversationRoomID, EnumRoomChargingState.Started))
                    {
                        mqChannel.Commit();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.DefaultLogger.Error(ex.Message, ex);
                return(false);
            }
        }
Пример #26
0
        public bool Handle(EventBus.Events.OrderEvaluationEvent evt)
        {
            if (evt == null)
            {
                return(true);
            }

            try
            {
                var ProviderID = "";
                var UserID     = "";

                #region 获取服务提供者的编号

                var order = orderService.GetOrder("", evt.OuterID);

                if (order != null)
                {
                    UserID = order.UserID;

                    switch (order.OrderType)
                    {
                    case EnumProductType.video:
                    {
                        ProviderID = new XuHos.BLL.UserOPDRegisterService(order.UserID).Single <XuHos.DTO.UserOPDRegisterDTO>(order.OrderOutID).DoctorID;
                    }; break;
                    }
                }
                #endregion


                if (string.IsNullOrEmpty(ProviderID) || string.IsNullOrEmpty(UserID))
                {
                    return(true);
                }

                #region 写评论记录
                ServiceEvaluation model = new ServiceEvaluation()
                {
                    UserID         = UserID,
                    EvaluationTags = evt.EvaluationTags,
                    ProviderID     = ProviderID,
                    Content        = evt.Content,
                    CreateTime     = DateTime.Now,
                    CreateUserID   = string.IsNullOrEmpty(evt.CreateUserID) ? UserID : evt.CreateUserID,
                    OuterID        = evt.OuterID,
                    Score          = evt.Score,
                    ServiceType    = order.OrderType
                };

                if (!doctorService.Evaluation(model))
                {
                    return(false);
                }
                #endregion

                #region 写领域消息,评论完成
                using (XuHos.EventBus.MQChannel mqChannel = new MQChannel())
                {
                    if (!mqChannel.Publish <XuHos.EventBus.Events.OrderEvaluationCompletedEvent>(new EventBus.Events.OrderEvaluationCompletedEvent()
                    {
                        Content = evt.Content,
                        CreateUserID = evt.CreateUserID,
                        EvaluationTags = evt.EvaluationTags,
                        OuterID = evt.OuterID,
                        ProviderID = ProviderID,
                        Score = evt.Score
                    }))
                    {
                        return(false);
                    }
                }
                #endregion
            }
            catch (Exception Ex)
            {
                XuHos.Common.LogHelper.WriteError(Ex);
                return(false);
            }

            return(true);
        }
        public bool Handle(EventBus.Events.OrderPayCompletedEvent evt)
        {
            if (evt != null && evt.OrderNo != "" && evt.OrderType == Common.Enum.EnumProductType.RenewUpgrade)
            {
                var LockName = $"{typeof(IfRenewUpgradePublishChannelDurationChangeEvent)}:{evt.OrderNo}";

                var lockValue = Guid.NewGuid().ToString("N");

                //获取分布式锁,获取锁失败时进行锁等待(锁超时时间5秒)
                if (LockName.Lock(lockValue, TimeSpan.FromSeconds(5)))
                {
                    try
                    {
                        //当前续费订单外部订单编号,是原始订单的订单编号
                        var renewUpgradeOrder = orderService.GetOrder(evt.OrderNo);

                        if (renewUpgradeOrder != null)
                        {
                            XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,需发布服务时长变更通知");

                            //当前续费订单外部订单编号,是原始订单的订单编号
                            var origOrder = orderService.GetOrder(renewUpgradeOrder.OrderOutID);

                            if (origOrder != null)
                            {
                                var Duration = 0;
                                #region 计算时长(如果续费订单是通过套餐购买则时长则按照套餐中定义的,如果不是则按照系统的时长计算)
                                if (Duration <= 0)
                                {
                                    if (origOrder.OrderType == Common.Enum.EnumProductType.video || origOrder.OrderType == Common.Enum.EnumProductType.Phone)
                                    {
                                        //30分钟
                                        Duration = 60 * 30;
                                    }
                                    else
                                    {
                                        //一天
                                        Duration = 60 * 60 * 24;
                                    }
                                }
                                #endregion

                                var room = roomService.GetChannelInfo(origOrder.OrderOutID);

                                if (room != null && room.RoomState == Common.Enum.EnumRoomState.AlreadyVisit)
                                {
                                    XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,就诊已经结束,续费操作无效");

                                    //忽略无效的续费
                                    return(true);
                                }
                                //原订单已经完成,这时候续费无效。续费订单会进行退款处理
                                else if (origOrder.OrderState == Common.Enum.EnumOrderState.Finish)
                                {
                                    XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,原订单{origOrder.OrderNo}已经完成,续费操作无效");
                                    //忽略无效的续费
                                    return(true);
                                }
                                else
                                {
                                    XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,发送服务时长变更通知");

                                    using (MQChannel channel = new MQChannel())
                                    {
                                        return(channel.Publish <EventBus.Events.ChannelDurationChangeEvent>(new EventBus.Events.ChannelDurationChangeEvent()
                                        {
                                            Duration = Duration,
                                            ServiceID = origOrder.OrderOutID,
                                            OrderNo = evt.OrderNo,
                                            NewUpgradeOrderNo = evt.OrderOutID
                                        }));
                                    }
                                }
                            }
                            else
                            {
                                XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,原订单不存在");
                                return(true);
                            }
                        }
                        else
                        {
                            XuHos.Common.LogHelper.WriteDebug($"订单续费:订单{evt.OrderNo}支付完成,订单不存在");
                            return(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        XuHos.Common.LogHelper.WriteError(ex);
                        return(false);
                    }
                    finally
                    {
                        LockName.UnLock(lockValue);
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #28
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);
        }
Пример #29
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);
        }
Пример #30
0
        public bool Handle(EventBus.Events.ChannelEnteredEvent evt)
        {
            if (evt == null || string.IsNullOrEmpty(evt.UserID))
            {
                return(true);
            }

            try
            {
                var    service  = new XuHos.BLL.Doctor.Implements.DoctorService();
                string doctorID = service.GetDoctorIDByUserID(evt.UserID);
                if (string.IsNullOrEmpty(doctorID))
                {
                    return(true);
                }

                ConversationRoomService roomService = new ConversationRoomService();
                var room = roomService.GetChannelInfo(evt.ChannelID);
                if (room == null)
                {
                    return(true);
                }

                // 判断医生是否已经进入过诊室
                var           enteredStateCacheKey = new XuHos.Common.Cache.Keys.EntityListCacheKey <string>(Common.Cache.Keys.StringCacheKeyType.Channel_EnteredState, evt.ChannelID.ToString());
                List <string> enteredStates        = enteredStateCacheKey.FromCache();
                if (enteredStates == null)
                {
                    enteredStates = new List <string>();
                }

                // 如果医生已进入过诊室
                if (enteredStates.Exists(x => x == evt.UserID))
                {
                    return(true);
                }

                enteredStates.Add(evt.UserID);

                // 将机器人加入诊室
                //int robotIdentifier = 0;
                //if (!AddRobotToChannel(evt.ChannelID, robotIdentifier))
                //    return false;
                int?doctorIdentifier = roomService.GetChannelUsersInfo(evt.ChannelID)?.Where(x => x.UserID == evt.UserID).Select(x => x.identifier).FirstOrDefault();
                if (!doctorIdentifier.HasValue)
                {
                    return(true);
                }

                using (MQChannel channle = new MQChannel())
                {
                    if (channle.Publish <EventBus.Events.ChannelSendGroupMsgEvent <string> >(new EventBus.Events.ChannelSendGroupMsgEvent <string>()
                    {
                        ChannelID = evt.ChannelID,
                        FromAccount = doctorIdentifier.Value,//robotIdentifier,
                        Msg = "您好,我是康美网络医院在线医生,很高兴为您服务!"
                    }))
                    {
                        // 记录进入诊室状态
                        enteredStates.ToCache(enteredStateCacheKey);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                LogHelper.WriteError(e);
                return(false);
            }
        }