李昊 4 年之前
父節點
當前提交
b3bb3ed1a0

+ 3 - 2
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminSystemRoleController.cs

@@ -2,6 +2,7 @@ using System.Collections.Generic;
 using System.Threading.Tasks;
 using GxPress.Request.Menu;
 using GxPress.Request.Role;
+using GxPress.Result.SystemRole;
 using GxPress.Service.Interface.Role;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
@@ -46,7 +47,7 @@ namespace GxPress.Api.AdminControllers
         /// </summary>
         /// <returns></returns>
         [HttpGet("role")]
-        public async Task<IEnumerable<Entity.SystemRole.SystemRole>> GetSystemRoleAllAsync()
+        public async Task<List<SystemRoleResult>> GetSystemRoleAllAsync()
         {
             return await roleService.GetSystemRoleAllAsync();
         }
@@ -65,7 +66,7 @@ namespace GxPress.Api.AdminControllers
         /// </summary>
         /// <param name="id"></param>
         /// <returns></returns>
-        [HttpDelete("role")]
+        [HttpDelete("role/{id}")]
         public async Task<bool> DeleteSystemRoleAsync(int id)
         {
             return await roleService.DeleteSystemRoleAsync(id);

+ 2 - 0
gx_api/GxPress/Model/GxPress.Entity/SystemRole/SystemRole.cs

@@ -1,3 +1,4 @@
+using System.Collections.Generic;
 using Datory.Annotations;
 
 namespace GxPress.Entity.SystemRole
@@ -15,5 +16,6 @@ namespace GxPress.Entity.SystemRole
         /// <value></value>
         [DataColumn]
         public string Name { get; set; }
+    
     }
 }

+ 3 - 0
gx_api/GxPress/Model/GxPress.Mappings/MenuMapping.cs

@@ -1,6 +1,7 @@
 using AutoMapper;
 using GxPress.Entity.Menus;
 using GxPress.Request.Menu;
+using GxPress.Result.SystemRole;
 
 namespace GxPress.Mappings
 {
@@ -12,6 +13,8 @@ namespace GxPress.Mappings
             CreateMap<Children, Menus>();
             CreateMap<MenuInRequest, Menus>();
             CreateMap<Menus, MenuInRequest>();
+            CreateMap<Menus, MenuInResult>();
+            CreateMap<MenuInResult, Menus>();
         }
     }
 }

+ 50 - 0
gx_api/GxPress/Model/GxPress.Result/SystemRole/SystemRoleResult.cs

@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+
+namespace GxPress.Result.SystemRole
+{
+    public class SystemRoleResult
+    {
+        public Entity.SystemRole.SystemRole SystemRole { get; set; }
+        public List<MenuInResult> MenuInResult { get; set; }
+    }
+    public class MenuInResult
+    {
+
+        /// <summary>
+        /// ID
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 父级ID
+        /// </summary>
+        /// <value></value>
+        public int ParentId { get; set; }
+        /// <summary>
+        /// 标题
+        /// </summary>
+        /// <value></value>
+        public string Title { get; set; }
+        /// <summary>
+        /// 名称
+        /// </summary>
+        /// <value></value>
+        public string Name { get; set; }
+        /// <summary>
+        /// 图标名称
+        /// </summary>
+        /// <value></value>
+        public string Icon { get; set; }
+        /// <summary>
+        /// 孩子
+        /// </summary>
+        /// <value></value>
+        public List<MenuInResult> Children { get; set; }
+        /// <summary>
+        /// 路径
+        /// </summary>
+        /// <value></value>
+
+        public string Path { get; set; }
+    }
+}

+ 4 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/SystemRoleMenus/SystemRoleMenusRepository.cs

@@ -63,5 +63,9 @@ namespace GxPress.Repository.Implement.SystemRoleMenus
             return true;
 
         }
