You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.0 KiB

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