From 63b01db83d9aad8a15276b4236a9a22e4aeef065 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 05 五月 2026 12:30:59 +0800
Subject: [PATCH] # Agent数据分析V3.0.1.7
---
src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java | 201 +++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 167 insertions(+), 34 deletions(-)
diff --git a/src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java b/src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java
index dddde68..45f4e22 100644
--- a/src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java
+++ b/src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java
@@ -37,6 +37,7 @@
import com.zy.core.utils.station.model.RerouteExecutionResult;
import com.zy.core.utils.station.model.RerouteSceneType;
import com.zy.core.utils.WmsOperateUtils;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -47,12 +48,18 @@
import java.util.Map;
import java.util.Objects;
+@Slf4j
@Component
public class StationRerouteProcessor {
private static final int OUT_ORDER_DISPATCH_LIMIT_SECONDS = 2;
private static final long STATION_MOVE_RESET_WAIT_MS = 1000L;
private static final int RUN_BLOCK_DIRECT_REASSIGN_LIMIT_SECONDS = 8 * 60;
private static final int RUN_BLOCK_DIRECT_REASSIGN_NEAREST_CACHE_SECONDS = 60 * 60 * 24;
+ private static final long CHECK_STATION_OUT_ORDER_SLOW_THRESHOLD_MS = 200L;
+ private static final long EXECUTE_REROUTE_PLAN_SLOW_THRESHOLD_MS = 200L;
+ private static final String RUN_BLOCK_DIRECT_REASSIGN_WMS_WARNING_PREFIX = "鍫靛閲嶅垎閰嶈姹俉MS澶辫触";
+ private static final String RUN_BLOCK_DIRECT_REASSIGN_WMS_WARNING =
+ RUN_BLOCK_DIRECT_REASSIGN_WMS_WARNING_PREFIX + "锛岃妫�鏌MS閲嶆柊鍒嗛厤搴撲綅鎺ュ彛";
@Autowired
private WrkMastService wrkMastService;
@@ -150,16 +157,19 @@
}
public void checkStationOutOrder(BasDevp basDevp, StationObjModel stationObjModel) {
+ long totalStartMs = System.currentTimeMillis();
try {
if (basDevp == null || basDevp.getDevpNo() == null || stationObjModel == null || stationObjModel.getStationId() == null) {
return;
}
+ long runtimeStartMs = System.currentTimeMillis();
StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
if (stationThread == null) {
return;
}
Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(stationObjModel.getStationId());
+ long runtimeCostMs = System.currentTimeMillis() - runtimeStartMs;
if (stationProtocol == null
|| !stationProtocol.isAutoing()
|| !stationProtocol.isLoading()
@@ -169,17 +179,25 @@
return;
}
+ long loadWrkStartMs = System.currentTimeMillis();
WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
+ long loadWrkCostMs = System.currentTimeMillis() - loadWrkStartMs;
if (wrkMast == null
|| !Objects.equals(wrkMast.getWrkSts(), WrkStsType.STATION_RUN.sts)
|| Objects.equals(stationProtocol.getStationId(), wrkMast.getStaNo())) {
return;
}
- if (stationOutboundDecisionSupport.shouldSkipOutOrderDispatchForExistingRoute(wrkMast.getWrkNo(), stationProtocol.getStationId())) {
+ long skipCheckStartMs = System.currentTimeMillis();
+ boolean skipForExistingRoute = stationOutboundDecisionSupport
+ .shouldSkipOutOrderDispatchForExistingRoute(wrkMast.getWrkNo(), stationProtocol.getStationId());
+ long skipCheckCostMs = System.currentTimeMillis() - skipCheckStartMs;
+ if (skipForExistingRoute) {
return;
}
+ long pathFactorStartMs = System.currentTimeMillis();
Double pathLenFactor = stationOutboundDecisionSupport.resolveOutboundPathLenFactor(wrkMast);
+ long pathFactorCostMs = System.currentTimeMillis() - pathFactorStartMs;
RerouteContext context = RerouteContext.create(
RerouteSceneType.OUT_ORDER,
basDevp,
@@ -193,7 +211,29 @@
.withSuppressDispatchGuard()
.withOutOrderDispatchLock()
.withResetSegmentCommandsBeforeDispatch();
- executeSharedReroute(context);
+ long rerouteStartMs = System.currentTimeMillis();
+ RerouteExecutionResult result = executeSharedReroute(context);
+ long rerouteCostMs = System.currentTimeMillis() - rerouteStartMs;
+ long totalCostMs = System.currentTimeMillis() - totalStartMs;
+ log.info("checkStationOutOrder profile, taskNo={}, stationId={}, deviceNo={}, batch={}, batchSeq={}, finalTargetStationId={}, pathLenFactor={}, runtimeCostMs={}ms, loadWrkCostMs={}ms, skipCheckCostMs={}ms, pathFactorCostMs={}ms, rerouteCostMs={}ms, totalCostMs={}ms, result={}",
+ stationProtocol.getTaskNo(),
+ stationProtocol.getStationId(),
+ stationObjModel.getDeviceNo(),
+ wrkMast.getBatch(),
+ wrkMast.getBatchSeq(),
+ wrkMast.getStaNo(),
+ pathLenFactor,
+ runtimeCostMs,
+ loadWrkCostMs,
+ skipCheckCostMs,
+ pathFactorCostMs,
+ rerouteCostMs,
+ totalCostMs,
+ result == null ? null : result.skipReason());
+ if (totalCostMs > CHECK_STATION_OUT_ORDER_SLOW_THRESHOLD_MS) {
+ log.warn("checkStationOutOrder slow, taskNo={}, stationId={}, totalCostMs={}ms, rerouteCostMs={}ms, loadWrkCostMs={}ms, pathFactorCostMs={}ms",
+ stationProtocol.getTaskNo(), stationProtocol.getStationId(), totalCostMs, rerouteCostMs, loadWrkCostMs, pathFactorCostMs);
+ }
} catch (Exception e) {
e.printStackTrace();
}
@@ -284,6 +324,7 @@
}
public RerouteDecision resolveSharedRerouteDecision(RerouteContext context) {
+ long startMs = System.currentTimeMillis();
if (context == null || context.wrkMast() == null || context.stationProtocol() == null) {
return RerouteDecision.skip("missing-runtime-dependency");
}
@@ -295,9 +336,13 @@
if (context.sceneType() == RerouteSceneType.IDLE_RECOVER
&& !Objects.equals(context.wrkMast().getWrkSts(), WrkStsType.STATION_RUN.sts)) {
Integer targetStationId = context.wrkMast().getStaNo();
- return targetStationId == null || Objects.equals(targetStationId, currentStationId)
+ RerouteDecision decision = targetStationId == null || Objects.equals(targetStationId, currentStationId)
? RerouteDecision.skip("same-station")
: RerouteDecision.proceed(targetStationId);
+ log.info("resolveSharedRerouteDecision profile, sceneType={}, taskNo={}, currentStationId={}, targetStationId={}, decision={}, decisionCostMs={}ms",
+ context.sceneType(), context.wrkMast().getWrkNo(), currentStationId, targetStationId,
+ decision.skip() ? decision.skipReason() : "proceed", System.currentTimeMillis() - startMs);
+ return decision;
}
OutOrderDispatchDecision dispatchDecision =
@@ -308,10 +353,15 @@
context.pathLenFactor()
);
Integer targetStationId = dispatchDecision == null ? null : dispatchDecision.getTargetStationId();
- if (targetStationId == null || Objects.equals(targetStationId, currentStationId)) {
- return RerouteDecision.skip("same-station");
- }
- return RerouteDecision.proceed(targetStationId, dispatchDecision);
+ RerouteDecision decision = targetStationId == null || Objects.equals(targetStationId, currentStationId)
+ ? RerouteDecision.skip("same-station")
+ : RerouteDecision.proceed(targetStationId, dispatchDecision);
+ log.info("resolveSharedRerouteDecision profile, sceneType={}, taskNo={}, currentStationId={}, targetStationId={}, decision={}, circle={}, decisionCostMs={}ms",
+ context.sceneType(), context.wrkMast().getWrkNo(), currentStationId, targetStationId,
+ decision.skip() ? decision.skipReason() : "proceed",
+ dispatchDecision != null && dispatchDecision.isCircle(),
+ System.currentTimeMillis() - startMs);
+ return decision;
}
public boolean shouldUseRunBlockDirectReassign(WrkMast wrkMast,
@@ -479,6 +529,7 @@
StationProtocol stationProtocol,
Integer taskNo,
Integer stationId) {
+ long startMs = System.currentTimeMillis();
boolean runBlockReroute = context.sceneType() == RerouteSceneType.RUN_BLOCK_REROUTE;
int currentTaskBufferCommandCount = countCurrentTaskBufferCommands(stationProtocol.getTaskBufferItems(), taskNo);
if (currentTaskBufferCommandCount > 0 && !runBlockReroute) {
@@ -490,37 +541,65 @@
taskNo,
currentTaskBufferCommandCount);
}
- if (!runBlockReroute
+ long suppressStartMs = System.currentTimeMillis();
+ boolean suppressDispatch = !runBlockReroute
&& context.checkSuppressDispatch()
&& stationMoveCoordinator != null
- && stationMoveCoordinator.shouldSuppressDispatch(taskNo, stationId, plan.command())) {
+ && stationMoveCoordinator.shouldSuppressDispatch(taskNo, stationId, plan.command());
+ long suppressCostMs = System.currentTimeMillis() - suppressStartMs;
+ if (suppressDispatch) {
return RerouteExecutionResult.skip("dispatch-suppressed");
}
- if (context.requireOutOrderDispatchLock()
- && !stationDispatchRuntimeStateSupport.tryAcquireOutOrderDispatchLock(taskNo, stationId, OUT_ORDER_DISPATCH_LIMIT_SECONDS)) {
+ long outOrderLockStartMs = System.currentTimeMillis();
+ boolean outOrderLockAcquired = !context.requireOutOrderDispatchLock()
+ || stationDispatchRuntimeStateSupport.tryAcquireOutOrderDispatchLock(taskNo, stationId, OUT_ORDER_DISPATCH_LIMIT_SECONDS);
+ long outOrderLockCostMs = System.currentTimeMillis() - outOrderLockStartMs;
+ if (!outOrderLockAcquired) {
return RerouteExecutionResult.skip("out-order-lock");
}
- if (!isBlank(context.executionLockKey())
- && !stationDispatchRuntimeStateSupport.tryAcquireLock(context.executionLockKey(), context.executionLockSeconds())) {
- return RerouteExecutionResult.skip("scene-lock");
+ long sceneLockStartMs = System.currentTimeMillis();
+ boolean sceneLockAcquired = isBlank(context.executionLockKey())
+ || stationDispatchRuntimeStateSupport.tryAcquireLock(context.executionLockKey(), context.executionLockSeconds());
+ long sceneLockCostMs = System.currentTimeMillis() - sceneLockStartMs;
+ if (!sceneLockAcquired) {
+ return RerouteExecutionResult.skip("scene-lock");
}
+ long resetCostMs = 0L;
if (context.resetSegmentCommandsBeforeDispatch()) {
+ long resetStartMs = System.currentTimeMillis();
stationDispatchRuntimeStateSupport.signalSegmentReset(taskNo, STATION_MOVE_RESET_WAIT_MS);
+ resetCostMs = System.currentTimeMillis() - resetStartMs;
}
int clearedCommandCount = 0;
+ long cancelSessionCostMs = 0L;
+ if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) {
+ long cancelSessionStartMs = System.currentTimeMillis();
+ stationMoveCoordinator.markCancelPending(taskNo, "reroute_pending");
+ stationMoveCoordinator.cancelSession(taskNo);
+ cancelSessionCostMs = System.currentTimeMillis() - cancelSessionStartMs;
+ }
+ long registerDispatchStartMs = System.currentTimeMillis();
+ preRegisterDispatchSession(context, plan);
+ long registerDispatchCostMs = System.currentTimeMillis() - registerDispatchStartMs;
+
+ long offerDispatchStartMs = System.currentTimeMillis();
boolean offered = offerDevpCommandWithDedup(context.dispatchDeviceNo(), plan.command(), plan.dispatchScene());
+ long offerDispatchCostMs = System.currentTimeMillis() - offerDispatchStartMs;
if (!offered) {
return RerouteExecutionResult.skip("dispatch-dedup");
}
- if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) {
- stationMoveCoordinator.markCancelPending(taskNo, "reroute_pending");
- stationMoveCoordinator.cancelSession(taskNo);
- }
applyRerouteDispatchEffects(context, plan, clearedCommandCount);
+ long totalCostMs = System.currentTimeMillis() - startMs;
+ log.info("executeReroutePlanWithTaskLock profile, sceneType={}, taskNo={}, stationId={}, suppressCostMs={}ms, outOrderLockCostMs={}ms, sceneLockCostMs={}ms, resetCostMs={}ms, cancelSessionCostMs={}ms, registerDispatchCostMs={}ms, offerDispatchCostMs={}ms, totalCostMs={}ms",
+ context.sceneType(), taskNo, stationId, suppressCostMs, outOrderLockCostMs, sceneLockCostMs, resetCostMs, cancelSessionCostMs, registerDispatchCostMs, offerDispatchCostMs, totalCostMs);
+ if (totalCostMs > EXECUTE_REROUTE_PLAN_SLOW_THRESHOLD_MS) {
+ log.warn("executeReroutePlanWithTaskLock slow, sceneType={}, taskNo={}, stationId={}, totalCostMs={}ms, resetCostMs={}ms, registerDispatchCostMs={}ms, offerDispatchCostMs={}ms",
+ context.sceneType(), taskNo, stationId, totalCostMs, resetCostMs, registerDispatchCostMs, offerDispatchCostMs);
+ }
return RerouteExecutionResult.dispatched(plan.command(), clearedCommandCount);
}
@@ -531,6 +610,24 @@
}
RerouteCommandPlan plan = buildRerouteCommandPlan(context, decision);
return executeReroutePlan(context, plan);
+ }
+
+ private void preRegisterDispatchSession(RerouteContext context, RerouteCommandPlan plan) {
+ if (context == null || plan == null || plan.command() == null || context.wrkMast() == null || context.stationProtocol() == null) {
+ return;
+ }
+ if (stationMoveCoordinator == null) {
+ return;
+ }
+ OutOrderDispatchDecision dispatchDecision =
+ plan.decision() == null ? null : plan.decision().dispatchDecision();
+ stationMoveCoordinator.recordDispatch(
+ context.wrkMast().getWrkNo(),
+ context.stationProtocol().getStationId(),
+ plan.dispatchScene(),
+ plan.command(),
+ dispatchDecision != null && dispatchDecision.isCircle()
+ );
}
private void applyRerouteDispatchEffects(RerouteContext context,
@@ -551,15 +648,6 @@
dispatchDecision,
plan.command()
);
- if (stationMoveCoordinator != null) {
- stationMoveCoordinator.recordDispatch(
- wrkMast.getWrkNo(),
- stationProtocol.getStationId(),
- plan.dispatchScene(),
- plan.command(),
- dispatchDecision != null && dispatchDecision.isCircle()
- );
- }
if (context.sceneType() == RerouteSceneType.RUN_BLOCK_REROUTE) {
News.info("杈撻�佺珯鐐瑰牭濉炲悗閲嶆柊璁$畻璺緞鍛戒护涓嬪彂鎴愬姛锛岀珯鐐瑰彿={}锛屽伐浣滃彿={}锛屽懡浠ゆ暟鎹�={}",
stationProtocol.getStationId(),
@@ -599,16 +687,31 @@
}
String response = wmsOperateUtils.applyReassignTaskLocNo(wrkMast.getWrkNo(), stationProtocol.getStationId());
if (Cools.isEmpty(response)) {
+ appendStationSystemWarning(stationProtocol, RUN_BLOCK_DIRECT_REASSIGN_WMS_WARNING);
News.taskError(wrkMast.getWrkNo(), "璇锋眰WMS閲嶆柊鍒嗛厤搴撲綅鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乺esponse锛歿}", response);
return;
}
- JSONObject jsonObject = JSON.parseObject(response);
- if (!jsonObject.getInteger("code").equals(200)) {
- News.error("璇锋眰WMS鎺ュ彛澶辫触锛侊紒锛乺esponse锛歿}", response);
+ JSONObject jsonObject;
+ try {
+ jsonObject = JSON.parseObject(response);
+ } catch (Exception e) {
+ appendStationSystemWarning(stationProtocol, RUN_BLOCK_DIRECT_REASSIGN_WMS_WARNING);
+ News.taskError(wrkMast.getWrkNo(), "璇锋眰WMS閲嶆柊鍒嗛厤搴撲綅鎺ュ彛鍝嶅簲瑙f瀽寮傚父锛侊紒锛乺esponse锛歿}", response, e);
+ return;
+ }
+ if (jsonObject == null || !Integer.valueOf(200).equals(jsonObject.getInteger("code"))) {
+ appendStationSystemWarning(stationProtocol, RUN_BLOCK_DIRECT_REASSIGN_WMS_WARNING);
+ News.taskError(wrkMast.getWrkNo(), "璇锋眰WMS鎺ュ彛澶辫触锛侊紒锛乺esponse锛歿}", response);
return;
}
StartupDto dto = jsonObject.getObject("data", StartupDto.class);
+ if (dto == null || Cools.isEmpty(dto.getLocNo())) {
+ appendStationSystemWarning(stationProtocol, RUN_BLOCK_DIRECT_REASSIGN_WMS_WARNING);
+ News.taskError(wrkMast.getWrkNo(), "璇锋眰WMS閲嶆柊鍒嗛厤搴撲綅鎺ュ彛澶辫触锛學MS鏈繑鍥炵洰鏍囧簱浣嶏紒锛侊紒response锛歿}", response);
+ return;
+ }
+ clearStationSystemWarningByPrefix(stationProtocol, RUN_BLOCK_DIRECT_REASSIGN_WMS_WARNING_PREFIX);
String sourceLocNo = wrkMast.getLocNo();
String locNo = dto.getLocNo();
@@ -678,10 +781,6 @@
stationProtocol.getStationId(),
RUN_BLOCK_DIRECT_REASSIGN_LIMIT_SECONDS);
stationDispatchRuntimeStateSupport.signalSegmentReset(wrkMast.getWrkNo(), STATION_MOVE_RESET_WAIT_MS);
- boolean offered = offerDevpCommandWithDedup(basDevp.getDevpNo(), command, "checkStationRunBlock_direct");
- if (!offered) {
- return;
- }
if (stationMoveCoordinator != null) {
stationMoveCoordinator.markCancelPending(wrkMast.getWrkNo(), "reroute_pending");
stationMoveCoordinator.cancelSession(wrkMast.getWrkNo());
@@ -693,6 +792,40 @@
false
);
}
+ boolean offered = offerDevpCommandWithDedup(basDevp.getDevpNo(), command, "checkStationRunBlock_direct");
+ if (!offered) {
+ News.warn("杈撻�佺珯鐐瑰牭濉炵洿娲惧懡浠ゅ叆闃熻鎷掔粷(鍙兘閲嶅)锛岀珯鐐瑰彿={}锛屽伐浣滃彿={}", stationProtocol.getStationId(), wrkMast.getWrkNo());
+ }
+ }
+
+ private void appendStationSystemWarning(StationProtocol stationProtocol, String warning) {
+ if (stationProtocol == null || Cools.isEmpty(warning)) {
+ return;
+ }
+ String currentWarning = stationProtocol.getSystemWarning();
+ if (Cools.isEmpty(currentWarning)) {
+ stationProtocol.setSystemWarning(warning);
+ return;
+ }
+ if (currentWarning.contains(warning)) {
+ return;
+ }
+ stationProtocol.setSystemWarning(currentWarning + ";" + warning);
+ }
+
+ private void clearStationSystemWarningByPrefix(StationProtocol stationProtocol, String warningPrefix) {
+ if (stationProtocol == null || Cools.isEmpty(warningPrefix) || Cools.isEmpty(stationProtocol.getSystemWarning())) {
+ return;
+ }
+ String[] warningParts = stationProtocol.getSystemWarning().split(";");
+ List<String> keepWarningList = new ArrayList<>();
+ for (String warningPart : warningParts) {
+ if (Cools.isEmpty(warningPart) || warningPart.startsWith(warningPrefix)) {
+ continue;
+ }
+ keepWarningList.add(warningPart);
+ }
+ stationProtocol.setSystemWarning(String.join(";", keepWarningList));
}
private int countCurrentTaskBufferCommands(List<StationTaskBufferItem> taskBufferItems, Integer currentTaskNo) {
--
Gitblit v1.9.1