123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package com.fdkankan.agent.controller;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.fdkankan.agent.common.BaseController;
- import com.fdkankan.agent.common.ResultCode;
- import com.fdkankan.agent.common.ResultData;
- import com.fdkankan.agent.entity.AgentNew;
- import com.fdkankan.agent.exception.BusinessException;
- import com.fdkankan.agent.request.AgentAddIncrementParam;
- import com.fdkankan.agent.request.AgentParam;
- import com.fdkankan.agent.request.LogListParam;
- import com.fdkankan.agent.response.AgentNewVo;
- import com.fdkankan.agent.service.IAgentNewLogService;
- import com.fdkankan.agent.service.IAgentNewService;
- import com.fdkankan.agent.service.IUserService;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.util.ArrayList;
- import java.util.List;
- @RestController
- @RequestMapping("/agent/agentManage")
- public class AgentNewController extends BaseController {
- @Autowired
- IAgentNewService agentNewService;
- @Autowired
- IUserService userService;
- @PostMapping("/list")
- public ResultData list(@RequestBody AgentParam param){
- if(param.getAgentId() == null){
- param.setAgentId(getAgent().getId());
- }
- return ResultData.ok(agentNewService.pageList(param));
- }
- @PostMapping("/checkUserName")
- public ResultData checkUserName(@RequestBody AgentNew param){
- if(StringUtils.isBlank(param.getUserName())){
- throw new BusinessException(ResultCode.PARAM_MISS);
- }
- Boolean bo = userService.checkUserName(param.getUserName());
- if(bo){
- return ResultData.ok(true);
- }else {
- return ResultData.error(0,ResultCode.USER_NOT_EXIST.msg, false);
- }
- }
- @PostMapping("/add")
- public ResultData add(@RequestBody AgentNew param){
- if(StringUtils.isBlank(param.getName()) || StringUtils.isBlank(param.getUserName())){
- throw new BusinessException(ResultCode.PARAM_MISS);
- }
- Boolean bo = userService.checkUserName(param.getUserName());
- if(!bo){
- throw new BusinessException(ResultCode.USER_NOT_EXIST);
- }
- AgentNew agentNew = agentNewService.getByName(param.getName().trim());
- if(agentNew != null){
- throw new BusinessException(ResultCode.AGENT_NOT_EMPTY);
- }
- agentNewService.checkUserName(param.getUserName());
- AgentNewVo agent = getAgent();
- if(agent.getAgentLevel() >3){
- throw new BusinessException(ResultCode.AGENT_NOT_SUB);
- }
- param.setParentId(agent.getId());
- param.setCreateAgentId(agent.getId());
- param.setAgentLevel(agent.getAgentLevel() + 1);
- agentNewService.save(param);
- return ResultData.ok();
- }
- @PostMapping("/update")
- public ResultData update(@RequestBody AgentNew param){
- if(param.getId() == null || StringUtils.isBlank(param.getName())){
- throw new BusinessException(ResultCode.PARAM_MISS);
- }
- if(StringUtils.isNotBlank(param.getName())){
- AgentNew agentNew = agentNewService.getByName(param.getName().trim());
- if(agentNew != null && !agentNew.getId().equals(param.getId())){
- throw new BusinessException(ResultCode.AGENT_NOT_EMPTY);
- }
- }
- LambdaUpdateWrapper<AgentNew> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(AgentNew::getId,param.getId());
- wrapper.set(AgentNew::getName,param.getName());
- wrapper.set(AgentNew::getNickName,param.getNickName());
- agentNewService.update(wrapper);
- return ResultData.ok();
- }
- @PostMapping("/addIncrementNum")
- public ResultData addIncrementNum(@RequestBody AgentAddIncrementParam param){
- param.setAgentId(getAgent().getId());
- agentNewService.addIncrementNum(param);
- return ResultData.ok();
- }
- @PostMapping("/banOrUnBan")
- public ResultData banOrUnBan(@RequestBody AgentNew param){
- if(param.getId() == null || param.getStatus() == null){
- throw new BusinessException(ResultCode.PARAM_MISS);
- }
- LambdaUpdateWrapper<AgentNew> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(AgentNew::getId,param.getId());
- wrapper.set(AgentNew::getStatus,param.getStatus());
- agentNewService.update(wrapper);
- return ResultData.ok();
- }
- @GetMapping("/getSubAgent")
- public ResultData getSubAgent(@RequestParam(required = false,defaultValue = "0") Integer type,@RequestParam(required = false)Integer agentId){
- if(agentId == null){
- agentId = getAgent().getId();
- }
- List<AgentNew> bySubAgent = agentNewService.getBySubAgent(agentId);
- List<AgentNew> allList = new ArrayList<>(bySubAgent);
- if(type == 1){
- List<AgentNew> agentNewList = agentNewService.getRecursionByAgentId(agentId);
- allList.addAll(agentNewList);
- }
- return ResultData.ok(allList);
- }
- }
|