SysRoleController.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.qmth.distributed.print.api;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.qmth.boot.api.constant.ApiConstant;
  4. import com.qmth.teachcloud.common.entity.SysRole;
  5. import com.qmth.teachcloud.common.service.SysRoleService;
  6. import com.qmth.teachcloud.common.util.Result;
  7. import com.qmth.teachcloud.common.util.ResultUtil;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiOperation;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.validation.BindingResult;
  12. import org.springframework.web.bind.annotation.*;
  13. import javax.validation.Valid;
  14. import java.security.NoSuchAlgorithmException;
  15. import java.util.List;
  16. /**
  17. * <p>
  18. * 角色表 前端控制器
  19. * </p>
  20. *
  21. * @author xf
  22. * @since 2021-03-23
  23. */
  24. @Api(tags = "角色Controller")
  25. @RestController
  26. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.sys}/role")
  27. public class SysRoleController {
  28. @Autowired
  29. private SysRoleService sysRoleService;
  30. /**
  31. * 查询
  32. *
  33. * @param name
  34. * @param enable
  35. * @param pageNumber
  36. * @param pageSize
  37. * @return
  38. */
  39. @ApiOperation(value = "查询")
  40. @RequestMapping(value = "/list", method = RequestMethod.POST)
  41. public Result list(@RequestParam(value = "name", required = false) String name,
  42. @RequestParam(value = "enable", required = false) Boolean enable,
  43. @RequestParam(value = "pageNumber", required = true) Integer pageNumber,
  44. @RequestParam(value = "pageSize", required = true) Integer pageSize) {
  45. return ResultUtil.ok(sysRoleService.list(name, enable, pageNumber, pageSize));
  46. }
  47. /**
  48. * 新增用户时查询角色方法
  49. *
  50. * @return
  51. */
  52. @ApiOperation(value = "新增用户时查询角色方法")
  53. @RequestMapping(value = "/list_to_user", method = RequestMethod.POST)
  54. public Result listToUser() {
  55. return ResultUtil.ok(sysRoleService.listToUser());
  56. }
  57. /**
  58. * 新增/修改
  59. *
  60. * @param role
  61. * @return
  62. */
  63. @ApiOperation(value = "新增/修改")
  64. @RequestMapping(value = "/save", method = RequestMethod.POST)
  65. public Result save(@Valid @RequestBody SysRole role, BindingResult bindingResult) {
  66. if (bindingResult.hasErrors()) {
  67. return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
  68. }
  69. return ResultUtil.ok(sysRoleService.saveRoleNew(role));
  70. }
  71. /**
  72. * 启用/禁用
  73. *
  74. * @param role
  75. * @return
  76. */
  77. @ApiOperation(value = "启用/禁用")
  78. @RequestMapping(value = "/enable", method = RequestMethod.POST)
  79. public Result enable(@RequestBody SysRole role) throws NoSuchAlgorithmException {
  80. return ResultUtil.ok(sysRoleService.enable(role));
  81. }
  82. /**
  83. * 删除
  84. *
  85. * @param id
  86. * @return
  87. */
  88. @ApiOperation(value = "删除")
  89. @RequestMapping(value = "/remove", method = RequestMethod.POST)
  90. public Result remove(Long id) {
  91. return ResultUtil.ok(sysRoleService.remove(id));
  92. }
  93. /**
  94. * 用户已绑定角色列表
  95. *
  96. * @param userId
  97. * @return
  98. */
  99. @ApiOperation(value = "用户已绑定角色列表")
  100. @RequestMapping(value = "/get_user_roles", method = RequestMethod.POST)
  101. public Result getUserRoles(@RequestParam(value = "userId", required = true) Long userId) {
  102. return ResultUtil.ok(sysRoleService.getUserRoles(userId));
  103. }
  104. }