李昊 4 years ago
parent
commit
044aa3908b

+ 2 - 1
gx_api/GxPress/Api/GxPress.Api/AppControllers/UserController.cs

@@ -458,7 +458,8 @@ namespace GxPress.Api.AppControllers
         [HttpPost("group-chat")]
         public async Task<IEnumerable<UserInfoResult>> GetGroupOrGroupChatUserInfosResult(UserInfoByGroupoRoGroupChatResult request)
         {
-            return await _userService.GetGroupOrGroupChatUserInfosResult(request.TypeValue, request.Id, request.Keyword);
+            request.UserId=_loginContext.AccountId;
+            return await _userService.GetGroupOrGroupChatUserInfosResult(request);
         }
     }
 }

+ 5 - 0
gx_api/GxPress/Model/GxPress.Result/User/UserResult.cs

@@ -132,6 +132,11 @@ namespace GxPress.Result.User
         /// </summary>
         /// <value></value>
         public string Keyword { get; set; }
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        /// <value></value>
+        public int UserId { get; set; }
     }
 
 }

+ 47 - 11
gx_api/GxPress/Service/GxPress.Service.Implement/UserService.cs

@@ -549,31 +549,67 @@ namespace GxPress.Service.Implement
         /// <param name="id"></param>
         /// <param name="keyword"></param>
         /// <returns></returns>
-        public async Task<IEnumerable<UserInfoResult>> GetGroupOrGroupChatUserInfosResult(int typeValue, int id, string keyword)
+        public async Task<IEnumerable<UserInfoResult>> GetGroupOrGroupChatUserInfosResult(UserInfoByGroupoRoGroupChatResult request)
         {
+            if (request.Id == 0)
+                return await GetAllGroupOrGroupChatUserInfosResult(request);
             //群聊
-            if (typeValue == 1)
+            if (request.TypeValue == 1)
             {
-                var groupChatUsers = await groupChatUserRepository.GetAllAsync(Q.Where(nameof(Entity.GroupChatUser.GroupChatId), id));
-                var result = await _userRepository.GetSearchUserInfoResults(keyword, groupChatUsers.Select(n => n.UserId));
+                var groupChatUsers = await groupChatUserRepository.GetAllAsync(Q.Where(nameof(Entity.GroupChatUser.GroupChatId), request.Id));
+                var result = await _userRepository.GetSearchUserInfoResults(request.Keyword, groupChatUsers.Select(n => n.UserId));
                 return result;
             }
             //小组
-            if (typeValue == 2)
+            if (request.TypeValue == 2)
             {
-                var groupUsers = await groupUserRepository.GetAllAsync(Q.Where(nameof(Entity.GroupUser.GroupId), id));
-                var result = await _userRepository.GetSearchUserInfoResults(keyword, groupUsers.Select(n => n.UserId));
+                var groupUsers = await groupUserRepository.GetAllAsync(Q.Where(nameof(Entity.GroupUser.GroupId), request.Id));
+                var result = await _userRepository.GetSearchUserInfoResults(request.Keyword, groupUsers.Select(n => n.UserId));
                 return result;
             }
             //自建小组
-            if (typeValue == 3)
+            if (request.TypeValue == 3)
             {
-                var addressGroupUsers = await addressBookGroupUserRepository.GetAllAsync(Q.Where(nameof(Entity.AddressBookGroupUser.AddressBookGroupId), id));
-                var result = await _userRepository.GetSearchUserInfoResults(keyword, addressGroupUsers.Select(n => n.UserId));
+                var addressGroupUsers = await addressBookGroupUserRepository.GetAllAsync(Q.Where(nameof(Entity.AddressBookGroupUser.AddressBookGroupId), request.Id));
+                var result = await _userRepository.GetSearchUserInfoResults(request.Keyword, addressGroupUsers.Select(n => n.UserId));
+                return result;
+            }
+            return null;
+        }
+        /// <summary>
+        /// 获取群聊和小组的用户
+        /// </summary>
+        /// <param name="typeValue"></param>
+        /// <param name="id"></param>
+        /// <param name="keyword"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<UserInfoResult>> GetAllGroupOrGroupChatUserInfosResult(UserInfoByGroupoRoGroupChatResult request)
+        {
+            //群聊
+            if (request.TypeValue == 1)
+            {
+                var groupIds = await groupChatUserRepository.GetAllAsync(Q.Where(nameof(Entity.GroupChatUser.UserId), request.UserId));
+                var groupChatUsers = await groupChatUserRepository.GetAllAsync(Q.WhereIn(nameof(Entity.GroupChatUser.GroupChatId), groupIds.Select(n => n.GroupChatId)));
+                var result = await _userRepository.GetSearchUserInfoResults(request.Keyword, groupChatUsers.Select(n => n.UserId));
+                return result;
+            }
+            //小组
+            if (request.TypeValue == 2)
+            {
+                var groupIds = await groupUserRepository.GetAllAsync(Q.Where(nameof(Entity.GroupUser.UserId), request.UserId));
+                var groupUsers = await groupUserRepository.GetAllAsync(Q.WhereIn(nameof(Entity.GroupUser.GroupId), groupIds.Select(n => n.GroupId)));
+                var result = await _userRepository.GetSearchUserInfoResults(request.Keyword, groupUsers.Select(n => n.UserId));
+                return result;
+            }
+            //自建小组
+            if (request.TypeValue == 3)
+            {
+                var addressBookGroupIds = await addressBookGroupUserRepository.GetAllAsync(Q.Where(nameof(Entity.AddressBookGroupUser.UserId), request.UserId));
+                var addressGroupUsers = await addressBookGroupUserRepository.GetAllAsync(Q.WhereIn(nameof(Entity.AddressBookGroupUser.AddressBookGroupId), addressBookGroupIds.Select(n => n.AddressBookGroupId)));
+                var result = await _userRepository.GetSearchUserInfoResults(request.Keyword, addressGroupUsers.Select(n => n.UserId));
                 return result;
             }
             return null;
         }
-
     }
 }

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/IUserService.cs

@@ -90,6 +90,6 @@ namespace GxPress.Service.Interface
         /// <param name="id"></param>
         /// <param name="keyword"></param>
         /// <returns></returns>
-         Task<IEnumerable<UserInfoResult>> GetGroupOrGroupChatUserInfosResult(int typeValue, int id, string keyword);
+         Task<IEnumerable<UserInfoResult>> GetGroupOrGroupChatUserInfosResult(UserInfoByGroupoRoGroupChatResult request);
     }
 }