From 1c6d2b037844239b907adfe3882d2cc41a99a3d3 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 06 五月 2026 17:18:16 +0800
Subject: [PATCH] #dfs

---
 src/main/java/com/zy/common/utils/NavigateUtils.java |   73 ++++++++++++++++++++++++++++++++++--
 1 files changed, 68 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/zy/common/utils/NavigateUtils.java b/src/main/java/com/zy/common/utils/NavigateUtils.java
index fa567ae..733a2ab 100644
--- a/src/main/java/com/zy/common/utils/NavigateUtils.java
+++ b/src/main/java/com/zy/common/utils/NavigateUtils.java
@@ -127,6 +127,13 @@
                     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,
@@ -135,9 +142,15 @@
                     runtimeSnapshot
             );
             if (context.allList.isEmpty()) {
-                log.warn("绔欑偣璺緞鍊欓�夎绠楃粨鏉燂紝鍘熷洜=empty_search_context锛宻tartStationId={}锛宔ndStationId={}锛宼askNo={}锛宼otalCostMs={}",
-                        startStationId, endStationId, currentTaskNo, elapsedMillis(totalStartNs));
-                return new ArrayList<>();
+                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;
             }
 
             long orderStartNs = System.nanoTime();
@@ -150,13 +163,15 @@
                     endStationId,
                     runtimeSnapshot
             );
-            List<List<NavigateNode>> normalizedPathList = normalizeCandidatePaths(orderedPathList);
-            log.info("绔欑偣璺緞鍊欓�夎绠楃粨鏉燂紝startStationId={}锛宔ndStationId={}锛宼askNo={}锛宺awCandidateCount={}锛宱rderedPathCount={}锛宯ormalizedPathCount={}锛宱rderCostMs={}锛宼otalCostMs={}",
+            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));
@@ -447,6 +462,54 @@
         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,
                                                 boolean includeWaypoint,
                                                 boolean includeSoftPreference) {

--
Gitblit v1.9.1