From 852664df1caf38831793b341edcada9dd7b6c22a Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 06 五月 2026 19:28:33 +0800
Subject: [PATCH] #dfs

---
 src/main/java/com/zy/common/utils/NavigateUtils.java |  175 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 152 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/zy/common/utils/NavigateUtils.java b/src/main/java/com/zy/common/utils/NavigateUtils.java
index 2dbe19c..733a2ab 100644
--- a/src/main/java/com/zy/common/utils/NavigateUtils.java
+++ b/src/main/java/com/zy/common/utils/NavigateUtils.java
@@ -27,6 +27,7 @@
 import com.zy.asrs.service.StationCycleCapacityService;
 import com.zy.asrs.service.StationPathPolicyService;
 import com.zy.core.News;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Scheduled;
 import com.zy.core.model.StationObjModel;
 import com.zy.core.model.command.StationCommand;
@@ -53,6 +54,7 @@
 import java.util.LinkedHashMap;
 
 @Component
+@Slf4j
 public class NavigateUtils {
 
     private static final long STATION_PATH_SLOW_LOG_THRESHOLD_MS = 500L;
@@ -111,29 +113,74 @@
                                                                  Integer endStationId,
                                                                  Integer currentTaskNo,
                                                                  Double pathLenFactor) {
-        StationPathResolvedPolicy resolvedPolicy = resolveStationPathPolicy(startStationId, endStationId);
-        StationPathRuntimeSnapshot runtimeSnapshot = loadStationPathRuntimeSnapshot(currentTaskNo);
-        StationPathSearchContext context = buildStationPathSearchContext(
-                startStationId,
-                endStationId,
-                resolvedPolicy,
-                StationPathCalcMode.REROUTE,
-                runtimeSnapshot
-        );
-        if (context.allList.isEmpty()) {
-            return new ArrayList<>();
-        }
+        long totalStartNs = System.nanoTime();
+        log.info("绔欑偣璺緞鍊欓�夎绠楀叆鍙o紝startStationId={}锛宔ndStationId={}锛宼askNo={}锛宲athLenFactor={}",
+                startStationId, endStationId, currentTaskNo, pathLenFactor);
+        try {
+            StationPathResolvedPolicy resolvedPolicy = resolveStationPathPolicy(startStationId, endStationId);
+            log.info("绔欑偣璺緞鍊欓�夌瓥鐣ヨВ鏋愬畬鎴愶紝startStationId={}锛宔ndStationId={}锛宼askNo={}锛宮atchedRule={}锛宺uleCode={}锛宲rofileCode={}锛宑ostMs={}",
+                    startStationId,
+                    endStationId,
+                    currentTaskNo,
+                    resolvedPolicy != null && resolvedPolicy.matchedRule(),
+                    resolvedPolicy == null || resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getRuleCode(),
+                    resolvedPolicy == null ? null : resolvedPolicy.getDefaultProfileCode(),
+                    elapsedMillis(totalStartNs));
+            StationPathRuntimeSnapshot runtimeSnapshot = loadStationPathRuntimeSnapshot(currentTaskNo);
+            List<NavigateNode> shortFallbackPath = buildRerouteShortFallbackPath(
+                    startStationId,
+                    endStationId,
+                    currentTaskNo,
+                    resolvedPolicy,
+                    runtimeSnapshot
+            );
+            StationPathSearchContext context = buildStationPathSearchContext(
+                    startStationId,
+                    endStationId,
+                    resolvedPolicy,
+                    StationPathCalcMode.REROUTE,
+                    runtimeSnapshot
+            );
+            if (context.allList.isEmpty()) {
+                List<List<NavigateNode>> fallbackCandidateList = normalizeCandidatePaths(Collections.singletonList(shortFallbackPath));
+                log.warn("绔欑偣璺緞鍊欓�夎绠楃粨鏉燂紝鍘熷洜=empty_search_context锛宻tartStationId={}锛宔ndStationId={}锛宼askNo={}锛宖allbackCandidateCount={}锛宖allbackPath={}锛宼otalCostMs={}",
+                        startStationId,
+                        endStationId,
+                        currentTaskNo,
+                        fallbackCandidateList.size(),
+                        JSON.toJSONString(extractStationIdList(shortFallbackPath)),
+                        elapsedMillis(totalStartNs));
+                return fallbackCandidateList;
+            }
 
-        List<List<NavigateNode>> orderedPathList = orderStationPathCandidates(
-                context.allList,
-                context.resolvedPolicy,
-                currentTaskNo,
-                pathLenFactor,
-                startStationId,
-                endStationId,
-                runtimeSnapshot
-        );
-        return normalizeCandidatePaths(orderedPathList);
+            long orderStartNs = System.nanoTime();
+            List<List<NavigateNode>> orderedPathList = orderStationPathCandidates(
+                    context.allList,
+                    context.resolvedPolicy,
+                    currentTaskNo,
+                    pathLenFactor,
+                    startStationId,
+                    endStationId,
+                    runtimeSnapshot
+            );
+            List<List<NavigateNode>> candidatePathList = appendShortFallbackCandidate(orderedPathList, shortFallbackPath);
+            List<List<NavigateNode>> normalizedPathList = normalizeCandidatePaths(candidatePathList);
+            log.info("绔欑偣璺緞鍊欓�夎绠楃粨鏉燂紝startStationId={}锛宔ndStationId={}锛宼askNo={}锛宺awCandidateCount={}锛宱rderedPathCount={}锛宖allbackPathLen={}锛宯ormalizedPathCount={}锛宱rderCostMs={}锛宼otalCostMs={}",
+                    startStationId,
+                    endStationId,
+                    currentTaskNo,
+                    context.allList.size(),
+                    orderedPathList == null ? null : orderedPathList.size(),
+                    shortFallbackPath == null ? 0 : shortFallbackPath.size(),
+                    normalizedPathList.size(),
+                    elapsedMillis(orderStartNs),
+                    elapsedMillis(totalStartNs));
+            return normalizedPathList;
+        } catch (Exception e) {
+            log.error("绔欑偣璺緞鍊欓�夎绠楀紓甯革紝startStationId={}锛宔ndStationId={}锛宼askNo={}锛宲athLenFactor={}锛宑ostMs={}",
+                    startStationId, endStationId, currentTaskNo, pathLenFactor, elapsedMillis(totalStartNs), e);
+            throw e;
+        }
     }
 
     public Map<Integer, Set<Integer>> loadUndirectedStationGraphSnapshot() {
@@ -413,6 +460,54 @@
             return new DirectPathSearchResult(degradedPath, includeWaypoint, false);
         }
         return DirectPathSearchResult.empty(includeWaypoint, includeSoftPreference);
