|
@@ -1,23 +1,29 @@
|
|
|
package com.fdkankan.agent.service.impl;
|
|
|
-import java.util.Date;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import com.baomidou.mybatisplus.annotation.TableField;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fdkankan.agent.common.PageInfo;
|
|
|
+import com.fdkankan.agent.common.ResultCode;
|
|
|
import com.fdkankan.agent.entity.AgentNew;
|
|
|
import com.fdkankan.agent.entity.AgentNewLog;
|
|
|
import com.fdkankan.agent.entity.IncrementType;
|
|
|
+import com.fdkankan.agent.exception.BusinessException;
|
|
|
import com.fdkankan.agent.mapper.IAgentNewMapper;
|
|
|
+import com.fdkankan.agent.request.AgentAddIncrementParam;
|
|
|
+import com.fdkankan.agent.request.AgentParam;
|
|
|
import com.fdkankan.agent.response.AgentNewVo;
|
|
|
import com.fdkankan.agent.service.IAgentNewLogService;
|
|
|
import com.fdkankan.agent.service.IAgentNewService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -87,4 +93,126 @@ public class AgentNewServiceImpl extends ServiceImpl<IAgentNewMapper, AgentNew>
|
|
|
this.update(wrapper);
|
|
|
agentNewLogService.save(agentNewLog);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object pageList(AgentParam param) {
|
|
|
+ if(param.getAgentId() == null){
|
|
|
+ throw new BusinessException(ResultCode.USER_NOT_EXIST);
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<AgentNew> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(AgentNew::getParentId,param.getAgentId());
|
|
|
+ if(StringUtils.isNotBlank(param.getAgentName())){
|
|
|
+ wrapper.like(AgentNew::getUserName,param.getAgentName());
|
|
|
+ }
|
|
|
+ Page<AgentNew> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
|
|
|
+ Set<Integer> ids = page.getRecords().stream().map(AgentNew::getSysUserId).collect(Collectors.toSet());
|
|
|
+ List<AgentNew> agentNews = this.listByIds(ids);
|
|
|
+ HashMap<Integer,AgentNew> map = new HashMap<>();
|
|
|
+ agentNews.forEach(e-> map.put(e.getId(),e));
|
|
|
+
|
|
|
+ for (AgentNew record : page.getRecords()) {
|
|
|
+ AgentNew agentNew = map.get(record.getSysUserId());
|
|
|
+ if(agentNew != null){
|
|
|
+ record.setCreateName(agentNew.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AgentNew getByName(String agentName) {
|
|
|
+ LambdaQueryWrapper<AgentNew> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(AgentNew::getName, agentName);
|
|
|
+ List<AgentNew> list = this.list(wrapper);
|
|
|
+ if(list == null || list.size() != 1) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return list.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void checkUserName(String userName) {
|
|
|
+ LambdaQueryWrapper<AgentNew> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(AgentNew::getUserName,userName);
|
|
|
+ List<AgentNew> list = this.list(wrapper);
|
|
|
+ if(list !=null && list.size() >0){
|
|
|
+ throw new BusinessException(ResultCode.AGENT_U_NOT_EMPTY);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addIncrementNum(AgentAddIncrementParam param) {
|
|
|
+ if(param.getId() == null ){
|
|
|
+ throw new BusinessException(ResultCode.PARAM_MISS);
|
|
|
+ }
|
|
|
+ AgentNew agentParent = this.getById(param.getAgentId());
|
|
|
+ if(agentParent == null){
|
|
|
+ throw new BusinessException(ResultCode.AGENT_NEW_EMPTY);
|
|
|
+ }
|
|
|
+ AgentNew agentNew = this.getById(param.getId());
|
|
|
+ if(agentNew == null){
|
|
|
+ throw new BusinessException(ResultCode.AGENT_NEW_EMPTY);
|
|
|
+ }
|
|
|
+ if(!agentNew.getParentId().equals(param.getAgentId())){
|
|
|
+ throw new BusinessException(ResultCode.NOT_PER);
|
|
|
+ }
|
|
|
+ if(param.getDownAddNum() <=0 && param.getMajorAddNum() <=0 && param.getHighAddNum() <=0 ){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int majorNum = agentParent.getMajorTotalNum() - agentParent.getMajorUseNum();
|
|
|
+ int highNum = agentParent.getHighTotalNum() - agentParent.getHighUseNum();
|
|
|
+ int downNum = agentParent.getDownTotalNum() - agentParent.getDownUseNum();
|
|
|
+
|
|
|
+ if(param.getMajorAddNum() > majorNum || param.getHighAddNum() > highNum || param.getDownAddNum() > downNum){
|
|
|
+ throw new BusinessException(ResultCode.NUM_NOT);
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<AgentNew> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(AgentNew::getId,param.getId());
|
|
|
+ if( param.getDownAddNum() >0){
|
|
|
+ wrapper.setSql("down_total_num = down_total_num + " + param.getDownAddNum());
|
|
|
+ }
|
|
|
+ if(param.getHighAddNum() >0){
|
|
|
+ wrapper.setSql("high_total_num = high_total_num + " + param.getHighAddNum());
|
|
|
+ }
|
|
|
+ if( param.getMajorAddNum() >0){
|
|
|
+ wrapper.setSql("major_total_num = major_total_num + " + param.getMajorAddNum());
|
|
|
+ }
|
|
|
+ this.update(wrapper);
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<AgentNew> wrapperParent = new LambdaUpdateWrapper<>();
|
|
|
+ wrapperParent.eq(AgentNew::getId,param.getAgentId());
|
|
|
+ if(param.getDownAddNum() >0){
|
|
|
+ wrapperParent.setSql("down_use_num = down_use_num + " + param.getDownAddNum());
|
|
|
+ }
|
|
|
+ if(param.getHighAddNum() >0){
|
|
|
+ wrapperParent.setSql("high_use_num = high_use_num + " + param.getHighAddNum());
|
|
|
+ }
|
|
|
+ if(param.getMajorAddNum() >0){
|
|
|
+ wrapperParent.setSql("major_use_num = major_use_num + " + param.getMajorAddNum());
|
|
|
+ }
|
|
|
+ this.update(wrapperParent);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AgentNew> getBySubAgent(Integer agentId) {
|
|
|
+ LambdaQueryWrapper<AgentNew> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(AgentNew::getParentId,agentId);
|
|
|
+ return this.list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HashMap<Integer, AgentNew> getMapByIds(List<Integer> subAgentIds) {
|
|
|
+ HashMap<Integer, AgentNew> map = new HashMap<>();
|
|
|
+ if(subAgentIds.isEmpty()){
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ List<AgentNew> list = this.listByIds(subAgentIds);
|
|
|
+ list.forEach(e -> map.put(e.getId(),e));
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|