AgentNewController.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.fdkankan.agent.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.fdkankan.agent.common.BaseController;
  5. import com.fdkankan.agent.common.ResultCode;
  6. import com.fdkankan.agent.common.ResultData;
  7. import com.fdkankan.agent.entity.AgentNew;
  8. import com.fdkankan.agent.exception.BusinessException;
  9. import com.fdkankan.agent.request.AgentAddIncrementParam;
  10. import com.fdkankan.agent.request.AgentParam;
  11. import com.fdkankan.agent.request.LogListParam;
  12. import com.fdkankan.agent.response.AgentNewVo;
  13. import com.fdkankan.agent.service.IAgentNewLogService;
  14. import com.fdkankan.agent.service.IAgentNewService;
  15. import com.fdkankan.agent.service.IUserService;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import javax.servlet.http.HttpServletRequest;
  20. import javax.servlet.http.HttpServletResponse;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. @RestController
  24. @RequestMapping("/agent/agentManage")
  25. public class AgentNewController extends BaseController {
  26. @Autowired
  27. IAgentNewService agentNewService;
  28. @Autowired
  29. IUserService userService;
  30. @PostMapping("/list")
  31. public ResultData list(@RequestBody AgentParam param){
  32. if(param.getAgentId() == null){
  33. param.setAgentId(getAgent().getId());
  34. }
  35. return ResultData.ok(agentNewService.pageList(param));
  36. }
  37. @PostMapping("/checkUserName")
  38. public ResultData checkUserName(@RequestBody AgentNew param){
  39. if(StringUtils.isBlank(param.getUserName())){
  40. throw new BusinessException(ResultCode.PARAM_MISS);
  41. }
  42. Boolean bo = userService.checkUserName(param.getUserName());
  43. if(bo){
  44. return ResultData.ok(true);
  45. }else {
  46. return ResultData.error(0,ResultCode.USER_NOT_EXIST.msg, false);
  47. }
  48. }
  49. @PostMapping("/add")
  50. public ResultData add(@RequestBody AgentNew param){
  51. if(StringUtils.isBlank(param.getName()) || StringUtils.isBlank(param.getUserName())){
  52. throw new BusinessException(ResultCode.PARAM_MISS);
  53. }
  54. Boolean bo = userService.checkUserName(param.getUserName());
  55. if(!bo){
  56. throw new BusinessException(ResultCode.USER_NOT_EXIST);
  57. }
  58. AgentNew agentNew = agentNewService.getByName(param.getName().trim());
  59. if(agentNew != null){
  60. throw new BusinessException(ResultCode.AGENT_NOT_EMPTY);
  61. }
  62. agentNewService.checkUserName(param.getUserName());
  63. AgentNewVo agent = getAgent();
  64. if(agent.getAgentLevel() >3){
  65. throw new BusinessException(ResultCode.AGENT_NOT_SUB);
  66. }
  67. param.setParentId(agent.getId());
  68. param.setCreateAgentId(agent.getId());
  69. param.setAgentLevel(agent.getAgentLevel() + 1);
  70. agentNewService.save(param);
  71. return ResultData.ok();
  72. }
  73. @PostMapping("/update")
  74. public ResultData update(@RequestBody AgentNew param){
  75. if(param.getId() == null || StringUtils.isBlank(param.getName())){
  76. throw new BusinessException(ResultCode.PARAM_MISS);
  77. }
  78. if(StringUtils.isNotBlank(param.getName())){
  79. AgentNew agentNew = agentNewService.getByName(param.getName().trim());
  80. if(agentNew != null && !agentNew.getId().equals(param.getId())){
  81. throw new BusinessException(ResultCode.AGENT_NOT_EMPTY);
  82. }
  83. }
  84. LambdaUpdateWrapper<AgentNew> wrapper = new LambdaUpdateWrapper<>();
  85. wrapper.eq(AgentNew::getId,param.getId());
  86. wrapper.set(AgentNew::getName,param.getName());
  87. wrapper.set(AgentNew::getNickName,param.getNickName());
  88. agentNewService.update(wrapper);
  89. return ResultData.ok();
  90. }
  91. @PostMapping("/addIncrementNum")
  92. public ResultData addIncrementNum(@RequestBody AgentAddIncrementParam param){
  93. param.setAgentId(getAgent().getId());
  94. agentNewService.addIncrementNum(param);
  95. return ResultData.ok();
  96. }
  97. @PostMapping("/banOrUnBan")
  98. public ResultData banOrUnBan(@RequestBody AgentNew param){
  99. if(param.getId() == null || param.getStatus() == null){
  100. throw new BusinessException(ResultCode.PARAM_MISS);
  101. }
  102. LambdaUpdateWrapper<AgentNew> wrapper = new LambdaUpdateWrapper<>();
  103. wrapper.eq(AgentNew::getId,param.getId());
  104. wrapper.set(AgentNew::getStatus,param.getStatus());
  105. agentNewService.update(wrapper);
  106. return ResultData.ok();
  107. }
  108. @GetMapping("/getSubAgent")
  109. public ResultData getSubAgent(@RequestParam(required = false,defaultValue = "0") Integer type,@RequestParam(required = false)Integer agentId){
  110. if(agentId == null){
  111. agentId = getAgent().getId();
  112. }
  113. List<AgentNew> bySubAgent = agentNewService.getBySubAgent(agentId);
  114. List<AgentNew> allList = new ArrayList<>(bySubAgent);
  115. if(type == 1){
  116. List<AgentNew> agentNewList = agentNewService.getRecursionByAgentId(agentId);
  117. allList.addAll(agentNewList);
  118. }
  119. return ResultData.ok(allList);
  120. }
  121. }