From 37348c5855649e98defe0f5b1557750cb7c84aa5 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 02 三月 2026 16:56:01 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java | 111 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 89 insertions(+), 22 deletions(-)
diff --git a/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java b/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
index 4530d45..a39b1b7 100644
--- a/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
+++ b/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
@@ -128,6 +128,8 @@
boolean initialized = false;
// 涓婁竴姝ユ墽琛屾椂闂达紙鐢ㄤ簬鍫靛妫�娴嬶級
long stepExecuteTime = System.currentTimeMillis();
+ // 閬垮厤鍦ㄥ埌杈剧洰鏍囧悗閲嶅鎵ц鍒颁綅閫昏緫
+ boolean arrivalHandled = false;
while (true) {
if (Thread.currentThread().isInterrupted()) {
@@ -144,12 +146,21 @@
if (command != null) {
taskLastUpdateTime.put(taskNo, System.currentTimeMillis());
- // 棣栨鎺ユ敹鍛戒护鏃跺垵濮嬪寲
- if (finalTargetStationId == null) {
- finalTargetStationId = command.getTargetStaNo();
- if (checkTaskNoInArea(taskNo)) {
- generateBarcode = true;
+ // 姣忔鎺ユ敹鍛戒护閮藉埛鏂扮洰鏍囷紝閬垮厤娌跨敤鏃х洰鏍囧鑷寸姸鎬佹姈鍔�
+ Integer commandTargetStationId = command.getTargetStaNo();
+ if (commandTargetStationId != null) {
+ if (!commandTargetStationId.equals(finalTargetStationId)) {
+ arrivalHandled = false;
+ News.info("[WCS Debug] 浠诲姟{}鍒囨崲鐩爣: {} -> {}", taskNo, finalTargetStationId,
+ commandTargetStationId);
}
+ finalTargetStationId = commandTargetStationId;
+ // 褰撳墠绔欑偣鍏堝悓姝ユ渶鏂扮洰鏍囷紝閬垮厤涓婂眰鍦ㄧ獥鍙f湡閲嶅涓嬪彂鍚屼竴璺緞
+ syncCurrentStationTarget(taskNo, currentStationId, finalTargetStationId);
+ }
+
+ if (!generateBarcode && checkTaskNoInArea(taskNo)) {
+ generateBarcode = true;
}
// 灏嗘柊璺緞杩藉姞鍒板緟鎵ц闃熷垪
@@ -157,15 +168,7 @@
if (newPath != null && !newPath.isEmpty()) {
// 鑾峰彇闃熷垪涓渶鍚庝竴涓珯鐐癸紙鐢ㄤ簬琛旀帴鐐瑰幓閲嶏級
Integer lastInQueue = getLastInQueue(pendingPathQueue);
- if (lastInQueue == null) {
- lastInQueue = currentStationId;
- }
-
- int startIndex = 0;
- // 濡傛灉鏂拌矾寰勭殑璧风偣涓庡綋鍓嶄綅缃垨闃熷垪鏈熬閲嶅锛屽垯璺宠繃
- if (lastInQueue != null && !newPath.isEmpty() && newPath.get(0).equals(lastInQueue)) {
- startIndex = 1;
- }
+ int startIndex = getPathAppendStartIndex(newPath, currentStationId, lastInQueue);
for (int i = startIndex; i < newPath.size(); i++) {
pendingPathQueue.offer(newPath.get(i));
@@ -232,6 +235,7 @@
currentStationId = nextStationId;
pendingPathQueue.poll();
stepExecuteTime = System.currentTimeMillis();
+ arrivalHandled = false;
News.info("[WCS Debug] 浠诲姟{}绉诲姩鍒扮珯鐐�: {}, 鍓╀綑闃熷垪: {}", taskNo, currentStationId,
pendingPathQueue.size());
sleep(1000); // 妯℃嫙绉诲姩鑰楁椂
@@ -261,18 +265,20 @@
// 璺緞闃熷垪涓虹┖锛岀瓑寰呮柊鐨勫垎娈靛懡浠�
if (currentStationId != null && finalTargetStationId != null
&& currentStationId.equals(finalTargetStationId)) {
- // 宸插埌杈炬渶缁堢洰鏍囷紝姝e父缁撴潫
- if (generateBarcode) {
- Integer targetDeviceNo = getDeviceNoByStationId(finalTargetStationId);
- if (targetDeviceNo != null) {
- generateStationBarcode(taskNo, finalTargetStationId, targetDeviceNo);
- News.info("[WCS Debug] 浠诲姟{}鍒拌揪鐩爣{}骞剁敓鎴愭潯鐮�", taskNo, finalTargetStationId);
+ // 宸插埌杈剧洰鏍囷紝鍏堟墽琛屼竴娆″埌浣嶉�昏緫锛岀劧鍚庣户缁瓑寰呬笅涓�鏉$Щ鍔ㄥ懡浠�
+ if (!arrivalHandled) {
+ if (generateBarcode) {
+ Integer targetDeviceNo = getDeviceNoByStationId(finalTargetStationId);
+ if (targetDeviceNo != null) {
+ generateStationBarcode(taskNo, finalTargetStationId, targetDeviceNo);
+ News.info("[WCS Debug] 浠诲姟{}鍒拌揪鐩爣{}骞剁敓鎴愭潯鐮�", taskNo, finalTargetStationId);
+ }
}
+ arrivalHandled = true;
}
- break;
}
- // 鏈埌杈炬渶缁堢洰鏍囷紝绛夊緟鏂扮殑鍒嗘鍛戒护
+ // 缁х画绛夊緟鏂扮殑鍒嗘鍛戒护
Long lastTime = taskLastUpdateTime.get(taskNo);
if (lastTime != null && System.currentTimeMillis() - lastTime > 30000) {
// 瓒呮椂锛�30绉掑唴娌℃湁鏀跺埌鏂板垎娈靛懡浠�
@@ -305,6 +311,67 @@
}
/**
+ * 璁$畻鏂拌矾寰勫湪闃熷垪涓殑杩藉姞璧风偣锛岄伩鍏嶉噸澶嶄笅鍙戝鑷磋矾寰勬潵鍥炶烦
+ */
+ private int getPathAppendStartIndex(List<Integer> newPath, Integer currentStationId, Integer lastInQueue) {
+ if (newPath == null || newPath.isEmpty()) {
+ return 0;
+ }
+
+ if (lastInQueue != null) {
+ int idx = newPath.lastIndexOf(lastInQueue);
+ if (idx >= 0) {
+ return idx + 1;
+ }
+ }
+
+ if (currentStationId != null) {
+ int idx = newPath.lastIndexOf(currentStationId);
+ if (idx >= 0) {
+ return idx + 1;
+ }
+ }
+
+ return 0;
+ }
+
+ /**
+ * 鍛戒护鍒氬埌杈炬椂鍚屾褰撳墠绔欑偣鐩爣锛岄檷浣庝笂灞傞噸澶嶅彂鍚屼竴璺緞鐨勬鐜�
+ */
+ private void syncCurrentStationTarget(Integer taskNo, Integer currentStationId, Integer targetStationId) {
+ if (currentStationId == null || targetStationId == null) {
+ return;
+ }
+ Integer currentDeviceNo = getDeviceNoByStationId(currentStationId);
+ if (currentDeviceNo == null) {
+ return;
+ }
+
+ lockStations(currentStationId);
+ try {
+ List<ZyStationStatusEntity> statusList = deviceStatusMap.get(currentDeviceNo);
+ if (statusList == null) {
+ return;
+ }
+
+ ZyStationStatusEntity currentStatus = statusList.stream()
+ .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null);
+ if (currentStatus == null) {
+ return;
+ }
+
+ if (currentStatus.getTaskNo() != null && currentStatus.getTaskNo() > 0
+ && !currentStatus.getTaskNo().equals(taskNo) && currentStatus.isLoading()) {
+ return;
+ }
+
+ updateStationDataInternal(currentStationId, currentDeviceNo, taskNo, targetStationId, null, null, null);
+ } finally {
+ unlockStations(currentStationId);
+ }
+ }
+
+ /**
* 鑾峰彇鏄惁鍏佽妫�鏌ュ牭濉炵殑閰嶇疆
*/
private boolean getFakeAllowCheckBlock() {
--
Gitblit v1.9.1