李昊 %!s(int64=4) %!d(string=hai) anos
pai
achega
2364fe7b25

+ 42 - 0
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminGroupController.cs

@@ -0,0 +1,42 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using GxPress.Repository.Interface;
+using GxPress.Request.App.Group;
+using GxPress.Result.App.Group;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace GxPress.Api.AdminControllers
+{
+    [Route("api/admin/group")]
+    [ApiController]
+    [Authorize]
+    public class AdminGroupController : Controller
+    {
+        private readonly IGroupRepository groupRepository;
+        public AdminGroupController(IGroupRepository groupRepository)
+        {
+            this.groupRepository = groupRepository;
+        }
+
+        /// <summary>
+        /// 获取小组列表
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("list")]
+        public async Task<IEnumerable<GroupDetailResult>> GetGroupDetailResults()
+        {
+            return await groupRepository.GetGroupDetailResults();
+        }
+        /// <summary>
+        /// 修改小组
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("update")]
+        public async Task<bool> Update(GroupUpRequest request)
+        {
+            return await groupRepository.UpdateAsync(request);
+        }
+    }
+}

+ 6 - 0
gx_api/GxPress/Model/GxPress.Entity/Group.cs

@@ -95,6 +95,12 @@ namespace GxPress.Entity
         [DataColumn]
         public string HistoryAvatarUrl { get; set; }
         /// <summary>
+        /// 排序
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int Sort { get; set; }
+        /// <summary>
         /// 是否申请
         /// </summary>
         /// <value></value>

+ 5 - 0
gx_api/GxPress/Model/GxPress.Request/App/Group/GroupUpRequest.cs

@@ -66,5 +66,10 @@ namespace GxPress.Request.App.Group
         /// </summary>
         /// <value></value>
         public int IsShow { get; set; }
+        /// <summary>
+        /// 排序
+        /// </summary>
+        /// <value></value>
+        public int Sort { get; set; }
     }
 }

+ 6 - 0
gx_api/GxPress/Model/GxPress.Result/App/Group/GroupDetailResult.cs

@@ -155,6 +155,12 @@ namespace GxPress.Result.App.Group
         /// </summary>
         /// <value></value>
         public bool IsApply { get; set; }
+        /// <summary>
+        /// 分类名称
+        /// </summary>
+        /// <value></value>
+
+        public string CategroyName { get; set; }
     }
     /// <summary>
     /// 用户小组列表

+ 31 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/GroupRepository.cs

@@ -78,6 +78,7 @@ namespace GxPress.Repository.Implement
                 FileHelper.SaveQRCodeFile(StringUtils.GetWebRootPath(_environment.WebRootPath),
                     JsonConvert.SerializeObject(qrCodeData));
             groupDto.QRCoder = resultPath.RelativePath;
+            groupDto.Sort = id;
             await _repository.UpdateAsync(groupDto);
             return id;
         }
@@ -112,6 +113,8 @@ namespace GxPress.Repository.Implement
                 group.IsAdmin = request.IsAdmin == 1;
             if (request.IsWords > 0)
                 group.IsWords = request.IsWords == 1;
+            if (request.Sort > 0)
+                group.Sort = request.Sort;
             return await _repository.UpdateAsync(group);
         }
         /// <summary>
@@ -599,5 +602,33 @@ namespace GxPress.Repository.Implement
             }
             return result;
         }
+        /// <summary>
+        /// 获取小组列表
+        /// </summary>
+        /// <returns></returns>
+        public async Task<IEnumerable<GroupDetailResult>> GetGroupDetailResults()
+        {
+            string sql = @"SELECT 
+                            a.*, b.Name AS CategroyName, c.Name AS UserName
+                        FROM
+                            tede_group a
+                                INNER JOIN
+                            tede_user c ON a.UserId = c.Id
+                                LEFT JOIN
+                            tede_category b ON a.GroupCategroyId = b.Id
+                        ORDER BY a.Sort DESC , a.CreatedDate DESC;";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var result = await connection
+                .QueryAsync<GroupDetailResult>(sql);
+            foreach (var item in result)
+            {
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+                item.QRCoder = StringUtils.AddDomainMin(item.QRCoder);
+            }
+            return result;
+        }
+
     }
 }

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

@@ -108,5 +108,11 @@ namespace GxPress.Repository.Interface
         /// <param name="request"></param>
         /// <returns></returns>
         Task<bool> UpdateAsync(Entity.Group group);
+
+        /// <summary>
+        /// 获取小组列表
+        /// </summary>
+        /// <returns></returns>
+        Task<IEnumerable<GroupDetailResult>> GetGroupDetailResults();
     }
 }