DomainNameController.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package cn.com.countrygarden.bi.main.controller;
  2. import cn.com.countrygarden.bi.main.core.Result;
  3. import cn.com.countrygarden.bi.main.exception.ServiceException;
  4. import cn.com.countrygarden.bi.main.model.AccessToken;
  5. import cn.com.countrygarden.bi.main.model.sys.Role;
  6. import cn.com.countrygarden.bi.main.service.MenuService;
  7. import cn.com.countrygarden.bi.main.service.RoleService;
  8. import cn.com.countrygarden.bi.main.service.UserFunctionService;
  9. import cn.com.countrygarden.bi.main.service.UserRoleService;
  10. import cn.com.countrygarden.bi.main.service.erp.impl.ExcelArrearageServiceImpl;
  11. import org.apache.commons.lang.StringUtils;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.*;
  15. import javax.servlet.http.HttpServletRequest;
  16. import java.util.Date;
  17. /**
  18. * package: cn.com.countrygarden.bi.main.controller
  19. * describe:
  20. * creat_user: lxin
  21. * creat_date: 2022/8/14
  22. * creat_time: 21:53
  23. **/
  24. @RestController("DomainNameController")
  25. @RequestMapping("/api/DomainName")//*0*/api/role"
  26. public class DomainNameController extends BaseController {
  27. @Autowired
  28. private MenuService menuService;//*0*
  29. @Autowired
  30. private UserRoleService userRoleService;//*0*
  31. @Autowired
  32. private UserFunctionService userFunctionService;//*0*
  33. @Autowired
  34. private RoleService roleService;//*0*
  35. private final org.slf4j.Logger logger = LoggerFactory.getLogger(ExcelArrearageServiceImpl.class);//*0*好像没用,去掉
  36. @GetMapping(value = "/listRole", produces = "application/json;charset=utf-8")
  37. public Result list(Role role,
  38. @RequestParam(value = "size", required = false, defaultValue = "10") int size,
  39. @RequestParam(value = "page", required = false, defaultValue = "1") int page,
  40. HttpServletRequest request){
  41. AccessToken token = this.getAccessToken();
  42. return roleService.queryRoleInfo(role,token.getUserCode(),page,size);
  43. }
  44. @PostMapping(value = "add")
  45. public Result add(Role role,
  46. @RequestParam(value = "menusIds", required = true)String menusIds,
  47. @RequestParam(value = "functionIds", required = true)String functionIds,
  48. HttpServletRequest request){
  49. if(StringUtils.isEmpty(role.getCode())){
  50. throw new ServiceException("接口异常,角色编号不能为空!");
  51. }
  52. boolean existFlag=roleService.checkRoleCodeExist(role.getCode());
  53. // 添加角色
  54. if(existFlag){
  55. throw new ServiceException("接口异常,角色编号不能重复");
  56. }
  57. AccessToken token = getAccessToken(request);
  58. roleService.checkIsAdmin(token.getUserCode());
  59. role.setCreatedBy(token.getUserCode());
  60. role.setCreatedDate(new Date());
  61. role.setEnable(true);
  62. return roleService.addRoleOrMenusAndFunctions(role,menusIds,functionIds);
  63. }
  64. @GetMapping(value = "/one", produces = "application/json;charset=utf-8")
  65. public Result queryById(@RequestParam(value = "id", required = true)Integer id,
  66. HttpServletRequest request){
  67. return roleService.queryDataById(id);
  68. }
  69. @PutMapping(value = "/edit")
  70. public Result edit(Role role,
  71. @RequestParam(value = "menusIds", required = true)String menusIds,
  72. @RequestParam(value = "functionIds", required = true)String functionIds,
  73. HttpServletRequest request){
  74. AccessToken token = getAccessToken(request);
  75. roleService.checkIsAdmin(token.getUserCode());
  76. role.setUpdatedBy(token.getUserCode());
  77. role.setUpdatedDate(new Date());
  78. return roleService.edit(role,menusIds,functionIds);
  79. }
  80. @DeleteMapping(value="/del")
  81. public Result del(@RequestParam(value = "id", required = true)Integer id){
  82. AccessToken token = this.getAccessToken();
  83. roleService.checkIsAdmin(token.getUserCode());
  84. return roleService.del(id);
  85. }
  86. }