コード例 #1
0
ファイル: SyncIMUid.cs プロジェクト: radtek/XuHos
        public bool Handle(EventBus.Events.UserRegisteredEvent evt)
        {
            try
            {
                if (evt == null)
                {
                    return(true);
                }

                XuHos.Integration.QQCloudy.IMHelper imService = new XuHos.Integration.QQCloudy.IMHelper();

                ConversationIMUidService imUidService = new ConversationIMUidService("");

                var identifier = imUidService.GetUserIMUid(evt.UserID);

                if (imService.CreateMember(identifier, "", ""))
                {
                    return(imUidService.EnableUid(new int[] { identifier }));
                }
            }
            catch (Exception E)
            {
                XuHos.Common.LogHelper.WriteError(E);
            }

            return(false);
        }
コード例 #2
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);
        }