李昊 4 年之前
父節點
當前提交
5765862eaf

+ 5 - 0
gx_api/GxPress/Model/GxPress.Request/UserMiddle/UserMiddleInRequest.cs

@@ -30,5 +30,10 @@ namespace GxPress.Request.UserMiddle
         /// </summary>
         /// <value></value>
         public int DataSourceId { get; set; }
+          /// <summary>
+        /// 对应来源ID 1 我的小组 2群聊
+        /// </summary>
+        /// <value></value>
+        public int SourceTypeValue { get; set; }
     }
 }

+ 11 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/GroupChatUserRepository.cs

@@ -234,5 +234,16 @@ namespace GxPress.Repository.Implement
         {
             return await _repository.InsertAsync(groupChatUser);
         }
+
+        public async Task<IEnumerable<int>> GetUserIdsAsync(int userId)
+        {
+            string sql = $"SELECT UserId FROM tede_group_chat_user where GroupChatId in(SELECT GroupChatId FROM tede_group_chat_user where UserId={userId})";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var items = await connection
+                .QueryAsync<int>(sql);
+            return items;
+        }
     }
 }

+ 14 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/GroupUserRepository.cs

@@ -144,5 +144,19 @@ namespace GxPress.Repository.Implement
                        .Where(nameof(GroupUser.GroupId), groupId)
                        .Where(nameof(GroupUser.UserId), userId)) > 0;
         }
+        /// <summary>
+        /// 根据用户ID获取所加入的小组用户
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<int>> GetGroupUserByUserIdAsync(int userId)
+        {
+            string sql = $"SELECT UserId FROM tede_group_user where GroupId in(SELECT GroupId FROM tede_group_user where UserId={userId})";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var result = await connection.QueryAsync<int>(sql);
+            return result;
+        }
     }
 }

+ 5 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/UserRepository.cs

@@ -830,6 +830,11 @@ namespace GxPress.Repository.Implement
             return await _repository.GetAllAsync(query);
         }
 
+        public async Task<IEnumerable<int>> GetAllIntsAsync(Query query)
+        {
+            return await _repository.GetAllAsync<int>(query);
+        }
+
         public Task<IEnumerable<User>> FindAllUserAsync()
         {
             throw new NotImplementedException();

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/IGroupChatUserRepository.cs

@@ -68,5 +68,6 @@ namespace GxPress.Repository.Interface
         /// <param name="groupChatUsers"></param>
         /// <returns></returns>
         Task<bool> InsertAsync(List<GroupChatUser> groupChatUsers);
+        Task<IEnumerable<int>> GetUserIdsAsync(int userId);
     }
 }

+ 6 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/IGroupUserRepository.cs

@@ -37,5 +37,11 @@ namespace GxPress.Repository.Interface
         /// <returns></returns>
         Task<bool> SetIsUDisturbAsync(int groupId, int userId);
         Task<bool> InsertAsync(List<GroupUser> groupUsers);
+        /// <summary>
+        /// 根据用户ID获取所加入的小组用户
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+       Task<IEnumerable<int>> GetGroupUserByUserIdAsync(int userId);
     }
 }

+ 2 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/IUserRepository.cs

@@ -7,11 +7,13 @@ using GxPress.Result.User;
 using Datory;
 using GxPress.Result.App.User;
 using GxPress.Result.Job;
