2021-08-23 16:57:25 +08:00
|
|
|
|
using Infrastructure;
|
|
|
|
|
|
using Infrastructure.Attribute;
|
|
|
|
|
|
using Infrastructure.Enums;
|
|
|
|
|
|
using Infrastructure.Model;
|
2022-05-13 22:13:44 +08:00
|
|
|
|
using Mapster;
|
2021-08-23 16:57:25 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using ZR.Admin.WebApi.Extensions;
|
|
|
|
|
|
using ZR.Admin.WebApi.Filters;
|
|
|
|
|
|
using ZR.Model.System;
|
2022-05-13 22:13:44 +08:00
|
|
|
|
using ZR.Model.System.Dto;
|
2021-09-16 19:35:17 +08:00
|
|
|
|
using ZR.Service.System.IService;
|
2021-08-23 16:57:25 +08:00
|
|
|
|
|
|
|
|
|
|
namespace ZR.Admin.WebApi.Controllers.System
|
|
|
|
|
|
{
|
2022-05-13 22:13:44 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 系统菜单
|
|
|
|
|
|
/// </summary>
|
2021-08-23 16:57:25 +08:00
|
|
|
|
[Verify]
|
|
|
|
|
|
[Route("/system/menu")]
|
|
|
|
|
|
public class SysMenuController : BaseController
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ISysRoleService sysRoleService;
|
|
|
|
|
|
private readonly ISysMenuService sysMenuService;
|
|
|
|
|
|
|
|
|
|
|
|
public SysMenuController(
|
|
|
|
|
|
ISysRoleService sysRoleService,
|
|
|
|
|
|
ISysMenuService sysMenuService)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.sysRoleService = sysRoleService;
|
|
|
|
|
|
this.sysMenuService = sysMenuService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-05-13 22:13:44 +08:00
|
|
|
|
/// 获取菜单列表
|
2021-08-23 16:57:25 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[ActionPermissionFilter(Permission = "system:menu:list")]
|
|
|
|
|
|
[HttpGet("list")]
|
2022-05-24 18:44:11 +08:00
|
|
|
|
public IActionResult TreeMenuList([FromQuery] MenuQueryDto menu)
|
2021-08-23 16:57:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
long userId = HttpContext.GetUId();
|
2022-01-15 21:31:40 +08:00
|
|
|
|
return SUCCESS(sysMenuService.SelectTreeMenuList(menu, userId), "yyyy-MM-dd HH:mm:ss");
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-05-13 22:13:44 +08:00
|
|
|
|
/// 根据菜单编号获取详细信息
|
2021-08-23 16:57:25 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="menuId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet("{menuId}")]
|
|
|
|
|
|
[ActionPermissionFilter(Permission = "system:menu:query")]
|
|
|
|
|
|
public IActionResult GetMenuInfo(int menuId = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return SUCCESS(sysMenuService.GetMenuByMenuId(menuId), "yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取菜单下拉树列表(分配角色所需菜单)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet("treeSelect")]
|
|
|
|
|
|
public IActionResult TreeSelect()
|
|
|
|
|
|
{
|
|
|
|
|
|
long userId = HttpContext.GetUId();
|
2022-05-24 18:44:11 +08:00
|
|
|
|
var list = sysMenuService.SelectMenuList(new MenuQueryDto(), userId).FindAll(f => f.visible == "0");
|
2021-08-23 16:57:25 +08:00
|
|
|
|
var treeMenus = sysMenuService.BuildMenuTreeSelect(list);
|
|
|
|
|
|
|
|
|
|
|
|
return SUCCESS(treeMenus);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取角色菜单信息
|
|
|
|
|
|
/// 加载对应角色菜单列表树
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="roleId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet("roleMenuTreeselect/{roleId}")]
|
|
|
|
|
|
public IActionResult RoleMenuTreeselect(int roleId)
|
|
|
|
|
|
{
|
|
|
|
|
|
long userId = HttpContext.GetUId();
|
2022-05-24 18:44:11 +08:00
|
|
|
|
var menus = sysMenuService.SelectMenuList(new MenuQueryDto(), userId);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
var checkedKeys = sysRoleService.SelectUserRoleMenus(roleId);
|
|
|
|
|
|
return SUCCESS(new
|
|
|
|
|
|
{
|
|
|
|
|
|
checkedKeys,
|
|
|
|
|
|
menus = sysMenuService.BuildMenuTreeSelect(menus),
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-05-13 22:13:44 +08:00
|
|
|
|
/// 修改菜单
|
2021-08-23 16:57:25 +08:00
|
|
|
|
/// </summary>
|
2022-04-23 20:29:40 +08:00
|
|
|
|
/// <param name="menuDto"></param>
|
2021-08-23 16:57:25 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost("edit")]
|
|
|
|
|
|
[Log(Title = "菜单管理", BusinessType = BusinessType.UPDATE)]
|
|
|
|
|
|
[ActionPermissionFilter(Permission = "system:menu:edit")]
|
2022-04-23 20:29:40 +08:00
|
|
|
|
public IActionResult MenuEdit([FromBody] MenuDto menuDto)
|
2021-08-23 16:57:25 +08:00
|
|
|
|
{
|
2022-04-23 20:29:40 +08:00
|
|
|
|
if (menuDto == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
|
2021-08-23 16:57:25 +08:00
|
|
|
|
//if (UserConstants.NOT_UNIQUE.Equals(sysMenuService.CheckMenuNameUnique(MenuDto)))
|
|
|
|
|
|
//{
|
2021-09-27 16:07:55 +08:00
|
|
|
|
// return ToResponse(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,菜单名称已存在"));
|
2021-08-23 16:57:25 +08:00
|
|
|
|
//}
|
2022-04-23 20:29:40 +08:00
|
|
|
|
var config = new TypeAdapterConfig();
|
|
|
|
|
|
//映射规则
|
|
|
|
|
|
config.ForType<SysMenu, MenuDto>()
|
|
|
|
|
|
.NameMatchingStrategy(NameMatchingStrategy.IgnoreCase);//忽略字段名称的大小写;//忽略除以上配置的所有字段
|
|
|
|
|
|
|
|
|
|
|
|
var modal = menuDto.Adapt<SysMenu>(config).ToUpdate(HttpContext);
|
|
|
|
|
|
if (UserConstants.YES_FRAME.Equals(modal.isFrame) && !modal.path.StartsWith("http"))
|
2021-08-23 16:57:25 +08:00
|
|
|
|
{
|
2022-04-23 20:29:40 +08:00
|
|
|
|
return ToResponse(ApiResult.Error($"修改菜单'{modal.MenuName}'失败,地址必须以http(s)://开头"));
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
2022-04-23 20:29:40 +08:00
|
|
|
|
if (modal.MenuId.Equals(modal.parentId))
|
2021-08-23 16:57:25 +08:00
|
|
|
|
{
|
2022-04-23 20:29:40 +08:00
|
|
|
|
return ToResponse(ApiResult.Error($"修改菜单'{modal.MenuName}'失败,上级菜单不能选择自己"));
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
2022-04-23 20:29:40 +08:00
|
|
|
|
modal.Update_by = HttpContext.GetName();
|
|
|
|
|
|
int result = sysMenuService.EditMenu(modal);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
|
2021-09-27 16:07:55 +08:00
|
|
|
|
return ToResponse(result);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-05-13 22:13:44 +08:00
|
|
|
|
/// 添加菜单
|
2021-08-23 16:57:25 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="MenuDto"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPut("add")]
|
|
|
|
|
|
[Log(Title = "菜单管理", BusinessType = BusinessType.INSERT)]
|
|
|
|
|
|
[ActionPermissionFilter(Permission = "system:menu:add")]
|
|
|
|
|
|
public IActionResult MenuAdd([FromBody] SysMenu MenuDto)
|
|
|
|
|
|
{
|
2021-09-27 16:07:55 +08:00
|
|
|
|
if (MenuDto == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
|
2021-08-23 16:57:25 +08:00
|
|
|
|
if (UserConstants.NOT_UNIQUE.Equals(sysMenuService.CheckMenuNameUnique(MenuDto)))
|
|
|
|
|
|
{
|
2022-04-23 20:29:40 +08:00
|
|
|
|
return ToResponse(ApiResult.Error($"新增菜单'{MenuDto.MenuName}'失败,菜单名称已存在"));
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (UserConstants.YES_FRAME.Equals(MenuDto.isFrame) && !MenuDto.path.StartsWith("http"))
|
|
|
|
|
|
{
|
2022-04-23 20:29:40 +08:00
|
|
|
|
return ToResponse(ApiResult.Error($"新增菜单'{MenuDto.MenuName}'失败,地址必须以http(s)://开头"));
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MenuDto.Create_by = User.Identity.Name;
|
|
|
|
|
|
int result = sysMenuService.AddMenu(MenuDto);
|
|
|
|
|
|
|
2021-09-27 16:07:55 +08:00
|
|
|
|
return ToResponse(result);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-05-13 22:13:44 +08:00
|
|
|
|
/// 菜单删除
|
2021-08-23 16:57:25 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="menuId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpDelete("{menuId}")]
|
|
|
|
|
|
[Log(Title = "菜单管理", BusinessType = BusinessType.DELETE)]
|
|
|
|
|
|
[ActionPermissionFilter(Permission = "system:menu:remove")]
|
|
|
|
|
|
public IActionResult Remove(int menuId = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sysMenuService.HasChildByMenuId(menuId))
|
|
|
|
|
|
{
|
2022-01-11 10:49:38 +08:00
|
|
|
|
return ToResponse(ResultCode.CUSTOM_ERROR, "存在子菜单,不允许删除");
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (sysMenuService.CheckMenuExistRole(menuId))
|
|
|
|
|
|
{
|
2022-01-11 10:49:38 +08:00
|
|
|
|
return ToResponse(ResultCode.CUSTOM_ERROR, "菜单已分配,不允许删除");
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
int result = sysMenuService.DeleteMenuById(menuId);
|
|
|
|
|
|
|
2021-09-27 16:07:55 +08:00
|
|
|
|
return ToResponse(result);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 保存排序
|
|
|
|
|
|
/// </summary>
|
2022-04-26 10:23:18 +08:00
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
/// <param name="value"></param>
|
2021-08-23 16:57:25 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[ActionPermissionFilter(Permission = "system:menu:update")]
|
2022-04-26 10:23:18 +08:00
|
|
|
|
[HttpGet("ChangeSort")]
|
2021-08-23 16:57:25 +08:00
|
|
|
|
[Log(Title = "保存排序", BusinessType = BusinessType.UPDATE)]
|
2022-04-26 10:23:18 +08:00
|
|
|
|
public IActionResult ChangeSort(int id = 0, int value = 0)
|
2021-08-23 16:57:25 +08:00
|
|
|
|
{
|
2022-04-26 10:23:18 +08:00
|
|
|
|
MenuDto MenuDto = new()
|
|
|
|
|
|
{
|
|
|
|
|
|
MenuId = id,
|
|
|
|
|
|
orderNum = value
|
|
|
|
|
|
};
|
2021-09-27 16:07:55 +08:00
|
|
|
|
if (MenuDto == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
|
2021-08-23 16:57:25 +08:00
|
|
|
|
|
|
|
|
|
|
int result = sysMenuService.ChangeSortMenu(MenuDto);
|
2021-09-27 16:07:55 +08:00
|
|
|
|
return ToResponse(result);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|