Ver código fonte

feat(sop): 增加营期最大天数限制以防止无限循环发送

- 在计算间隔天数前获取模板中的最大天数配置
- 当当前天数超出模板最大天数时跳过处理逻辑
- 更新跨天逻辑,确保不会超过设定的最大天数范围
- 添加相关日志记录以便追踪营期结束情况
xw 1 semana atrás
pai
commit
d27487f0c6

+ 21 - 1
fs-qw-task/src/main/java/com/fs/app/taskService/impl/SopLogsTaskServiceImpl.java

@@ -463,6 +463,13 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
                 return;
             }
 
+            // 获取模板中配置的最大天数,防止超出范围后循环发送
+            Integer maxDayNum = tempSettings.stream()
+                    .map(QwSopTempRules::getDayNum)
+                    .filter(Objects::nonNull)
+                    .max(Integer::compareTo)
+                    .orElse(0);
+            
             int intervalDay = (int) (daysBetween / tempGap);
             if (intervalDay < 0 || intervalDay >= tempSettings.size()) {
                 log.info("用户日志 {} 的 intervalDay {} 超出 TempSettings 范围,跳过处理。", logVo.getId(), intervalDay);
@@ -474,6 +481,13 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
             }else{
                 day++;
             }
+            
+            // 如果当前天数超过模板配置的最大天数,则跳过处理
+            if (day > maxDayNum) {
+                log.info("用户日志 {} 的 day {} 超出模板最大天数 {},营期已结束,跳过处理。", logVo.getId(), day, maxDayNum);
+                return;
+            }
+            
             List<QwSopTempSetting.Content> contents = getDay(tempSettings, day);
             if (contents == null || contents.isEmpty()) {
                 log.error("SOP ID {} 的 TempSetting 内容为空,跳过处理。天数 {}", logVo.getSopId(),day);
@@ -541,7 +555,13 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
 //                    return;
 //                }
 
-                // 重新拿新的 “天” 的 Setting
+                // 如果跨天后的天数超过模板配置的最大天数,则跳过处理
+                if (day > maxDayNum) {
+                    log.info("跨天后,用户日志 {} 的 day {} 超出模板最大天数 {},营期已结束,跳过处理。", logVo.getId(), day, maxDayNum);
+                    return;
+                }
+
+                // 重新拿新的 "天" 的 Setting
                 contents = getDay(tempSettings, day);
                 if (contents == null || contents.isEmpty()) {
                     log.error("跨天-SOP ID {} 的 TempSetting 内容为空,跳过处理。", logVo.getSopId());