✨ 角色管理新增导出角色菜单
This commit is contained in:
parent
0e043c5716
commit
9d87d75a09
@ -11,6 +11,11 @@ using ZR.Service.System.IService;
|
|||||||
using ZR.Admin.WebApi.Extensions;
|
using ZR.Admin.WebApi.Extensions;
|
||||||
using ZR.Model.System.Dto;
|
using ZR.Model.System.Dto;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
|
using ZR.Service;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Aliyun.OSS;
|
||||||
|
using MiniExcelLibs.OpenXml;
|
||||||
|
using MiniExcelLibs;
|
||||||
|
|
||||||
namespace ZR.Admin.WebApi.Controllers.System
|
namespace ZR.Admin.WebApi.Controllers.System
|
||||||
{
|
{
|
||||||
@ -22,11 +27,14 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
public class SysRoleController : BaseController
|
public class SysRoleController : BaseController
|
||||||
{
|
{
|
||||||
private readonly ISysRoleService sysRoleService;
|
private readonly ISysRoleService sysRoleService;
|
||||||
|
private readonly ISysMenuService sysMenuService;
|
||||||
|
|
||||||
public SysRoleController(
|
public SysRoleController(
|
||||||
ISysRoleService sysRoleService)
|
ISysRoleService sysRoleService,
|
||||||
|
ISysMenuService sysMenuService)
|
||||||
{
|
{
|
||||||
this.sysRoleService = sysRoleService;
|
this.sysRoleService = sysRoleService;
|
||||||
|
this.sysMenuService = sysMenuService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -179,5 +187,23 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
string sFileName = ExportExcel(list, "sysrole", "角色");
|
string sFileName = ExportExcel(list, "sysrole", "角色");
|
||||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导出角色菜单
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "角色菜单导出")]
|
||||||
|
[HttpGet("exportRoleMenu")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public IActionResult ExportRoleMenu(int roleId)
|
||||||
|
{
|
||||||
|
MenuQueryDto dto = new() { Status = "0", MenuTypeIds = "M,C,F" };
|
||||||
|
|
||||||
|
var list = sysMenuService.SelectRoleMenuListByRole(dto, roleId);
|
||||||
|
|
||||||
|
var result = ExportExcelMini(list, roleId.ToString(), "角色菜单");
|
||||||
|
return ExportExcel(result.Item2, result.Item1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using MiniExcelLibs.Attributes;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace ZR.Model.System.Dto
|
namespace ZR.Model.System.Dto
|
||||||
@ -7,7 +9,9 @@ namespace ZR.Model.System.Dto
|
|||||||
{
|
{
|
||||||
//{"parentId":0,"menuName":"aaa","icon":"documentation","menuType":"M","orderNum":999,"visible":0,"status":0,"path":"aaa"}
|
//{"parentId":0,"menuName":"aaa","icon":"documentation","menuType":"M","orderNum":999,"visible":0,"status":0,"path":"aaa"}
|
||||||
[Required(ErrorMessage = "菜单id不能为空")]
|
[Required(ErrorMessage = "菜单id不能为空")]
|
||||||
|
[ExcelColumn(Name = "菜单id")]
|
||||||
public int MenuId { get; set; }
|
public int MenuId { get; set; }
|
||||||
|
[ExcelColumn(Name = "菜单名")]
|
||||||
public string MenuName { get; set; }
|
public string MenuName { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 父菜单ID
|
/// 父菜单ID
|
||||||
@ -22,17 +26,20 @@ namespace ZR.Model.System.Dto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 路由地址
|
/// 路由地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ExcelColumn(Name = "路由地址")]
|
||||||
public string Path { get; set; } = "#";
|
public string Path { get; set; } = "#";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 组件路径
|
/// 组件路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ExcelColumn(Name = "组件地址")]
|
||||||
public string Component { get; set; }
|
public string Component { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否缓存(1缓存 0不缓存)
|
/// 是否缓存(1缓存 0不缓存)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Required(ErrorMessage = "是否缓存不能为空")]
|
[Required(ErrorMessage = "是否缓存不能为空")]
|
||||||
|
[ExcelColumn(Name = "是否缓存")]
|
||||||
public int IsCache { get; set; }
|
public int IsCache { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否外链 1、是 0、否
|
/// 是否外链 1、是 0、否
|
||||||
@ -60,6 +67,7 @@ namespace ZR.Model.System.Dto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 权限字符串
|
/// 权限字符串
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ExcelColumn(Name = "权限字符串")]
|
||||||
public string Perms { get; set; }
|
public string Perms { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -70,6 +78,7 @@ namespace ZR.Model.System.Dto
|
|||||||
/// 翻译key
|
/// 翻译key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string MenuNameKey { get; set; }
|
public string MenuNameKey { get; set; }
|
||||||
|
public List<MenuDto> Children { get; set; } = new List<MenuDto>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MenuQueryDto
|
public class MenuQueryDto
|
||||||
|
|||||||
30
ZR.Model/System/Dto/RoleMenuExportDto.cs
Normal file
30
ZR.Model/System/Dto/RoleMenuExportDto.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using MiniExcelLibs.Attributes;
|
||||||
|
using SqlSugar.DbConvert;
|
||||||
|
using ZR.Model.System.Enums;
|
||||||
|
|
||||||
|
namespace ZR.Model.System.Dto
|
||||||
|
{
|
||||||
|
public class RoleMenuExportDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 一级目录名
|
||||||
|
/// </summary>
|
||||||
|
[ExcelColumn(Name = "菜单", Width = 50)]
|
||||||
|
public string MenuName { get; set; }
|
||||||
|
//[ExcelColumn(Name = "菜单名", Width = 20)]
|
||||||
|
//public string MenuName1 { get; set; }
|
||||||
|
//[ExcelColumn(Name = "权限按钮", Width = 20)]
|
||||||
|
//public string MenuName2 { get; set; }
|
||||||
|
[ExcelColumn(Name = "路径", Width = 20)]
|
||||||
|
public string Path { get; set; }
|
||||||
|
[ExcelColumn(Name = "组件名", Width = 20)]
|
||||||
|
public string Component { get; set; }
|
||||||
|
[ExcelColumn(Name = "权限字符", Width = 20)]
|
||||||
|
public string Perms { get; set; }
|
||||||
|
//[ExcelColumn(Name = "菜单类型")]
|
||||||
|
//[SqlSugar.SugarColumn(SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||||
|
//public MenuType MenuType { get; set; }
|
||||||
|
//[ExcelColumn(Name = "菜单状态")]
|
||||||
|
//public MenuStatus Status { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
15
ZR.Model/System/Enums/MenuStatus.cs
Normal file
15
ZR.Model/System/Enums/MenuStatus.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ZR.Model.System.Enums
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 菜单状态(0正常 1停用)
|
||||||
|
/// </summary>
|
||||||
|
public enum MenuStatus
|
||||||
|
{
|
||||||
|
[Description("正常")]
|
||||||
|
正常 = 0,
|
||||||
|
[Description("停用")]
|
||||||
|
停用 = 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
19
ZR.Model/System/Enums/MenuType.cs
Normal file
19
ZR.Model/System/Enums/MenuType.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ZR.Model.System.Enums
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// M目录 C菜单 F按钮 L链接
|
||||||
|
/// </summary>
|
||||||
|
public enum MenuType
|
||||||
|
{
|
||||||
|
[Description("目录")]
|
||||||
|
M,
|
||||||
|
[Description("菜单")]
|
||||||
|
C,
|
||||||
|
[Description("按钮")]
|
||||||
|
F,
|
||||||
|
[Description("链接")]
|
||||||
|
L
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -40,6 +40,8 @@ namespace ZR.Service.System.IService
|
|||||||
List<TreeSelectVo> BuildMenuTreeSelect(List<SysMenu> menus);
|
List<TreeSelectVo> BuildMenuTreeSelect(List<SysMenu> menus);
|
||||||
|
|
||||||
void AddSysMenu(GenTable genTableInfo, string permPrefix, bool showEdit, bool showExport);
|
void AddSysMenu(GenTable genTableInfo, string permPrefix, bool showEdit, bool showExport);
|
||||||
|
List<SysMenu> SelectTreeMenuListByRoles(MenuQueryDto menu, List<long> roles);
|
||||||
|
List<RoleMenuExportDto> SelectRoleMenuListByRole(MenuQueryDto menu, int roleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using Infrastructure.Attribute;
|
using Infrastructure.Attribute;
|
||||||
using Infrastructure.Extensions;
|
using Infrastructure.Extensions;
|
||||||
|
using JinianNet.JNTemplate.Dynamic;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -7,6 +8,7 @@ using System.Linq;
|
|||||||
using ZR.Common;
|
using ZR.Common;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
using ZR.Model.System.Dto;
|
using ZR.Model.System.Dto;
|
||||||
|
using ZR.Model.System.Enums;
|
||||||
using ZR.Model.System.Generate;
|
using ZR.Model.System.Generate;
|
||||||
using ZR.Model.System.Vo;
|
using ZR.Model.System.Vo;
|
||||||
using ZR.Service.System.IService;
|
using ZR.Service.System.IService;
|
||||||
@ -220,7 +222,7 @@ namespace ZR.Service
|
|||||||
/// <param name="menu"></param>
|
/// <param name="menu"></param>
|
||||||
/// <param name="roles">用户角色集合</param>
|
/// <param name="roles">用户角色集合</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private List<SysMenu> SelectTreeMenuListByRoles(MenuQueryDto menu, List<long> roles)
|
public List<SysMenu> SelectTreeMenuListByRoles(MenuQueryDto menu, List<long> roles)
|
||||||
{
|
{
|
||||||
var roleMenus = Context.Queryable<SysRoleMenu>()
|
var roleMenus = Context.Queryable<SysRoleMenu>()
|
||||||
.Where(r => roles.Contains(r.Role_id))
|
.Where(r => roles.Contains(r.Role_id))
|
||||||
@ -237,6 +239,35 @@ namespace ZR.Service
|
|||||||
.ToTree(it => it.Children, it => it.ParentId, 0);
|
.ToTree(it => it.Children, it => it.ParentId, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据用户查询系统菜单列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="menu"></param>
|
||||||
|
/// <param name="roleId">用户角色</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<RoleMenuExportDto> SelectRoleMenuListByRole(MenuQueryDto menu, int roleId)
|
||||||
|
{
|
||||||
|
var menuIds = Context.Queryable<SysRoleMenu>()
|
||||||
|
.Where(r => r.Role_id == roleId)
|
||||||
|
.Select(f => f.Menu_id).Distinct().ToList();
|
||||||
|
|
||||||
|
return Context.Queryable<SysMenu>()
|
||||||
|
.InnerJoin<SysMenu>((t1, t2) => t1.MenuId == t2.ParentId)
|
||||||
|
.InnerJoin<SysMenu>((t1, t2, t3) => t2.MenuId == t3.ParentId)
|
||||||
|
.Where((t1, t2, t3) => menuIds.Contains(t1.MenuId))
|
||||||
|
.Select((t1, t2, t3) => new RoleMenuExportDto()
|
||||||
|
{
|
||||||
|
MenuName = $"{t1.MenuName}->{t2.MenuName}->{t3.MenuName}",
|
||||||
|
//MenuName1 = t2.MenuName,
|
||||||
|
//MenuName2 = t3.MenuName,
|
||||||
|
Path = t2.Path,
|
||||||
|
Component = t2.Component,
|
||||||
|
Perms = t3.Perms,
|
||||||
|
//MenuType = (MenuType)Enum.Parse(typeof(MenuType), t3.MenuType) //(MenuType)t3.MenuType,
|
||||||
|
//Status = t3.Status
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取所有菜单
|
/// 获取所有菜单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user