SysRoleController.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package com.simuwang.manage.api.system;
  2. import com.simuwang.base.common.support.MybatisPage;
  3. import com.simuwang.base.common.support.vo.OnlyIdNameVO;
  4. import com.simuwang.base.pojo.dto.DeleteByIdCmd;
  5. import com.simuwang.base.pojo.dto.GetByIdQuery;
  6. import com.simuwang.base.pojo.dto.UpdateStatusCmd;
  7. import com.simuwang.base.pojo.dto.sys.RoleAddCmd;
  8. import com.simuwang.base.pojo.dto.sys.RoleEditCmd;
  9. import com.simuwang.base.pojo.dto.sys.RoleMenuAssignCmd;
  10. import com.simuwang.base.pojo.dto.sys.RoleQuery;
  11. import com.simuwang.base.pojo.vo.sys.SysRoleVO;
  12. import com.simuwang.manage.service.system.SysRoleService;
  13. import jakarta.validation.Valid;
  14. import org.springframework.web.bind.annotation.*;
  15. import java.util.List;
  16. /**
  17. * 角色管理相关接口
  18. */
  19. @RestController
  20. @RequestMapping("/v1/sys/role")
  21. public class SysRoleController {
  22. private final SysRoleService service;
  23. public SysRoleController(SysRoleService service) {
  24. this.service = service;
  25. }
  26. /**
  27. * 分页接口
  28. *
  29. * @param query 角色列表分页请求参数
  30. * @return /
  31. */
  32. @GetMapping("page")
  33. public MybatisPage<SysRoleVO> page(RoleQuery query) {
  34. return this.service.findPage(query);
  35. }
  36. /**
  37. * 新增角色
  38. *
  39. * @param command 角色信息
  40. */
  41. @PostMapping("save")
  42. public boolean save(@Valid @RequestBody RoleAddCmd command) {
  43. this.service.insert(command);
  44. return true;
  45. }
  46. /**
  47. * 更新角色
  48. *
  49. * @param command 角色id+角色信息
  50. */
  51. @PostMapping("update")
  52. public boolean update(@Valid @RequestBody RoleEditCmd command) {
  53. this.service.update(command);
  54. return true;
  55. }
  56. /**
  57. * 更新角色状态接口
  58. *
  59. * @param command 角色id+状态对象
  60. */
  61. @PostMapping("update-status")
  62. public boolean updateStatus(@Valid @RequestBody UpdateStatusCmd command) {
  63. this.service.updateStatus(command);
  64. return true;
  65. }
  66. /**
  67. * 根据id删除角色信息接口
  68. *
  69. * @param command 角色id对象
  70. */
  71. @PostMapping("del")
  72. public boolean deleteById(@Valid @RequestBody DeleteByIdCmd command) {
  73. this.service.delete(command);
  74. return true;
  75. }
  76. /**
  77. * 给角色分配权限
  78. *
  79. * @param command 角色id对象
  80. */
  81. @PostMapping("assign-perms")
  82. public boolean assignPermissions(@Valid @RequestBody RoleMenuAssignCmd command) {
  83. this.service.assignPerms(command);
  84. return true;
  85. }
  86. /**
  87. * 获取角色分配的权限
  88. *
  89. * @param query 角色id对象
  90. */
  91. @GetMapping("list-assign-perms")
  92. public List<OnlyIdNameVO> listAssignPerms(@Valid @RequestBody GetByIdQuery query) {
  93. return this.service.getRolePerms(query);
  94. }
  95. }