|
|
@@ -4,23 +4,32 @@ import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
|
import cc.uncarbon.framework.core.exception.BusinessException;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.jtzx.crm.module.sys.common.QueueCommon;
|
|
|
import com.jtzx.crm.module.sys.entity.*;
|
|
|
import com.jtzx.crm.module.sys.mapper.*;
|
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataInsertOrUpdateDTO;
|
|
|
import com.jtzx.crm.module.sys.model.request.TransferUserReqDTO;
|
|
|
import com.jtzx.crm.module.sys.model.response.SysCustomerDataBO;
|
|
|
import com.jtzx.crm.module.sys.model.response.TransferUserReqBO;
|
|
|
+import com.redismq.utils.RedisMQTemplate;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.time.Duration;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -43,6 +52,11 @@ public class SysCustomerDataService {
|
|
|
|
|
|
private final SysUserMapper sysUserMapper;
|
|
|
|
|
|
+ private final SysParamMapper sysParamMapper;
|
|
|
+
|
|
|
+ private final RedisMQTemplate redisMQTemplate;
|
|
|
+
|
|
|
+ private final RedisTemplate<String, Object> stringSetRedisTemplate;
|
|
|
|
|
|
/**
|
|
|
* 根据 ID 取详情
|
|
|
@@ -203,7 +217,33 @@ public class SysCustomerDataService {
|
|
|
* @param customerId
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void claimCustomer(Long customerId) {
|
|
|
+ public void claimCustomer(Long customerId) throws BusinessException {
|
|
|
+
|
|
|
+ SysParamEntity sysParamEntity =
|
|
|
+ sysParamMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<>(SysParamEntity.class)
|
|
|
+ );
|
|
|
+ if (sysParamEntity == null) {
|
|
|
+ throw new BusinessException(400, "参数配置未设置");
|
|
|
+ }
|
|
|
+ // 客户持有上限判断
|
|
|
+ if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
|
|
|
+ if (sysParamEntity.getHoldTopCount() != null && sysParamEntity.getHoldTopCount() > 0) {
|
|
|
+ long customerCount =
|
|
|
+ sysCustomerDataMapper.selectCount(
|
|
|
+ new LambdaQueryWrapper<>(SysCustomerDataEntity.class)
|
|
|
+ .select(
|
|
|
+ SysCustomerDataEntity::getId
|
|
|
+ )
|
|
|
+ .eq(SysCustomerDataEntity::getClaimUserId, UserContextHolder.getUserId())
|
|
|
+ );
|
|
|
+ if (customerCount > 0 && customerCount > sysParamEntity.getHoldTopCount()) {
|
|
|
+ throw new BusinessException(400, "认领数量已超过设定的持有数量上限,不能再进行认领操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(customerId);
|
|
|
if (sysCustomerDataEntity == null) {
|
|
|
throw new BusinessException(400, "客户不存在");
|
|
|
@@ -250,6 +290,21 @@ public class SysCustomerDataService {
|
|
|
.operDataType(0)
|
|
|
.build();
|
|
|
sysCustomerOperLogMapper.insert(logEntity);
|
|
|
+
|
|
|
+ //添加自动退回定时任务
|
|
|
+ if (sysParamEntity.getBackPublicDayCount() != null && sysParamEntity.getBackPublicDayCount() > 0) {
|
|
|
+ Integer backPublicDayCount = sysParamEntity.getBackPublicDayCount();//单位为 天
|
|
|
+ DateTime date = DateUtil.date();
|
|
|
+ //结束的时间
|
|
|
+ DateTime dateTime = DateUtil.offsetDay(date, backPublicDayCount);
|
|
|
+ //计算结束时间,单位 秒
|
|
|
+ long between = ChronoUnit.SECONDS.between(DateUtil.toLocalDateTime(date), DateUtil.toLocalDateTime(dateTime));
|
|
|
+ if (between > 0) {
|
|
|
+ // 将对象转换为 json 数据
|
|
|
+ String data = JSONUtil.toJsonStr(sysCustomerDataEntity);
|
|
|
+ redisMQTemplate.sendDelayMessage(data, QueueCommon.AUTO_RECORD_ORDER_DATA, Duration.ofSeconds(between));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -273,6 +328,37 @@ public class SysCustomerDataService {
|
|
|
throw new BusinessException(400, "认领人不正确,无权操作");
|
|
|
}
|
|
|
}
|
|
|
+ // 每日手动退回公海上限判断
|
|
|
+ if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
|
|
|
+ SysParamEntity sysParamEntity =
|
|
|
+ sysParamMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<>(SysParamEntity.class)
|
|
|
+ );
|
|
|
+ if (sysParamEntity == null) {
|
|
|
+ throw new BusinessException(400, "参数配置未设置");
|
|
|
+ }
|
|
|
+ if (sysParamEntity.getDayBackTopCount() != null && sysParamEntity.getDayBackTopCount() > 0) {
|
|
|
+ String key = "return_customer_data_" + sysCustomerDataEntity.getClaimUserId();
|
|
|
+ //先从redis中获取当日退回公海次数
|
|
|
+ Object count = stringSetRedisTemplate.opsForValue().get(key);
|
|
|
+ if (count == null) {
|
|
|
+ DateTime date = DateUtil.date();
|
|
|
+ DateTime dateTime = DateUtil.endOfDay(date);//当日的结束时间
|
|
|
+ //计算结束时间,单位 秒
|
|
|
+ long between = ChronoUnit.SECONDS.between(DateUtil.toLocalDateTime(date), DateUtil.toLocalDateTime(dateTime));
|
|
|
+ if (between > 0) {
|
|
|
+ stringSetRedisTemplate.opsForValue().set(key, 1, between, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ((Integer) count <= sysParamEntity.getDayBackTopCount()) {
|
|
|
+ stringSetRedisTemplate.opsForValue().increment(key);
|
|
|
+ }else {
|
|
|
+ throw new BusinessException(400, "操作失败,已超过每日手动退回公海上限");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
sysCustomerDataMapper.returnCustomerData(customerId);
|
|
|
//添加认领日志
|
|
|
SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
|