|
@@ -3,12 +3,14 @@ package com.jtzx.crm.module.sys.service;
|
|
|
import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
|
import cc.uncarbon.framework.core.exception.BusinessException;
|
|
import cc.uncarbon.framework.core.exception.BusinessException;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
-
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.jtzx.crm.module.sys.entity.SysCustomerDataEntity;
|
|
import com.jtzx.crm.module.sys.entity.SysCustomerDataEntity;
|
|
|
|
|
+import com.jtzx.crm.module.sys.entity.SysCustomerFollowEntity;
|
|
|
import com.jtzx.crm.module.sys.entity.SysCustomerOperLogEntity;
|
|
import com.jtzx.crm.module.sys.entity.SysCustomerOperLogEntity;
|
|
|
import com.jtzx.crm.module.sys.entity.SysUserGroupRelationEntity;
|
|
import com.jtzx.crm.module.sys.entity.SysUserGroupRelationEntity;
|
|
|
import com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper;
|
|
import com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper;
|
|
|
|
|
+import com.jtzx.crm.module.sys.mapper.SysCustomerFollowMapper;
|
|
|
import com.jtzx.crm.module.sys.mapper.SysCustomerOperLogMapper;
|
|
import com.jtzx.crm.module.sys.mapper.SysCustomerOperLogMapper;
|
|
|
import com.jtzx.crm.module.sys.mapper.SysUserGroupRelationMapper;
|
|
import com.jtzx.crm.module.sys.mapper.SysUserGroupRelationMapper;
|
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataInsertOrUpdateDTO;
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataInsertOrUpdateDTO;
|
|
@@ -19,7 +21,6 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Collection;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -36,6 +37,8 @@ public class SysCustomerDataService {
|
|
|
|
|
|
|
|
private final SysUserGroupRelationMapper sysUserGroupRelationMapper;
|
|
private final SysUserGroupRelationMapper sysUserGroupRelationMapper;
|
|
|
|
|
|
|
|
|
|
+ private final SysCustomerFollowMapper sysCustomerFollowMapper;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据 ID 取详情
|
|
* 根据 ID 取详情
|
|
@@ -57,6 +60,7 @@ public class SysCustomerDataService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Long adminInsert(AdminSysCustomerDataInsertOrUpdateDTO dto) {
|
|
public Long adminInsert(AdminSysCustomerDataInsertOrUpdateDTO dto) {
|
|
|
log.info("[后台管理-客户(学校)数据-新增] >> DTO={}", dto);
|
|
log.info("[后台管理-客户(学校)数据-新增] >> DTO={}", dto);
|
|
|
|
|
+
|
|
|
dto.setId(null);
|
|
dto.setId(null);
|
|
|
SysCustomerDataEntity entity = new SysCustomerDataEntity();
|
|
SysCustomerDataEntity entity = new SysCustomerDataEntity();
|
|
|
BeanUtil.copyProperties(dto, entity);
|
|
BeanUtil.copyProperties(dto, entity);
|
|
@@ -64,20 +68,7 @@ public class SysCustomerDataService {
|
|
|
entity.setClaimStatus(0);
|
|
entity.setClaimStatus(0);
|
|
|
entity.setSuccessStatus(0);
|
|
entity.setSuccessStatus(0);
|
|
|
sysCustomerDataMapper.insert(entity);
|
|
sysCustomerDataMapper.insert(entity);
|
|
|
-
|
|
|
|
|
- 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())
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
//添加操作日志
|
|
//添加操作日志
|
|
|
- String operData = dto.getStr();
|
|
|
|
|
SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
|
.customerId(entity.getId())
|
|
.customerId(entity.getId())
|
|
|
.customerName(entity.getName())
|
|
.customerName(entity.getName())
|
|
@@ -89,11 +80,8 @@ public class SysCustomerDataService {
|
|
|
.provinceName(entity.getProvinceName())
|
|
.provinceName(entity.getProvinceName())
|
|
|
.cityId(entity.getCityId())
|
|
.cityId(entity.getCityId())
|
|
|
.cityName(entity.getCityName())
|
|
.cityName(entity.getCityName())
|
|
|
- .content(operData)
|
|
|
|
|
|
|
+ .content(dto.getStr())
|
|
|
.build();
|
|
.build();
|
|
|
- if (userGroupRelation != null) {
|
|
|
|
|
- logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
|
|
|
|
|
- }
|
|
|
|
|
sysCustomerOperLogMapper.insert(logEntity);
|
|
sysCustomerOperLogMapper.insert(logEntity);
|
|
|
return entity.getId();
|
|
return entity.getId();
|
|
|
}
|
|
}
|
|
@@ -108,11 +96,7 @@ public class SysCustomerDataService {
|
|
|
if (entity == null) {
|
|
if (entity == null) {
|
|
|
throw new BusinessException(400, "无效客户(学校)数据ID");
|
|
throw new BusinessException(400, "无效客户(学校)数据ID");
|
|
|
}
|
|
}
|
|
|
- String compareTo = entity.compareTo(dto);
|
|
|
|
|
- BeanUtil.copyProperties(dto, entity);
|
|
|
|
|
- sysCustomerDataMapper.updateById(entity);
|
|
|
|
|
-
|
|
|
|
|
- //添加操作日志
|
|
|
|
|
|
|
+ //查询用户的小组信息
|
|
|
SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
|
|
SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
|
|
|
new LambdaQueryWrapper<SysUserGroupRelationEntity>()
|
|
new LambdaQueryWrapper<SysUserGroupRelationEntity>()
|
|
|
.select(
|
|
.select(
|
|
@@ -120,9 +104,13 @@ public class SysCustomerDataService {
|
|
|
SysUserGroupRelationEntity::getGroupId
|
|
SysUserGroupRelationEntity::getGroupId
|
|
|
)
|
|
)
|
|
|
.eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
|
|
.eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
|
|
|
- .eq(SysUserGroupRelationEntity::getProvinceId, entity.getProvinceId())
|
|
|
|
|
- .eq(SysUserGroupRelationEntity::getCityId, entity.getCityId())
|
|
|
|
|
|
|
+ .eq(SysUserGroupRelationEntity::getProvinceId, dto.getProvinceId())
|
|
|
|
|
+ .eq(SysUserGroupRelationEntity::getCityId, dto.getCityId())
|
|
|
|
|
+ .last("limit 1")
|
|
|
);
|
|
);
|
|
|
|
|
+ BeanUtil.copyProperties(dto, entity);
|
|
|
|
|
+ sysCustomerDataMapper.updateById(entity);
|
|
|
|
|
+
|
|
|
SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
|
.customerId(entity.getId())
|
|
.customerId(entity.getId())
|
|
|
.customerName(entity.getName())
|
|
.customerName(entity.getName())
|
|
@@ -134,7 +122,7 @@ public class SysCustomerDataService {
|
|
|
.provinceName(entity.getProvinceName())
|
|
.provinceName(entity.getProvinceName())
|
|
|
.cityId(entity.getCityId())
|
|
.cityId(entity.getCityId())
|
|
|
.cityName(entity.getCityName())
|
|
.cityName(entity.getCityName())
|
|
|
- .content(compareTo)
|
|
|
|
|
|
|
+ .content(entity.compareTo(dto))
|
|
|
.build();
|
|
.build();
|
|
|
if (userGroupRelation != null) {
|
|
if (userGroupRelation != null) {
|
|
|
logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
|
|
logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
|
|
@@ -150,18 +138,18 @@ public class SysCustomerDataService {
|
|
|
log.info("[后台管理-客户(学校)数据-删除] >> id={}", id);
|
|
log.info("[后台管理-客户(学校)数据-删除] >> id={}", id);
|
|
|
SysCustomerDataEntity entity = sysCustomerDataMapper.selectById(id);
|
|
SysCustomerDataEntity entity = sysCustomerDataMapper.selectById(id);
|
|
|
if (entity != null) {
|
|
if (entity != null) {
|
|
|
- sysCustomerDataMapper.deleteById(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())
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ //查询有没有跟进,有跟进就不能删
|
|
|
|
|
+ long count =
|
|
|
|
|
+ sysCustomerFollowMapper.selectCount(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysCustomerFollowEntity::getCustomerId
|
|
|
|
|
+ )
|
|
|
|
|
+ .eq(SysCustomerFollowEntity::getCustomerId, entity.getId())
|
|
|
|
|
+ );
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ throw new BusinessException(400, "不能删除");
|
|
|
|
|
+ }
|
|
|
SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
|
.customerId(entity.getId())
|
|
.customerId(entity.getId())
|
|
|
.customerName(entity.getName())
|
|
.customerName(entity.getName())
|
|
@@ -175,13 +163,102 @@ public class SysCustomerDataService {
|
|
|
.cityName(entity.getCityName())
|
|
.cityName(entity.getCityName())
|
|
|
.content(entity.getStr())
|
|
.content(entity.getStr())
|
|
|
.build();
|
|
.build();
|
|
|
- if (userGroupRelation != null) {
|
|
|
|
|
- logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
|
|
|
|
|
- }
|
|
|
|
|
sysCustomerOperLogMapper.insert(logEntity);
|
|
sysCustomerOperLogMapper.insert(logEntity);
|
|
|
|
|
+ sysCustomerDataMapper.deleteById(id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 认领操作
|
|
|
|
|
+ * @param customerId
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void claimCustomer(Long customerId) {
|
|
|
|
|
+ SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(customerId);
|
|
|
|
|
+ if (sysCustomerDataEntity == null) {
|
|
|
|
|
+ throw new BusinessException(400, "客户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ //查询用户的小组信息
|
|
|
|
|
+ SysUserGroupRelationEntity userGroupRelation = sysUserGroupRelationMapper.selectOne(
|
|
|
|
|
+ new LambdaQueryWrapper<SysUserGroupRelationEntity>()
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysUserGroupRelationEntity::getId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getGroupId
|
|
|
|
|
+ )
|
|
|
|
|
+ .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
|
|
|
|
|
+ .eq(SysUserGroupRelationEntity::getProvinceId, sysCustomerDataEntity.getProvinceId())
|
|
|
|
|
+ .eq(SysUserGroupRelationEntity::getCityId, sysCustomerDataEntity.getCityId())
|
|
|
|
|
+ .last("limit 1")
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")) {
|
|
|
|
|
+ if (userGroupRelation == null) {
|
|
|
|
|
+ throw new BusinessException(400, "无权操作");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ sysCustomerDataEntity.setClaimUserId(UserContextHolder.getUserId());
|
|
|
|
|
+ sysCustomerDataEntity.setClaimUserName(UserContextHolder.getUserName());
|
|
|
|
|
+ sysCustomerDataEntity.setClaimStatus(1);
|
|
|
|
|
+ sysCustomerDataEntity.setClaimDatetime(LocalDateTime.now());
|
|
|
|
|
+ if (userGroupRelation != null) {
|
|
|
|
|
+ sysCustomerDataEntity.setClaimUserGroupId(userGroupRelation.getGroupId());
|
|
|
|
|
+ }
|
|
|
|
|
+ sysCustomerDataMapper.updateById(sysCustomerDataEntity);
|
|
|
|
|
+ //添加认领日志
|
|
|
|
|
+ SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
|
|
|
+ .customerId(sysCustomerDataEntity.getId())
|
|
|
|
|
+ .customerName(sysCustomerDataEntity.getName())
|
|
|
|
|
+ .operUserId(UserContextHolder.getUserId())
|
|
|
|
|
+ .operName(UserContextHolder.getUserName())
|
|
|
|
|
+ .operAction(0)
|
|
|
|
|
+ .operDatetime(LocalDateTime.now())
|
|
|
|
|
+ .provinceId(sysCustomerDataEntity.getProvinceId())
|
|
|
|
|
+ .provinceName(sysCustomerDataEntity.getProvinceName())
|
|
|
|
|
+ .cityId(sysCustomerDataEntity.getCityId())
|
|
|
|
|
+ .cityName(sysCustomerDataEntity.getCityName())
|
|
|
|
|
+ .content(sysCustomerDataEntity.getCustomString())
|
|
|
|
|
+ .operUserGroupId(sysCustomerDataEntity.getClaimUserGroupId())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ sysCustomerOperLogMapper.insert(logEntity);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 客户退回公海
|
|
|
|
|
+ * @param customerId
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void returnCustomerData(Long customerId) {
|
|
|
|
|
+ //先查询有没有赢单
|
|
|
|
|
+ SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(customerId);
|
|
|
|
|
+ if (sysCustomerDataEntity == null) {
|
|
|
|
|
+ throw new BusinessException(400,"客户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(sysCustomerDataEntity.getSuccessStatus()==1){
|
|
|
|
|
+ throw new BusinessException(400,"客户已赢单,不能退回公海");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("admin")){
|
|
|
|
|
+ if(!sysCustomerDataEntity.getClaimUserId().equals(UserContextHolder.getUserId())){
|
|
|
|
|
+ throw new BusinessException(400,"认领人不正确,无权操作");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ sysCustomerDataMapper.returnCustomerData(customerId);
|
|
|
|
|
+ //添加认领日志
|
|
|
|
|
+ SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|
|
|
|
|
+ .customerId(sysCustomerDataEntity.getId())
|
|
|
|
|
+ .customerName(sysCustomerDataEntity.getName())
|
|
|
|
|
+ .operUserId(UserContextHolder.getUserId())
|
|
|
|
|
+ .operName(UserContextHolder.getUserName())
|
|
|
|
|
+ .operAction(3)
|
|
|
|
|
+ .operDatetime(LocalDateTime.now())
|
|
|
|
|
+ .provinceId(sysCustomerDataEntity.getProvinceId())
|
|
|
|
|
+ .provinceName(sysCustomerDataEntity.getProvinceName())
|
|
|
|
|
+ .cityId(sysCustomerDataEntity.getCityId())
|
|
|
|
|
+ .cityName(sysCustomerDataEntity.getCityName())
|
|
|
|
|
+ .content(sysCustomerDataEntity.returnCustomString())
|
|
|
|
|
+ .operUserGroupId(sysCustomerDataEntity.getClaimUserGroupId())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ sysCustomerOperLogMapper.insert(logEntity);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
----------------------------------------------------------------
|
|
----------------------------------------------------------------
|