From 9b8ff50b66361c4b56074b7586b2d5951ecf2091 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 02 四月 2026 15:02:14 +0800
Subject: [PATCH] #优化运行速度
---
src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java | 303 +++++++++++++++++++++++++++++++-------------------
1 files changed, 188 insertions(+), 115 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 42034af..9deba63 100644
--- a/src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java
+++ b/src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java
@@ -83,53 +83,76 @@
if (stationThread == null) {
continue;
}
-
- List<Integer> runBlockReassignLocStationList = new ArrayList<>();
- for (StationObjModel stationObjModel : basDevp.getRunBlockReassignLocStationList$()) {
- runBlockReassignLocStationList.add(stationObjModel.getStationId());
- }
- List<Integer> outOrderStationIds = basDevp.getOutOrderIntList();
-
for (StationProtocol stationProtocol : stationThread.getStatus()) {
- if (stationProtocol.isAutoing()
- && stationProtocol.isLoading()
- && stationProtocol.getTaskNo() > 0
- && stationProtocol.isRunBlock()) {
- WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
- if (wrkMast == null) {
- News.info("杈撻�佺珯鐐瑰彿={} 杩愯闃诲锛屼絾鏃犳硶鎵惧埌瀵瑰簲浠诲姟锛屽伐浣滃彿={}", stationProtocol.getStationId(), stationProtocol.getTaskNo());
- continue;
- }
-
- Object lock = redisUtil.get(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo());
- if (lock != null) {
- continue;
- }
- redisUtil.set(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo(), "lock", 15);
-
- if (shouldUseRunBlockDirectReassign(wrkMast, stationProtocol.getStationId(), runBlockReassignLocStationList)) {
- executeRunBlockDirectReassign(basDevp, stationThread, stationProtocol, wrkMast);
- continue;
- }
-
- Double pathLenFactor = stationOutboundDecisionSupport.resolveOutboundPathLenFactor(wrkMast);
- RerouteContext context = RerouteContext.create(
- RerouteSceneType.RUN_BLOCK_REROUTE,
- basDevp,
- stationThread,
- stationProtocol,
- wrkMast,
- outOrderStationIds,
- pathLenFactor,
- "checkStationRunBlock_reroute"
- ).withRunBlockCommand()
- .withSuppressDispatchGuard()
- .withCancelSessionBeforeDispatch()
- .withResetSegmentCommandsBeforeDispatch();
- executeSharedReroute(context);
+ if (stationProtocol == null || stationProtocol.getStationId() == null) {
+ continue;
}
+ checkStationRunBlock(basDevp, stationProtocol.getStationId());
}
}
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void checkStationRunBlock(BasDevp basDevp, Integer stationId) {
+ try {
+ if (basDevp == null || basDevp.getDevpNo() == null || stationId == null) {
+ return;
+ }
+ 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(stationId);
+ if (stationProtocol == null
+ || !stationProtocol.isAutoing()
+ || !stationProtocol.isLoading()
+ || stationProtocol.getTaskNo() <= 0
+ || !stationProtocol.isRunBlock()) {
+ return;
+ }
+
+ List<Integer> runBlockReassignLocStationList = new ArrayList<>();
+ for (StationObjModel stationObjModel : basDevp.getRunBlockReassignLocStationList$()) {
+ runBlockReassignLocStationList.add(stationObjModel.getStationId());
+ }
+ List<Integer> outOrderStationIds = basDevp.getOutOrderIntList();
+
+ WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
+ if (wrkMast == null) {
+ News.info("杈撻�佺珯鐐瑰彿={} 杩愯闃诲锛屼絾鏃犳硶鎵惧埌瀵瑰簲浠诲姟锛屽伐浣滃彿={}", stationProtocol.getStationId(), stationProtocol.getTaskNo());
+ return;
+ }
+
+ Object lock = redisUtil.get(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo());
+ if (lock != null) {
+ return;
+ }
+ redisUtil.set(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo(), "lock", 15);
+
+ if (shouldUseRunBlockDirectReassign(wrkMast, stationProtocol.getStationId(), runBlockReassignLocStationList)) {
+ executeRunBlockDirectReassign(basDevp, stationThread, stationProtocol, wrkMast);
+ return;
+ }
+
+ Double pathLenFactor = stationOutboundDecisionSupport.resolveOutboundPathLenFactor(wrkMast);
+ RerouteContext context = RerouteContext.create(
+ RerouteSceneType.RUN_BLOCK_REROUTE,
+ basDevp,
+ stationThread,
+ stationProtocol,
+ wrkMast,
+ outOrderStationIds,
+ pathLenFactor,
+ "checkStationRunBlock_reroute"
+ ).withRunBlockCommand()
+ .withSuppressDispatchGuard()
+ .withCancelSessionBeforeDispatch()
+ .withResetSegmentCommandsBeforeDispatch();
+ executeSharedReroute(context);
} catch (Exception e) {
e.printStackTrace();
}
@@ -145,11 +168,8 @@
}
for (StationProtocol stationProtocol : stationThread.getStatus()) {
- if (stationProtocol.isAutoing()
- && stationProtocol.isLoading()
- && stationProtocol.getTaskNo() > 0
- && !stationProtocol.isRunBlock()) {
- checkStationIdleRecover(basDevp, stationThread, stationProtocol, basDevp.getOutOrderIntList());
+ if (stationProtocol != null && stationProtocol.getStationId() != null) {
+ checkStationIdleRecover(basDevp, stationProtocol.getStationId());
}
}
}
@@ -158,53 +178,87 @@
}
}
+ public void checkStationIdleRecover(BasDevp basDevp, Integer stationId) {
+ try {
+ if (basDevp == null || basDevp.getDevpNo() == null || stationId == null) {
+ return;
+ }
+ 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(stationId);
+ if (stationProtocol == null
+ || !stationProtocol.isAutoing()
+ || !stationProtocol.isLoading()
+ || stationProtocol.getTaskNo() <= 0
+ || stationProtocol.isRunBlock()) {
+ return;
+ }
+ checkStationIdleRecover(basDevp, stationThread, stationProtocol, basDevp.getOutOrderIntList());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
public void checkStationOutOrder() {
List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<BasDevp>());
for (BasDevp basDevp : basDevps) {
+ List<StationObjModel> orderList = basDevp.getOutOrderList$();
+ for (StationObjModel stationObjModel : orderList) {
+ checkStationOutOrder(basDevp, stationObjModel);
+ }
+ }
+ }
+
+ public void checkStationOutOrder(BasDevp basDevp, StationObjModel stationObjModel) {
+ try {
+ if (basDevp == null || basDevp.getDevpNo() == null || stationObjModel == null || stationObjModel.getStationId() == null) {
+ return;
+ }
StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
if (stationThread == null) {
- continue;
+ return;
}
Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
- List<StationObjModel> orderList = basDevp.getOutOrderList$();
- List<Integer> outOrderStationIds = basDevp.getOutOrderIntList();
- for (StationObjModel stationObjModel : orderList) {
- StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId());
- if (stationProtocol == null
- || !stationProtocol.isAutoing()
- || !stationProtocol.isLoading()
- || stationProtocol.getTaskNo() <= 0
- || stationProtocol.isRunBlock()
- || !stationProtocol.getStationId().equals(stationProtocol.getTargetStaNo())) {
- continue;
- }
-
- WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
- if (wrkMast == null
- || !Objects.equals(wrkMast.getWrkSts(), WrkStsType.STATION_RUN.sts)
- || Objects.equals(stationProtocol.getStationId(), wrkMast.getStaNo())) {
- continue;
- }
- if (stationOutboundDecisionSupport.shouldSkipOutOrderDispatchForExistingRoute(wrkMast.getWrkNo(), stationProtocol.getStationId())) {
- continue;
- }
-
- Double pathLenFactor = stationOutboundDecisionSupport.resolveOutboundPathLenFactor(wrkMast);
- RerouteContext context = RerouteContext.create(
- RerouteSceneType.OUT_ORDER,
- basDevp,
- stationThread,
- stationProtocol,
- wrkMast,
- outOrderStationIds,
- pathLenFactor,
- "checkStationOutOrder"
- ).withDispatchDeviceNo(stationObjModel.getDeviceNo())
- .withSuppressDispatchGuard()
- .withOutOrderDispatchLock()
- .withResetSegmentCommandsBeforeDispatch();
- executeSharedReroute(context);
+ StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(stationObjModel.getStationId());
+ if (stationProtocol == null
+ || !stationProtocol.isAutoing()
+ || !stationProtocol.isLoading()
+ || stationProtocol.getTaskNo() <= 0
+ || stationProtocol.isRunBlock()
+ || !stationProtocol.getStationId().equals(stationProtocol.getTargetStaNo())) {
+ return;
}
+
+ WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
+ 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())) {
+ return;
+ }
+
+ Double pathLenFactor = stationOutboundDecisionSupport.resolveOutboundPathLenFactor(wrkMast);
+ RerouteContext context = RerouteContext.create(
+ RerouteSceneType.OUT_ORDER,
+ basDevp,
+ stationThread,
+ stationProtocol,
+ wrkMast,
+ basDevp.getOutOrderIntList(),
+ pathLenFactor,
+ "checkStationOutOrder"
+ ).withDispatchDeviceNo(stationObjModel.getDeviceNo())
+ .withSuppressDispatchGuard()
+ .withOutOrderDispatchLock()
+ .withResetSegmentCommandsBeforeDispatch();
+ executeSharedReroute(context);
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
@@ -215,41 +269,60 @@
if (stationThread == null) {
continue;
}
-
- List<Integer> outOrderList = basDevp.getOutOrderIntList();
for (StationProtocol stationProtocol : stationThread.getStatus()) {
- if (!stationProtocol.isAutoing()
- || !stationProtocol.isLoading()
- || stationProtocol.getTaskNo() <= 0
- || !stationOutboundDecisionSupport.isWatchingCircleArrival(stationProtocol.getTaskNo(), stationProtocol.getStationId())) {
+ if (stationProtocol == null || stationProtocol.getStationId() == null) {
continue;
}
-
- WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
- if (wrkMast == null
- || !Objects.equals(wrkMast.getWrkSts(), WrkStsType.STATION_RUN.sts)
- || Objects.equals(stationProtocol.getStationId(), wrkMast.getStaNo())) {
- continue;
- }
-
- Double pathLenFactor = stationOutboundDecisionSupport.resolveOutboundPathLenFactor(wrkMast);
- RerouteContext context = RerouteContext.create(
- RerouteSceneType.WATCH_CIRCLE,
- basDevp,
- stationThread,
- stationProtocol,
- wrkMast,
- outOrderList,
- pathLenFactor,
- "watchCircleStation"
- ).withSuppressDispatchGuard()
- .withOutOrderDispatchLock()
- .withResetSegmentCommandsBeforeDispatch();
- executeSharedReroute(context);
+ watchCircleStation(basDevp, stationProtocol.getStationId());
}
}
}
+ public void watchCircleStation(BasDevp basDevp, Integer stationId) {
+ try {
+ if (basDevp == null || basDevp.getDevpNo() == null || stationId == null) {
+ return;
+ }
+ 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(stationId);
+ if (stationProtocol == null
+ || !stationProtocol.isAutoing()
+ || !stationProtocol.isLoading()
+ || stationProtocol.getTaskNo() <= 0
+ || !stationOutboundDecisionSupport.isWatchingCircleArrival(stationProtocol.getTaskNo(), stationProtocol.getStationId())) {
+ return;
+ }
+
+ WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
+ if (wrkMast == null
+ || !Objects.equals(wrkMast.getWrkSts(), WrkStsType.STATION_RUN.sts)
+ || Objects.equals(stationProtocol.getStationId(), wrkMast.getStaNo())) {
+ return;
+ }
+
+ Double pathLenFactor = stationOutboundDecisionSupport.resolveOutboundPathLenFactor(wrkMast);
+ RerouteContext context = RerouteContext.create(
+ RerouteSceneType.WATCH_CIRCLE,
+ basDevp,
+ stationThread,
+ stationProtocol,
+ wrkMast,
+ basDevp.getOutOrderIntList(),
+ pathLenFactor,
+ "watchCircleStation"
+ ).withSuppressDispatchGuard()
+ .withOutOrderDispatchLock()
+ .withResetSegmentCommandsBeforeDispatch();
+ executeSharedReroute(context);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
public RerouteCommandPlan buildRerouteCommandPlan(RerouteContext context,
RerouteDecision decision) {
if (context == null) {
--
Gitblit v1.9.1