From 26784989e73fc36c6315e54939d1b13a50eb5020 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 26 三月 2026 21:03:00 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java | 111 +++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 83 insertions(+), 28 deletions(-)
diff --git a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
index e86d367..e3ece21 100644
--- a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -382,10 +382,11 @@
boolean complete = false;
Integer targetDeviceNo = null;
+ StationThread stationThread = null;
BasStation basStation = basStationService.getOne(new QueryWrapper<BasStation>().eq("station_id", targetStaNo));
if (basStation != null) {
targetDeviceNo = basStation.getDeviceNo();
- StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
+ stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
if (stationThread != null) {
Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
StationProtocol stationProtocol = statusMap.get(basStation.getStationId());
@@ -396,11 +397,26 @@
}
if (complete) {
+ attemptClearTaskPath(stationThread, wrkNo);
completeStationRunTask(wrkMast, targetDeviceNo);
}
}
} catch (Exception e) {
e.printStackTrace();
+ }
+ }
+
+ private void attemptClearTaskPath(StationThread stationThread, Integer taskNo) {
+ if (stationThread == null || taskNo == null || taskNo <= 0) {
+ return;
+ }
+ try {
+ boolean cleared = stationThread.clearPath(taskNo);
+ if (cleared) {
+ News.info("杈撻�佺珯鐐逛换鍔¤繍琛屽畬鎴愬悗娓呯悊娈嬬暀璺緞锛屽伐浣滃彿={}", taskNo);
+ }
+ } catch (Exception e) {
+ News.error("杈撻�佺珯鐐逛换鍔¤繍琛屽畬鎴愬悗娓呯悊娈嬬暀璺緞寮傚父锛屽伐浣滃彿={}", taskNo, e);
}
}
@@ -804,17 +820,19 @@
if (taskNo == null || taskNo <= 0 || stationId == null) {
return RerouteExecutionResult.skip("invalid-station-task");
}
- boolean runBlockReroute = context.sceneType() == RerouteSceneType.RUN_BLOCK_REROUTE;
- if (runBlockReroute) {
- // 绔欑偣杩涘叆鍫靛鍚庯紝璁惧渚у彲鑳藉凡缁忔妸涔嬪墠棰勪笅鍙戠殑鍒嗘鍛戒护娓呮帀浜嗐��
- // 鍏堜綔搴熸湰鍦� session/segment 鐘舵�侊紝鍐嶆寜鏂拌矾绾块噸鍙戯紝閬垮厤琚棫鐘舵�佸弽鍚戝崱浣忋��
- if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) {
- stationMoveCoordinator.cancelSession(taskNo);
- }
- if (context.resetSegmentCommandsBeforeDispatch()) {
- resetSegmentMoveCommandsBeforeReroute(taskNo);
- }
+ if (stationMoveCoordinator != null) {
+ return stationMoveCoordinator.withTaskDispatchLock(taskNo,
+ () -> executeReroutePlanWithTaskLock(context, plan, stationProtocol, taskNo, stationId));
}
+ return executeReroutePlanWithTaskLock(context, plan, stationProtocol, taskNo, stationId);
+ }
+
+ private RerouteExecutionResult executeReroutePlanWithTaskLock(RerouteContext context,
+ RerouteCommandPlan plan,
+ StationProtocol stationProtocol,
+ Integer taskNo,
+ Integer stationId) {
+ boolean runBlockReroute = context.sceneType() == RerouteSceneType.RUN_BLOCK_REROUTE;
if (context.checkRecentDispatch()
&& shouldSkipIdleRecoverForRecentDispatch(taskNo, stationId)) {
return RerouteExecutionResult.skip("recent-dispatch");
@@ -846,6 +864,22 @@
if (context.requireOutOrderDispatchLock()
&& !tryAcquireOutOrderDispatchLock(taskNo, stationId)) {
return RerouteExecutionResult.skip("out-order-lock");
+ }
+
+ if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) {
+ // 鍒囪矾鍓嶅厛鎶婃棫 session 缃负 CANCEL_PENDING锛岃宸茬粡鎺掗槦涓殑鏃у垎娈电嚎绋嬪湪鏈�缁堝彂閫佸墠鍋滀笅銆�
+ stationMoveCoordinator.markCancelPending(taskNo, "reroute_pending");
+ }
+
+ if (runBlockReroute) {
+ // 绔欑偣杩涘叆鍫靛鍚庯紝璁惧渚у彲鑳藉凡缁忔妸涔嬪墠棰勪笅鍙戠殑鍒嗘鍛戒护娓呮帀浜嗐��
+ // 鍏堜綔搴熸湰鍦� session/segment 鐘舵�侊紝鍐嶆寜鏂拌矾绾块噸鍙戯紝閬垮厤琚棫鐘舵�佸弽鍚戝崱浣忋��
+ if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) {
+ stationMoveCoordinator.cancelSession(taskNo);
+ }
+ if (context.resetSegmentCommandsBeforeDispatch()) {
+ resetSegmentMoveCommandsBeforeReroute(taskNo);
+ }
}
if (!runBlockReroute
@@ -1863,32 +1897,53 @@
}
private boolean shouldSkipIdleRecoverForRecentDispatch(Integer taskNo, Integer stationId) {
- if (stationMoveCoordinator == null || taskNo == null || taskNo <= 0 || stationId == null) {
+ if (taskNo == null || taskNo <= 0 || stationId == null) {
return false;
}
- StationMoveSession session = stationMoveCoordinator.loadSession(taskNo);
- if (session == null || !session.isActive() || session.getLastIssuedAt() == null) {
- return false;
- }
- // 鍒嗘鎵ц杩囩▼涓紝鍒氫笅鍙戜笅涓�娈靛懡浠ゆ椂锛宻ession 鐨� currentStationId/dispatchStationId
- // 鍙兘杩樻病鏉ュ緱鍙婂拰褰撳墠瑙傚療绔欑偣瀹屽叏瀵归綈锛涘彧瑕佸綋鍓嶇珯鐐逛粛鍦ㄨ繖鏉℃椿鍔ㄨ矾绾块噷锛�
- // 灏辫鏄庤繖娆� recent dispatch 浠嶇劧鍜屽畠鐩稿叧锛宨dle recover 涓嶅簲鍦� 10 绉掔獥鍙e唴鍐嶆浠嬪叆銆�
- if (!Objects.equals(stationId, session.getCurrentStationId())
- && !Objects.equals(stationId, session.getDispatchStationId())
- && !session.containsStation(stationId)) {
- return false;
- }
- long elapsedMs = System.currentTimeMillis() - session.getLastIssuedAt();
long thresholdMs = STATION_IDLE_RECOVER_SECONDS * 1000L;
- if (elapsedMs >= thresholdMs) {
+ StationMoveSession session = stationMoveCoordinator == null ? null : stationMoveCoordinator.loadSession(taskNo);
+ if (session != null && session.isActive() && session.getLastIssuedAt() != null) {
+ // 鍒嗘鎵ц杩囩▼涓紝鍒氫笅鍙戜笅涓�娈靛懡浠ゆ椂锛宻ession 鐨� currentStationId/dispatchStationId
+ // 鍙兘杩樻病鏉ュ緱鍙婂拰褰撳墠瑙傚療绔欑偣瀹屽叏瀵归綈锛涘彧瑕佸綋鍓嶇珯鐐逛粛鍦ㄨ繖鏉℃椿鍔ㄨ矾绾块噷锛�
+ // 灏辫鏄庤繖娆� recent dispatch 浠嶇劧鍜屽畠鐩稿叧锛宨dle recover 涓嶅簲鍦� 10 绉掔獥鍙e唴鍐嶆浠嬪叆銆�
+ if (Objects.equals(stationId, session.getCurrentStationId())
+ || Objects.equals(stationId, session.getDispatchStationId())
+ || session.containsStation(stationId)) {
+ long elapsedMs = System.currentTimeMillis() - session.getLastIssuedAt();
+ if (elapsedMs < thresholdMs) {
+ saveStationTaskIdleTrack(new StationTaskIdleTrack(taskNo, stationId, System.currentTimeMillis()));
+ News.info("杈撻�佺珯鐐逛换鍔″垰瀹屾垚鍛戒护涓嬪彂锛屽凡璺宠繃鍋滅暀閲嶇畻銆傜珯鐐瑰彿={}锛屽伐浣滃彿={}锛岃窛涓婃涓嬪彂={}ms锛宺outeVersion={}",
+ stationId, taskNo, elapsedMs, session.getRouteVersion());
+ return true;
+ }
+ }
+ }
+ if (!hasRecentIssuedMoveCommand(taskNo, stationId, thresholdMs)) {
return false;
}
saveStationTaskIdleTrack(new StationTaskIdleTrack(taskNo, stationId, System.currentTimeMillis()));
- News.info("杈撻�佺珯鐐逛换鍔″垰瀹屾垚鍛戒护涓嬪彂锛屽凡璺宠繃鍋滅暀閲嶇畻銆傜珯鐐瑰彿={}锛屽伐浣滃彿={}锛岃窛涓婃涓嬪彂={}ms锛宺outeVersion={}",
- stationId, taskNo, elapsedMs, session.getRouteVersion());
+ News.info("杈撻�佺珯鐐逛换鍔″垰瀹屾垚鍛戒护涓嬪彂锛屽凡璺宠繃鍋滅暀閲嶇畻銆傜珯鐐瑰彿={}锛屽伐浣滃彿={}锛岃窛鏈�杩戝懡浠や笅鍙�<{}ms锛宺outeVersion={}",
+ stationId, taskNo, thresholdMs, session == null ? null : session.getRouteVersion());
return true;
}
+ private boolean hasRecentIssuedMoveCommand(Integer taskNo, Integer stationId, long thresholdMs) {
+ if (taskNo == null || taskNo <= 0 || stationId == null || thresholdMs <= 0L || basStationOptService == null) {
+ return false;
+ }
+ Date thresholdTime = new Date(System.currentTimeMillis() - thresholdMs);
+ List<BasStationOpt> optList = basStationOptService.list(new QueryWrapper<BasStationOpt>()
+ .select("id")
+ .eq("task_no", taskNo)
+ .eq("station_id", stationId)
+ .eq("mode", String.valueOf(StationCommandType.MOVE))
+ .eq("send", 1)
+ .ge("send_time", thresholdTime)
+ .orderByDesc("send_time")
+ .last("limit 1"));
+ return optList != null && !optList.isEmpty();
+ }
+
private void resetSegmentMoveCommandsBeforeReroute(Integer taskNo) {
if (redisUtil == null || taskNo == null || taskNo <= 0) {
return;
--
Gitblit v1.9.1