From 1654b0a8c149f86d38f3202cb88c655ad0a25384 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 01 四月 2026 10:33:25 +0800
Subject: [PATCH] #出库任务路径计算增加cache
---
src/main/java/com/zy/core/thread/impl/station/StationSegmentExecutor.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 52 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/station/StationSegmentExecutor.java b/src/main/java/com/zy/core/thread/impl/station/StationSegmentExecutor.java
index 50ca80f..95209a6 100644
--- a/src/main/java/com/zy/core/thread/impl/station/StationSegmentExecutor.java
+++ b/src/main/java/com/zy/core/thread/impl/station/StationSegmentExecutor.java
@@ -89,6 +89,7 @@
long lastSeenAt = System.currentTimeMillis();
int segCursor = 0;
Integer lastCurrentStationId = null;
+ int lastMatchedPathIndex = -1;
boolean firstRun = true;
while (true) {
try {
@@ -144,12 +145,17 @@
break;
}
- int currentIndex = effectiveFullPath.indexOf(currentStation.getStationId());
+ int currentIndex = resolveCurrentPathIndex(
+ effectiveFullPath,
+ currentStation.getStationId(),
+ lastMatchedPathIndex
+ );
if (currentIndex < 0) {
Thread.sleep(500L);
firstRun = false;
continue;
}
+ lastMatchedPathIndex = currentIndex;
int remaining = effectiveFullPath.size() - currentIndex - 1;
if (remaining <= 0) {
@@ -192,10 +198,55 @@
}
}
+ private int resolveCurrentPathIndex(List<Integer> fullPathStationIds,
+ Integer currentStationId,
+ int lastMatchedPathIndex) {
+ if (fullPathStationIds == null || fullPathStationIds.isEmpty() || currentStationId == null) {
+ return -1;
+ }
+ if (lastMatchedPathIndex >= 0
+ && lastMatchedPathIndex < fullPathStationIds.size()
+ && equalsInteger(currentStationId, fullPathStationIds.get(lastMatchedPathIndex))) {
+ return lastMatchedPathIndex;
+ }
+
+ int nextIndex = findNextStationIndex(fullPathStationIds, currentStationId, Math.max(lastMatchedPathIndex + 1, 0));
+ if (nextIndex >= 0) {
+ return nextIndex;
+ }
+ return findNextStationIndex(fullPathStationIds, currentStationId, 0);
+ }
+
+ private int findNextStationIndex(List<Integer> path, Integer stationId, int fromIndex) {
+ if (path == null || path.isEmpty() || stationId == null) {
+ return -1;
+ }
+ int startIdx = Math.max(fromIndex, 0);
+ for (int i = startIdx; i < path.size(); i++) {
+ if (equalsInteger(stationId, path.get(i))) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
private boolean sendSegmentWithRetry(StationCommand command,
StationTaskTraceRegistry traceRegistry,
Integer traceVersion,
Integer currentStationId) {
+ // 鍦ㄤ笅鍙戞柊鍒嗘鍓嶆鏌ヨ矾鐢辩増鏈槸鍚︿粛鐒舵湁鏁堬紝閬垮厤鍦ㄨ矾鐢辩増鏈凡鏇存柊鐨勬儏鍐典笅涓嬪彂鏃х増鏈懡浠�
+ if (!isRouteDispatchable(command == null ? null : command.getTaskNo(), command == null ? null : command.getRouteVersion())) {
+ if (traceRegistry != null && command != null) {
+ traceRegistry.markCancelled(command.getTaskNo(), traceVersion, currentStationId,
+ buildDetails("reason", "route_version_replaced_before_segment_send", "routeVersion", command.getRouteVersion()));
+ }
+ markCancelled(command == null ? null : command.getTaskNo(),
+ command == null ? null : command.getRouteVersion(),
+ currentStationId,
+ "route_version_replaced_before_segment_send");
+ return false;
+ }
+
while (true) {
SegmentSendResult sendResult = executeLockedSegmentSend(command, traceRegistry, traceVersion, currentStationId);
if (sendResult == SegmentSendResult.CANCELLED) {
--
Gitblit v1.9.1