RoleController.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.api.base.controll;
  2. import com.api.base.model.Role;
  3. import com.api.base.service.PowerService;
  4. import com.api.base.service.RoleService;
  5. import com.api.core.controller.Ctrl;
  6. import com.api.core.annotation.PowerEnable;
  7. import com.api.core.response.Result;
  8. import com.api.core.response.ResultGenerator;
  9. import com.github.pagehelper.PageHelper;
  10. import com.github.pagehelper.PageInfo;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiImplicitParam;
  13. import io.swagger.annotations.ApiImplicitParams;
  14. import io.swagger.annotations.ApiOperation;
  15. import org.springframework.cache.annotation.CacheEvict;
  16. import org.springframework.web.bind.annotation.PostMapping;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestParam;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import tk.mybatis.mapper.entity.Condition;
  21. import tk.mybatis.mapper.entity.Example;
  22. import javax.annotation.Resource;
  23. import java.util.List;
  24. /**
  25. * Created by CodeGenerator on 2019/03/25.
  26. */
  27. @PowerEnable(name = "角色管理",url = "/role")
  28. @Api(value = "角色管理", tags = {"角色管理"})
  29. @RestController
  30. @RequestMapping("/role")
  31. public class RoleController extends Ctrl {
  32. @Resource
  33. private RoleService roleService;
  34. @Resource
  35. private PowerService powerService;
  36. @ApiOperation(value = "添加角色", tags = {"角色管理"}, notes = "添加角色")
  37. @PostMapping(value = "/add",name = "添加角色")
  38. public Result add(Role role) {
  39. roleService.save(role);
  40. return ResultGenerator.genSuccessResult();
  41. }
  42. @ApiOperation(value = "添加角色", tags = {"角色管理"}, notes = "添加角色")
  43. @ApiImplicitParams({
  44. @ApiImplicitParam(name = "where", value = "条件json", dataType = "String", paramType = "query"),
  45. @ApiImplicitParam(name = "page", value = "页数", dataType = "Integer", paramType = "query"),
  46. @ApiImplicitParam(name = "size", value = "条数", dataType = "Integer", paramType = "query"),
  47. })
  48. @PostMapping(value = "/list",name = "角色列表")
  49. public Result list(@RequestParam String where , @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
  50. PageHelper.startPage(page, size);
  51. Condition c= new Condition(Role.class);
  52. Example.Criteria criteria = c.createCriteria();
  53. buildWhere(where, criteria);
  54. List<Role> list = roleService.findByCondition(c);
  55. PageInfo<Role> pageInfo = new PageInfo<>(list);
  56. return ResultGenerator.genSuccessResult(pageInfo);
  57. }
  58. @ApiOperation(value = "角色添加权限", tags = {"角色管理"}, notes = "角色添加权限")
  59. @ApiImplicitParams({
  60. @ApiImplicitParam(name = "powers", value = "权限json", dataType = "String", paramType = "query"),
  61. @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", paramType = "query"),
  62. })
  63. @PostMapping(value = "/add/power",name = "角色添加权限")
  64. @CacheEvict(value = "power",key = "#roleId")
  65. public Result addPower(String powers, Long roleId){
  66. roleService.addPower( powers,roleId);
  67. return ResultGenerator.genSuccessResult();
  68. }
  69. @ApiOperation(value = "获取角色权限", tags = {"角色管理"}, notes = "获取角色权限")
  70. @ApiImplicitParams({
  71. @ApiImplicitParam(name = "roleId", value = "角色id", dataType = "Long", paramType = "query"),
  72. })
  73. @PostMapping(value = "/get/power",name = "获取角色权限")
  74. public Result getPowers(Long roleId){
  75. List powers = powerService.getByRole(roleId);
  76. return ResultGenerator.genSuccessResult(powers);
  77. }
  78. }