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.

90 lines
2.6 KiB

  1. package com.example.demo.controller;
  2. import com.example.demo.domain.entity.Role;
  3. import com.example.demo.domain.vo.Page;
  4. import com.example.demo.domain.vo.Result;
  5. import com.example.demo.domain.vo.RoleVo;
  6. import com.example.demo.service.RefundService;
  7. import com.example.demo.service.RoleService;
  8. import lombok.RequiredArgsConstructor;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.util.ObjectUtils;
  12. import org.springframework.web.bind.annotation.*;
  13. import java.util.List;
  14. /**
  15. * @program: gold-java
  16. * @ClassName RoleController
  17. * @description:
  18. * @author: Double
  19. * @create: 202507-15 11:23
  20. * @Version 1.0
  21. **/
  22. @RestController
  23. @RequestMapping("/role")
  24. @RequiredArgsConstructor
  25. @Slf4j
  26. @CrossOrigin
  27. public class RoleController {
  28. @Autowired
  29. private RoleService roleService;
  30. //新增角色
  31. @PostMapping("/add")
  32. public Result addRole(@RequestBody RoleVo roleVo) {
  33. return roleService.addRole(roleVo);
  34. }
  35. //删除角色
  36. @PostMapping("/delete")
  37. public Result deleteRole(@RequestBody RoleVo roleVo) {
  38. return roleService.deleteRole(roleVo);
  39. }
  40. //查找全部角色
  41. @PostMapping("/selectAll")
  42. public Result selectRole() {
  43. List<RoleVo> list = roleService.selectAllRole();
  44. return Result.success(list);
  45. }
  46. //获取上级角色的下属角色列表
  47. @PostMapping("/selectSub")
  48. public Result selectSub(@RequestBody RoleVo roleVo) {
  49. Integer id = roleVo.getId();
  50. List<RoleVo> list=roleService.selectSubRole(id);
  51. return Result.success(list);
  52. }
  53. //获取当前角色的上级角色
  54. @PostMapping("/selectFather")
  55. public Result selectFather(@RequestBody RoleVo roleVo) {
  56. Integer id = roleVo.getId();
  57. RoleVo role = roleService.selectFather(id);
  58. return Result.success(role);
  59. }
  60. //角色明细筛选
  61. @PostMapping("/selectBy")
  62. public Result selectBy(@RequestBody Page page) {
  63. try {
  64. //页码校验
  65. if (ObjectUtils.isEmpty(page.getPageNum())) {
  66. return Result.error("页码数为空!");
  67. }
  68. //页面大小校验
  69. if (ObjectUtils.isEmpty(page.getPageSize())) {
  70. return Result.error("页大小为空!");
  71. } else {
  72. return Result.success(roleService.selectBy(page.getPageNum(), page.getPageSize(), page.getRoleVo()));
  73. }
  74. } catch (Exception e) {
  75. e.printStackTrace();
  76. return Result.error("请检查筛选数据的格式");
  77. }
  78. }
  79. }