李昊 пре 4 година
родитељ
комит
d78636b8f7

+ 6 - 1
gx_api/GxPress/Model/GxPress.Entity/tede2/Group/GroupCategory.cs

@@ -27,6 +27,11 @@ namespace GxPress.Entity.tede2.Group
         /// <value></value>
         [DataColumn]
         public int ParentId { get; set; }
-
+        /// <summary>
+        /// 排序
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int Sort { get; set; }
     }
 }

+ 11 - 1
gx_api/GxPress/Model/GxPress.Result/Web/GroupCategoryResult.cs

@@ -19,7 +19,7 @@ namespace GxPress.Result.Web
         /// 图标
         /// </summary>
         /// <value></value>
-        public string ImageUrls { get; set;}
+        public string ImageUrls { get; set; }
         /// <summary>
         /// 父级ID
         /// </summary>
@@ -30,5 +30,15 @@ namespace GxPress.Result.Web
         /// </summary>
         /// <value></value>
         public bool IsChildren { get; set; }
+        /// <summary>
+        /// 排序
+        /// </summary>
+        /// <value></value>
+        public int Sort { get; set; }
+        /// <summary>
+        /// 小组个数
+        /// </summary>
+        /// <value></value>
+        public int GroupCount { get; set; }
     }
 }

+ 16 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/Group/GroupCategoryRepository.cs

@@ -96,10 +96,24 @@ namespace GxPress.Repository.Implement.Group
         /// <returns></returns>
         public async Task<IEnumerable<GroupCategoryResult>> GetAllAsync(int parentId)
         {
-            var result = await _repository.GetAllAsync<GroupCategoryResult>(Q.Where(nameof(Entity.tede2.Group.GroupCategory.ParentId), parentId).OrderByDesc(nameof(Entity.tede2.Group.GroupCategory.CreatedDate)));
+            var sql = $@"SELECT 
+                            *,
+                            (SELECT 
+                                    COUNT(1)
+                                FROM
+                                    tede_group
+                                WHERE
+                                    GroupCategroyId = a.Id) AS GroupCount
+                        FROM
+                            tede_group_piazza AS a where a.ParentId={parentId}
+                        ORDER BY a.Sort DESC , a.CreatedDate DESC";
+            var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var result = await connection.QueryAsync<GroupCategoryResult>(sql);
             foreach (var item in result)
             {
-                item.IsChildren = await _repository.ExistsAsync(Q.Where(nameof(Entity.tede2.Group.GroupCategory.ParentId), item.Id));
+                //item.IsChildren = await _repository.ExistsAsync(Q.Where(nameof(Entity.tede2.Group.GroupCategory.ParentId), item.Id));
                 item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
             }
             return result;