|
|
@@ -1,15 +1,16 @@
|
|
|
package com.ydtech.modules.esm.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
import com.ydtech.core.page.HttpResult;
|
|
|
+import com.ydtech.core.page.PageResult;
|
|
|
import com.ydtech.exception.SystemException;
|
|
|
import com.ydtech.modules.admin.model.SysUser;
|
|
|
import com.ydtech.modules.admin.model.dto.SysUserDto;
|
|
|
+import com.ydtech.modules.admin.model.vo.AppCustomerManagementQueryVo;
|
|
|
import com.ydtech.modules.admin.model.vo.SysReferrerVo;
|
|
|
-import com.ydtech.modules.admin.model.vo.SysUserBaseVO;
|
|
|
import com.ydtech.modules.admin.service.SysUserService;
|
|
|
import com.ydtech.modules.base.model.dto.PageDto;
|
|
|
import com.ydtech.modules.base.model.vo.PageVo;
|
|
|
@@ -21,6 +22,7 @@ import com.ydtech.modules.esm.model.vo.EsmUserCountVO;
|
|
|
import com.ydtech.modules.esm.model.vo.EsmUserPolicyVO;
|
|
|
import com.ydtech.modules.esm.model.vo.TeamUserQryVO;
|
|
|
import com.ydtech.modules.esm.service.EsmUserReferrerService;
|
|
|
+import com.ydtech.modules.order.entity.BasePageResult;
|
|
|
import com.ydtech.utils.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
@@ -30,8 +32,10 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.sql.DataSource;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
@Service
|
|
|
@@ -54,20 +58,22 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
|
|
|
EsmUserReferrer esmUserReferrer = esmUserReferrerService.getById(userId);
|
|
|
//找不到用户的推荐关系
|
|
|
- if(esmUserReferrer == null){
|
|
|
+ if (esmUserReferrer == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- List<EsmUserReferrer> esmUserReferrers = esmUserReferrerService.list(new LambdaQueryWrapper<EsmUserReferrer>().eq(EsmUserReferrer::getAffiliation, esmUserReferrer.getAffiliation()));
|
|
|
+ List<EsmUserReferrer> esmUserReferrers =
|
|
|
+ esmUserReferrerService.list(new LambdaQueryWrapper<EsmUserReferrer>().eq(EsmUserReferrer::getAffiliation,
|
|
|
+ esmUserReferrer.getAffiliation()));
|
|
|
findParentsRecursive(esmUserReferrer.getReferrerId(), esmUserReferrers, referrers);
|
|
|
return referrers;
|
|
|
}
|
|
|
|
|
|
- private static void findParentsRecursive(String userId, List<EsmUserReferrer> esmUserReferrers,List<EsmUserReferrer> referrers) {
|
|
|
+ private static void findParentsRecursive(String userId, List<EsmUserReferrer> esmUserReferrers, List<EsmUserReferrer> referrers) {
|
|
|
EsmUserReferrer collect = esmUserReferrers.stream().filter(item -> item.getId().equals(userId)).findFirst().get();
|
|
|
- if(collect != null){
|
|
|
- if(collect.getId().equals(collect.getReferrerId())){
|
|
|
+ if (collect != null) {
|
|
|
+ if (collect.getId().equals(collect.getReferrerId())) {
|
|
|
referrers.add(collect);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
referrers.add(collect);
|
|
|
findParentsRecursive(collect.getReferrerId(), esmUserReferrers, referrers);
|
|
|
}
|
|
|
@@ -106,6 +112,7 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
oneTempList.addAll(oneMap.get("list2"));
|
|
|
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public void addReferrer(String referrerId, String nextPK) {
|
|
|
//if(referrerId.equals(nextPK)) throw new SystemException("推荐人不能是自己");
|
|
|
@@ -132,7 +139,7 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
eur.setLevel(referrer.getLevel() + 1);
|
|
|
eur.setAffiliation(referrer.getAffiliation());
|
|
|
esmUserReferrerService.saveOrUpdate(eur);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//已经级联过的代理再作为推荐人的时候,推荐人是传入的推荐人信息
|
|
|
SysUser user = sysUserService.getById(referrerId);
|
|
|
eur.setId(nextPK);
|
|
|
@@ -153,15 +160,15 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<String> getUpUser(String userId,List<String> list){
|
|
|
+ public List<String> getUpUser(String userId, List<String> list) {
|
|
|
|
|
|
- EsmUserReferrer esmUserReferrer=this.getById(userId);
|
|
|
- if(esmUserReferrer==null){
|
|
|
+ EsmUserReferrer esmUserReferrer = this.getById(userId);
|
|
|
+ if (esmUserReferrer == null) {
|
|
|
return list;
|
|
|
}
|
|
|
list.add(esmUserReferrer.getId());
|
|
|
- if(!esmUserReferrer.getReferrerId().equals(userId)){
|
|
|
- getUpUser(esmUserReferrer.getReferrerId(),list);
|
|
|
+ if (!esmUserReferrer.getReferrerId().equals(userId)) {
|
|
|
+ getUpUser(esmUserReferrer.getReferrerId(), list);
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
@@ -169,26 +176,26 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
|
|
|
@Override
|
|
|
public Page<SysUser> getUserPage(Page page, SysUserDto dto) {
|
|
|
- return baseMapper.getUserPage(page,dto);
|
|
|
+ return baseMapper.getUserPage(page, dto);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Page<QueryChannel> getQueryChannelPage(Page page, QueryChannel queryChannel) {
|
|
|
- return baseMapper.getQueryChannelPage(page,queryChannel);
|
|
|
+ return baseMapper.getQueryChannelPage(page, queryChannel);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public HttpResult<PageVo<SysReferrerVo>> gainReferrerPage(PageDto<SysReferrerVo> pageDto) {
|
|
|
|
|
|
- if(StringUtils.isNotEmpty(pageDto.getDto().getAffiliation())){
|
|
|
- EsmUserReferrer esmUserReferrer=this.getById(pageDto.getDto().getAffiliation());
|
|
|
- if(esmUserReferrer==null){
|
|
|
+ if (StringUtils.isNotEmpty(pageDto.getDto().getAffiliation())) {
|
|
|
+ EsmUserReferrer esmUserReferrer = this.getById(pageDto.getDto().getAffiliation());
|
|
|
+ if (esmUserReferrer == null) {
|
|
|
return HttpResult.error("工号有误,请重新输入");
|
|
|
}
|
|
|
- List<String> up3list=new ArrayList<>();
|
|
|
- getUpUser(pageDto.getDto().getAffiliation(),up3list);
|
|
|
- List<String> down3list=this.baseMapper.getIdDown3(pageDto.getDto().getAffiliation());
|
|
|
- List<String> ids=new ArrayList<>();
|
|
|
+ List<String> up3list = new ArrayList<>();
|
|
|
+ getUpUser(pageDto.getDto().getAffiliation(), up3list);
|
|
|
+ List<String> down3list = this.baseMapper.getIdDown3(pageDto.getDto().getAffiliation());
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
ids.addAll(up3list);
|
|
|
ids.addAll(down3list);
|
|
|
ids.add(pageDto.getDto().getAffiliation());
|
|
|
@@ -209,7 +216,7 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
//计算mysql分页总页数
|
|
|
int totalPages = total % pageDto.getPageSize() == 0 ? total / pageDto.getPageSize() : total / pageDto.getPageSize() + 1;
|
|
|
|
|
|
- //响应
|
|
|
+ //响应
|
|
|
pageVo.setTotalSize(total);
|
|
|
pageVo.setPageNum(pageDto.getPageNum());
|
|
|
pageVo.setPageSize(pageDto.getPageSize());
|
|
|
@@ -225,11 +232,12 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
|
|
|
/**
|
|
|
* 人员业绩统计
|
|
|
+ *
|
|
|
* @param whereCase
|
|
|
* @param paramValues
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<EsmUserPolicyVO> countUserPolicy(String whereCase, Object[] paramValues){
|
|
|
+ public List<EsmUserPolicyVO> countUserPolicy(String whereCase, Object[] paramValues) {
|
|
|
List<EsmUserPolicyVO> recordList = new ArrayList<EsmUserPolicyVO>();
|
|
|
|
|
|
String sql = "select b.teamlevel,b.name username,\n" +
|
|
|
@@ -265,11 +273,12 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
|
|
|
/**
|
|
|
* 团队业绩统计
|
|
|
+ *
|
|
|
* @param whereCase
|
|
|
* @param paramValues
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<EsmTeamPolicyVO> countTeamPolicy(String whereCase, Object[] paramValues){
|
|
|
+ public List<EsmTeamPolicyVO> countTeamPolicy(String whereCase, Object[] paramValues) {
|
|
|
List<EsmTeamPolicyVO> recordList = new ArrayList<>();
|
|
|
|
|
|
String sql = "select teamlevel,sum(teamnum) teamnum, sum(sumpremium) sumpremium,sum(usernum) usernum from \n" +
|
|
|
@@ -308,38 +317,40 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
|
|
|
return recordList;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 人员团队业绩统计--所有业务员都可查询
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public EsmUserCountVO queryUserCount(TeamUserQryVO record) {
|
|
|
- EsmUserCountVO esmUserCountVO=new EsmUserCountVO();
|
|
|
- List<EsmTeamPolicyVO> hzList =new ArrayList<>();
|
|
|
- List<EsmUserPolicyVO> userPolicyList=new ArrayList<>();
|
|
|
- List<EsmUserPolicyVO> userPolicyList0=new ArrayList<>();
|
|
|
- List<EsmUserPolicyVO> userPolicyList1=new ArrayList<>();
|
|
|
- List<EsmUserPolicyVO> userPolicyList2=new ArrayList<>();
|
|
|
- List<EsmUserPolicyVO> userPolicyList3=new ArrayList<>();
|
|
|
- EsmUserReferrer esmUserReferrer=getById(record.getId());
|
|
|
- if(esmUserReferrer!=null){
|
|
|
- List<String> userList1 =new ArrayList<>();
|
|
|
- List<String> userList2 =new ArrayList<>();
|
|
|
- List<String> userList3 =new ArrayList<>();
|
|
|
+ EsmUserCountVO esmUserCountVO = new EsmUserCountVO();
|
|
|
+ List<EsmTeamPolicyVO> hzList = new ArrayList<>();
|
|
|
+ List<EsmUserPolicyVO> userPolicyList = new ArrayList<>();
|
|
|
+ List<EsmUserPolicyVO> userPolicyList0 = new ArrayList<>();
|
|
|
+ List<EsmUserPolicyVO> userPolicyList1 = new ArrayList<>();
|
|
|
+ List<EsmUserPolicyVO> userPolicyList2 = new ArrayList<>();
|
|
|
+ List<EsmUserPolicyVO> userPolicyList3 = new ArrayList<>();
|
|
|
+ EsmUserReferrer esmUserReferrer = getById(record.getId());
|
|
|
+ if (esmUserReferrer != null) {
|
|
|
+ List<String> userList1 = new ArrayList<>();
|
|
|
+ List<String> userList2 = new ArrayList<>();
|
|
|
+ List<String> userList3 = new ArrayList<>();
|
|
|
//本级信息
|
|
|
//明细数据加工
|
|
|
List<String> userList0 = new ArrayList<>();
|
|
|
userList0.add(esmUserReferrer.getId());
|
|
|
- userPolicyList0= this.baseMapper.queryOrderCount(userList0,record.getStartdate(),record.getEnddate());
|
|
|
+ userPolicyList0 = this.baseMapper.queryOrderCount(userList0, record.getStartdate(), record.getEnddate());
|
|
|
//汇总数据加工
|
|
|
- EsmTeamPolicyVO esmTeamPolicyVO0=this.baseMapper.queryOrderCountHz(userList0,record.getStartdate(),record.getEnddate());
|
|
|
- EsmTeamPolicyVO esmTeamPolicyVO1=new EsmTeamPolicyVO();
|
|
|
- EsmTeamPolicyVO esmTeamPolicyVO2=new EsmTeamPolicyVO();
|
|
|
- if(esmTeamPolicyVO0==null){
|
|
|
- esmTeamPolicyVO0=new EsmTeamPolicyVO();
|
|
|
+ EsmTeamPolicyVO esmTeamPolicyVO0 = this.baseMapper.queryOrderCountHz(userList0, record.getStartdate(), record.getEnddate());
|
|
|
+ EsmTeamPolicyVO esmTeamPolicyVO1 = new EsmTeamPolicyVO();
|
|
|
+ EsmTeamPolicyVO esmTeamPolicyVO2 = new EsmTeamPolicyVO();
|
|
|
+ if (esmTeamPolicyVO0 == null) {
|
|
|
+ esmTeamPolicyVO0 = new EsmTeamPolicyVO();
|
|
|
esmTeamPolicyVO0.setSumpremium(0);
|
|
|
esmTeamPolicyVO0.setUsernum(0);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
esmTeamPolicyVO0.setUsernum(1);
|
|
|
}
|
|
|
esmTeamPolicyVO0.setTeamlevel("本人");
|
|
|
@@ -348,10 +359,11 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
// 一级团队信息
|
|
|
userList1 = this.baseMapper.getIdDown_1(esmUserReferrer.getId());
|
|
|
esmTeamPolicyVO1.setTeamlevel("一级团队");
|
|
|
- if(userList1!=null && userList1.size()>0){
|
|
|
- userPolicyList1=this.baseMapper.queryOrderCount(userList1,record.getStartdate(),record.getEnddate());
|
|
|
- EsmTeamPolicyVO esmTeamPolicyVO1_t=this.baseMapper.queryOrderCountHz(userList1,record.getStartdate(),record.getEnddate());
|
|
|
- if(esmTeamPolicyVO1_t!=null){
|
|
|
+ if (userList1 != null && userList1.size() > 0) {
|
|
|
+ userPolicyList1 = this.baseMapper.queryOrderCount(userList1, record.getStartdate(), record.getEnddate());
|
|
|
+ EsmTeamPolicyVO esmTeamPolicyVO1_t = this.baseMapper.queryOrderCountHz(userList1, record.getStartdate(),
|
|
|
+ record.getEnddate());
|
|
|
+ if (esmTeamPolicyVO1_t != null) {
|
|
|
esmTeamPolicyVO1.setSumpremium(esmTeamPolicyVO1_t.getSumpremium());
|
|
|
esmTeamPolicyVO1.setUsernum(userPolicyList1.size());//出单人力
|
|
|
}
|
|
|
@@ -360,10 +372,11 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
userList2 = this.baseMapper.getIdDown_2(esmUserReferrer.getId());
|
|
|
|
|
|
esmTeamPolicyVO2.setTeamlevel("二级团队");
|
|
|
- if(userList2!=null && userList2.size()>0){
|
|
|
- userPolicyList2=this.baseMapper.queryOrderCount(userList2,record.getStartdate(),record.getEnddate());
|
|
|
- EsmTeamPolicyVO esmTeamPolicyVO2_t=this.baseMapper.queryOrderCountHz(userList2,record.getStartdate(),record.getEnddate());
|
|
|
- if(esmTeamPolicyVO2_t!=null){
|
|
|
+ if (userList2 != null && userList2.size() > 0) {
|
|
|
+ userPolicyList2 = this.baseMapper.queryOrderCount(userList2, record.getStartdate(), record.getEnddate());
|
|
|
+ EsmTeamPolicyVO esmTeamPolicyVO2_t = this.baseMapper.queryOrderCountHz(userList2, record.getStartdate(),
|
|
|
+ record.getEnddate());
|
|
|
+ if (esmTeamPolicyVO2_t != null) {
|
|
|
esmTeamPolicyVO2.setSumpremium(esmTeamPolicyVO2_t.getSumpremium());
|
|
|
esmTeamPolicyVO2.setUsernum(userPolicyList2.size());
|
|
|
}
|
|
|
@@ -382,21 +395,21 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
}
|
|
|
|
|
|
//临时团队
|
|
|
- List<String> registList= this.baseMapper.getIdDown3_regist(record.getId());
|
|
|
- EsmTeamPolicyVO esmTeamPolicyVO9=new EsmTeamPolicyVO();
|
|
|
+ List<String> registList = this.baseMapper.getIdDown3_regist(record.getId());
|
|
|
+ EsmTeamPolicyVO esmTeamPolicyVO9 = new EsmTeamPolicyVO();
|
|
|
esmTeamPolicyVO9.setTeamlevel("临时团队");
|
|
|
- esmTeamPolicyVO9.setTeamnum(registList==null?0:registList.size());
|
|
|
+ esmTeamPolicyVO9.setTeamnum(registList == null ? 0 : registList.size());
|
|
|
|
|
|
//汇总
|
|
|
- List<String> userList=new ArrayList<>();
|
|
|
+ List<String> userList = new ArrayList<>();
|
|
|
userList.addAll(userList0);
|
|
|
userList.addAll(userList1);
|
|
|
userList.addAll(userList2);
|
|
|
userList.addAll(registList);
|
|
|
- userPolicyList=this.baseMapper.queryOrderCount(userList,record.getStartdate(),record.getEnddate());
|
|
|
- EsmTeamPolicyVO esmTeamPolicyVO=new EsmTeamPolicyVO();
|
|
|
- EsmTeamPolicyVO esmTeamPolicyVO_t=this.baseMapper.queryOrderCountHz(userList,record.getStartdate(),record.getEnddate());
|
|
|
- if(esmTeamPolicyVO_t!=null){
|
|
|
+ userPolicyList = this.baseMapper.queryOrderCount(userList, record.getStartdate(), record.getEnddate());
|
|
|
+ EsmTeamPolicyVO esmTeamPolicyVO = new EsmTeamPolicyVO();
|
|
|
+ EsmTeamPolicyVO esmTeamPolicyVO_t = this.baseMapper.queryOrderCountHz(userList, record.getStartdate(), record.getEnddate());
|
|
|
+ if (esmTeamPolicyVO_t != null) {
|
|
|
esmTeamPolicyVO.setSumpremium(esmTeamPolicyVO_t.getSumpremium());
|
|
|
esmTeamPolicyVO.setUsernum(userPolicyList.size());
|
|
|
}
|
|
|
@@ -412,7 +425,7 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
esmUserCountVO.setUserPolicyList0(userPolicyList0);
|
|
|
esmUserCountVO.setUserPolicyList1(userPolicyList1);
|
|
|
esmUserCountVO.setUserPolicyList2(userPolicyList2);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new SystemException("内部错误");
|
|
|
}
|
|
|
|
|
|
@@ -420,9 +433,26 @@ public class EsmUserReferrerServiceImpl extends ServiceImpl<EsmUserReferrerMappe
|
|
|
}
|
|
|
|
|
|
|
|
|
- public List<EsmUserReferrer> queryList(String affiliation){
|
|
|
+ public List<EsmUserReferrer> queryList(String affiliation) {
|
|
|
return super.baseMapper.queryList(affiliation);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BasePageResult<SysUser> getTeamUser(AppCustomerManagementQueryVo managementQueryVo, String userId) {
|
|
|
+ List<EsmUserReferrer> esmUserReferrers = lambdaQuery().eq(EsmUserReferrer::getReferrerId, userId).list();
|
|
|
+ if (esmUserReferrers.isEmpty()) {
|
|
|
+ return new BasePageResult<>();
|
|
|
+ }
|
|
|
+ int i = esmUserReferrers.get(0).getLevel() + 3;
|
|
|
+ PageHelper.startPage(managementQueryVo.getPageNum(), managementQueryVo.getPageSize());
|
|
|
+ List<SysUser> byTeam = baseMapper.getByTeam(userId, i);
|
|
|
+ PageResult<SysUser> sysUserPageResult = new PageResult<>(byTeam);
|
|
|
+ return new BasePageResult<>(managementQueryVo.getPageNum(), managementQueryVo.getPageSize(), sysUserPageResult.getTotalPages(),
|
|
|
+ sysUserPageResult.getPageSize(), sysUserPageResult.getContent());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|