|
|
@@ -1,24 +1,27 @@
|
|
|
package com.jtzx.crm.module.sys.service;
|
|
|
|
|
|
+import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
|
import cc.uncarbon.framework.core.exception.BusinessException;
|
|
|
-import cc.uncarbon.framework.core.page.PageParam;
|
|
|
import cc.uncarbon.framework.core.page.PageResult;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.text.CharSequenceUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.jtzx.crm.module.sys.entity.SysCustomerPersonEntity;
|
|
|
-import com.jtzx.crm.module.sys.mapper.SysCustomerPersonMapper;
|
|
|
+import com.jtzx.crm.module.sys.entity.*;
|
|
|
+import com.jtzx.crm.module.sys.mapper.*;
|
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonInsertOrUpdateDTO;
|
|
|
-import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonListDTO;
|
|
|
import com.jtzx.crm.module.sys.model.response.SysCustomerPersonBO;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -31,36 +34,29 @@ public class SysCustomerPersonService {
|
|
|
|
|
|
private final SysCustomerPersonMapper sysCustomerPersonMapper;
|
|
|
|
|
|
+ private final SysCustomerDataMapper sysCustomerDataMapper;
|
|
|
+
|
|
|
+ private final SysUserGroupRelationMapper sysUserGroupRelationMapper;
|
|
|
+
|
|
|
+ private final SysCustomerOperLogMapper sysCustomerOperLogMapper;
|
|
|
+
|
|
|
+ private final SysCustomerFollowMapper sysCustomerFollowMapper;
|
|
|
|
|
|
/**
|
|
|
- * 后台管理-分页列表
|
|
|
+ * 后台管理-联系人列表
|
|
|
*/
|
|
|
- public PageResult<SysCustomerPersonBO> adminList(PageParam pageParam, AdminSysCustomerPersonListDTO dto) {
|
|
|
- Page<SysCustomerPersonEntity> entityPage = sysCustomerPersonMapper.selectPage(
|
|
|
- new Page<>(pageParam.getPageNum(), pageParam.getPageSize()),
|
|
|
+ public List<SysCustomerPersonBO> adminList(Long customerId, Long positionId,Long userId) {
|
|
|
+ List<SysCustomerPersonEntity> entityPage = sysCustomerPersonMapper.selectList(
|
|
|
new QueryWrapper<SysCustomerPersonEntity>()
|
|
|
.lambda()
|
|
|
// 客户表主id
|
|
|
- .eq(Objects.nonNull(dto.getCustomerId()), SysCustomerPersonEntity::getCustomerId, dto.getCustomerId())
|
|
|
- // 姓名
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getName()), SysCustomerPersonEntity::getName, CharSequenceUtil.cleanBlank(dto.getName()))
|
|
|
+ .eq(SysCustomerPersonEntity::getCustomerId, customerId)
|
|
|
+ //创建人过滤
|
|
|
+ .eq(userId!=null,SysCustomerPersonEntity::getCreatedBy,userId)
|
|
|
// 职务id(param_base_data表主id)
|
|
|
- .eq(Objects.nonNull(dto.getPositionId()), SysCustomerPersonEntity::getPositionId, dto.getPositionId())
|
|
|
- // 职务名称
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getPositionName()), SysCustomerPersonEntity::getPositionName, CharSequenceUtil.cleanBlank(dto.getPositionName()))
|
|
|
- // 手机号
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getPhoneNo()), SysCustomerPersonEntity::getPhoneNo, CharSequenceUtil.cleanBlank(dto.getPhoneNo()))
|
|
|
- // 办公电话
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getOfficePhoneNo()), SysCustomerPersonEntity::getOfficePhoneNo, CharSequenceUtil.cleanBlank(dto.getOfficePhoneNo()))
|
|
|
- // 备注
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getRemark()), SysCustomerPersonEntity::getRemark, CharSequenceUtil.cleanBlank(dto.getRemark()))
|
|
|
- // 时间区间
|
|
|
- .between(Objects.nonNull(dto.getBeginAt()) && Objects.nonNull(dto.getEndAt()), SysCustomerPersonEntity::getCreatedAt, dto.getBeginAt(), dto.getEndAt())
|
|
|
- // 排序
|
|
|
- .orderByDesc(SysCustomerPersonEntity::getCreatedAt)
|
|
|
+ .eq(positionId != null, SysCustomerPersonEntity::getPositionId, positionId)
|
|
|
);
|
|
|
-
|
|
|
- return this.entityPage2BOPage(entityPage);
|
|
|
+ return this.entityList2BOs(entityPage);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -84,12 +80,32 @@ public class SysCustomerPersonService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Long adminInsert(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
|
|
|
log.info("[后台管理-客户(学校)联系人数据-新增] >> DTO={}", dto);
|
|
|
+ SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(dto.getCustomerId());
|
|
|
+ if (sysCustomerDataEntity == null) {
|
|
|
+ throw new BusinessException(400, "客户不存在");
|
|
|
+ }
|
|
|
dto.setId(null);
|
|
|
SysCustomerPersonEntity entity = new SysCustomerPersonEntity();
|
|
|
BeanUtil.copyProperties(dto, entity);
|
|
|
|
|
|
sysCustomerPersonMapper.insert(entity);
|
|
|
|
|
|
+ //新增联系人日志
|
|
|
+ SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
|
+ .customerId(entity.getId())
|
|
|
+ .customerName(entity.getName())
|
|
|
+ .operUserId(UserContextHolder.getUserId())
|
|
|
+ .operName(UserContextHolder.getUserName())
|
|
|
+ .operAction(11)
|
|
|
+ .operDatetime(LocalDateTime.now())
|
|
|
+ .provinceId(sysCustomerDataEntity.getProvinceId())
|
|
|
+ .provinceName(sysCustomerDataEntity.getProvinceName())
|
|
|
+ .cityId(sysCustomerDataEntity.getCityId())
|
|
|
+ .cityName(sysCustomerDataEntity.getCityName())
|
|
|
+ .content(dto.getStr())
|
|
|
+ .build();
|
|
|
+ sysCustomerOperLogMapper.insert(logEntity);
|
|
|
+
|
|
|
return entity.getId();
|
|
|
}
|
|
|
|
|
|
@@ -99,20 +115,92 @@ public class SysCustomerPersonService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void adminUpdate(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
|
|
|
log.info("[后台管理-客户(学校)联系人数据-编辑] >> DTO={}", dto);
|
|
|
+ SysCustomerDataEntity entity = sysCustomerDataMapper.selectById(dto.getId());
|
|
|
+ if (entity == null) {
|
|
|
+ throw new BusinessException(400, "无效客户(学校)数据ID");
|
|
|
+ }
|
|
|
+ //查询用户的小组数据
|
|
|
+ SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<SysUserGroupRelationEntity>()
|
|
|
+ .select(
|
|
|
+ SysUserGroupRelationEntity::getId,
|
|
|
+ SysUserGroupRelationEntity::getGroupId
|
|
|
+ )
|
|
|
+ .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
|
|
|
+ .eq(SysUserGroupRelationEntity::getProvinceId, entity.getProvinceId())
|
|
|
+ .eq(SysUserGroupRelationEntity::getCityId, entity.getCityId())
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ SysCustomerPersonEntity sysCustomerPersonEntity = sysCustomerPersonMapper.selectById(dto.getId());
|
|
|
+ BeanUtil.copyProperties(dto, sysCustomerPersonEntity);
|
|
|
+ sysCustomerPersonEntity.setId(null);
|
|
|
+ sysCustomerPersonMapper.updateById(sysCustomerPersonEntity);
|
|
|
|
|
|
- SysCustomerPersonEntity entity = new SysCustomerPersonEntity();
|
|
|
- BeanUtil.copyProperties(dto, entity);
|
|
|
-
|
|
|
- sysCustomerPersonMapper.updateById(entity);
|
|
|
+ SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
|
+ .customerId(entity.getId())
|
|
|
+ .customerName(entity.getName())
|
|
|
+ .operUserId(UserContextHolder.getUserId())
|
|
|
+ .operName(UserContextHolder.getUserName())
|
|
|
+ .operAction(12)
|
|
|
+ .operDatetime(LocalDateTime.now())
|
|
|
+ .provinceId(entity.getProvinceId())
|
|
|
+ .provinceName(entity.getProvinceName())
|
|
|
+ .cityId(entity.getCityId())
|
|
|
+ .cityName(entity.getCityName())
|
|
|
+ .content(sysCustomerPersonEntity.compareTo(dto))
|
|
|
+ .build();
|
|
|
+ if (userGroupRelation != null) {
|
|
|
+ logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
|
|
|
+ }
|
|
|
+ sysCustomerOperLogMapper.insert(logEntity);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 后台管理-删除
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void adminDelete(Collection<Long> ids) {
|
|
|
- log.info("[后台管理-客户(学校)联系人数据-删除] >> ids={}", ids);
|
|
|
- sysCustomerPersonMapper.deleteByIds(ids);
|
|
|
+ public void adminDelete(Long id) {
|
|
|
+ log.info("[后台管理-客户(学校)联系人数据-删除] >> id={}", id);
|
|
|
+ SysCustomerPersonEntity sysCustomerPersonEntity = sysCustomerPersonMapper.selectById(id);
|
|
|
+ if (sysCustomerPersonEntity == null) {
|
|
|
+ throw new BusinessException(400, "联系人不存在");
|
|
|
+ }
|
|
|
+ SysCustomerDataEntity entity = sysCustomerDataMapper.selectById(sysCustomerPersonEntity.getCustomerId());
|
|
|
+ if (entity == null) {
|
|
|
+ throw new BusinessException(400, "无效客户(学校)数据ID");
|
|
|
+ }
|
|
|
+ //查询用户的小组数据
|
|
|
+ SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<SysUserGroupRelationEntity>()
|
|
|
+ .select(
|
|
|
+ SysUserGroupRelationEntity::getId,
|
|
|
+ SysUserGroupRelationEntity::getGroupId
|
|
|
+ )
|
|
|
+ .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
|
|
|
+ .eq(SysUserGroupRelationEntity::getProvinceId, entity.getProvinceId())
|
|
|
+ .eq(SysUserGroupRelationEntity::getCityId, entity.getCityId())
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
|
+ .customerId(entity.getId())
|
|
|
+ .customerName(entity.getName())
|
|
|
+ .operUserId(UserContextHolder.getUserId())
|
|
|
+ .operName(UserContextHolder.getUserName())
|
|
|
+ .operAction(13)
|
|
|
+ .operDatetime(LocalDateTime.now())
|
|
|
+ .provinceId(entity.getProvinceId())
|
|
|
+ .provinceName(entity.getProvinceName())
|
|
|
+ .cityId(entity.getCityId())
|
|
|
+ .cityName(entity.getCityName())
|
|
|
+ .content(sysCustomerPersonEntity.getStr())
|
|
|
+ .build();
|
|
|
+ if (userGroupRelation != null) {
|
|
|
+ logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
|
|
|
+ }
|
|
|
+ sysCustomerOperLogMapper.insert(logEntity);
|
|
|
+
|
|
|
+
|
|
|
+ sysCustomerPersonMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -152,12 +240,37 @@ public class SysCustomerPersonService {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
+ //查询上次跟进
|
|
|
+ List<SysCustomerFollowEntity> lastFollowEntityList =
|
|
|
+ sysCustomerFollowMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)
|
|
|
+ .select(
|
|
|
+ SysCustomerFollowEntity::getCustomerId,
|
|
|
+ SysCustomerFollowEntity::getPositionId,
|
|
|
+ SysCustomerFollowEntity::getCreatedAt
|
|
|
+ )
|
|
|
+ .eq(SysCustomerFollowEntity::getCustomerId, entityList.getFirst().getCustomerId())
|
|
|
+ .in(SysCustomerFollowEntity::getPositionId, entityList.stream().map(SysCustomerPersonEntity::getPositionId).distinct().toList())
|
|
|
+ .orderByDesc(SysCustomerFollowEntity::getCreatedAt)
|
|
|
+ );
|
|
|
+
|
|
|
// 深拷贝
|
|
|
List<SysCustomerPersonBO> ret = new ArrayList<>(entityList.size());
|
|
|
entityList.forEach(
|
|
|
- entity -> ret.add(this.entity2BO(entity))
|
|
|
- );
|
|
|
-
|
|
|
+ entity -> {
|
|
|
+ SysCustomerPersonBO bo = this.entity2BO(entity);
|
|
|
+ if(CollUtil.isNotEmpty(lastFollowEntityList)){
|
|
|
+ List<SysCustomerFollowEntity> list = lastFollowEntityList.stream()
|
|
|
+ .filter(lastFollowEntity -> lastFollowEntity.getPositionId().equals(entity.getPositionId()))
|
|
|
+ .sorted(Comparator.comparing(SysCustomerFollowEntity::getCreatedAt).reversed())
|
|
|
+ .toList();
|
|
|
+ if(CollUtil.isNotEmpty(list)){
|
|
|
+ bo.setLastFollowDate(
|
|
|
+ list.getFirst().getCreatedAt());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ret.add(bo);
|
|
|
+ });
|
|
|
return ret;
|
|
|
}
|
|
|
|