UmsRoleController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.macro.mall.controller;
  2. import com.macro.mall.common.api.CommonPage;
  3. import com.macro.mall.common.api.CommonResult;
  4. import com.macro.mall.model.*;
  5. import com.macro.mall.service.UmsRoleService;
  6. import io.swagger.annotations.Api;
  7. import io.swagger.annotations.ApiOperation;
  8. import io.swagger.v3.oas.annotations.tags.Tag;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Controller;
  11. import org.springframework.web.bind.annotation.*;
  12. import java.util.List;
  13. /**
  14. * 后台用户角色管理Controller
  15. * Created by macro on 2018/9/30.
  16. */
  17. @Controller
  18. @Api(tags = "UmsRoleController")
  19. @Tag(name = "UmsRoleController", description = "后台用户角色管理")
  20. @RequestMapping("/role")
  21. public class UmsRoleController {
  22. @Autowired
  23. private UmsRoleService roleService;
  24. @ApiOperation("添加角色")
  25. @RequestMapping(value = "/create", method = RequestMethod.POST)
  26. @ResponseBody
  27. public CommonResult create(@RequestBody UmsRole role) {
  28. int count = roleService.create(role);
  29. if (count > 0) {
  30. return CommonResult.success(count);
  31. }
  32. return CommonResult.failed();
  33. }
  34. @ApiOperation("修改角色")
  35. @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
  36. @ResponseBody
  37. public CommonResult update(@PathVariable Long id, @RequestBody UmsRole role) {
  38. int count = roleService.update(id, role);
  39. if (count > 0) {
  40. return CommonResult.success(count);
  41. }
  42. return CommonResult.failed();
  43. }
  44. @ApiOperation("批量删除角色")
  45. @RequestMapping(value = "/delete", method = RequestMethod.POST)
  46. @ResponseBody
  47. public CommonResult delete(@RequestParam("ids") List<Long> ids) {
  48. int count = roleService.delete(ids);
  49. if (count > 0) {
  50. return CommonResult.success(count);
  51. }
  52. return CommonResult.failed();
  53. }
  54. @ApiOperation("获取所有角色")
  55. @RequestMapping(value = "/listAll", method = RequestMethod.GET)
  56. @ResponseBody
  57. public CommonResult<List<UmsRole>> listAll() {
  58. List<UmsRole> roleList = roleService.list();
  59. return CommonResult.success(roleList);
  60. }
  61. @ApiOperation("根据角色名称分页获取角色列表")
  62. @RequestMapping(value = "/list", method = RequestMethod.GET)
  63. @ResponseBody
  64. public CommonResult<CommonPage<UmsRole>> list(@RequestParam(value = "keyword", required = false) String keyword,
  65. @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
  66. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
  67. List<UmsRole> roleList = roleService.list(keyword, pageSize, pageNum);
  68. return CommonResult.success(CommonPage.restPage(roleList));
  69. }
  70. @ApiOperation("修改角色状态")
  71. @RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
  72. @ResponseBody
  73. public CommonResult updateStatus(@PathVariable Long id, @RequestParam(value = "status") Integer status) {
  74. UmsRole umsRole = new UmsRole();
  75. umsRole.setStatus(status);
  76. int count = roleService.update(id, umsRole);
  77. if (count > 0) {
  78. return CommonResult.success(count);
  79. }
  80. return CommonResult.failed();
  81. }
  82. @ApiOperation("获取角色相关菜单")
  83. @RequestMapping(value = "/listMenu/{roleId}", method = RequestMethod.GET)
  84. @ResponseBody
  85. public CommonResult<List<UmsMenu>> listMenu(@PathVariable Long roleId) {
  86. List<UmsMenu> roleList = roleService.listMenu(roleId);
  87. return CommonResult.success(roleList);
  88. }
  89. @ApiOperation("获取角色相关资源")
  90. @RequestMapping(value = "/listResource/{roleId}", method = RequestMethod.GET)
  91. @ResponseBody
  92. public CommonResult<List<UmsResource>> listResource(@PathVariable Long roleId) {
  93. List<UmsResource> roleList = roleService.listResource(roleId);
  94. return CommonResult.success(roleList);
  95. }
  96. @ApiOperation("给角色分配菜单")
  97. @RequestMapping(value = "/allocMenu", method = RequestMethod.POST)
  98. @ResponseBody
  99. public CommonResult allocMenu(@RequestParam Long roleId, @RequestParam List<Long> menuIds) {
  100. int count = roleService.allocMenu(roleId, menuIds);
  101. return CommonResult.success(count);
  102. }
  103. @ApiOperation("给角色分配资源")
  104. @RequestMapping(value = "/allocResource", method = RequestMethod.POST)
  105. @ResponseBody
  106. public CommonResult allocResource(@RequestParam Long roleId, @RequestParam List<Long> resourceIds) {
  107. int count = roleService.allocResource(roleId, resourceIds);
  108. return CommonResult.success(count);
  109. }
  110. }