using Attribute; using Dto; using Enums; using Filters; using Infrastructure; using Microsoft.AspNetCore.Mvc; using Middleware; using Services; namespace Controllers { /// /// 用户角色管理 /// [Verify] [Route("system/userRole")] [ApiExplorerSettings(GroupName = "sys")] public class SysUserRoleController : BaseController { private readonly ISysUserRoleService SysUserRoleService; private readonly ISysUserService UserService; public SysUserRoleController( ISysUserRoleService sysUserRoleService, ISysUserService userService) { SysUserRoleService = sysUserRoleService; UserService = userService; } /// /// 根据角色编号获取已分配的用户 /// /// /// [HttpGet("list")] [ActionPermissionFilter(Permission = "system:roleusers:list")] public IActionResult GetList([FromQuery] RoleUserQueryDto roleUserQueryDto) { var list = SysUserRoleService.GetSysUsersByRoleId(roleUserQueryDto); return SUCCESS(list, TIME_FORMAT_FULL); } /// /// 添加角色用户 /// /// [HttpPost("create")] [ActionPermissionFilter(Permission = "system:roleusers:add")] [Log(Title = "添加角色用户", BusinessType = BusinessType.INSERT)] public IActionResult Create([FromBody] RoleUsersCreateDto roleUsersCreateDto) { var response = SysUserRoleService.InsertRoleUser(roleUsersCreateDto); return SUCCESS(response); } /// /// 删除角色用户 /// /// /// [HttpPost("delete")] [ActionPermissionFilter(Permission = "system:roleusers:remove")] [Log(Title = "删除角色用户", BusinessType = BusinessType.DELETE)] public IActionResult Delete([FromBody] RoleUsersCreateDto roleUsersCreateDto) { return SUCCESS(SysUserRoleService.DeleteRoleUserByUserIds(roleUsersCreateDto.RoleId, roleUsersCreateDto.UserIds)); } /// /// 获取未分配用户角色 /// /// /// [HttpGet("GetExcludeUsers")] public IActionResult GetExcludeUsers([FromQuery] RoleUserQueryDto roleUserQueryDto) { if (roleUserQueryDto.RoleId <= 0) { throw new CustomException(ResultCode.PARAM_ERROR, "roleId不能为空"); } // 获取未添加用户 var list = SysUserRoleService.GetExcludedSysUsersByRoleId(roleUserQueryDto); return SUCCESS(list, TIME_FORMAT_FULL); } } }