From cc9439b33e3f8ec9ba3e274bc3b392d3cef20ae6 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 01 四月 2026 14:47:13 +0800
Subject: [PATCH] #入库任务路径计算增加cache

---
 src/main/java/com/zy/common/service/CommonService.java |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 59 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/zy/common/service/CommonService.java b/src/main/java/com/zy/common/service/CommonService.java
index 578a1a4..08395d7 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -31,7 +31,7 @@
 @Service
 public class CommonService {
 
-    private static final long OUT_STATION_ROUTE_CACHE_SECONDS = 300L;
+    private static final long OUT_STATION_ROUTE_CACHE_SECONDS = 60 * 60 * 24 * 30;
 
     @Autowired
     private WrkMastService wrkMastService;
@@ -656,12 +656,18 @@
             stationList = basDualCrnp.getInStationList$();
         }
 
+        Integer cachedTargetStationId = resolveCachedInStationId(findCrnNoResult, sourceStationId, stationList);
+        if (cachedTargetStationId != null) {
+            return cachedTargetStationId;
+        }
+
         Integer targetStationId = null;
         for (StationObjModel stationObjModel : stationList) {
             try {
                 List<NavigateNode> navigateNodes = navigateUtils.calcReachablePathByStationId(sourceStationId, stationObjModel.getStationId());
                 if(!navigateNodes.isEmpty()) {
                     targetStationId = stationObjModel.getStationId();
+                    cacheInStationId(findCrnNoResult, sourceStationId, targetStationId);
                     break;
                 }
             } catch (Exception e) {
@@ -710,6 +716,58 @@
     }
 
     /**
+     * 鍏ュ簱璺緞鎼滅储鍚屾牱浠d环杈冮珮锛屽彧缂撳瓨宸茬‘璁ゅ彲杈剧殑鐩爣绔欑偣缁撴灉锛屽苟閫氳繃 TTL 闄愬埗闄堟棫椋庨櫓銆�
+     */
+    private Integer resolveCachedInStationId(FindCrnNoResult findCrnNoResult,
+                                             Integer sourceStationId,
+                                             List<StationObjModel> stationList) {
+        if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
+                || findCrnNoResult.getCrnNo() == null || sourceStationId == null
+                || stationList == null || stationList.isEmpty()) {
+            return null;
+        }
+
+        Object cacheValue = redisUtil.get(buildInStationRouteCacheKey(findCrnNoResult, sourceStationId));
+        if (cacheValue == null) {
+            return null;
+        }
+
+        Integer cachedStationId = parseInteger(cacheValue);
+        if (cachedStationId == null) {
+            return null;
+        }
+
+        for (StationObjModel stationObjModel : stationList) {
+            if (stationObjModel != null && cachedStationId.equals(stationObjModel.getStationId())) {
+                return cachedStationId;
+            }
+        }
+        return null;
+    }
+
+    private void cacheInStationId(FindCrnNoResult findCrnNoResult,
+                                  Integer sourceStationId,
+                                  Integer targetStationId) {
+        if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
+                || findCrnNoResult.getCrnNo() == null || sourceStationId == null
+                || targetStationId == null) {
+            return;
+        }
+        redisUtil.set(buildInStationRouteCacheKey(findCrnNoResult, sourceStationId),
+                targetStationId,
+                OUT_STATION_ROUTE_CACHE_SECONDS);
+    }
+
+    private String buildInStationRouteCacheKey(FindCrnNoResult findCrnNoResult, Integer sourceStationId) {
+        return RedisKeyType.IN_STATION_ROUTE_CACHE.key
+                + findCrnNoResult.getCrnType().name()
+                + "_"
+                + findCrnNoResult.getCrnNo()
+                + "_"
+                + sourceStationId;
+    }
+
+    /**
      * 鍑哄簱璺緞鎼滅储浠d环杈冮珮锛屽彧缂撳瓨宸茬‘璁ゅ彲杈剧殑绔欑偣缁撴灉锛屽苟閫氳繃 TTL 鎺у埗闄堟棫椋庨櫓銆�
      */
     private Integer resolveCachedOutStationId(FindCrnNoResult findCrnNoResult,

--
Gitblit v1.9.1