李昊 4 years ago
parent
commit
642aa3fd53

+ 5 - 4
GxPress/Api/GxPress.Api/AppControllers/GroupChatController.cs

@@ -186,14 +186,15 @@ namespace GxPress.Api.AppControllers
         {
             return await _groupChatRepository.SetIsOpenQrCoderAsync(groupChatImId, _loginContext.AccountId);
         }
-         /// <summary>
+        /// <summary>
         /// 获取用户加入的群
         /// </summary>
         /// <returns></returns>
-        [HttpGet("list")]
-        public async Task<IEnumerable<GroupChat>> GetGroupChatsAsync()
+        [HttpPost("list")]
+        public async Task<IEnumerable<GroupChat>> GetGroupChatsAsync(GroupChatSearchRequest request)
         {
-            return await _groupChatRepository.GetGroupChatsAsync(_loginContext.AccountId);
+            request.UserId = _loginContext.AccountId;
+            return await _groupChatRepository.GetGroupChatsAsync(request);
         }
     }
 }

+ 6 - 1
GxPress/Model/GxPress.Request/GroupChat/GroupChatSearchRequest.cs

@@ -7,9 +7,14 @@ namespace GxPress.Request.GroupChat
     /// <summary>
     /// 根据UserID查询群
     /// </summary>
-   public class GroupChatSearchRequest
+    public class GroupChatSearchRequest
     {
         /// <summary>
+        /// 搜索字段
+        /// </summary>
+        /// <value></value>
+        public string KeyWord { get; set; }
+        /// <summary>
         /// UserId
         /// </summary>
         public int UserId { get; set; }

+ 7 - 4
GxPress/Repository/GxPress.Repository.Implement/GroupChatRepository.cs

@@ -435,21 +435,24 @@ namespace GxPress.Repository.Implement
         /// <summary>
         /// 获取用户加入的群
         /// </summary>
-        /// <param name="userId"></param>
+        /// <param name="request"></param>
         /// <returns></returns>
-        public async Task<IEnumerable<GroupChat>> GetGroupChatsAsync(int userId)
+        public async Task<IEnumerable<GroupChat>> GetGroupChatsAsync(GroupChatSearchRequest request)
         {
+            var sqlStr = string.Empty;
+            if (!string.IsNullOrEmpty(request.KeyWord))
+                sqlStr = $" and a.Name like '%{request.KeyWord}%'";
             string sql = $@"SELECT 
                                     *,(select count(1) from tede_group_chat_user where GroupChatId=a.Id) as UserCount
                                 FROM
                                     tede_group_chat a
                                 WHERE
-                                    a.id IN (SELECT 
+                                   1=1 {sqlStr} and  a.id IN (SELECT 
                                             GroupChatId
                                         FROM
                                             tede_group_chat_user
                                         WHERE
-                                            UserId = {userId})
+                                            UserId = {request.UserId})
                                 ORDER BY a.CreatedDate DESC";
             var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
             var database = new Database(databaseType, _connectionString);

+ 1 - 1
GxPress/Repository/GxPress.Repository.Interface/IGroupChatRepository.cs

@@ -85,6 +85,6 @@ namespace GxPress.Repository.Interface
         /// </summary>
         /// <param name="userId"></param>
         /// <returns></returns>
-        Task<IEnumerable<GroupChat>> GetGroupChatsAsync(int userId);
+        Task<IEnumerable<GroupChat>> GetGroupChatsAsync(GroupChatSearchRequest request);
     }
 }