From bdf43f554f9bc7f0de94e7530e79af9193341334 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 19 三月 2026 15:38:49 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java | 87 +++++++++++++++++++++++++++++++++++--------
1 files changed, 71 insertions(+), 16 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 ccf3230..d2cfe98 100644
--- a/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
+++ b/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
@@ -27,6 +27,7 @@
import java.util.Arrays;
public class ZyStationFakeSegConnect implements ZyStationConnectApi {
+ private static final long DEFAULT_FAKE_RUN_BLOCK_TIMEOUT_MS = 10000L;
// 绔欑偣绾ч攣锛氭瘡涓珯鐐圭嫭绔嬩竴鎶婇攣锛屾彁鍗囧苟鍙戞�ц兘
private final Map<Integer, ReentrantLock> stationLocks = new ConcurrentHashMap<>();
@@ -128,6 +129,9 @@
boolean initialized = false;
// 涓婁竴姝ユ墽琛屾椂闂达紙鐢ㄤ簬鍫靛妫�娴嬶級
long stepExecuteTime = System.currentTimeMillis();
+ long runBlockTimeoutMs = getFakeRunBlockTimeoutMs();
+ // 浠呭湪姣忔鍒拌揪鐩爣鏃舵墽琛屼竴娆″埌浣嶅鐞嗭紝閬垮厤閲嶅鐢熸垚鏉$爜
+ boolean arrivalHandled = false;
while (true) {
if (Thread.currentThread().isInterrupted()) {
@@ -143,11 +147,21 @@
StationCommand command = commandQueue.poll(100, TimeUnit.MILLISECONDS);
if (command != null) {
taskLastUpdateTime.put(taskNo, System.currentTimeMillis());
+ List<Integer> newPath = command.getNavigatePath();
+ Integer lastInQueue = getLastInQueue(pendingPathQueue);
+ int startIndex = getPathAppendStartIndex(newPath, currentStationId, lastInQueue);
+
+ if (newPath != null && !newPath.isEmpty() && startIndex < 0) {
+ News.info("[WCS Debug] 浠诲姟{}蹇界暐鏃犳硶琛旀帴鐨勬棫璺緞娈�: {}, 褰撳墠浣嶇疆: {}, 闃熷垪灏�: {}", taskNo,
+ newPath, currentStationId, lastInQueue);
+ continue;
+ }
// 姣忔鎺ユ敹鍛戒护閮藉埛鏂扮洰鏍囷紝閬垮厤娌跨敤鏃х洰鏍囧鑷寸姸鎬佹姈鍔�
Integer commandTargetStationId = command.getTargetStaNo();
if (commandTargetStationId != null) {
if (!commandTargetStationId.equals(finalTargetStationId)) {
+ arrivalHandled = false;
News.info("[WCS Debug] 浠诲姟{}鍒囨崲鐩爣: {} -> {}", taskNo, finalTargetStationId,
commandTargetStationId);
}
@@ -161,12 +175,7 @@
}
// 灏嗘柊璺緞杩藉姞鍒板緟鎵ц闃熷垪
- List<Integer> newPath = command.getNavigatePath();
if (newPath != null && !newPath.isEmpty()) {
- // 鑾峰彇闃熷垪涓渶鍚庝竴涓珯鐐癸紙鐢ㄤ簬琛旀帴鐐瑰幓閲嶏級
- Integer lastInQueue = getLastInQueue(pendingPathQueue);
- int startIndex = getPathAppendStartIndex(newPath, currentStationId, lastInQueue);
-
for (int i = startIndex; i < newPath.size(); i++) {
pendingPathQueue.offer(newPath.get(i));
}
@@ -232,6 +241,7 @@
currentStationId = nextStationId;
pendingPathQueue.poll();
stepExecuteTime = System.currentTimeMillis();
+ arrivalHandled = false;
News.info("[WCS Debug] 浠诲姟{}绉诲姩鍒扮珯鐐�: {}, 鍓╀綑闃熷垪: {}", taskNo, currentStationId,
pendingPathQueue.size());
sleep(1000); // 妯℃嫙绉诲姩鑰楁椂
@@ -240,7 +250,8 @@
if (!checkTaskNoInArea(taskNo)) {
boolean fakeAllowCheckBlock = getFakeAllowCheckBlock();
- if (fakeAllowCheckBlock && System.currentTimeMillis() - stepExecuteTime > 10000) {
+ if (fakeAllowCheckBlock
+ && System.currentTimeMillis() - stepExecuteTime > runBlockTimeoutMs) {
// 璁ゅ畾鍫靛
boolean result = runBlockStation(taskNo, currentStationId, currentDeviceNo, taskNo,
currentStationId);
@@ -261,18 +272,17 @@
// 璺緞闃熷垪涓虹┖锛岀瓑寰呮柊鐨勫垎娈靛懡浠�
if (currentStationId != null && finalTargetStationId != null
&& currentStationId.equals(finalTargetStationId)) {
- // 宸插埌杈剧洰鏍囷細绔嬪嵆娓呯┖褰撳墠闃熷垪骞剁粨鏉熸湰杞墽琛岋紝鍚庣画鏂板懡浠ら噸鏂板垱寤烘墽琛岀嚎绋�
- 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;
}
- commandQueue.clear();
- pendingPathQueue.clear();
- News.info("[WCS Debug] 浠诲姟{}鍒拌揪鐩爣鍚庢竻绌洪槦鍒楀苟缁撴潫锛岀瓑寰呭悗缁柊鍛戒护閲嶅惎", taskNo);
- break;
}
// 缁х画绛夊緟鏂扮殑鍒嗘鍛戒护
@@ -327,6 +337,11 @@
if (idx >= 0) {
return idx + 1;
}
+ return -1;
+ }
+
+ if (lastInQueue != null) {
+ return -1;
}
return 0;
@@ -384,6 +399,25 @@
return fakeAllowCheckBlock;
}
+ private long getFakeRunBlockTimeoutMs() {
+ long timeoutMs = DEFAULT_FAKE_RUN_BLOCK_TIMEOUT_MS;
+ Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+ if (systemConfigMapObj instanceof Map) {
+ Map<?, ?> systemConfigMap = (Map<?, ?>) systemConfigMapObj;
+ Object value = systemConfigMap.get("fakeRunBlockTimeoutMs");
+ if (value != null) {
+ try {
+ long parsed = Long.parseLong(String.valueOf(value).trim());
+ if (parsed > 0) {
+ timeoutMs = parsed;
+ }
+ } catch (Exception ignore) {
+ }
+ }
+ }
+ return timeoutMs;
+ }
+
@Override
public CommandResponse sendOriginCommand(String address, short[] data) {
return new CommandResponse(true, "鍘熷鍛戒护宸插彈鐞嗭紙寮傛鎵ц锛�");
@@ -411,6 +445,10 @@
}
if (command.getCommandType() == StationCommandType.WRITE_INFO) {
+ if (command.getBarcode() != null) {
+ updateStationBarcode(deviceNo, stationId, command.getBarcode());
+ return;
+ }
if (taskNo == 9998 && targetStationId == 0) {
// 鐢熸垚鍑哄簱绔欑偣浠跨湡鏁版嵁
generateFakeOutStationData(deviceNo, stationId);
@@ -466,6 +504,23 @@
}
}
+ private void updateStationBarcode(Integer deviceNo, Integer stationId, String barcode) {
+ List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
+ if (statusList == null) {
+ return;
+ }
+
+ ZyStationStatusEntity status = statusList.stream()
+ .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null);
+ if (status == null) {
+ return;
+ }
+
+ synchronized (status) {
+ status.setBarcode(barcode);
+ }
+ }
+
// segmentedPathCommand 鏂规硶宸插垹闄わ紝鍔熻兘宸叉暣鍚堝埌 runTaskLoop
private Integer getDeviceNoByStationId(Integer stationId) {
--
Gitblit v1.9.1