Exemplo n.º 1
0
        public ApiResult GetRoomInfo([FromUri] int ChannelID)
        {
            var bll  = new BLL.Sys.Implements.ConversationRoomService();
            var room = bll.GetChannelInfo(ChannelID);

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


            return(room.ToApiResultForObject());
        }
Exemplo n.º 2
0
        public ApiResult MediaConfig(int ChannelID, int Identifier)
        {
            var bll = new XuHos.Integration.QQCloudy.IMHelper();

            BLL.Sys.Implements.ConversationRoomService roomService = new BLL.Sys.Implements.ConversationRoomService();
            var room = roomService.GetChannelInfo(ChannelID);

            //获取服务时长
            var Duration  = room.Duration;
            var TotalTime = room.TotalTime;

            //如果没有服务时长,则默认30分钟
            if (Duration <= 0)
            {
                Duration = 60 * 30; //30分钟
            }

            var config = bll.MediaConfig(ChannelID, Identifier, Duration, TotalTime, room.DisableWebSdkInteroperability);

            return(config.ToApiResultForObject());
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建聊天的房间
        /// </summary>
        /// <param name="OPDRegisterID"></param>
        /// <returns></returns>
        public bool CreateIMRoom(string OPDRegisterID)
        {
            try
            {
                using (DAL.EF.DBEntities db = new DBEntities())
                {
                    var model = (from opd in db.UserOpdRegisters.Where(a => a.OPDRegisterID == OPDRegisterID)
                                 join user in db.Users on opd.UserID equals user.UserID
                                 join member in db.UserMembers on opd.MemberID equals member.MemberID
                                 select new
                    {
                        OPDType = opd.OPDType,
                        DoctorID = opd.DoctorID,             //opd.DoctorID,
                        UserID = opd.UserID,
                        MemberID = opd.MemberID,
                        member.MemberName,
                        user.PhotoUrl,
                        user.UserCNName,
                        user.UserENName
                    }).FirstOrDefault();


                    if (model != null)
                    {
                        #region 创建IM群组
                        XuHos.Integration.QQCloudy.IMHelper imservice    = new XuHos.Integration.QQCloudy.IMHelper();
                        ConversationIMUidService            imUidService = new ConversationIMUidService(CurrentOperatorUserID);
                        var roomService = new BLL.Sys.Implements.ConversationRoomService();

                        BLL.Doctor.Implements.DoctorService doctorService = new Doctor.Implements.DoctorService();

                        //房间信息
                        var room = roomService.GetChannelInfo(OPDRegisterID);

                        if (room != null)
                        {
                            var GroupName      = model.OPDType.GetEnumDescript();
                            var Introduction   = "";
                            var Notification   = "";
                            var groupMembers   = new List <int>();
                            var channelMembers = new List <RequestChannelMemberDTO>();

                            //患者信息
                            var userIdentifier = imUidService.GetUserIMUid(model.UserID);
                            if (userIdentifier > 0)
                            {
                                groupMembers.Add(userIdentifier);
                                channelMembers.Add(new RequestChannelMemberDTO()
                                {
                                    Identifier   = userIdentifier,
                                    UserType     = EnumUserType.User,
                                    UserID       = model.UserID,
                                    UserMemberID = model.MemberID,
                                    PhotoUrl     = model.PhotoUrl,
                                    UserCNName   = model.MemberName,
                                    UserENName   = model.MemberName
                                });
                            }

                            //获取医生信息(如果走导诊系统,此时还未分配医生,分诊后才会把分诊医生加入到IM组)
                            if (!string.IsNullOrEmpty(model.DoctorID))
                            {
                                var doctorInfo       = doctorService.GetDoctorInfo(model.DoctorID);
                                var doctorIdentifier = imUidService.GetDoctorIMUid(model.DoctorID);
                                if (doctorIdentifier > 0)
                                {
                                    groupMembers.Add(doctorIdentifier);
                                    channelMembers.Add(new RequestChannelMemberDTO()
                                    {
                                        Identifier   = doctorIdentifier,
                                        UserID       = doctorInfo.UserID,
                                        UserType     = EnumUserType.Doctor,
                                        UserMemberID = doctorInfo.User.MemberID,
                                        PhotoUrl     = doctorInfo.User._PhotoUrl,//DTO已经进行了路径转换,这里需要使用没有转换之前的数据
                                        UserENName   = doctorInfo.DoctorEnName,
                                        UserCNName   = doctorInfo.DoctorName
                                    });
                                }
                            }

                            if (room.Enable)
                            {
                                if (imservice.AddGroupMember(room.ChannelID, groupMembers))
                                {
                                    return(roomService.InsertChannelMembers(room.ChannelID, channelMembers));
                                }
                            }
                            else
                            {
                                //创建裙子成功
                                if (imservice.CreateGroup(room.ChannelID, GroupName, model.OPDType, groupMembers, Introduction, Notification))
                                {
                                    using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                                    {
                                        if (mqChannel.Publish <EventBus.Events.ChannelCreatedEvent>(new EventBus.Events.ChannelCreatedEvent()
                                        {
                                            ChannelID = room.ChannelID,
                                            ServiceID = room.ServiceID,
                                            ServiceType = room.ServiceType
                                        }))
                                        {
                                            room.Enable = true;

                                            if (roomService.CompareAndSetChannelInfo(room))
                                            {
                                                return(roomService.InsertChannelMembers(room.ChannelID, channelMembers));
                                            }
                                        }
                                        else
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            return(true);
                        }

                        #endregion
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            //出现数据库并发更新异常需要重试
            catch (DbUpdateConcurrencyException ex)
            {
                return(CreateIMRoom(OPDRegisterID));
            }

            return(false);
        }
Exemplo n.º 4
0
        public ApiResult SetRoomState([FromBody] BLL.Sys.DTOs.Request.RequestConversationRoomSetStateDTO request)
        {
            try
            {
                var roomService = new BLL.Sys.Implements.ConversationRoomService();
                var room        = roomService.GetChannelInfo(request.ChannelID);

                #region 记录操作日志
                EnumUserOperationType?type = null;
                switch (room.ServiceType)
                {
                case EnumDoctorServiceType.VidServiceType:
                    type = EnumUserOperationType.EnterVidService;
                    break;

                case EnumDoctorServiceType.AudServiceType:
                    type = EnumUserOperationType.EnterAudService;
                    break;

                case EnumDoctorServiceType.PicServiceType:
                    type = EnumUserOperationType.EnterPicService;
                    break;
                }
                switch (request.State)
                {
                case EnumRoomState.InMedicalTreatment:
                    break;

                case EnumRoomState.Disconnection:
                    if (type.HasValue)
                    {
                        type = type.Value + 1;
                    }
                    break;

                default:
                    type = null;
                    break;
                }
                if (type.HasValue)
                {
                    using (XuHos.EventBus.MQChannel channel = new EventBus.MQChannel())
                    {
                        channel.Publish <XuHos.EventBus.Events.UserOperatorLogEvent>(new EventBus.Events.UserOperatorLogEvent()
                        {
                            UserID       = CurrentOperatorUserID,
                            OperatorTime = DateTime.Now,
                            UserType     = CurrentOperatorUserType,
                            OperatorType = type.Value,
                            OperatorName = type.Value.GetEnumDescript(),
                            OrgID        = CurrentOperatorOrgID,
                            Remark       = "",
                            ModuleName   = ""
                        });
                    }
                }
                #endregion

                //期望的房间状态
                var ExpectedState = request.ExpectedState.HasValue ? request.ExpectedState.Value: room.RoomState; //如果客户端没有指定期望的状态则系统获取(兼容之前版本)

                //并集并交换房间状态(如果设置失败则返回最新的状态)
                var ret = roomService.CompareAndSetChannelState(request.ChannelID,
                                                                CurrentOperatorUserID,
                                                                request.State,
                                                                request.DisableWebSdkInteroperability,
                                                                ref ExpectedState);

                return(ret.ToApiResultForApiStatus(ExpectedState));
            }
            catch (Exception ex)
            {
                XuHos.Common.LogHelper.WriteError(ex);
                return(EnumApiStatus.BizError.ToApiResultForApiStatus(ex.Message));
            }
        }
Exemplo n.º 5
0
        public ApiResult GetRoomWaitingCount(string DoctorID, int ChannelID)
        {
            var bll = new BLL.Sys.Implements.ConversationRoomService();

            return(bll.GetWaitingCount(DoctorID, ChannelID).ToApiResultForObject());
        }
Exemplo n.º 6
0
        public ApiResult GetUsersInfo(BLL.Sys.DTOs.Request.RequestGetMemberInfoDTO request)
        {
            var bll = new BLL.Sys.Implements.ConversationRoomService();

            return(bll.GetChannelUsersInfo(request.ChannelID, request.Identifiers).ToApiResultForObject());
        }
Exemplo n.º 7
0
        public dynamic CallBack(
            string SdkAppid,
            string CallbackCommand,
            string ClientIP,
            string OptPlatform,
            [FromBody] dynamic model)
        {
            try
            {
                //发单聊消息之前回调 https://www.qcloud.com/doc/product/269/1632
                if (CallbackCommand == "C2C.CallbackBeforeSendMsg")
                {
                    /*{
                     *  "CallbackCommand": "C2C.CallbackBeforeSendMsg",  // 回调命令
                     *  "From_Account": "jared",  // 发送者
                     *  "To_Account": "Jonh",  // 接收者
                     *  "MsgBody": [  // 消息体,参见TIMMessage消息对象
                     *      {
                     *          "MsgType": "TIMTextElem", // 文本
                     *          "MsgContent": {
                     *              "Text": "red packet"
                     *          }
                     *      }
                     *  ]
                     * }*/

                    //TODO:过滤垃圾消息,修改用户的消息,记录日志
                }
                //发单聊消息之后回调 https://www.qcloud.com/doc/product/269/2716
                else if (CallbackCommand == "C2C.CallbackAfterSendMsg")
                {
                    /*{
                     *  "CallbackCommand": "C2C.CallbackAfterSendMsg",  // 回调命令
                     *  "From_Account": "jared",  // 发送者
                     *  "To_Account": "Jonh",  // 接收者
                     *  "MsgBody": [  // 消息体,参见TIMMessage消息对象
                     *      {
                     *          "MsgType": "TIMTextElem", // 文本
                     *          "MsgContent": {
                     *              "Text": "red packet"
                     *          }
                     *      }
                     *  ]
                     * }*/
                }
                //群内发言之前回调 https://www.qcloud.com/doc/product/269/1619
                else if (CallbackCommand == "Group.CallbackBeforeSendMsg")
                {
                    #region 群内发言之前回调

                    /*{
                     *  "CallbackCommand": "Group.CallbackBeforeSendMsg",  // 回调命令
                     *  "GroupId": "@TGS#2J4SZEAEL",  // 群组ID
                     *  "Type": "Public",  // 群组类型
                     *  "From_Account": "jared",  // 发送者
                     *  "Operator_Account":"admin", //请求的发起者
                     *  "Random": 123456,  // 随机数
                     *  "MsgBody": [  // 消息体,参见TIMMessage消息对象
                     *      {
                     *          "MsgType": "TIMTextElem", // 文本
                     *          "MsgContent": {
                     *              "Text": "red packet"
                     *          }
                     *      }
                     *  ]
                     * }*/

                    //群组编号
                    int GroupId = model.GroupId;
                    //房间编号
                    int ChannelID = GroupId;
                    //发送者
                    string From_Account = model.From_Account;
                    //消息主题内容
                    dynamic MsgBody = model.MsgBody;

                    string MsgSeq = Guid.NewGuid().ToString("N");

                    if (From_Account != null)
                    {
                        ConversationMessage[] messages = new ConversationMessage[MsgBody.Count];
                        BLL.Sys.Implements.ConversationRoomService bllRoom = new BLL.Sys.Implements.ConversationRoomService();
                        //获取房间
                        var room = bllRoom.GetChannelInfo(ChannelID);

                        if (room != null)
                        {
                            #region 记录聊天日志

                            int i = 0;
                            foreach (var msg in MsgBody)
                            {
                                var msgType = msg.MsgType;
                                var content = Newtonsoft.Json.JsonConvert.SerializeObject(msg);
                                messages[i] = new ConversationMessage();
                                messages[i].ConversationMessageID = Guid.NewGuid().ToString("N");
                                messages[i].ConversationRoomID    = GroupId;      //房间
                                messages[i].MessageContent        = content;      //内容
                                messages[i].MessageState          = 0;            //消息状态
                                messages[i].MessageTime           = DateTime.Now; //消息发送时间
                                messages[i].MessageType           = msgType;      //消息发送类型 TIMTextElem/TIMImageElem/TIMCustomElem
                                messages[i].ServiceID             = room.ServiceID;
                                messages[i].UserID       = From_Account.ToString();
                                messages[i].MessageSeq   = MsgSeq;
                                messages[i].MessageIndex = i;
                                i++;
                            }

                            using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                            {
                                if (mqChannel.Publish <EventBus.Events.ChannelNewMsgEvent>(new EventBus.Events.ChannelNewMsgEvent()
                                {
                                    ChannelID = GroupId,
                                    ServiceID = room.ServiceID,
                                    ServiceType = room.ServiceType,
                                    FromAccount = From_Account,
                                    Messages = messages,
                                    OptPlatform = OptPlatform
                                }))
                                {
                                    // 0为允许发言
                                    return(new { ActionStatus = "OK", ErrorInfo = "", ErrorCode = 0 });
                                }
                                else
                                {
                                    // 0为允许发言
                                    return(new { ActionStatus = "OK", ErrorInfo = "", ErrorCode = 1 });
                                }
                            }

                            #endregion
                        }
                    }

                    #endregion
                }
                //群内发言之后回调 https://www.qcloud.com/doc/product/269/2661
                else if (CallbackCommand == "Group.CallbackAfterSendMsg")
                {
                    /*{
                     *  "CallbackCommand": "Group.CallbackAfterSendMsg",  // 回调命令
                     *  "GroupId": "@TGS#2J4SZEAEL",  // 群组ID
                     *  "Type": "Public",  // 群组类型
                     *  "From_Account": "jared",  // 发送者
                     *  "MsgBody": [  // 消息体,参见TIMMessage消息对象
                     *      {
                     *          "MsgType": "TIMTextElem", // 文本
                     *          "MsgContent": {
                     *              "Text": "red packet"
                     *          }
                     *      }
                     *  ]
                     * }*/
                }
                //状态变更回调 https://www.qcloud.com/doc/product/269/2570
                else if (CallbackCommand == "State.StateChange")
                {
                    /*{
                     *  "CallbackCommand": "State.StateChange",
                     *      "Info": {
                     *          "Action": "Logout",
                     *          "To_Account": "testuser316",
                     *          "Reason": "Unregister"
                     *      }
                     * }
                     */
                    var Action     = model.Info.Action;
                    var To_Account = model.Info.To_Account;

                    using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                    {
                        if (mqChannel.Publish <EventBus.Events.UserOnlineStateChangedEvent>(new EventBus.Events.UserOnlineStateChangedEvent()
                        {
                            Action = Action,
                            UserID = To_Account,
                        }))
                        {
                            // 0为允许发言
                            return(new { ActionStatus = "OK", ErrorInfo = "", ErrorCode = 0 });
                        }
                        else
                        {
                            // 0为允许发言
                            return(new { ActionStatus = "OK", ErrorInfo = "", ErrorCode = 1 });
                        }
                    }
                }

                //正常返回
                return(new { ActionStatus = "OK", ErrorInfo = "", ErrorCode = 0 });
            }
            catch (Exception E)
            {
                LogHelper.WriteError(E.GetDetailException());

                return(new { ActionStatus = "OK", ErrorInfo = E.GetDetailException().StackTrace, ErrorCode = 0 });
            }
        }