|
@@ -11,14 +11,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
-import com.jtzx.crm.module.sys.entity.SysCustomerFollowAuditEntity;
|
|
|
|
|
-import com.jtzx.crm.module.sys.entity.SysCustomerFollowEntity;
|
|
|
|
|
-import com.jtzx.crm.module.sys.entity.SysGroupEntity;
|
|
|
|
|
-import com.jtzx.crm.module.sys.entity.SysParamBaseDataEntity;
|
|
|
|
|
-import com.jtzx.crm.module.sys.mapper.SysCustomerFollowAuditMapper;
|
|
|
|
|
-import com.jtzx.crm.module.sys.mapper.SysCustomerFollowMapper;
|
|
|
|
|
-import com.jtzx.crm.module.sys.mapper.SysGroupMapper;
|
|
|
|
|
-import com.jtzx.crm.module.sys.mapper.SysParamBaseDataMapper;
|
|
|
|
|
|
|
+import com.jtzx.crm.module.sys.entity.*;
|
|
|
|
|
+import com.jtzx.crm.module.sys.mapper.*;
|
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataFollowListDTO;
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataFollowListDTO;
|
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerFollowReqDTO;
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerFollowReqDTO;
|
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerOperLogListDTO;
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerOperLogListDTO;
|
|
@@ -29,10 +23,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.Collections;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 客户跟进业务
|
|
* 客户跟进业务
|
|
@@ -50,6 +41,8 @@ public class SysCustomerDataFollowService {
|
|
|
|
|
|
|
|
private final SysCustomerFollowAuditMapper sysCustomerFollowAuditMapper;
|
|
private final SysCustomerFollowAuditMapper sysCustomerFollowAuditMapper;
|
|
|
|
|
|
|
|
|
|
+ private final SysCustomerDataMapper sysCustomerDataMapper;
|
|
|
|
|
+
|
|
|
private final SysCustomerUserCommonService sysCustomerUserCommonService;
|
|
private final SysCustomerUserCommonService sysCustomerUserCommonService;
|
|
|
|
|
|
|
|
private final SysCustomerOperLogService sysCustomerOperLogService;
|
|
private final SysCustomerOperLogService sysCustomerOperLogService;
|
|
@@ -72,7 +65,7 @@ public class SysCustomerDataFollowService {
|
|
|
//产品信息
|
|
//产品信息
|
|
|
resultData.setProductData(sysCustomerUserCommonService.handleProductData());
|
|
resultData.setProductData(sysCustomerUserCommonService.handleProductData());
|
|
|
//省市信息
|
|
//省市信息
|
|
|
- SysCustomerSelectBO sysCustomerSelectBO = sysCustomerUserCommonService.querySelectDataByType2( true);
|
|
|
|
|
|
|
+ SysCustomerSelectBO sysCustomerSelectBO = sysCustomerUserCommonService.querySelectDataByType2(true);
|
|
|
if (sysCustomerSelectBO != null && CollUtil.isNotEmpty(sysCustomerSelectBO.getRegionData())) {
|
|
if (sysCustomerSelectBO != null && CollUtil.isNotEmpty(sysCustomerSelectBO.getRegionData())) {
|
|
|
//省市信息
|
|
//省市信息
|
|
|
resultData.setRegionData(sysCustomerSelectBO.getRegionData());
|
|
resultData.setRegionData(sysCustomerSelectBO.getRegionData());
|
|
@@ -116,24 +109,19 @@ public class SysCustomerDataFollowService {
|
|
|
List<Long> cityIds = sysCustomerUserCommonService.queryUserCityIds1(dto.getProvinceId());
|
|
List<Long> cityIds = sysCustomerUserCommonService.queryUserCityIds1(dto.getProvinceId());
|
|
|
List<BindUserBO> bindUserBOS = sysCustomerUserCommonService.queryBindUserListByCityId(cityIds);
|
|
List<BindUserBO> bindUserBOS = sysCustomerUserCommonService.queryBindUserListByCityId(cityIds);
|
|
|
if (CollUtil.isNotEmpty(bindUserBOS)) {
|
|
if (CollUtil.isNotEmpty(bindUserBOS)) {
|
|
|
- if (CollUtil.isEmpty(userIds)) {
|
|
|
|
|
|
|
+ if (CollUtil.isEmpty(userIds) && !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
|
|
|
userIds.addAll(
|
|
userIds.addAll(
|
|
|
bindUserBOS.stream()
|
|
bindUserBOS.stream()
|
|
|
.map(BindUserBO::getId).toList());
|
|
.map(BindUserBO::getId).toList());
|
|
|
}
|
|
}
|
|
|
- if (CollUtil.isEmpty(groupIds)) {
|
|
|
|
|
|
|
+ if (CollUtil.isEmpty(groupIds) && !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
|
|
|
groupIds.addAll(
|
|
groupIds.addAll(
|
|
|
bindUserBOS.stream()
|
|
bindUserBOS.stream()
|
|
|
.map(BindUserBO::getGroupId).distinct().toList());
|
|
.map(BindUserBO::getGroupId).distinct().toList());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (CollUtil.isEmpty(userIds) || CollUtil.isEmpty(groupIds)) {
|
|
|
|
|
- return new PageResult<SysCustomerFollowListBO>()
|
|
|
|
|
- .setCurrent(1)
|
|
|
|
|
- .setSize(dto.getPageSize())
|
|
|
|
|
- .setTotal(0)
|
|
|
|
|
- .setRecords(Lists.newArrayList());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
Page<SysCustomerFollowEntity> entityPage = sysCustomerFollowMapper.selectPage(
|
|
Page<SysCustomerFollowEntity> entityPage = sysCustomerFollowMapper.selectPage(
|
|
|
new Page<>(dto.getPageNum(), dto.getPageSize()),
|
|
new Page<>(dto.getPageNum(), dto.getPageSize()),
|
|
|
new QueryWrapper<SysCustomerFollowEntity>()
|
|
new QueryWrapper<SysCustomerFollowEntity>()
|
|
@@ -141,7 +129,7 @@ public class SysCustomerDataFollowService {
|
|
|
// 名称
|
|
// 名称
|
|
|
.like(CharSequenceUtil.isNotBlank(dto.getQueryStr()), SysCustomerFollowEntity::getCustomerName, CharSequenceUtil.cleanBlank(dto.getQueryStr()))
|
|
.like(CharSequenceUtil.isNotBlank(dto.getQueryStr()), SysCustomerFollowEntity::getCustomerName, CharSequenceUtil.cleanBlank(dto.getQueryStr()))
|
|
|
//用户判断
|
|
//用户判断
|
|
|
- .in(SysCustomerFollowEntity::getClaimUserId, userIds)
|
|
|
|
|
|
|
+ .in(CollUtil.isNotEmpty(userIds), SysCustomerFollowEntity::getClaimUserId, userIds)
|
|
|
// 学段id(param_base_data表主id)
|
|
// 学段id(param_base_data表主id)
|
|
|
.eq(Objects.nonNull(dto.getStageId()), SysCustomerFollowEntity::getStageId, dto.getStageId())
|
|
.eq(Objects.nonNull(dto.getStageId()), SysCustomerFollowEntity::getStageId, dto.getStageId())
|
|
|
// 省份id(省份表主id)
|
|
// 省份id(省份表主id)
|
|
@@ -149,9 +137,9 @@ public class SysCustomerDataFollowService {
|
|
|
// 城市id(不为空时)
|
|
// 城市id(不为空时)
|
|
|
.eq(Objects.nonNull(dto.getCityId()), SysCustomerFollowEntity::getCityId, dto.getCityId())
|
|
.eq(Objects.nonNull(dto.getCityId()), SysCustomerFollowEntity::getCityId, dto.getCityId())
|
|
|
// 城市id(为空时)
|
|
// 城市id(为空时)
|
|
|
- .in(Objects.isNull(dto.getCityId()), SysCustomerFollowEntity::getCityId, cityIds)
|
|
|
|
|
|
|
+ .in(Objects.isNull(dto.getCityId()) && CollUtil.isNotEmpty(cityIds), SysCustomerFollowEntity::getCityId, cityIds)
|
|
|
//小组
|
|
//小组
|
|
|
- .in(SysCustomerFollowEntity::getClaimUserGroupId, groupIds)
|
|
|
|
|
|
|
+ .in(CollUtil.isNotEmpty(groupIds), SysCustomerFollowEntity::getClaimUserGroupId, groupIds)
|
|
|
//开始时间
|
|
//开始时间
|
|
|
.ge(dto.getStartDatetime() != null, SysCustomerFollowEntity::getClaimDatetime, dto.getStartDatetime())
|
|
.ge(dto.getStartDatetime() != null, SysCustomerFollowEntity::getClaimDatetime, dto.getStartDatetime())
|
|
|
//结束时间
|
|
//结束时间
|
|
@@ -176,7 +164,7 @@ public class SysCustomerDataFollowService {
|
|
|
if (dto.getGroupId() != null) {
|
|
if (dto.getGroupId() != null) {
|
|
|
groupIds.add(dto.getGroupId());
|
|
groupIds.add(dto.getGroupId());
|
|
|
}
|
|
}
|
|
|
- SysCustomerSelectBO selectBO = sysCustomerUserCommonService.querySelectDataByType2( true);
|
|
|
|
|
|
|
+ SysCustomerSelectBO selectBO = sysCustomerUserCommonService.querySelectDataByType2(true);
|
|
|
if (selectBO != null && CollUtil.isNotEmpty(selectBO.getRegionData())) {
|
|
if (selectBO != null && CollUtil.isNotEmpty(selectBO.getRegionData())) {
|
|
|
List<Long> cityIds = Lists.newArrayList();
|
|
List<Long> cityIds = Lists.newArrayList();
|
|
|
selectBO.getRegionData()
|
|
selectBO.getRegionData()
|
|
@@ -422,15 +410,15 @@ public class SysCustomerDataFollowService {
|
|
|
.ge(startDateTime != null, SysCustomerFollowEntity::getOrderDatetime, startDateTime)
|
|
.ge(startDateTime != null, SysCustomerFollowEntity::getOrderDatetime, startDateTime)
|
|
|
.le(endDateTime != null, SysCustomerFollowEntity::getOrderDatetime, endDateTime)
|
|
.le(endDateTime != null, SysCustomerFollowEntity::getOrderDatetime, endDateTime)
|
|
|
.eq(SysCustomerFollowEntity::getOrderType, orderType)
|
|
.eq(SysCustomerFollowEntity::getOrderType, orderType)
|
|
|
- .ne(orderType==1,SysCustomerFollowEntity::getOrderStatus, 2)
|
|
|
|
|
|
|
+ .ne(orderType == 1, SysCustomerFollowEntity::getOrderStatus, 2)
|
|
|
.and(StrUtil.isNotEmpty(queryStr), z ->
|
|
.and(StrUtil.isNotEmpty(queryStr), z ->
|
|
|
- z.like(SysCustomerFollowEntity::getCustomerName, queryStr)
|
|
|
|
|
- .or().like(SysCustomerFollowEntity::getClaimUserName, queryStr)
|
|
|
|
|
|
|
+ z.like(SysCustomerFollowEntity::getCustomerName, queryStr)
|
|
|
|
|
+ .or().like(SysCustomerFollowEntity::getClaimUserName, queryStr)
|
|
|
// .or().like(SysCustomerFollowEntity::getCustomerPersonName, queryStr)
|
|
// .or().like(SysCustomerFollowEntity::getCustomerPersonName, queryStr)
|
|
|
// .or().like(SysCustomerFollowEntity::getPositionName, queryStr)
|
|
// .or().like(SysCustomerFollowEntity::getPositionName, queryStr)
|
|
|
)
|
|
)
|
|
|
- .orderByDesc(orderType==0,SysCustomerFollowEntity::getOrderDatetime, SysCustomerFollowEntity::getCreatedAt)
|
|
|
|
|
- .orderByDesc(orderType==1,SysCustomerFollowEntity::getCreatedAt)
|
|
|
|
|
|
|
+ .orderByDesc(orderType == 0, SysCustomerFollowEntity::getOrderDatetime, SysCustomerFollowEntity::getCreatedAt)
|
|
|
|
|
+ .orderByDesc(orderType == 1, SysCustomerFollowEntity::getCreatedAt)
|
|
|
);
|
|
);
|
|
|
return this.entityList2BOs(listData);
|
|
return this.entityList2BOs(listData);
|
|
|
}
|
|
}
|
|
@@ -460,6 +448,31 @@ public class SysCustomerDataFollowService {
|
|
|
if (CollUtil.isEmpty(entityList)) {
|
|
if (CollUtil.isEmpty(entityList)) {
|
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
|
}
|
|
}
|
|
|
|
|
+ //查询客户学校数据
|
|
|
|
|
+ List<SysCustomerDataEntity> customerDataEntityList =
|
|
|
|
|
+ sysCustomerDataMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<SysCustomerDataEntity>()
|
|
|
|
|
+ .select(SysCustomerDataEntity::getId, SysCustomerDataEntity::getName, SysCustomerDataEntity::getAddress)
|
|
|
|
|
+ .in(SysCustomerDataEntity::getId, entityList.stream().map(SysCustomerFollowEntity::getCustomerId).distinct().toList())
|
|
|
|
|
+ );
|
|
|
|
|
+ if(CollUtil.isEmpty(customerDataEntityList)){
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //查询当前登录用户对 customer 的上次跟进时间
|
|
|
|
|
+ List<SysCustomerFollowEntity> customerFollowList =
|
|
|
|
|
+ sysCustomerFollowMapper.selectList(
|
|
|
|
|
+ new QueryWrapper<SysCustomerFollowEntity>()
|
|
|
|
|
+ .lambda()
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysCustomerFollowEntity::getCustomerId,
|
|
|
|
|
+ SysCustomerFollowEntity::getClaimUserGroupId,
|
|
|
|
|
+ SysCustomerFollowEntity::getClaimUserId,
|
|
|
|
|
+ SysCustomerFollowEntity::getClaimDatetime
|
|
|
|
|
+ )
|
|
|
|
|
+ .eq(SysCustomerFollowEntity::getClaimUserId, UserContextHolder.getUserId())
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
|
|
|
//查询审核数据
|
|
//查询审核数据
|
|
|
List<Long> customerFollowIds =
|
|
List<Long> customerFollowIds =
|
|
@@ -468,22 +481,22 @@ public class SysCustomerDataFollowService {
|
|
|
.filter(Objects::nonNull).distinct().toList();
|
|
.filter(Objects::nonNull).distinct().toList();
|
|
|
|
|
|
|
|
List<SysCustomerFollowAuditEntity> auditData =
|
|
List<SysCustomerFollowAuditEntity> auditData =
|
|
|
- sysCustomerFollowAuditMapper.selectList(
|
|
|
|
|
- new LambdaQueryWrapper<SysCustomerFollowAuditEntity>()
|
|
|
|
|
- .select(
|
|
|
|
|
- SysCustomerFollowAuditEntity::getCustomerFollowId,
|
|
|
|
|
- SysCustomerFollowAuditEntity::getCustomerId,
|
|
|
|
|
- SysCustomerFollowAuditEntity::getAuditStatus
|
|
|
|
|
- )
|
|
|
|
|
- .in(SysCustomerFollowAuditEntity::getCustomerFollowId, customerFollowIds)
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ sysCustomerFollowAuditMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<SysCustomerFollowAuditEntity>()
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysCustomerFollowAuditEntity::getCustomerFollowId,
|
|
|
|
|
+ SysCustomerFollowAuditEntity::getCustomerId,
|
|
|
|
|
+ SysCustomerFollowAuditEntity::getAuditStatus
|
|
|
|
|
+ )
|
|
|
|
|
+ .in(SysCustomerFollowAuditEntity::getCustomerFollowId, customerFollowIds)
|
|
|
|
|
+ );
|
|
|
//查询小组数据
|
|
//查询小组数据
|
|
|
List<Long> groupIds =
|
|
List<Long> groupIds =
|
|
|
entityList.stream()
|
|
entityList.stream()
|
|
|
.map(SysCustomerFollowEntity::getClaimUserGroupId)
|
|
.map(SysCustomerFollowEntity::getClaimUserGroupId)
|
|
|
.filter(Objects::nonNull).distinct().toList();
|
|
.filter(Objects::nonNull).distinct().toList();
|
|
|
List<SysGroupEntity> groupEntityList = Lists.newArrayList();
|
|
List<SysGroupEntity> groupEntityList = Lists.newArrayList();
|
|
|
- if(CollUtil.isNotEmpty(groupIds)){
|
|
|
|
|
|
|
+ if (CollUtil.isNotEmpty(groupIds)) {
|
|
|
groupEntityList.addAll(sysGroupMapper.selectByIds(groupIds));
|
|
groupEntityList.addAll(sysGroupMapper.selectByIds(groupIds));
|
|
|
}
|
|
}
|
|
|
//查询学段
|
|
//查询学段
|
|
@@ -509,6 +522,20 @@ public class SysCustomerDataFollowService {
|
|
|
entityList.forEach(
|
|
entityList.forEach(
|
|
|
entity -> {
|
|
entity -> {
|
|
|
SysCustomerFollowListBO bo = this.entity2BO(entity);
|
|
SysCustomerFollowListBO bo = this.entity2BO(entity);
|
|
|
|
|
+ if(CollUtil.isNotEmpty(customerDataEntityList)){
|
|
|
|
|
+ customerDataEntityList.stream()
|
|
|
|
|
+ .filter(x -> x.getId().equals(entity.getCustomerId()))
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .ifPresent(e -> bo.setAddress(e.getAddress()));
|
|
|
|
|
+ }
|
|
|
|
|
+ //上次跟进
|
|
|
|
|
+ if (CollUtil.isNotEmpty(customerFollowList)) {
|
|
|
|
|
+ customerFollowList.stream()
|
|
|
|
|
+ .filter(x -> x.getCustomerId().equals(entity.getCustomerId()))
|
|
|
|
|
+ .filter(x -> x.getClaimUserId().equals(entity.getClaimUserId()))
|
|
|
|
|
+ .max(Comparator.comparing(SysCustomerFollowEntity::getClaimDatetime))
|
|
|
|
|
+ .ifPresent(e -> bo.setLastClaimDatetime(e.getClaimDatetime()));
|
|
|
|
|
+ }
|
|
|
if (CollUtil.isNotEmpty(groupEntityList)) {
|
|
if (CollUtil.isNotEmpty(groupEntityList)) {
|
|
|
groupEntityList.stream()
|
|
groupEntityList.stream()
|
|
|
.filter(x -> x.getId().equals(entity.getClaimUserGroupId()))
|
|
.filter(x -> x.getId().equals(entity.getClaimUserGroupId()))
|
|
@@ -534,7 +561,7 @@ public class SysCustomerDataFollowService {
|
|
|
.ifPresent(e -> bo.setFollowName(e.getTitle()));
|
|
.ifPresent(e -> bo.setFollowName(e.getTitle()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(CollUtil.isNotEmpty(auditData)){
|
|
|
|
|
|
|
+ if (CollUtil.isNotEmpty(auditData)) {
|
|
|
auditData.stream()
|
|
auditData.stream()
|
|
|
.filter(x -> x.getCustomerFollowId().equals(entity.getId()))
|
|
.filter(x -> x.getCustomerFollowId().equals(entity.getId()))
|
|
|
.findFirst()
|
|
.findFirst()
|
|
@@ -562,6 +589,10 @@ public class SysCustomerDataFollowService {
|
|
|
// 可以在此处为BO填充字段
|
|
// 可以在此处为BO填充字段
|
|
|
bo.setClaimUserName(entity.getClaimUserName());
|
|
bo.setClaimUserName(entity.getClaimUserName());
|
|
|
bo.setClaimDatetime(entity.getClaimDatetime());
|
|
bo.setClaimDatetime(entity.getClaimDatetime());
|
|
|
|
|
+ bo.setTypeName("首单客户");
|
|
|
|
|
+ if (entity.getSuccessStatus() != null && entity.getSuccessStatus() == 1) {
|
|
|
|
|
+ bo.setTypeName("存量客户");
|
|
|
|
|
+ }
|
|
|
return bo;
|
|
return bo;
|
|
|
}
|
|
}
|
|
|
|
|
|