97 lines
3.4 KiB
C#
97 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using IRaCIS.Application.Interfaces;
|
|
using IRaCIS.Application.ViewModels;
|
|
using IRaCIS.Core.Application.Contracts.RequestAndResponse;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace IRaCIS.Api.Controllers
|
|
{
|
|
[Route("menu")]
|
|
[ApiController, Authorize, ApiExplorerSettings(GroupName = "Management")]
|
|
public class MenuController : ControllerBase
|
|
{
|
|
private readonly IMenuService _menuService;
|
|
public MenuController(IMenuService menuService)
|
|
{
|
|
_menuService = menuService;
|
|
}
|
|
|
|
/// <summary> 获取完整菜单功能树形列表 </summary>
|
|
[HttpGet, Route("getMenuFunction")]
|
|
public IResponseOutput<List<MenuTreeNode>> GetMenuTreeAll()
|
|
{
|
|
|
|
return ResponseOutput.Ok(_menuService.GetTreeAll());
|
|
|
|
|
|
}
|
|
|
|
/// <summary> 在某个父节点下面 新增子菜单</summary>
|
|
[HttpPost, Route("addOrUpdateMenu")]
|
|
public IResponseOutput AddOrUpdateMenu(MenuFunctionCommand menuViewModel)
|
|
{
|
|
if (menuViewModel.ParentId == Guid.Empty)
|
|
{
|
|
|
|
return ResponseOutput.NotOk("ParentId 不能为空");
|
|
|
|
}
|
|
var userId = Guid.Parse(User.FindFirst("id").Value);
|
|
return _menuService.AddOrUpdateMenu(menuViewModel, userId);
|
|
}
|
|
/// <summary>根据Id删除节点</summary>
|
|
[HttpDelete, Route("deleteMenuFunction/{menuFunctionId:guid}")]
|
|
public IResponseOutput DeleteMenuFunction(Guid menuFunctionId)
|
|
{
|
|
return _menuService.DeleteMenuFunction(menuFunctionId);
|
|
}
|
|
/// <summary>
|
|
/// 获取某角色 菜单树 勾选情况 和 功能勾选情况
|
|
/// </summary>
|
|
/// <param name="roleId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("getRoleMenuFunction/{roleId:guid}")]
|
|
public IResponseOutput<List<MenuTreeNodeSelect>> GetTreeWithSelect(Guid roleId)
|
|
{
|
|
var treelist = _menuService.GetMenuFunctionIsSelectByRoleId(roleId);
|
|
|
|
return ResponseOutput.Ok(treelist);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取路由节点下的功能选中情况
|
|
/// </summary>
|
|
/// <param name="roleId"></param>
|
|
/// <param name="parentId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("getRoleFunction/{roleId:guid}/{parentId:guid}")]
|
|
public IResponseOutput<List<MenuTreeNodeSelect>> GetRoleFunctionTreeWithSelect(Guid roleId, Guid parentId)
|
|
{
|
|
var treelist = _menuService.GetFunctionIsSelectByRoleId(roleId, parentId);
|
|
return ResponseOutput.Ok(treelist);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新角色拥有的菜单 只传递操作的项
|
|
/// </summary>
|
|
/// <param name="selectModel"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("updateRoleMenu")]
|
|
public IResponseOutput UpdateRoleMenuSelect(RoleMenuFunctionSelectDTO selectModel)
|
|
{
|
|
return _menuService.UpdateRoleMenuSelect(selectModel.RoleId, selectModel.MenuFunctionId);
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[HttpPost, Route("updateRoleFunction")]
|
|
public IResponseOutput UpdateRoleFunctionSelect(FunctionSelectDTO selectModel)
|
|
{
|
|
return _menuService.UpdateRoleFunctionSelect(selectModel);
|
|
}
|
|
}
|
|
}
|