SysUserRoleController.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Attribute;
  2. using Dto;
  3. using Enums;
  4. using Filters;
  5. using Infrastructure;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Middleware;
  8. using Services;
  9. namespace Controllers
  10. {
  11. /// <summary>
  12. /// 用户角色管理
  13. /// </summary>
  14. [Verify]
  15. [Route("system/userRole")]
  16. [ApiExplorerSettings(GroupName = "sys")]
  17. public class SysUserRoleController : BaseController
  18. {
  19. private readonly ISysUserRoleService SysUserRoleService;
  20. private readonly ISysUserService UserService;
  21. public SysUserRoleController(
  22. ISysUserRoleService sysUserRoleService,
  23. ISysUserService userService)
  24. {
  25. SysUserRoleService = sysUserRoleService;
  26. UserService = userService;
  27. }
  28. /// <summary>
  29. /// 根据角色编号获取已分配的用户
  30. /// </summary>
  31. /// <param name="roleUserQueryDto"></param>
  32. /// <returns></returns>
  33. [HttpGet("list")]
  34. [ActionPermissionFilter(Permission = "system:roleusers:list")]
  35. public IActionResult GetList([FromQuery] RoleUserQueryDto roleUserQueryDto)
  36. {
  37. var list = SysUserRoleService.GetSysUsersByRoleId(roleUserQueryDto);
  38. return SUCCESS(list, TIME_FORMAT_FULL);
  39. }
  40. /// <summary>
  41. /// 添加角色用户
  42. /// </summary>
  43. /// <returns></returns>
  44. [HttpPost("create")]
  45. [ActionPermissionFilter(Permission = "system:roleusers:add")]
  46. [Log(Title = "添加角色用户", BusinessType = BusinessType.INSERT)]
  47. public IActionResult Create([FromBody] RoleUsersCreateDto roleUsersCreateDto)
  48. {
  49. var response = SysUserRoleService.InsertRoleUser(roleUsersCreateDto);
  50. return SUCCESS(response);
  51. }
  52. /// <summary>
  53. /// 删除角色用户
  54. /// </summary>
  55. /// <param name="roleUsersCreateDto"></param>
  56. /// <returns></returns>
  57. [HttpPost("delete")]
  58. [ActionPermissionFilter(Permission = "system:roleusers:remove")]
  59. [Log(Title = "删除角色用户", BusinessType = BusinessType.DELETE)]
  60. public IActionResult Delete([FromBody] RoleUsersCreateDto roleUsersCreateDto)
  61. {
  62. return SUCCESS(SysUserRoleService.DeleteRoleUserByUserIds(roleUsersCreateDto.RoleId, roleUsersCreateDto.UserIds));
  63. }
  64. /// <summary>
  65. /// 获取未分配用户角色
  66. /// </summary>
  67. /// <param name="roleUserQueryDto"></param>
  68. /// <returns></returns>
  69. [HttpGet("GetExcludeUsers")]
  70. public IActionResult GetExcludeUsers([FromQuery] RoleUserQueryDto roleUserQueryDto)
  71. {
  72. if (roleUserQueryDto.RoleId <= 0)
  73. {
  74. throw new CustomException(ResultCode.PARAM_ERROR, "roleId不能为空");
  75. }
  76. // 获取未添加用户
  77. var list = SysUserRoleService.GetExcludedSysUsersByRoleId(roleUserQueryDto);
  78. return SUCCESS(list, TIME_FORMAT_FULL);
  79. }
  80. }
  81. }