瀏覽代碼

refactor(sys): 优化客户认领逻辑,移除参数配置依赖

- 注释删除了SysParamMapper及相关查询,改为使用SysUserEntity中的配置参数
- 增加用户存在性校验,避免用户不存在时继续操作
- 使用当前用户的持有上限替代原参数持有上限判断
- 使用当前用户的退回天数参数替换原参数配置
- 优化每日手动退回公海次数限制,使用用户相关配置替代全局参数
- 统一异常提示,提升错误信息准确性和用户体验
zhangxf 3 周之前
父節點
當前提交
d4400701c1
共有 1 個文件被更改,包括 29 次插入 和 23 次删除
  1. 29 23
      src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataService.java

+ 29 - 23
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataService.java

@@ -52,8 +52,6 @@ public class SysCustomerDataService {
 
     private final SysUserMapper sysUserMapper;
 
-    private final SysParamMapper sysParamMapper;
-
     private final RedisMQTemplate redisMQTemplate;
 
     private final RedisTemplate<String, Object> stringSetRedisTemplate;
@@ -219,16 +217,20 @@ public class SysCustomerDataService {
     @Transactional(rollbackFor = Exception.class)
     public void claimCustomer(Long customerId) throws BusinessException {
 
-        SysParamEntity sysParamEntity =
-                sysParamMapper.selectOne(
-                        new LambdaQueryWrapper<>(SysParamEntity.class)
-                );
-        if (sysParamEntity == null) {
-            throw new BusinessException(400, "参数配置未设置");
+//        SysParamEntity sysParamEntity =
+//                sysParamMapper.selectOne(
+//                        new LambdaQueryWrapper<>(SysParamEntity.class)
+//                );
+//        if (sysParamEntity == null) {
+//            throw new BusinessException(400, "参数配置未设置");
+//        }
+        SysUserEntity sysUserEntity = sysUserMapper.selectById(UserContextHolder.getUserId());
+        if (sysUserEntity == null) {
+            throw new BusinessException(400, "用户不存在");
         }
         // 客户持有上限判断
-        if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
-            if (sysParamEntity.getHoldTopCount() != null && sysParamEntity.getHoldTopCount() > 0) {
+        if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+            if (sysUserEntity.getHoldTopCount() != null && sysUserEntity.getHoldTopCount() > 0) {
                 long customerCount =
                         sysCustomerDataMapper.selectCount(
                                 new LambdaQueryWrapper<>(SysCustomerDataEntity.class)
@@ -237,7 +239,7 @@ public class SysCustomerDataService {
                                         )
                                         .eq(SysCustomerDataEntity::getClaimUserId, UserContextHolder.getUserId())
                         );
-                if (customerCount > 0 && customerCount > sysParamEntity.getHoldTopCount()) {
+                if (customerCount > 0 && customerCount > sysUserEntity.getHoldTopCount()) {
                     throw new BusinessException(400, "认领数量已超过设定的持有数量上限,不能再进行认领操作");
                 }
             }
@@ -292,8 +294,8 @@ public class SysCustomerDataService {
         sysCustomerOperLogMapper.insert(logEntity);
 
         //添加自动退回定时任务
-        if (sysParamEntity.getBackPublicDayCount() != null && sysParamEntity.getBackPublicDayCount() > 0) {
-            Integer backPublicDayCount = sysParamEntity.getBackPublicDayCount();//单位为 天
+        if (sysUserEntity.getBackPublicDayCount() != null && sysUserEntity.getBackPublicDayCount() > 0) {
+            Integer backPublicDayCount = sysUserEntity.getBackPublicDayCount();//单位为 天
             DateTime date = DateUtil.date();
             //结束的时间
             DateTime dateTime = DateUtil.offsetDay(date, backPublicDayCount);
@@ -329,15 +331,19 @@ public class SysCustomerDataService {
             }
         }
         // 每日手动退回公海上限判断
-        if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
-            SysParamEntity sysParamEntity =
-                    sysParamMapper.selectOne(
-                            new LambdaQueryWrapper<>(SysParamEntity.class)
-                    );
-            if (sysParamEntity == null) {
-                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, "参数配置未设置");
+//            }
+            SysUserEntity sysUserEntity = sysUserMapper.selectById(UserContextHolder.getUserId());
+            if (sysUserEntity == null) {
+                throw new BusinessException(400, "用户不存在");
             }
-            if (sysParamEntity.getDayBackTopCount() != null && sysParamEntity.getDayBackTopCount() > 0) {
+            if (sysUserEntity.getDayBackTopCount() != null && sysUserEntity.getDayBackTopCount() > 0) {
                 String key = "return_customer_data_" + sysCustomerDataEntity.getClaimUserId();
                 //先从redis中获取当日退回公海次数
                 Object count = stringSetRedisTemplate.opsForValue().get(key);
@@ -350,9 +356,9 @@ public class SysCustomerDataService {
                         stringSetRedisTemplate.opsForValue().set(key, 1, between, TimeUnit.SECONDS);
                     }
                 } else {
-                    if ((Integer) count <= sysParamEntity.getDayBackTopCount()) {
+                    if ((Integer) count <= sysUserEntity.getDayBackTopCount()) {
                         stringSetRedisTemplate.opsForValue().increment(key);
-                    }else {
+                    } else {
                         throw new BusinessException(400, "操作失败,已超过每日手动退回公海上限");
                     }
                 }