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; } /// 获取完整菜单功能树形列表 [HttpGet, Route("getMenuFunction")] public IResponseOutput> GetMenuTreeAll() { return ResponseOutput.Ok(_menuService.GetTreeAll()); } /// 在某个父节点下面 新增子菜单 [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); } /// 根据Id删除节点 [HttpDelete, Route("deleteMenuFunction/{menuFunctionId:guid}")] public IResponseOutput DeleteMenuFunction(Guid menuFunctionId) { return _menuService.DeleteMenuFunction(menuFunctionId); } /// /// 获取某角色 菜单树 勾选情况 和 功能勾选情况 /// /// /// [HttpGet, Route("getRoleMenuFunction/{roleId:guid}")] public IResponseOutput> GetTreeWithSelect(Guid roleId) { var treelist = _menuService.GetMenuFunctionIsSelectByRoleId(roleId); return ResponseOutput.Ok(treelist); } /// /// 获取路由节点下的功能选中情况 /// /// /// /// [HttpGet, Route("getRoleFunction/{roleId:guid}/{parentId:guid}")] public IResponseOutput> GetRoleFunctionTreeWithSelect(Guid roleId, Guid parentId) { var treelist = _menuService.GetFunctionIsSelectByRoleId(roleId, parentId); return ResponseOutput.Ok(treelist); } /// /// 更新角色拥有的菜单 只传递操作的项 /// /// /// [HttpPost, Route("updateRoleMenu")] public IResponseOutput UpdateRoleMenuSelect(RoleMenuFunctionSelectDTO selectModel) { return _menuService.UpdateRoleMenuSelect(selectModel.RoleId, selectModel.MenuFunctionId); } /// /// /// [HttpPost, Route("updateRoleFunction")] public IResponseOutput UpdateRoleFunctionSelect(FunctionSelectDTO selectModel) { return _menuService.UpdateRoleFunctionSelect(selectModel); } } }