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/thread/impl/ZyStationV5Thread.java | 142 ++++++++++++++++++++++++++++++++++++-----------
1 files changed, 108 insertions(+), 34 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java b/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java
index 212a2ec..d2d97e6 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java
@@ -28,9 +28,11 @@
import com.zy.core.model.Task;
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.StationProtocol;
+import com.zy.core.model.protocol.StationTaskBufferItem;
import com.zy.core.network.DeviceConnectPool;
import com.zy.core.network.ZyStationConnectDriver;
import com.zy.core.network.entity.ZyStationStatusEntity;
+import com.zy.core.service.StationTaskLoopService;
import com.zy.core.thread.impl.v5.StationV5SegmentExecutor;
import com.zy.core.trace.StationTaskTraceRegistry;
import com.zy.core.utils.DeviceLogRedisKeyBuilder;
@@ -59,7 +61,7 @@
private static final int RUN_BLOCK_REROUTE_STATE_EXPIRE_SECONDS = 60 * 60 * 24;
private static final int SHORT_PATH_REPEAT_AVOID_THRESHOLD = 2;
- private static final int LOOP_REPEAT_TRIGGER_COUNT = 2;
+ private static final int LOOP_REPEAT_TRIGGER_COUNT = 3;
private static final int LOCAL_LOOP_NEIGHBOR_HOP = 3;
private List<StationProtocol> statusList = new ArrayList<>();
@@ -170,6 +172,7 @@
stationProtocol.setEnableIn(statusEntity.isEnableIn());
stationProtocol.setWeight(statusEntity.getWeight());
stationProtocol.setTaskWriteIdx(statusEntity.getTaskWriteIdx());
+ stationProtocol.setTaskBufferItems(statusEntity.getTaskBufferItems());
}
if (!Cools.isEmpty(stationProtocol.getSystemWarning())) {
@@ -237,6 +240,16 @@
Integer stationId,
Integer targetStationId,
Integer palletSize) {
+ return getCommand(commandType, taskNo, stationId, targetStationId, palletSize, null);
+ }
+
+ @Override
+ public StationCommand getCommand(StationCommandType commandType,
+ Integer taskNo,
+ Integer stationId,
+ Integer targetStationId,
+ Integer palletSize,
+ Double pathLenFactor) {
StationCommand stationCommand = new StationCommand();
stationCommand.setTaskNo(taskNo);
stationCommand.setStationId(stationId);
@@ -245,7 +258,7 @@
stationCommand.setCommandType(commandType);
if (commandType == StationCommandType.MOVE && !stationId.equals(targetStationId)) {
- List<NavigateNode> nodes = calcPathNavigateNodes(taskNo, stationId, targetStationId);
+ List<NavigateNode> nodes = calcPathNavigateNodes(taskNo, stationId, targetStationId, pathLenFactor);
return fillMoveCommandPath(stationCommand, nodes, taskNo, stationId, targetStationId);
}
return stationCommand;
@@ -256,30 +269,40 @@
Integer stationId,
Integer targetStationId,
Integer palletSize) {
+ return getRunBlockRerouteCommand(taskNo, stationId, targetStationId, palletSize, null);
+ }
+
+ @Override
+ public synchronized StationCommand getRunBlockRerouteCommand(Integer taskNo,
+ Integer stationId,
+ Integer targetStationId,
+ Integer palletSize,
+ Double pathLenFactor) {
if (taskNo == null || taskNo <= 0 || stationId == null || targetStationId == null) {
return null;
}
if (Objects.equals(stationId, targetStationId)) {
- return getCommand(StationCommandType.MOVE, taskNo, stationId, targetStationId, palletSize);
+ return getCommand(StationCommandType.MOVE, taskNo, stationId, targetStationId, palletSize, pathLenFactor);
}
RunBlockRerouteState rerouteState = loadRunBlockRerouteState(taskNo, stationId);
- TaskLoopRerouteState taskLoopRerouteState = loadTaskLoopRerouteState(taskNo);
- LoopIdentity currentLoopIdentity = resolveStationLoopIdentity(stationId);
+ StationTaskLoopService taskLoopService = loadStationTaskLoopService();
+ StationTaskLoopService.LoopEvaluation loopEvaluation = taskLoopService == null
+ ? new StationTaskLoopService.LoopEvaluation(taskNo, stationId, StationTaskLoopService.LoopIdentitySnapshot.empty(), 0, 0, false)
+ : taskLoopService.evaluateLoop(taskNo, stationId, true);
log.info("杈撻�佺嚎鍫靛閲嶈鍒掔幆绾胯瘑鍒紝taskNo={}, stationId={}, scopeType={}, localStationCount={}, sourceLoopStationCount={}",
taskNo,
stationId,
- currentLoopIdentity.getScopeType(),
- currentLoopIdentity.getLocalStationCount(),
- currentLoopIdentity.getSourceLoopStationCount());
+ loopEvaluation.getLoopIdentity().getScopeType(),
+ loopEvaluation.getLoopIdentity().getLocalStationCount(),
+ loopEvaluation.getLoopIdentity().getSourceLoopStationCount());
rerouteState.setTaskNo(taskNo);
rerouteState.setBlockStationId(stationId);
rerouteState.setLastTargetStationId(targetStationId);
rerouteState.setPlanCount((rerouteState.getPlanCount() == null ? 0 : rerouteState.getPlanCount()) + 1);
rerouteState.setLastPlanTime(System.currentTimeMillis());
- taskLoopRerouteState.setTaskNo(taskNo);
- List<List<NavigateNode>> candidatePathList = calcCandidatePathNavigateNodes(taskNo, stationId, targetStationId);
+ List<List<NavigateNode>> candidatePathList = calcCandidatePathNavigateNodes(taskNo, stationId, targetStationId, pathLenFactor);
if (candidatePathList.isEmpty()) {
saveRunBlockRerouteState(rerouteState);
log.warn("杈撻�佺嚎鍫靛閲嶈鍒掑け璐ワ紝鍊欓�夎矾寰勪负绌猴紝taskNo={}, planCount={}, stationId={}, targetStationId={}",
@@ -289,8 +312,7 @@
StationCommand rerouteCommand = selectAvailableRerouteCommand(
rerouteState,
- taskLoopRerouteState,
- currentLoopIdentity,
+ loopEvaluation,
candidatePathList,
taskNo,
stationId,
@@ -303,8 +325,7 @@
rerouteState.resetIssuedRoutes();
rerouteCommand = selectAvailableRerouteCommand(
rerouteState,
- taskLoopRerouteState,
- currentLoopIdentity,
+ loopEvaluation,
candidatePathList,
taskNo,
stationId,
@@ -315,10 +336,9 @@
if (rerouteCommand != null) {
saveRunBlockRerouteState(rerouteState);
- touchTaskLoopRerouteState(taskLoopRerouteState, currentLoopIdentity);
- syncTaskTraceLoopAlert(taskNo, stationId, currentLoopIdentity,
- resolveCurrentLoopIssuedCount(taskLoopRerouteState, currentLoopIdentity));
- saveTaskLoopRerouteState(taskLoopRerouteState);
+ if (taskLoopService != null) {
+ taskLoopService.recordLoopIssue(loopEvaluation, "RUN_BLOCK_REROUTE");
+ }
log.info("杈撻�佺嚎鍫靛閲嶈鍒掗�変腑鍊欓�夎矾绾匡紝taskNo={}, planCount={}, stationId={}, targetStationId={}, route={}",
taskNo, rerouteState.getPlanCount(), stationId, targetStationId, JSON.toJSONString(rerouteCommand.getNavigatePath()));
return rerouteCommand;
@@ -335,6 +355,45 @@
}
@Override
+ public synchronized boolean clearPath(Integer taskNo) {
+ if (taskNo == null || taskNo <= 0) {
+ return false;
+ }
+ if (zyStationConnectDriver == null) {
+ return false;
+ }
+ List<StationProtocol> status = getStatus();
+ if (status == null || status.isEmpty()) {
+ return false;
+ }
+
+ boolean found = false;
+ boolean success = true;
+ for (StationProtocol stationProtocol : status) {
+ List<StationTaskBufferItem> taskBufferItems = stationProtocol == null ? null : stationProtocol.getTaskBufferItems();
+ if (taskBufferItems == null || taskBufferItems.isEmpty()) {
+ continue;
+ }
+ Integer stationId = stationProtocol.getStationId();
+ for (StationTaskBufferItem item : taskBufferItems) {
+ if (item == null || !Objects.equals(taskNo, item.getTaskNo())) {
+ continue;
+ }
+ found = true;
+ if (!zyStationConnectDriver.clearTaskBufferSlot(stationId, item.getSlotIdx())) {
+ success = false;
+ log.warn("杈撻�佺珯缂撳瓨鍖烘畫鐣欒矾寰勬竻鐞嗗け璐ャ�俿tationId={}, slotIdx={}, taskNo={}",
+ stationId, item.getSlotIdx(), item.getTaskNo());
+ continue;
+ }
+ item.setTaskNo(0);
+ item.setTargetStaNo(0);
+ }
+ }
+ return found && success;
+ }
+
+ @Override
public CommandResponse sendCommand(StationCommand command) {
CommandResponse commandResponse = null;
try {
@@ -343,6 +402,9 @@
e.printStackTrace();
} finally {
BasStationOptService optService = SpringUtils.getBean(BasStationOptService.class);
+ if (optService == null) {
+ return commandResponse;
+ }
List<ZyStationStatusEntity> statusListEntity = zyStationConnectDriver.getStatus();
ZyStationStatusEntity matched = null;
if (statusListEntity != null) {
@@ -365,12 +427,10 @@
null,
JSON.toJSONString(command),
JSON.toJSONString(matched),
- 1,
+ commandResponse != null && Boolean.TRUE.equals(commandResponse.getResult()) ? 1 : 0,
JSON.toJSONString(commandResponse)
);
- if (optService != null) {
- optService.save(basStationOpt);
- }
+ optService.save(basStationOpt);
}
return commandResponse;
}
@@ -385,22 +445,26 @@
return zyStationConnectDriver.readOriginCommand(address, length);
}
- private List<NavigateNode> calcPathNavigateNodes(Integer taskNo, Integer startStationId, Integer targetStationId) {
+ private List<NavigateNode> calcPathNavigateNodes(Integer taskNo,
+ Integer startStationId,
+ Integer targetStationId,
+ Double pathLenFactor) {
NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
if (navigateUtils == null) {
return new ArrayList<>();
}
- return navigateUtils.calcByStationId(startStationId, targetStationId, taskNo);
+ return navigateUtils.calcByStationId(startStationId, targetStationId, taskNo, pathLenFactor);
}
private List<List<NavigateNode>> calcCandidatePathNavigateNodes(Integer taskNo,
Integer startStationId,
- Integer targetStationId) {
+ Integer targetStationId,
+ Double pathLenFactor) {
NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
if (navigateUtils == null) {
return new ArrayList<>();
}
- return navigateUtils.calcCandidatePathByStationId(startStationId, targetStationId, taskNo);
+ return navigateUtils.calcCandidatePathByStationId(startStationId, targetStationId, taskNo, pathLenFactor);
}
private StationCommand buildMoveCommand(Integer taskNo,
@@ -455,8 +519,7 @@
}
private StationCommand selectAvailableRerouteCommand(RunBlockRerouteState rerouteState,
- TaskLoopRerouteState taskLoopRerouteState,
- LoopIdentity currentLoopIdentity,
+ StationTaskLoopService.LoopEvaluation loopEvaluation,
List<List<NavigateNode>> candidatePathList,
Integer taskNo,
Integer stationId,
@@ -467,7 +530,6 @@
}
Set<String> issuedRouteSignatureSet = rerouteState.getIssuedRouteSignatureSet();
- int currentLoopIssuedCount = resolveExpectedLoopIssuedCount(taskLoopRerouteState, currentLoopIdentity);
List<RerouteCandidateCommand> candidateCommandList = new ArrayList<>();
for (List<NavigateNode> candidatePath : candidatePathList) {
StationCommand rerouteCommand = buildMoveCommand(taskNo, stationId, targetStationId, palletSize, candidatePath);
@@ -483,9 +545,13 @@
candidateCommand.setRouteSignature(routeSignature);
candidateCommand.setPathLength(rerouteCommand.getNavigatePath().size());
candidateCommand.setIssuedCount(rerouteState.getRouteIssueCountMap().getOrDefault(routeSignature, 0));
- candidateCommand.setLoopFingerprint(currentLoopIdentity.getLoopFingerprint());
- candidateCommand.setLoopIssuedCount(currentLoopIssuedCount);
- candidateCommand.setCurrentLoopHitCount(countCurrentLoopStationHit(rerouteCommand.getNavigatePath(), currentLoopIdentity.getStationIdSet()));
+ candidateCommand.setLoopFingerprint(loopEvaluation.getLoopIdentity().getLoopFingerprint());
+ candidateCommand.setLoopIssuedCount(loopEvaluation.getExpectedLoopIssueCount());
+ candidateCommand.setLoopTriggered(loopEvaluation.isLargeLoopTriggered());
+ candidateCommand.setCurrentLoopHitCount(countCurrentLoopStationHit(
+ rerouteCommand.getNavigatePath(),
+ loopEvaluation.getLoopIdentity().getStationIdSet()
+ ));
candidateCommandList.add(candidateCommand);
}
if (candidateCommandList.isEmpty()) {
@@ -550,8 +616,7 @@
shortestPathOverused = true;
}
if (!Cools.isEmpty(candidateCommand.getLoopFingerprint())
- && candidateCommand.getLoopIssuedCount() != null
- && isLoopRepeatTriggered(candidateCommand.getLoopIssuedCount())) {
+ && Boolean.TRUE.equals(candidateCommand.getLoopTriggered())) {
currentLoopOverused = true;
}
}
@@ -784,6 +849,14 @@
builder.append(stationNo);
}
return builder.toString();
+ }
+
+ private StationTaskLoopService loadStationTaskLoopService() {
+ try {
+ return SpringUtils.getBean(StationTaskLoopService.class);
+ } catch (Exception ignore) {
+ return null;
+ }
}
private String buildRunBlockRerouteStateKey(Integer taskNo, Integer blockStationId) {
@@ -1161,6 +1234,7 @@
private Integer issuedCount;
private String loopFingerprint;
private Integer loopIssuedCount;
+ private Boolean loopTriggered;
private Integer currentLoopHitCount;
}
--
Gitblit v1.9.1