using HybirdFrameworkCore.Entity; using Microsoft.AspNetCore.Mvc; using Service.System.Roles; using Entity.Dto.Req; using Entity.Dto.Resp; using Common.Enum; using Entity.Base; using Entity.DbModel.System; namespace WebStarter.Controllers.System { [Produces("application/json")] [ApiController] public class SysRoleController { private SysRoleService _sysRoleServices; public SysRoleController(ILogger logger, SysRoleService sysRoleServices) { _sysRoleServices = sysRoleServices; } /// /// 获取角色分页列表 /// /// /// [HttpPost] [Route("api/sysRole/page")] public async Task>> RolePage(PageRoleReq input) { return Result>.Success(await _sysRoleServices.Page(input)); } /// /// 获取角色列表 /// /// [HttpGet] [Route("api/sysRole/list")] public async Task> GetList() { return await _sysRoleServices.GetList(); } /// /// 增加角色 /// /// /// [HttpPost] [Route("/api/sysRole/add")] public async Task> AddRole([FromBody] AddRoleReq input) { int result = 0; var data = await _sysRoleServices.AddRole(input); if (data == "增加角色成功") result = 200; return Result.Success(result); } /// /// 更新角色 /// /// /// [HttpPost] [Route("/api/sysRole/update")] public async Task> UpdateRole([FromBody] UpdateRoleReq input) { int result = 0; var data = await _sysRoleServices.UpdateRole(input); if (data == "数据更新成功") result = 200; return Result.Success(result); } /// /// 删除角色 /// /// /// [HttpPost] [Route("/api/sysRole/delete")] public async Task> DeleteRole([FromBody] DeleteRoleReq input) { int result = 0; var data = await _sysRoleServices.DeleteRole(input); if (data == "删除角色成功") { result = 200; return Result.Success(result); } else { return Result.Fail(result); } } /// /// 授权角色菜单 /// /// /// [HttpPost] [Route("/api/sysRole/grantMenu")] public async Task GrantMenu([FromBody] RoleMenuReq input) { await _sysRoleServices.GrantMenu(input); } /// /// 根据角色Id获取菜单Id集合 /// /// /// [HttpGet] [Route("/api/sysRole/ownMenuList/{id}")] public async Task> GetOwnMenuList(long id) { RoleReq roleInput = new RoleReq { Id = id, Status = StatusEnum.Enable }; return await _sysRoleServices.GetOwnMenuList(roleInput); } /// /// 设置角色状态 /// /// /// [HttpPost] [Route("/api/sysRole/setStatus")] public async Task SetStatus([FromBody] RoleReq input) { await _sysRoleServices.SetStatus(input); } } }