|
@@ -1,25 +1,30 @@
|
|
|
package com.jtzx.crm.module.sys.service;
|
|
package com.jtzx.crm.module.sys.service;
|
|
|
|
|
|
|
|
-import cc.uncarbon.framework.core.constant.HelioConstant;
|
|
|
|
|
-import cc.uncarbon.framework.core.exception.BusinessException;
|
|
|
|
|
-import cc.uncarbon.framework.core.page.PageParam;
|
|
|
|
|
-import cc.uncarbon.framework.core.page.PageResult;
|
|
|
|
|
-import com.jtzx.crm.module.sys.entity.SysCustomerFollowEntity;
|
|
|
|
|
-import com.jtzx.crm.module.sys.mapper.SysCustomerFollowMapper;
|
|
|
|
|
-import com.jtzx.crm.module.sys.model.request.AdminSysCustomerFollowInsertOrUpdateDTO;
|
|
|
|
|
-import com.jtzx.crm.module.sys.model.request.AdminSysCustomerFollowListDTO;
|
|
|
|
|
-import com.jtzx.crm.module.sys.model.response.SysCustomerFollowBO;
|
|
|
|
|
|
|
+import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
|
|
|
+import cc.uncarbon.framework.crud.entity.HelioBaseEntity;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.text.CharSequenceUtil;
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
|
+import com.jtzx.crm.module.sys.entity.*;
|
|
|
|
|
+import com.jtzx.crm.module.sys.mapper.*;
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.request.AdminSysCustomerFollowInsertOrUpdateDTO;
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.response.CustomerFollowOverViewBO;
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.response.CustomerProductBO;
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.response.CustomerProductOverViewBO;
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.response.SysCustomerFollowDataBO;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Comparator;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -32,211 +37,422 @@ public class SysCustomerFollowService {
|
|
|
|
|
|
|
|
private final SysCustomerFollowMapper sysCustomerFollowMapper;
|
|
private final SysCustomerFollowMapper sysCustomerFollowMapper;
|
|
|
|
|
|
|
|
|
|
+ private final SysCustomerDataMapper sysCustomerDataMapper;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 后台管理-分页列表
|
|
|
|
|
- */
|
|
|
|
|
- public PageResult<SysCustomerFollowBO> adminList(PageParam pageParam, AdminSysCustomerFollowListDTO dto) {
|
|
|
|
|
- Page<SysCustomerFollowEntity> entityPage = sysCustomerFollowMapper.selectPage(
|
|
|
|
|
- new Page<>(pageParam.getPageNum(), pageParam.getPageSize()),
|
|
|
|
|
- new QueryWrapper<SysCustomerFollowEntity>()
|
|
|
|
|
- .lambda()
|
|
|
|
|
- // 认领人(跟进)id
|
|
|
|
|
- .eq(Objects.nonNull(dto.getClaimUserId()), SysCustomerFollowEntity::getClaimUserId, dto.getClaimUserId())
|
|
|
|
|
- // 认领人(跟进)名称
|
|
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getClaimUserName()), SysCustomerFollowEntity::getClaimUserName, CharSequenceUtil.cleanBlank(dto.getClaimUserName()))
|
|
|
|
|
- // 认领人员所在的项目组id
|
|
|
|
|
- .eq(Objects.nonNull(dto.getClaimUserGroupId()), SysCustomerFollowEntity::getClaimUserGroupId, dto.getClaimUserGroupId())
|
|
|
|
|
- // 跟进时间
|
|
|
|
|
- .eq(Objects.nonNull(dto.getClaimDatetime()), SysCustomerFollowEntity::getClaimDatetime, dto.getClaimDatetime())
|
|
|
|
|
- // 客户表主id
|
|
|
|
|
- .eq(Objects.nonNull(dto.getCustomerId()), SysCustomerFollowEntity::getCustomerId, dto.getCustomerId())
|
|
|
|
|
- // 客户名称
|
|
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getCustomerName()), SysCustomerFollowEntity::getCustomerName, CharSequenceUtil.cleanBlank(dto.getCustomerName()))
|
|
|
|
|
- // 产品id(param_base_data表主id)
|
|
|
|
|
- .eq(Objects.nonNull(dto.getProductId()), SysCustomerFollowEntity::getProductId, dto.getProductId())
|
|
|
|
|
- // 产品名称
|
|
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getProductName()), SysCustomerFollowEntity::getProductName, CharSequenceUtil.cleanBlank(dto.getProductName()))
|
|
|
|
|
- // 跟进状态id,赢单状态id固定-37,方案演示id固定-33
|
|
|
|
|
- .eq(Objects.nonNull(dto.getFollowId()), SysCustomerFollowEntity::getFollowId, dto.getFollowId())
|
|
|
|
|
- // 跟进状态的名称
|
|
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getFollowName()), SysCustomerFollowEntity::getFollowName, CharSequenceUtil.cleanBlank(dto.getFollowName()))
|
|
|
|
|
- // 是否赢单,0-否,1-是
|
|
|
|
|
- .eq(Objects.nonNull(dto.getSuccessStatus()), SysCustomerFollowEntity::getSuccessStatus, dto.getSuccessStatus())
|
|
|
|
|
- // 联系人id(customer_person表主id)
|
|
|
|
|
- .eq(Objects.nonNull(dto.getCustomerPersonId()), SysCustomerFollowEntity::getCustomerPersonId, dto.getCustomerPersonId())
|
|
|
|
|
- // 联系人名称
|
|
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getCustomerPersonName()), SysCustomerFollowEntity::getCustomerPersonName, CharSequenceUtil.cleanBlank(dto.getCustomerPersonName()))
|
|
|
|
|
- // 职务id(param_base_data表主id)
|
|
|
|
|
- .eq(Objects.nonNull(dto.getPositionId()), SysCustomerFollowEntity::getPositionId, dto.getPositionId())
|
|
|
|
|
- // 职务名称
|
|
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getPositionName()), SysCustomerFollowEntity::getPositionName, CharSequenceUtil.cleanBlank(dto.getPositionName()))
|
|
|
|
|
- // 跟进内容
|
|
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getFollowContent()), SysCustomerFollowEntity::getFollowContent, CharSequenceUtil.cleanBlank(dto.getFollowContent()))
|
|
|
|
|
- // 预约待办类型,0-预约,1-待办,(follow_id=33时为预约,其它为待办),这个数据可以为null
|
|
|
|
|
- .eq(Objects.nonNull(dto.getOrderType()), SysCustomerFollowEntity::getOrderType, dto.getOrderType())
|
|
|
|
|
- // 待办时间
|
|
|
|
|
- .eq(Objects.nonNull(dto.getOrderDatetime()), SysCustomerFollowEntity::getOrderDatetime, dto.getOrderDatetime())
|
|
|
|
|
- // 预约,待办取消状态,0-未取消,1-已取消(预约的取消需要填写取消原因,待办的取消是一个开关,不需要填写原因)
|
|
|
|
|
- .eq(Objects.nonNull(dto.getOrderStatus()), SysCustomerFollowEntity::getOrderStatus, dto.getOrderStatus())
|
|
|
|
|
- // 预约取消原因
|
|
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getCancelRemark()), SysCustomerFollowEntity::getCancelRemark, CharSequenceUtil.cleanBlank(dto.getCancelRemark()))
|
|
|
|
|
- // 时间区间
|
|
|
|
|
- .between(Objects.nonNull(dto.getBeginAt()) && Objects.nonNull(dto.getEndAt()), SysCustomerFollowEntity::getCreatedAt, dto.getBeginAt(), dto.getEndAt())
|
|
|
|
|
- // 排序
|
|
|
|
|
- .orderByDesc(SysCustomerFollowEntity::getCreatedAt)
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- return this.entityPage2BOPage(entityPage);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private final SysCustomerPersonMapper sysCustomerPersonMapper;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 根据 ID 取详情
|
|
|
|
|
- *
|
|
|
|
|
- * @param id 主键ID
|
|
|
|
|
- * @return null or BO
|
|
|
|
|
- */
|
|
|
|
|
- public SysCustomerFollowBO getOneById(Long id) {
|
|
|
|
|
- return this.getOneById(id, false);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private final SysParamBaseDataMapper sysParamBaseDataMapper;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 根据 ID 取详情
|
|
|
|
|
- *
|
|
|
|
|
- * @param id 主键ID
|
|
|
|
|
- * @param throwIfInvalidId 是否在 ID 无效时抛出异常
|
|
|
|
|
- * @return null or BO
|
|
|
|
|
- */
|
|
|
|
|
- public SysCustomerFollowBO getOneById(Long id, boolean throwIfInvalidId) throws BusinessException {
|
|
|
|
|
- SysCustomerFollowEntity entity = sysCustomerFollowMapper.selectById(id);
|
|
|
|
|
- if (throwIfInvalidId && entity == null) {
|
|
|
|
|
- throw new BusinessException(400, "无效客户跟进数据信息ID");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private final SysCustomerFollowAuditMapper sysCustomerFollowAuditMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final SysUserRoleRelationMapper sysUserRoleRelationMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final SysUserMapper sysUserMapper;
|
|
|
|
|
|
|
|
- return this.entity2BO(entity);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 后台管理-新增
|
|
* 后台管理-新增
|
|
|
*/
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Long adminInsert(AdminSysCustomerFollowInsertOrUpdateDTO dto) {
|
|
|
|
|
|
|
+ public void adminInsert(AdminSysCustomerFollowInsertOrUpdateDTO dto) {
|
|
|
log.info("[后台管理-客户跟进数据信息-新增] >> DTO={}", dto);
|
|
log.info("[后台管理-客户跟进数据信息-新增] >> DTO={}", dto);
|
|
|
- this.checkExistence(dto);
|
|
|
|
|
-
|
|
|
|
|
dto.setId(null);
|
|
dto.setId(null);
|
|
|
|
|
+ // 参数校验
|
|
|
|
|
+ this.checkParam(dto);
|
|
|
|
|
+ // 处理参数
|
|
|
|
|
+ this.handleParams(dto);
|
|
|
SysCustomerFollowEntity entity = new SysCustomerFollowEntity();
|
|
SysCustomerFollowEntity entity = new SysCustomerFollowEntity();
|
|
|
BeanUtil.copyProperties(dto, entity);
|
|
BeanUtil.copyProperties(dto, entity);
|
|
|
-
|
|
|
|
|
sysCustomerFollowMapper.insert(entity);
|
|
sysCustomerFollowMapper.insert(entity);
|
|
|
-
|
|
|
|
|
- return entity.getId();
|
|
|
|
|
|
|
+ if (dto.getOrderType() != null && dto.getOrderType() == 0 && dto.getOrderDatetime() != null) {
|
|
|
|
|
+ entity.setOrderStatus(0);
|
|
|
|
|
+ entity.setOrderDatetime(dto.getOrderDatetime());
|
|
|
|
|
+ if (!dto.getOrderDatetime().isAfter(LocalDateTime.now())) {
|
|
|
|
|
+ entity.setOrderStatus(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ sysCustomerFollowMapper.updateById(entity);
|
|
|
|
|
+ if (dto.getOrderDatetime().isAfter(LocalDateTime.now())) {
|
|
|
|
|
+ //TODO 发送定时任务,时间到之后改为已结束
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 后台管理-编辑
|
|
|
|
|
|
|
+ * 处理跟进总览
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param customerId
|
|
|
|
|
+ * @return
|
|
|
*/
|
|
*/
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
- public void adminUpdate(AdminSysCustomerFollowInsertOrUpdateDTO dto) {
|
|
|
|
|
- log.info("[后台管理-客户跟进数据信息-编辑] >> DTO={}", dto);
|
|
|
|
|
- this.checkExistence(dto);
|
|
|
|
|
-
|
|
|
|
|
- SysCustomerFollowEntity entity = new SysCustomerFollowEntity();
|
|
|
|
|
- BeanUtil.copyProperties(dto, entity);
|
|
|
|
|
|
|
+ public CustomerFollowOverViewBO handleCustomerFollowOverViewData(Long customerId, Long userId) {
|
|
|
|
|
+ CustomerFollowOverViewBO customerFollowOverViewBO = CustomerFollowOverViewBO.builder().build();
|
|
|
|
|
+ customerFollowOverViewBO.setHistoryProductCount(0);
|
|
|
|
|
+ customerFollowOverViewBO.setHistoryPersonCount(0);
|
|
|
|
|
+ customerFollowOverViewBO.setHistoryFollowCount(0);
|
|
|
|
|
+ customerFollowOverViewBO.setSuccessCount(0);
|
|
|
|
|
+ customerFollowOverViewBO.setFailedCount(0);
|
|
|
|
|
+ List<SysCustomerFollowEntity> followEntityList =
|
|
|
|
|
+ sysCustomerFollowMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysCustomerFollowEntity::getId,
|
|
|
|
|
+ SysCustomerFollowEntity::getProductId,
|
|
|
|
|
+ SysCustomerFollowEntity::getClaimUserId,
|
|
|
|
|
+ SysCustomerFollowEntity::getFollowId
|
|
|
|
|
+ )
|
|
|
|
|
+ .eq(SysCustomerFollowEntity::getCustomerId, customerId)
|
|
|
|
|
+ .ne(userId != null, SysCustomerFollowEntity::getClaimUserId, userId)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(followEntityList)) {
|
|
|
|
|
+ customerFollowOverViewBO.setHistoryProductCount(
|
|
|
|
|
+ followEntityList.stream()
|
|
|
|
|
+ .map(SysCustomerFollowEntity::getProductId)
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .toList().size());
|
|
|
|
|
+ customerFollowOverViewBO.setHistoryPersonCount(
|
|
|
|
|
+ followEntityList.stream()
|
|
|
|
|
+ .map(SysCustomerFollowEntity::getClaimUserId)
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .toList().size());
|
|
|
|
|
+ customerFollowOverViewBO.setHistoryFollowCount(
|
|
|
|
|
+ followEntityList.stream()
|
|
|
|
|
+ .map(SysCustomerFollowEntity::getId)
|
|
|
|
|
+ .toList().size());
|
|
|
|
|
+ if (userId != null) {
|
|
|
|
|
+ customerFollowOverViewBO.setSuccessCount(
|
|
|
|
|
+ followEntityList.stream()
|
|
|
|
|
+ .filter(e -> e.getFollowId().equals(37L))// 赢单
|
|
|
|
|
+ .toList().size());
|
|
|
|
|
+ customerFollowOverViewBO.setFailedCount(
|
|
|
|
|
+ followEntityList.stream()
|
|
|
|
|
+ .filter(e -> e.getFollowId().equals(36L)) //输单
|
|
|
|
|
+ .toList().size());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return customerFollowOverViewBO;
|
|
|
|
|
|
|
|
- sysCustomerFollowMapper.updateById(entity);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 后台管理-删除
|
|
|
|
|
|
|
+ * 查询公海客户产品信息总览
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param customerId
|
|
|
|
|
+ * @return
|
|
|
*/
|
|
*/
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
- public void adminDelete(Collection<Long> ids) {
|
|
|
|
|
- log.info("[后台管理-客户跟进数据信息-删除] >> ids={}", ids);
|
|
|
|
|
- sysCustomerFollowMapper.deleteByIds(ids);
|
|
|
|
|
|
|
+ public List<CustomerProductOverViewBO> queryProductOverViewData(Long customerId) {
|
|
|
|
|
+
|
|
|
|
|
+ List<CustomerProductOverViewBO> productOverViewBOList = new ArrayList<>();
|
|
|
|
|
+ List<SysCustomerFollowEntity> followEntityList =
|
|
|
|
|
+ sysCustomerFollowMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysCustomerFollowEntity::getProductId,
|
|
|
|
|
+ SysCustomerFollowEntity::getProductName
|
|
|
|
|
+ )
|
|
|
|
|
+ .eq(SysCustomerFollowEntity::getCustomerId, customerId));
|
|
|
|
|
+
|
|
|
|
|
+ if (CollUtil.isNotEmpty(followEntityList)) {
|
|
|
|
|
+ List<Long> productIdList = followEntityList.stream()
|
|
|
|
|
+ .map(SysCustomerFollowEntity::getProductId).distinct().toList();
|
|
|
|
|
+
|
|
|
|
|
+ List<SysParamBaseDataEntity> productDataList =
|
|
|
|
|
+ sysParamBaseDataMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysParamBaseDataEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysParamBaseDataEntity::getId,
|
|
|
|
|
+ SysParamBaseDataEntity::getTitle
|
|
|
|
|
+ )
|
|
|
|
|
+ .in(SysParamBaseDataEntity::getId, productIdList)
|
|
|
|
|
+ .orderByAsc(SysParamBaseDataEntity::getSortCode)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(productDataList)) {
|
|
|
|
|
+ productDataList.forEach(e -> {
|
|
|
|
|
+ CustomerProductOverViewBO bo = CustomerProductOverViewBO.builder()
|
|
|
|
|
+ .productId(e.getId())
|
|
|
|
|
+ .productName(e.getTitle())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ bo.setCount(
|
|
|
|
|
+ followEntityList.stream()
|
|
|
|
|
+ .filter(x -> x.getProductId().equals(e.getId()))
|
|
|
|
|
+ .toList().size());
|
|
|
|
|
+ productOverViewBOList.add(bo);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return productOverViewBOList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- ----------------------------------------------------------------
|
|
|
|
|
- 私有方法 private methods
|
|
|
|
|
- ----------------------------------------------------------------
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 跟进产品数据信息
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param customerId
|
|
|
|
|
+ * @param userId
|
|
|
|
|
+ * @return
|
|
|
*/
|
|
*/
|
|
|
|
|
+ public List<CustomerProductBO> queryCustomerProductData(Long customerId, Long userId) {
|
|
|
|
|
+ List<CustomerProductBO> productBOList = new ArrayList<>();
|
|
|
|
|
+ List<SysCustomerFollowEntity> followEntityList =
|
|
|
|
|
+ sysCustomerFollowMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)
|
|
|
|
|
+ .eq(SysCustomerFollowEntity::getCustomerId, customerId)
|
|
|
|
|
+ .eq(SysCustomerFollowEntity::getClaimUserId, userId)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(followEntityList)) {
|
|
|
|
|
+ List<Long> productIdList = followEntityList.stream()
|
|
|
|
|
+ .map(SysCustomerFollowEntity::getProductId).distinct().toList();
|
|
|
|
|
+
|
|
|
|
|
+ List<SysParamBaseDataEntity> productDataList =
|
|
|
|
|
+ sysParamBaseDataMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysParamBaseDataEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysParamBaseDataEntity::getId,
|
|
|
|
|
+ SysParamBaseDataEntity::getTitle,
|
|
|
|
|
+ SysParamBaseDataEntity::getSortCode
|
|
|
|
|
+ )
|
|
|
|
|
+ .in(SysParamBaseDataEntity::getId, productIdList)
|
|
|
|
|
+ .orderByAsc(SysParamBaseDataEntity::getSortCode)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(productDataList)) {
|
|
|
|
|
+ productDataList.forEach(product -> {
|
|
|
|
|
+ List<SysCustomerFollowEntity> list = followEntityList.stream()
|
|
|
|
|
+ .filter(x -> x.getProductId().equals(product.getId()))
|
|
|
|
|
+ .toList();
|
|
|
|
|
+
|
|
|
|
|
+ CustomerProductBO bo = CustomerProductBO.builder().build();
|
|
|
|
|
+ bo.setProductId(product.getId());
|
|
|
|
|
+ bo.setProductName(product.getTitle());
|
|
|
|
|
+ bo.setSortCode(product.getSortCode());
|
|
|
|
|
+ bo.setCount(list.size());
|
|
|
|
|
+ list.stream().collect(Collectors.groupingBy(SysCustomerFollowEntity::getClaimUserId))
|
|
|
|
|
+ .forEach((id, entities) ->
|
|
|
|
|
+ entities.stream().max(Comparator.comparing(SysCustomerFollowEntity::getCreatedAt))
|
|
|
|
|
+ .ifPresent(entity -> {
|
|
|
|
|
+ bo.setFollowId(entity.getFollowId());
|
|
|
|
|
+ bo.setFollowName(entity.getFollowName());
|
|
|
|
|
+ bo.setCustomerPersonId(entity.getCustomerPersonId());
|
|
|
|
|
+ bo.setCustomerPersonName(entity.getCustomerPersonName());
|
|
|
|
|
+ bo.setLastFollowTime(entity.getCreatedAt());
|
|
|
|
|
+ }));
|
|
|
|
|
+ productBOList.add(bo);
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return productBOList;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 实体转 BO
|
|
|
|
|
|
|
+ * 查询预约待办
|
|
|
*
|
|
*
|
|
|
- * @param entity 实体
|
|
|
|
|
- * @return BO
|
|
|
|
|
|
|
+ * @param customerId
|
|
|
|
|
+ * @param userId
|
|
|
|
|
+ * @return
|
|
|
*/
|
|
*/
|
|
|
- private SysCustomerFollowBO entity2BO(SysCustomerFollowEntity entity) {
|
|
|
|
|
- if (entity == null) {
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ public List<SysCustomerFollowDataBO> handleOrderData(Long customerId, Long userId) {
|
|
|
|
|
+ List<SysCustomerFollowDataBO> orderList = Lists.newArrayList();
|
|
|
|
|
+ List<SysCustomerFollowEntity> followEntityList =
|
|
|
|
|
+ sysCustomerFollowMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)
|
|
|
|
|
+ .eq(SysCustomerFollowEntity::getCustomerId, customerId)
|
|
|
|
|
+ .eq(SysCustomerFollowEntity::getClaimUserId, userId)
|
|
|
|
|
+ .eq(SysCustomerFollowEntity::getOrderStatus,0)//待开始的
|
|
|
|
|
+ .isNotNull(SysCustomerFollowEntity::getOrderType)//预约待办不能为空的
|
|
|
|
|
+ .orderByDesc(SysCustomerFollowEntity::getCreatedAt)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(followEntityList)) {
|
|
|
|
|
+ orderList = followEntityList.stream().map(entity -> {
|
|
|
|
|
+ SysCustomerFollowDataBO bo = SysCustomerFollowDataBO.builder()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ BeanUtils.copyProperties(entity, bo);
|
|
|
|
|
+ return bo;
|
|
|
|
|
+ }).toList();
|
|
|
}
|
|
}
|
|
|
|
|
+ return orderList;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- SysCustomerFollowBO bo = new SysCustomerFollowBO();
|
|
|
|
|
- BeanUtil.copyProperties(entity, bo);
|
|
|
|
|
|
|
|
|
|
- // 可以在此处为BO填充字段
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理参数
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param dto
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void handleParams(AdminSysCustomerFollowInsertOrUpdateDTO dto) {
|
|
|
|
|
+ //处理联系人
|
|
|
|
|
+ SysCustomerPersonEntity sysCustomerPersonEntity = sysCustomerPersonMapper.selectById(dto.getCustomerPersonId());
|
|
|
|
|
+ if (sysCustomerPersonEntity == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,联系人不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ dto.setCustomerPersonName(sysCustomerPersonEntity.getName());
|
|
|
|
|
+ //处理产品
|
|
|
|
|
+ SysParamBaseDataEntity productDataEntity = sysParamBaseDataMapper.selectById(dto.getProductId());
|
|
|
|
|
+ if (productDataEntity == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,产品不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ dto.setProductName(productDataEntity.getTitle());
|
|
|
|
|
+ //处理跟进状态
|
|
|
|
|
+ SysParamBaseDataEntity followDataEntity = sysParamBaseDataMapper.selectById(dto.getFollowId());
|
|
|
|
|
+ if (followDataEntity == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,跟进状态不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ dto.setFollowName(followDataEntity.getTitle());
|
|
|
|
|
+ //处理职务
|
|
|
|
|
+ SysParamBaseDataEntity positionDataEntity = sysParamBaseDataMapper.selectById(dto.getPositionId());
|
|
|
|
|
+ if (positionDataEntity == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,职务不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ dto.setPositionName(positionDataEntity.getTitle());
|
|
|
|
|
+ //处理客户
|
|
|
|
|
+ SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(dto.getCustomerId());
|
|
|
|
|
+ if (sysCustomerDataEntity == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,客户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ dto.setClaimUserGroupId(sysCustomerDataEntity.getClaimUserGroupId());
|
|
|
|
|
+ //省市数据
|
|
|
|
|
+ dto.setCustomerName(sysCustomerDataEntity.getName());
|
|
|
|
|
+ dto.setStageId(sysCustomerDataEntity.getStageId());
|
|
|
|
|
+ dto.setStageName(sysCustomerDataEntity.getStageName());
|
|
|
|
|
+ dto.setProvinceId(sysCustomerDataEntity.getProvinceId());
|
|
|
|
|
+ dto.setProvinceName(sysCustomerDataEntity.getProvinceName());
|
|
|
|
|
+ dto.setCityId(sysCustomerDataEntity.getCityId());
|
|
|
|
|
+ dto.setCityName(sysCustomerDataEntity.getCityName());
|
|
|
|
|
+ dto.setFollowId(UserContextHolder.getUserId()); // 处理认领人(跟进)id
|
|
|
|
|
+ dto.setFollowName(UserContextHolder.getUserName()); // 处理认领人(跟进)name
|
|
|
|
|
+ //处理赢单
|
|
|
|
|
+ if (dto.getFollowId() == 37) {
|
|
|
|
|
+ dto.setSuccessStatus(1);
|
|
|
|
|
+ // 处理客户表的赢单字段
|
|
|
|
|
+// sysCustomerDataEntity.setSuccessStatus(1); //这个状态不在这里使用,赢单需要审核,只有审核通过后才能改这个状态,这里只把赢单人先设置
|
|
|
|
|
+// sysCustomerDataEntity.setSuccessUserId(UserContextHolder.getUserId());
|
|
|
|
|
+// sysCustomerDataEntity.setSuccessUserName(UserContextHolder.getUserName());
|
|
|
|
|
+// sysCustomerDataMapper.updateById(sysCustomerDataEntity);
|
|
|
|
|
+ //发送赢单审核
|
|
|
|
|
+ this.addFollowAuditData(sysCustomerDataEntity, followDataEntity,
|
|
|
|
|
+ sysCustomerPersonEntity, productDataEntity, positionDataEntity, dto.getFollowContent());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return bo;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 实体 List 转 BO List
|
|
|
|
|
|
|
+ * 添加赢单跟进审核数据
|
|
|
*
|
|
*
|
|
|
- * @param entityList 实体 List
|
|
|
|
|
- * @return BO List
|
|
|
|
|
|
|
+ * @param sysCustomerDataEntity
|
|
|
*/
|
|
*/
|
|
|
- private List<SysCustomerFollowBO> entityList2BOs(List<SysCustomerFollowEntity> entityList) {
|
|
|
|
|
- if (CollUtil.isEmpty(entityList)) {
|
|
|
|
|
- return Collections.emptyList();
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void addFollowAuditData(SysCustomerDataEntity sysCustomerDataEntity,
|
|
|
|
|
+ SysParamBaseDataEntity followDataEntity,
|
|
|
|
|
+ SysCustomerPersonEntity sysCustomerPersonEntity,
|
|
|
|
|
+ SysParamBaseDataEntity productDataEntity,
|
|
|
|
|
+ SysParamBaseDataEntity positionDataEntity,
|
|
|
|
|
+ String followContent) {
|
|
|
|
|
+ //先查询管理员数据
|
|
|
|
|
+ List<SysUserRoleRelationEntity> adminUserList =
|
|
|
|
|
+ sysUserRoleRelationMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysUserRoleRelationEntity.class)
|
|
|
|
|
+ .select(SysUserRoleRelationEntity::getUserId)
|
|
|
|
|
+ .eq(SysUserRoleRelationEntity::getRoleValue, "Admin")
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isEmpty(adminUserList)) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,管理员不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 深拷贝
|
|
|
|
|
- List<SysCustomerFollowBO> ret = new ArrayList<>(entityList.size());
|
|
|
|
|
- entityList.forEach(
|
|
|
|
|
- entity -> ret.add(this.entity2BO(entity))
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- return ret;
|
|
|
|
|
|
|
+ List<Long> userIds =
|
|
|
|
|
+ adminUserList.stream()
|
|
|
|
|
+ .map(SysUserRoleRelationEntity::getUserId)
|
|
|
|
|
+ .distinct().toList();
|
|
|
|
|
+ List<SysUserEntity> sysUserEntities = sysUserMapper.selectByIds(userIds);
|
|
|
|
|
+ if (CollUtil.isEmpty(sysUserEntities)) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,管理员不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ adminUserList.forEach(adminUser -> {
|
|
|
|
|
+ SysCustomerFollowAuditEntity entity =
|
|
|
|
|
+ this.getFollowAuditEntity(sysCustomerDataEntity, followDataEntity, sysCustomerPersonEntity,
|
|
|
|
|
+ productDataEntity, positionDataEntity, followContent);
|
|
|
|
|
+ entity.setAuditUserId(adminUser.getUserId()); // 设置审核人id
|
|
|
|
|
+ sysUserEntities.stream().findFirst().ifPresent(sysUserEntity -> entity.setAuditUserName(sysUserEntity.getUserName()));
|
|
|
|
|
+ sysCustomerFollowAuditMapper.insert(entity);
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 实体分页转 BO 分页
|
|
|
|
|
|
|
+ * 获取跟进审核数据
|
|
|
*
|
|
*
|
|
|
- * @param entityPage 实体分页
|
|
|
|
|
- * @return BO 分页
|
|
|
|
|
|
|
+ * @param sysCustomerDataEntity
|
|
|
|
|
+ * @param sysCustomerPersonEntity
|
|
|
|
|
+ * @param productDataEntity
|
|
|
|
|
+ * @param positionDataEntity
|
|
|
|
|
+ * @param followContent
|
|
|
|
|
+ * @return
|
|
|
*/
|
|
*/
|
|
|
- private PageResult<SysCustomerFollowBO> entityPage2BOPage(Page<SysCustomerFollowEntity> entityPage) {
|
|
|
|
|
- return new PageResult<SysCustomerFollowBO>()
|
|
|
|
|
- .setCurrent(entityPage.getCurrent())
|
|
|
|
|
- .setSize(entityPage.getSize())
|
|
|
|
|
- .setTotal(entityPage.getTotal())
|
|
|
|
|
- .setRecords(this.entityList2BOs(entityPage.getRecords()));
|
|
|
|
|
|
|
+ public SysCustomerFollowAuditEntity getFollowAuditEntity(SysCustomerDataEntity sysCustomerDataEntity,
|
|
|
|
|
+ SysParamBaseDataEntity followDataEntity,
|
|
|
|
|
+ SysCustomerPersonEntity sysCustomerPersonEntity,
|
|
|
|
|
+ SysParamBaseDataEntity productDataEntity,
|
|
|
|
|
+ SysParamBaseDataEntity positionDataEntity,
|
|
|
|
|
+ String followContent) {
|
|
|
|
|
+ SysCustomerFollowAuditEntity entity = SysCustomerFollowAuditEntity.builder().build();
|
|
|
|
|
+ entity.setClaimUserId(sysCustomerDataEntity.getClaimUserId());
|
|
|
|
|
+ entity.setClaimUserName(sysCustomerDataEntity.getClaimUserName());
|
|
|
|
|
+ entity.setClaimUserGroupId(sysCustomerDataEntity.getClaimUserGroupId());
|
|
|
|
|
+ entity.setClaimDatetime(LocalDateTime.now());
|
|
|
|
|
+ entity.setCustomerId(sysCustomerDataEntity.getId());
|
|
|
|
|
+ entity.setCustomerName(sysCustomerDataEntity.getName());
|
|
|
|
|
+ entity.setFollowId(followDataEntity.getId());
|
|
|
|
|
+ entity.setFollowName(followDataEntity.getTitle());
|
|
|
|
|
+ entity.setCustomerPersonId(sysCustomerPersonEntity.getId());
|
|
|
|
|
+ entity.setCustomerPersonName(sysCustomerPersonEntity.getName());
|
|
|
|
|
+ entity.setPositionId(positionDataEntity.getId());
|
|
|
|
|
+ entity.setPositionName(positionDataEntity.getTitle());
|
|
|
|
|
+ entity.setFollowContent(followContent);
|
|
|
|
|
+ entity.setProductId(productDataEntity.getId());
|
|
|
|
|
+ entity.setProductName(productDataEntity.getTitle());
|
|
|
|
|
+ entity.setAuditStatus(0);
|
|
|
|
|
+// entity.setAuditUserId(0L);
|
|
|
|
|
+// entity.setAuditUserName("");
|
|
|
|
|
+ return entity;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 检查是否已存在同名数据
|
|
|
|
|
|
|
+ * 校验参数
|
|
|
*
|
|
*
|
|
|
- * @param dto DTO
|
|
|
|
|
|
|
+ * @param dto
|
|
|
*/
|
|
*/
|
|
|
- private void checkExistence(AdminSysCustomerFollowInsertOrUpdateDTO dto) {
|
|
|
|
|
- /*
|
|
|
|
|
- 可以根据自己业务需要,解禁这段代码,修改判断条件和文案
|
|
|
|
|
-
|
|
|
|
|
- SysCustomerFollowEntity existingEntity = sysCustomerFollowMapper.selectOne(
|
|
|
|
|
- new QueryWrapper<SysCustomerFollowEntity>()
|
|
|
|
|
- .lambda()
|
|
|
|
|
- .select(SysCustomerFollowEntity::getId)
|
|
|
|
|
- .eq(SysCustomerFollowEntity::getTitle, dto.getTitle())
|
|
|
|
|
- .last(HelioConstant.CRUD.SQL_LIMIT_1)
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- if (existingEntity != null && !existingEntity.getId().equals(dto.getId())) {
|
|
|
|
|
- throw new BusinessException(400, "已存在相同客户跟进数据信息,请重新输入");
|
|
|
|
|
- }
|
|
|
|
|
- */
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void checkParam(AdminSysCustomerFollowInsertOrUpdateDTO dto) {
|
|
|
|
|
+
|
|
|
|
|
+ if (dto.getCustomerId() == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,客户不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getProductId() == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,产品不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getFollowId() == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,跟进状态不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getCustomerPersonId() == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,联系人不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getPositionId() == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,职务不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isEmpty(dto.getFollowContent())) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,跟进内容不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (dto.getOrderType() != null && dto.getOrderDatetime() == null) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,预约待办时间不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (dto.getOrderDatetime() != null && dto.getOrderDatetime().isBefore(LocalDateTime.now())) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,预约待办时间不能在当前时间之前");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (dto.getFollowId() == 33) {
|
|
|
|
|
+ if (dto.getOrderType() == null || dto.getOrderType() == 1) {
|
|
|
|
|
+ throw new RuntimeException("参数错误,方案演示时,预约待办类型不能为空或待办");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|