+        public async Task<bool> DeleteAsync(int roleId)
+        {
+            return await _repository.DeleteAsync(Q.Where(nameof(Entity.SystemRole.SystemRoleMenus.RoleId), roleId)) > 0;
+        }
     }
 }

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/SystemRoleMenus/ISystemRoleMenusRepository.cs

@@ -15,5 +15,6 @@ namespace GxPress.Repository.Interface.SystemRoleMenus
         Task<bool> InsertAsync(SystemRoleMenusInRequest models);
 
         Task<IEnumerable<Entity.SystemRole.SystemRoleMenus>> GetAllAsync(int roleId);
+        Task<bool> DeleteAsync(int roleId);
     }
 }

+ 23 - 3
gx_api/GxPress/Service/GxPress.Service.Implement/Role/RoleService.cs

@@ -10,6 +10,7 @@ using System.Transactions;
 using AutoMapper;
 using GxPress.Request.Menu;
 using System.Transactions;
+using GxPress.Result.SystemRole;
 
 namespace GxPress.Service.Implement.Role
 {
@@ -66,9 +67,27 @@ namespace GxPress.Service.Implement.Role
             return true;
         }
 
-        public async Task<IEnumerable<Entity.SystemRole.SystemRole>> GetSystemRoleAllAsync()
+        public async Task<List<SystemRoleResult>> GetSystemRoleAllAsync()
         {
-            return await systemRoleRepository.GetSystemRolesAllAsync();
+            var result = new List<SystemRoleResult>();
+            var systemRoles = await systemRoleRepository.GetSystemRolesAllAsync();
+            foreach (var systemRole in systemRoles)
+            {
+                var models = await systemRoleMenusRepository.GetAllAsync(systemRole.Id);
+                var item = await menusRepository.GetAllAsync(models.Select(n => n.MenuId).ToList());
+                var systemRoleResult = new SystemRoleResult();
+                systemRoleResult.SystemRole = systemRole;
+                var menuInRequest = new List<MenuInResult>();
+                var model = item.Where(n => n.ParentId == 0).Select(n => _mapper.Map<MenuInResult>(n)).ToList();
+                foreach (var request in model)
+                {
+                    request.Children = item.Where(n => n.ParentId == request.Id).Select(n => _mapper.Map<MenuInResult>(n)).ToList();
+                }
+                systemRoleResult.MenuInResult = model;
+                result.Add(systemRoleResult);
+            }
+            return result;
+
         }
         /// <summary>
         /// 修改权限
@@ -104,6 +123,7 @@ namespace GxPress.Service.Implement.Role
         /// <returns></returns>
         public async Task<bool> DeleteSystemRoleAsync(int id)
         {
+            await systemRoleMenusRepository.DeleteAsync(id);
             return await systemRoleRepository.DeleteAsync(id);
         }
         /// <summary>
@@ -194,7 +214,7 @@ namespace GxPress.Service.Implement.Role
             result = item.Where(n => n.ParentId == 0).Select(n => _mapper.Map<MenuInRequest>(n)).ToList();
             foreach (var request in result)
             {
-                request.Children=item.Where(n => n.ParentId == request.Id).Select(n => _mapper.Map<MenuInRequest>(n)).ToList();
+                request.Children = item.Where(n => n.ParentId == request.Id).Select(n => _mapper.Map<MenuInRequest>(n)).ToList();
             }
             return result;
         }

+ 2 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/Role/IRoleService.cs

@@ -2,6 +2,7 @@ using System.Collections.Generic;
 using System.Threading.Tasks;
 using GxPress.Request.Menu;
 using GxPress.Request.Role;
+using GxPress.Result.SystemRole;
 
 namespace GxPress.Service.Interface.Role
 {
@@ -69,6 +70,6 @@ namespace GxPress.Service.Interface.Role
         /// 获取所有权限
         /// </summary>
         /// <returns></returns>
-        Task<IEnumerable<Entity.SystemRole.SystemRole>> GetSystemRoleAllAsync();
+        Task<List<SystemRoleResult>> GetSystemRoleAllAsync();
     }
 }