+    }
+
+    private List<NavigateNode> buildRerouteShortFallbackPath(Integer startStationId,
+                                                             Integer endStationId,
+                                                             Integer currentTaskNo,
+                                                             StationPathResolvedPolicy resolvedPolicy,
+                                                             StationPathRuntimeSnapshot runtimeSnapshot) {
+        long startNs = System.nanoTime();
+        try {
+            List<NavigateNode> path = findStationDirectPath(
+                    startStationId,
+                    endStationId,
+                    currentTaskNo,
+                    0.0d,
+                    StationPathCalcMode.OPTIMAL,
+                    resolvedPolicy,
+                    runtimeSnapshot
+            );
+            List<NavigateNode> normalizedPath = normalizeStationPath(path);
+            log.info("绔欑偣璺緞鍫靛閲嶈鍒掔煭璺緞淇濆簳璁$畻瀹屾垚锛宻tartStationId={}锛宔ndStationId={}锛宼askNo={}锛宲athLen={}锛宲ath={}锛宑ostMs={}",
+                    startStationId,
+                    endStationId,
+                    currentTaskNo,
+                    normalizedPath.size(),
+                    JSON.toJSONString(extractStationIdList(normalizedPath)),
+                    elapsedMillis(startNs));
+            return normalizedPath;
+        } catch (Exception e) {
+            log.warn("绔欑偣璺緞鍫靛閲嶈鍒掔煭璺緞淇濆簳璁$畻澶辫触锛宻tartStationId={}锛宔ndStationId={}锛宼askNo={}锛宑ostMs={}锛宔rror={}",
+                    startStationId,
+                    endStationId,
+                    currentTaskNo,
+                    elapsedMillis(startNs),
+                    e.toString());
+            return new ArrayList<>();
+        }
+    }
+
+    private List<List<NavigateNode>> appendShortFallbackCandidate(List<List<NavigateNode>> orderedPathList,
+                                                                  List<NavigateNode> shortFallbackPath) {
+        List<List<NavigateNode>> candidatePathList = new ArrayList<>();
+        if (orderedPathList != null && !orderedPathList.isEmpty()) {
+            candidatePathList.addAll(orderedPathList);
+        }
+        if (shortFallbackPath != null && !shortFallbackPath.isEmpty()) {
+            candidatePathList.add(shortFallbackPath);
+        }
+        return candidatePathList;
     }
 
     private List<NavigateNode> searchDirectPath(DirectStationPathContext context,
@@ -2685,6 +2780,8 @@
         }
         Integer lev = startStation.getStationLev();
         stepCostMap.put("loadStartStation", elapsedMillis(stepStartNs));