+using SqlKata;
 
 namespace GxPress.Repository.Interface
 {
     public interface IUserRepository : IRepository
     {
+         Task<IEnumerable<int>> GetAllIntsAsync(Query query);
         Task<User> GetAsync(int id);
         Task<User> GetAsync(SqlKata.Query query);
         Task<UserDetail> GetDetailAsync(int id);

+ 55 - 18
gx_api/GxPress/Service/GxPress.Service.Implement/UserMiddle/UserMiddleService.cs

@@ -16,13 +16,17 @@ namespace GxPress.Service.Implement.UserMiddle
         private readonly IAddressBookGroupUserRepository _addressBookGroupUserRepository;
         private readonly IAddressBookGroupRepository _addressBookGroupRepository;
         private readonly IDepartmentRepository _departmentRepository;
-        public UserMiddleService(IUserMiddleRepository userMiddleRepository, IUserRepository userRepository, IAddressBookGroupUserRepository addressBookGroupUserRepository, IDepartmentRepository departmentRepository, IAddressBookGroupRepository addressBookGroupRepository)
+        private readonly IGroupChatUserRepository groupChatUserRepository;
+        private readonly IGroupUserRepository groupUserRepository;
+        public UserMiddleService(IUserMiddleRepository userMiddleRepository, IUserRepository userRepository, IAddressBookGroupUserRepository addressBookGroupUserRepository, IDepartmentRepository departmentRepository, IAddressBookGroupRepository addressBookGroupRepository, IGroupChatUserRepository groupChatUserRepository, IGroupUserRepository groupUserRepository)
         {
             _userMiddleRepoitory = userMiddleRepository;
             _userRepoitory = userRepository;
             _addressBookGroupUserRepository = addressBookGroupUserRepository;
             _departmentRepository = departmentRepository;
             _addressBookGroupRepository = addressBookGroupRepository;
+            this.groupChatUserRepository = groupChatUserRepository;
+            this.groupUserRepository = groupUserRepository;
         }
         /// <summary>
         /// 添加用户中间表
@@ -39,6 +43,7 @@ namespace GxPress.Service.Implement.UserMiddle
                     var userMiddleDto = new Entity.UserMiddle.UserMiddle();
                     userMiddleDto.SourceId = userMiddle.SourceId;
                     userMiddleDto.SourceType = userMiddle.SourceType;
+                    userMiddleDto.SourceTypeValue = userMiddle.SourceTypeValue;
                     userMiddleDto.MiddleType = userMiddle.MiddleType;
                     userMiddleDto.SourceName = userMiddle.SourceName;
                     userMiddleDto.DataSourceId = userMiddle.DataSourceId;
@@ -61,12 +66,12 @@ namespace GxPress.Service.Implement.UserMiddle
             return await _userMiddleRepoitory.DeleteAsync(query);
         }
 
-       /// <summary>
-       ///  删除收件人
-       /// </summary>
-       /// <param name="dataSourceId"></param>
-       /// <param name="middleType">类型类型 1 通知 2话题 3 收藏 4笔记 5 普通站内信 6匿名站内信 7小组  10:通知收件人 20:通知抄送人 30:站内信收集人 40:站内信抄送人 400 会议纪要</param>
-       /// <returns></returns>
+        /// <summary>
+        ///  删除收件人
+        /// </summary>
+        /// <param name="dataSourceId"></param>
+        /// <param name="middleType">类型类型 1 通知 2话题 3 收藏 4笔记 5 普通站内信 6匿名站内信 7小组  10:通知收件人 20:通知抄送人 30:站内信收集人 40:站内信抄送人 400 会议纪要</param>
+        /// <returns></returns>
         public async Task<bool> DeleteAsync(int dataSourceId, int middleType)
         {
             return await _userMiddleRepoitory.DeleteAsync(Q.Where(nameof(Entity.UserMiddle.UserMiddle.DataSourceId), dataSourceId).Where(nameof(Entity.UserMiddle.UserMiddle.MiddleType), middleType));
@@ -91,9 +96,7 @@ namespace GxPress.Service.Implement.UserMiddle
             List<Entity.User> users = new List<Entity.User>();
             var userIds = new List<int>();
             userIds = userMiddles.Where(n => n.SourceType == 0).Select(n => n.SourceId).ToList();
-            if (userIds.Count() > 0)
-                //获取用户
-                users.AddRange(await _userRepoitory.GetAllAsync(Q.WhereIn(nameof(Entity.User.Id), userIds)));
+
             foreach (var userMiddle in userMiddles)
             {
                 if (userMiddle.SourceType != 0)
@@ -102,13 +105,48 @@ namespace GxPress.Service.Implement.UserMiddle
                     {
                         if (userMiddle.SourceId == 0)
                             //获取所有用户
-                            users.AddRange(await _userRepoitory.GetAllAsync(Q.Where(nameof(Entity.User.Id), ">", 0)));
+                            userIds.AddRange(await _userRepoitory.GetAllIntsAsync(Q.Select(nameof(Entity.User.Id)).Where(nameof(Entity.User.Id), ">", 0)));
                         else
                         {
                             //递归获取部门
                             var departments = new List<Entity.Department>();
                             departments = await _departmentRepository.GetDepartmentById(userMiddle.SourceId, departments);
-                            users.AddRange(await _userRepoitory.GetAllAsync(Q.WhereIn(nameof(Entity.User.DepartmentId), departments.Select(n => n.Id))));
+                            userIds.AddRange(await _userRepoitory.GetAllIntsAsync(Q.WhereIn(nameof(Entity.User.DepartmentId), departments.Select(n => n.Id))));
+                        }
+                    }
+                    if (userMiddle.SourceType == 2)
+                    {
+                        /// <summary>
+                        /// 我的小组
+                        /// </summary>
+                        /// <value></value>
+                        if (userMiddle.SourceTypeValue == 1)
+                        {
+                            if (userMiddle.SourceId == 0)
+                            {
+                                userIds.AddRange(await groupUserRepository.GetGroupUserByUserIdAsync(userId));
+                            }
+                            else
+                            {
+                                var groupUsers = await groupUserRepository.GetAllAsync(Q.Where(nameof(Entity.GroupUser.GroupId), userMiddle.SourceId));
+                                userIds.AddRange(groupUsers.Select(n => n.UserId));
+                            }
+                        }
+                        /// <summary>
+                        /// 我的群聊
+                        /// </summary>
+                        /// <value></value>
+                        if (userMiddle.SourceTypeValue == 2)
+                        {
+                            if (userMiddle.SourceId == 0)
+                            {
+                                userIds.AddRange(await groupChatUserRepository.GetUserIdsAsync(userId));
+                            }
+                            else
+                            {
+                                var groupChatUsers = await groupChatUserRepository.GetAllAsync(Q.Where(nameof(Entity.GroupChatUser.GroupChatId), userMiddle.SourceId));
+                                userIds.AddRange(groupChatUsers.Select(n => n.UserId));
+                            }
                         }
                     }
                     if (userMiddle.SourceType == 3)
@@ -117,21 +155,20 @@ namespace GxPress.Service.Implement.UserMiddle
                         {
                             var addressBookGroups = await _addressBookGroupRepository.GetAllAsync(Q.Where(nameof(Entity.AddressBookGroup.UserId), userId));
                             var addressBookGroupUsers = await _addressBookGroupUserRepository.GetAllAsync(Q.WhereIn(nameof(Entity.AddressBookGroupUser.AddressBookGroupId), addressBookGroups.Select(n => n.Id)));
-                            userIds = addressBookGroupUsers.Select(n => n.UserId).ToList();
-                            //获取用户
-                            users.AddRange(await _userRepoitory.GetAllAsync(Q.WhereIn(nameof(Entity.User.Id), userIds)));
+                            userIds.AddRange(addressBookGroupUsers.Select(n => n.UserId).ToList());
                         }
                         else
                         {
                             //获取自建分组
                             var addressBookGroupUsers = await _addressBookGroupUserRepository.GetAllAsync(Q.Where(nameof(Entity.AddressBookGroupUser.AddressBookGroupId), userMiddle.SourceId));
-                            userIds = addressBookGroupUsers.Select(n => n.UserId).ToList();
-                            //获取用户
-                            users.AddRange(await _userRepoitory.GetAllAsync(Q.WhereIn(nameof(Entity.User.Id), userIds)));
+                            userIds.AddRange(addressBookGroupUsers.Select(n => n.UserId).ToList());
                         }
                     }
                 }
             }
+            if (userIds.Count() > 0)
+                //获取用户
+                users.AddRange(await _userRepoitory.GetAllAsync(Q.WhereIn(nameof(Entity.User.Id), userIds)));
             users = users.Distinct().ToList();
             return users;
         }