李昊 4 år sedan
förälder
incheckning
3a851bdd87

+ 24 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/GroupRepository.cs

@@ -406,7 +406,30 @@ namespace GxPress.Repository.Implement
         /// <returns></returns>
         public async Task<IEnumerable<Entity.Group>> GetAllAsync(int categoryId)
         {
-            return await _repository.GetAllAsync(Q.Where(nameof(Entity.Group.GroupCategroyId), categoryId));
+            var sql = $@"SELECT 
+                            *,
+                            (SELECT 
+                                    COUNT(1)
+                                FROM
+                                    tede_group_user
+                                WHERE
+                                    GroupId = a.Id) AS UserCount,
+                            (SELECT 
+                                    COUNT(1)
+                                FROM
+                                    tede_topic
+                                WHERE
+                                    GroupId = a.Id) AS GroupArticleCount
+                        FROM
+                            tede_group a
+                        WHERE
+                            a.GroupCategroyId = {categoryId}";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var result = await connection.QueryAsync<Entity.Group>(sql);
+            //return await _repository.GetAllAsync(Q.Where(nameof(Entity.Group.GroupCategroyId), categoryId));
+            return result;
         }
         /// <summary>
         /// 用户小组列表

+ 2 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Group/GroupService.Category.cs

@@ -13,7 +13,8 @@ namespace GxPress.Service.Implement.Group
         /// <returns></returns>
         public async Task<IEnumerable<Entity.Group>> GetAllAsync(int categoryId)
         {
-            return await _groupRepository.GetAllAsync(categoryId);
+            var group= await _groupRepository.GetAllAsync(categoryId);
+            return group;
         }
     }
 }