+        log.info("绔欑偣璺緞鎼滅储涓婁笅鏂囧姞杞借捣鐐瑰畬鎴愶紝startStationId={}锛宔ndStationId={}锛宮ode={}锛宭ev={}锛宑ostMs={}",
+                startStationId, endStationId, calcMode, lev, stepCostMap.get("loadStartStation"));
 
         stepStartNs = System.nanoTime();
         NavigateSolution navigateSolution = new NavigateSolution();
@@ -2701,6 +2798,16 @@
             throw new CoolException("鏈壘鍒拌 缁堢偣 瀵瑰簲鐨勮妭鐐�");
         }
         stepCostMap.put("loadStationMapAndNode", elapsedMillis(stepStartNs));
+        log.info("绔欑偣璺緞鎼滅储涓婁笅鏂囧姞杞藉湴鍥惧畬鎴愶紝startStationId={}锛宔ndStationId={}锛宮ode={}锛宮apRows={}锛宻tartNode=({},{})锛宔ndNode=({},{})锛宑ostMs={}",
+                startStationId,
+                endStationId,
+                calcMode,
+                stationMap.size(),
+                startNode.getX(),
+                startNode.getY(),
+                endNode.getX(),
+                endNode.getY(),
+                stepCostMap.get("loadStationMapAndNode"));
 
         stepStartNs = System.nanoTime();
         StationPathProfileConfig profileConfig = resolvedPolicy.getProfileConfig() == null
@@ -2714,9 +2821,17 @@
                 endStationId,
                 calcMode == null ? "" : calcMode.name());
         int calcMaxDepth = safeInt(profileConfig.getCalcMaxDepth(), 120);
-        int calcMaxPaths = safeInt(profileConfig.getCalcMaxPaths(), 500);
+        int calcMaxPaths = safeInt(profileConfig.getCalcMaxPaths(), 50);
         int calcMaxCost = safeInt(profileConfig.getCalcMaxCost(), 300);
         List<Integer> guideStationSequence = buildGuideStationSequence(startStationId, endStationId, resolvedPolicy.getRuleConfig());
+        log.info("绔欑偣璺緞鍊欓�夋灇涓惧紑濮嬶紝startStationId={}锛宔ndStationId={}锛宮ode={}锛宑alcMaxDepth={}锛宑alcMaxPaths={}锛宑alcMaxCost={}锛実uideStationSequence={}",
+                startStationId,
+                endStationId,
+                calcMode,
+                calcMaxDepth,
+                calcMaxPaths,
+                calcMaxCost,
+                JSON.toJSONString(guideStationSequence));
         stepStartNs = System.nanoTime();
         List<List<NavigateNode>> allList = navigateSolution.allSimplePaths(
                 stationMap,
@@ -2729,6 +2844,12 @@
         );
         stepCostMap.put("allSimplePaths", elapsedMillis(stepStartNs));
         rawCandidateCount = allList.size();
+        log.info("绔欑偣璺緞鍊欓�夋灇涓惧畬鎴愶紝startStationId={}锛宔ndStationId={}锛宮ode={}锛宺awCandidateCount={}锛宑ostMs={}",
+                startStationId,
+                endStationId,
+                calcMode,
+                rawCandidateCount,
+                stepCostMap.get("allSimplePaths"));
         if (allList.isEmpty()) {
             logStationPathSearchContextSlow(startStationId, endStationId, calcMode, lev, rawCandidateCount, filteredCandidateCount, stepCostMap, totalStartNs);
             return StationPathSearchContext.empty(resolvedPolicy);
@@ -2738,6 +2859,14 @@
         allList = filterNonAutoStationPaths(allList, statusMap);
         stepCostMap.put("filterNonAutoStation", elapsedMillis(stepStartNs));
         filteredCandidateCount = allList.size();
+        log.info("绔欑偣璺緞鍊欓�夎嚜鍔ㄧ姸鎬佽繃婊ゅ畬鎴愶紝startStationId={}锛宔ndStationId={}锛宮ode={}锛宺awCandidateCount={}锛宖ilteredCandidateCount={}锛宻tatusCount={}锛宑ostMs={}",
+                startStationId,
+                endStationId,
+                calcMode,
+                rawCandidateCount,
+                filteredCandidateCount,
+                statusMap.size(),
+                stepCostMap.get("filterNonAutoStation"));
         if (allList.isEmpty()) {
             News.info("[WCS Debug] 绔欑偣璺緞鍊欓�夊叏閮ㄨ杩囨护锛屽瓨鍦ㄩ潪鑷姩绔欑偣,startStationId={},endStationId={}", startStationId, endStationId);
             logStationPathSearchContextSlow(startStationId, endStationId, calcMode, lev, rawCandidateCount, filteredCandidateCount, stepCostMap, totalStartNs);

--
Gitblit v1.9.1