Forráskód Böngészése

每日9点和四点发送物流消息,状态未变更发送消息

yh 3 hete
szülő
commit
1d27213a61

+ 20 - 4
fs-service/src/main/java/com/fs/erp/service/impl/DfOrderServiceImpl.java

@@ -1276,9 +1276,27 @@ public class DfOrderServiceImpl implements IErpOrderService {
                 orderId, order.getDeliveryType(), stateEx, isStateChanged);
 
 
-        // 状态变化了不发,状态未变更才发
-        if(isStateChanged){
+        // 4. 检查Redis中是否今天已经发送过
+        String todayDate = cn.hutool.core.date.DateUtil.today();
+        String todayRedisKey = "ai:express:sent:" + orderId + ":" + todayDate;
+
+        Object sentValue = redisCache.getCacheObject(todayRedisKey);
+
+        log.info("Redis发送检查 - orderId: {}, todayDate: {}, todayRedisKey: {}, 今天是否已发送: {}",
+                orderId, todayDate, todayRedisKey, sentValue != null);
+
+        // 5. 判断发送逻辑
+        if (isStateChanged) {
+            // 状态变化了,不发送
             return;
+        } else {
+            // 状态没有变化,检查今天是否已发送过发货信息
+            if (sentValue != null && ("0".equals(stateEx) || "1".equals(stateEx) || "2".equals(stateEx))) {
+                log.info("物流状态未变化且今天已发送过,跳过AI消息发送 - orderId: {}", orderId);
+                return;
+            } else {
+                log.info("物流状态未变化但今天未发送过,执行AI消息发送逻辑 - orderId: {}", orderId);
+            }
         }
 
         //判断是否添加相关企微员工
@@ -1412,8 +1430,6 @@ public class DfOrderServiceImpl implements IErpOrderService {
                                         cn.hutool.core.date.DateTime endOfToday = cn.hutool.core.date.DateUtil.endOfDay(cn.hutool.core.date.DateUtil.date());
                                         long secondsUntilTomorrow = (endOfToday.getTime() - System.currentTimeMillis()) / 1000 + 7200; // 加2小时缓冲
 
-                                        String todayDate = cn.hutool.core.date.DateUtil.today();
-                                        String todayRedisKey = "ai:express:sent:" + orderId + ":" + todayDate;
                                         redisCache.setCacheObject(todayRedisKey, "1", (int) secondsUntilTomorrow, java.util.concurrent.TimeUnit.SECONDS);
                                         log.info("设置今天Redis发送标识 - orderId: {}, todayRedisKey: {}, 过期时间(秒): {}", orderId, todayRedisKey, secondsUntilTomorrow);