From 44e258e4f5370a14e92e3c15bccd32e1e4d7280c Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 02 四月 2026 23:17:25 +0800
Subject: [PATCH] #路径清理
---
src/main/java/com/zy/core/utils/station/StationRegularDispatchProcessor.java | 353 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 178 insertions(+), 175 deletions(-)
diff --git a/src/main/java/com/zy/core/utils/station/StationRegularDispatchProcessor.java b/src/main/java/com/zy/core/utils/station/StationRegularDispatchProcessor.java
index f55f553..833d97a 100644
--- a/src/main/java/com/zy/core/utils/station/StationRegularDispatchProcessor.java
+++ b/src/main/java/com/zy/core/utils/station/StationRegularDispatchProcessor.java
@@ -65,100 +65,11 @@
public void stationInExecute() {
try {
- DispatchLimitConfig baseLimitConfig = stationDispatchLoadSupport.getDispatchLimitConfig(null, null);
- int[] currentStationTaskCountRef = new int[]{stationDispatchLoadSupport.countCurrentStationTask()};
- LoadGuardState loadGuardState = stationDispatchLoadSupport.buildLoadGuardState(baseLimitConfig);
-
List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>());
for (BasDevp basDevp : basDevps) {
- StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
- if (stationThread == null) {
- continue;
- }
-
- Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
List<StationObjModel> stationList = basDevp.getBarcodeStationList$();
for (StationObjModel entity : stationList) {
- Integer stationId = entity.getStationId();
- if (!stationMap.containsKey(stationId)) {
- continue;
- }
-
- StationProtocol stationProtocol = stationMap.get(stationId);
- if (stationProtocol == null) {
- continue;
- }
-
- Object lock = redisUtil.get(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId);
- if (lock != null) {
- continue;
- }
-
- if (!stationProtocol.isAutoing()
- || !stationProtocol.isLoading()
- || stationProtocol.getTaskNo() <= 0) {
- continue;
- }
-
- WrkMast wrkMast = wrkMastService.getOne(new QueryWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
- if (wrkMast == null || !Objects.equals(wrkMast.getWrkSts(), WrkStsType.NEW_INBOUND.sts)) {
- continue;
- }
-
- String locNo = wrkMast.getLocNo();
- FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
- if (findCrnNoResult == null) {
- News.taskInfo(wrkMast.getWrkNo(), "{}宸ヤ綔,鏈尮閰嶅埌鍫嗗灈鏈�", wrkMast.getWrkNo());
- continue;
- }
-
- Integer targetStationId = commonService.findInStationId(findCrnNoResult, stationId);
- if (targetStationId == null) {
- News.taskInfo(wrkMast.getWrkNo(), "{}绔欑偣,鎼滅储鍏ュ簱绔欑偣澶辫触", stationId);
- continue;
- }
-
- DispatchLimitConfig limitConfig = stationDispatchLoadSupport.getDispatchLimitConfig(stationProtocol.getStationId(), targetStationId);
- LoopHitResult loopHitResult = stationDispatchLoadSupport.findPathLoopHit(
- limitConfig,
- stationProtocol.getStationId(),
- targetStationId,
- loadGuardState
- );
- if (stationDispatchLoadSupport.isDispatchBlocked(limitConfig, currentStationTaskCountRef[0], loadGuardState, loopHitResult.isThroughLoop())) {
- continue;
- }
-
- StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationId, targetStationId, 0);
- if (command == null) {
- News.taskInfo(wrkMast.getWrkNo(), "{}宸ヤ綔,鑾峰彇杈撻�佺嚎鍛戒护澶辫触", wrkMast.getWrkNo());
- continue;
- }
-
- Date now = new Date();
- wrkMast.setWrkSts(WrkStsType.INBOUND_STATION_RUN.sts);
- wrkMast.setSourceStaNo(stationProtocol.getStationId());
- wrkMast.setStaNo(targetStationId);
- wrkMast.setSystemMsg("");
- wrkMast.setIoTime(now);
- wrkMast.setModiTime(now);
- if (wrkMastService.updateById(wrkMast)) {
- wrkAnalysisService.markInboundStationStart(wrkMast, now);
- boolean offered = offerDevpCommandWithDedup(basDevp.getDevpNo(), command, "stationInExecute");
- if (offered && stationMoveCoordinator != null) {
- stationMoveCoordinator.recordDispatch(
- wrkMast.getWrkNo(),
- stationProtocol.getStationId(),
- "stationInExecute",
- command,
- false
- );
- }
- News.info("杈撻�佺珯鐐瑰叆搴撳懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽伐浣滃彿={}锛屽懡浠ゆ暟鎹�={}", stationId, wrkMast.getWrkNo(), JSON.toJSONString(command));
- redisUtil.set(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId, "lock", 5);
- loadGuardState.reserveLoopTask(loopHitResult.getLoopNo());
- stationDispatchLoadSupport.saveLoopLoadReserve(wrkMast.getWrkNo(), loopHitResult);
- }
+ stationInExecute(basDevp, entity);
}
}
} catch (Exception e) {
@@ -166,41 +77,46 @@
}
}
- public void stationOutExecuteFinish() {
+ public void stationOutExecuteFinish(StationObjModel stationObjModel) {
try {
- List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN.sts));
- for (WrkMast wrkMast : wrkMasts) {
- Integer wrkNo = wrkMast.getWrkNo();
- Integer targetStaNo = wrkMast.getStaNo();
- if (wrkNo == null || targetStaNo == null) {
- continue;
- }
-
- boolean complete = false;
- Integer targetDeviceNo = null;
- StationThread stationThread = null;
- BasStation basStation = basStationService.getOne(new QueryWrapper<BasStation>().eq("station_id", targetStaNo));
- if (basStation != null) {
- targetDeviceNo = basStation.getDeviceNo();
- stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
- if (stationThread != null) {
- Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
- StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(basStation.getStationId());
- boolean arrived = stationProtocol != null && wrkNo.equals(stationProtocol.getTaskNo());
- if (arrived || stationThread.hasRecentArrival(basStation.getStationId(), wrkNo)) {
- complete = true;
- if (!arrived) {
- News.info("杈撻�佺珯鐐瑰嚭搴撳埌杈惧垽瀹氫娇鐢ㄦ渶杩戝埌绔欒ˉ鍋匡紝宸ヤ綔鍙�={}锛岀洰鏍囩珯={}", wrkNo, targetStaNo);
- }
- }
- }
- }
-
- if (complete) {
- attemptClearTaskPath(stationThread, wrkNo);
- completeStationRunTask(wrkMast, targetDeviceNo);
- }
+ if (stationObjModel == null) {
+ return;
}
+
+ StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
+ if (stationThread == null) {
+ return;
+ }
+ Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
+ StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(stationObjModel.getStationId());
+ if (stationProtocol == null) {
+ return;
+ }
+ if (stationProtocol.getTaskNo() <= 0) {
+ return;
+ }
+ WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
+ if (wrkMast == null) {
+ return;
+ }
+
+ if (!wrkMast.getWrkSts().equals(WrkStsType.STATION_RUN.sts)) {
+ return;
+ }
+ Integer wrkNo = wrkMast.getWrkNo();
+
+ if (stationMoveCoordinator != null) {
+ stationMoveCoordinator.finishSession(wrkMast.getWrkNo());
+ }
+ Date now = new Date();
+ wrkMast.setWrkSts(WrkStsType.STATION_RUN_COMPLETE.sts);
+ wrkMast.setIoTime(now);
+ wrkMast.setModiTime(now);
+ wrkMastService.updateById(wrkMast);
+ wrkAnalysisService.markOutboundStationComplete(wrkMast, now);
+ notifyUtils.notify(String.valueOf(SlaveType.Devp), stationObjModel.getDeviceNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.STATION_OUT_TASK_RUN_COMPLETE, null);
+ redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkMast.getWrkNo(), "lock", 60);
+ attemptClearTaskPath(stationThread, wrkNo);
} catch (Exception e) {
e.printStackTrace();
}
@@ -210,45 +126,56 @@
try {
List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN_COMPLETE.sts));
for (WrkMast wrkMast : wrkMasts) {
- Integer wrkNo = wrkMast.getWrkNo();
- Integer targetStaNo = wrkMast.getStaNo();
-
- Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkNo);
- if (lock != null) {
- continue;
- }
-
- BasStation basStation = basStationService.getOne(new QueryWrapper<BasStation>().eq("station_id", targetStaNo));
- if (basStation == null) {
- continue;
- }
-
- StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
- if (stationThread == null) {
- continue;
- }
-
- Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
- StationProtocol stationProtocol = statusMap.get(basStation.getStationId());
- if (stationProtocol == null) {
- continue;
- }
-
- if (!Objects.equals(stationProtocol.getTaskNo(), wrkNo)) {
- if (stationMoveCoordinator != null) {
- stationMoveCoordinator.finishSession(wrkNo);
- }
- wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts);
- wrkMast.setIoTime(new Date());
- wrkMastService.updateById(wrkMast);
- }
+ checkTaskToComplete(wrkMast);
}
} catch (Exception e) {
e.printStackTrace();
}
}
- private void attemptClearTaskPath(StationThread stationThread, Integer taskNo) {
+ public void checkTaskToComplete(WrkMast wrkMast) {
+ try {
+ if (wrkMast == null || wrkMast.getWrkNo() == null || wrkMast.getStaNo() == null) {
+ return;
+ }
+ Integer wrkNo = wrkMast.getWrkNo();
+ Integer targetStaNo = wrkMast.getStaNo();
+
+ Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkNo);
+ if (lock != null) {
+ return;
+ }
+
+ BasStation basStation = basStationService.getOne(new QueryWrapper<BasStation>().eq("station_id", targetStaNo));
+ if (basStation == null) {
+ return;
+ }
+
+ StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
+ if (stationThread == null) {
+ return;
+ }
+
+ Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
+ StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(basStation.getStationId());
+ if (stationProtocol == null) {
+ return;
+ }
+
+ if (!Objects.equals(stationProtocol.getTaskNo(), wrkNo)) {
+ if (stationMoveCoordinator != null) {
+ stationMoveCoordinator.finishSession(wrkNo);
+ }
+ wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts);
+ wrkMast.setIoTime(new Date());
+ wrkMastService.updateById(wrkMast);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void attemptClearTaskPath(StationThread stationThread, Integer taskNo) {
if (stationThread == null || taskNo == null || taskNo <= 0) {
return;
}
@@ -262,27 +189,103 @@
}
}
- private void completeStationRunTask(WrkMast wrkMast, Integer deviceNo) {
- if (wrkMast == null || wrkMast.getWrkNo() == null) {
- return;
- }
- if (stationMoveCoordinator != null) {
- stationMoveCoordinator.finishSession(wrkMast.getWrkNo());
- }
- Date now = new Date();
- wrkMast.setWrkSts(WrkStsType.STATION_RUN_COMPLETE.sts);
- wrkMast.setIoTime(now);
- wrkMast.setModiTime(now);
- wrkMastService.updateById(wrkMast);
- wrkAnalysisService.markOutboundStationComplete(wrkMast, now);
- if (deviceNo != null) {
- notifyUtils.notify(String.valueOf(SlaveType.Devp), deviceNo, String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.STATION_OUT_TASK_RUN_COMPLETE, null);
- }
- redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkMast.getWrkNo(), "lock", 60);
- }
-
private boolean offerDevpCommandWithDedup(Integer deviceNo, StationCommand command, String scene) {
StationCommandDispatchResult dispatchResult = stationCommandDispatcher.dispatch(deviceNo, command, "station-operate-process", scene);
return dispatchResult.isAccepted();
}
+
+ public void stationInExecute(BasDevp basDevp, StationObjModel entity) {
+ if (basDevp == null || basDevp.getDevpNo() == null || entity == null || entity.getStationId() == null) {
+ return;
+ }
+
+ Integer stationId = entity.getStationId();
+ StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
+ if (stationThread == null) {
+ return;
+ }
+
+ Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
+ if (stationMap == null || !stationMap.containsKey(stationId)) {
+ return;
+ }
+
+ StationProtocol stationProtocol = stationMap.get(stationId);
+ if (stationProtocol == null) {
+ return;
+ }
+
+ Object lock = redisUtil.get(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId);
+ if (lock != null) {
+ return;
+ }
+
+ if (!stationProtocol.isAutoing()
+ || !stationProtocol.isLoading()
+ || stationProtocol.getTaskNo() <= 0) {
+ return;
+ }
+
+ WrkMast wrkMast = wrkMastService.getOne(new QueryWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
+ if (wrkMast == null || !Objects.equals(wrkMast.getWrkSts(), WrkStsType.NEW_INBOUND.sts)) {
+ return;
+ }
+
+ String locNo = wrkMast.getLocNo();
+ FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
+ if (findCrnNoResult == null) {
+ News.taskInfo(wrkMast.getWrkNo(), "{}宸ヤ綔,鏈尮閰嶅埌鍫嗗灈鏈�", wrkMast.getWrkNo());
+ return;
+ }
+
+ Integer targetStationId = commonService.findInStationId(findCrnNoResult, stationId);
+ if (targetStationId == null) {
+ News.taskInfo(wrkMast.getWrkNo(), "{}绔欑偣,鎼滅储鍏ュ簱绔欑偣澶辫触", stationId);
+ return;
+ }
+
+ DispatchLimitConfig limitConfig = stationDispatchLoadSupport.getDispatchLimitConfig(stationProtocol.getStationId(), targetStationId);
+ int currentStationTaskCount = stationDispatchLoadSupport.countCurrentStationTask();
+ LoadGuardState loadGuardState = stationDispatchLoadSupport.buildLoadGuardState(limitConfig);
+ LoopHitResult loopHitResult = stationDispatchLoadSupport.findPathLoopHit(
+ limitConfig,
+ stationProtocol.getStationId(),
+ targetStationId,
+ loadGuardState
+ );
+ if (stationDispatchLoadSupport.isDispatchBlocked(limitConfig, currentStationTaskCount, loadGuardState, loopHitResult.isThroughLoop())) {
+ return;
+ }
+
+ StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationId, targetStationId, 0);
+ if (command == null) {
+ News.taskInfo(wrkMast.getWrkNo(), "{}宸ヤ綔,鑾峰彇杈撻�佺嚎鍛戒护澶辫触", wrkMast.getWrkNo());
+ return;
+ }
+
+ Date now = new Date();
+ wrkMast.setWrkSts(WrkStsType.INBOUND_STATION_RUN.sts);
+ wrkMast.setSourceStaNo(stationProtocol.getStationId());
+ wrkMast.setStaNo(targetStationId);
+ wrkMast.setSystemMsg("");
+ wrkMast.setIoTime(now);
+ wrkMast.setModiTime(now);
+ if (wrkMastService.updateById(wrkMast)) {
+ wrkAnalysisService.markInboundStationStart(wrkMast, now);
+ boolean offered = offerDevpCommandWithDedup(basDevp.getDevpNo(), command, "stationInExecute");
+ if (offered && stationMoveCoordinator != null) {
+ stationMoveCoordinator.recordDispatch(
+ wrkMast.getWrkNo(),
+ stationProtocol.getStationId(),
+ "stationInExecute",
+ command,
+ false
+ );
+ }
+ News.info("杈撻�佺珯鐐瑰叆搴撳懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽伐浣滃彿={}锛屽懡浠ゆ暟鎹�={}", stationId, wrkMast.getWrkNo(), JSON.toJSONString(command));
+ redisUtil.set(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId, "lock", 5);
+ loadGuardState.reserveLoopTask(loopHitResult.getLoopNo());
+ stationDispatchLoadSupport.saveLoopLoadReserve(wrkMast.getWrkNo(), loopHitResult);
+ }
+ }
}
--
Gitblit v1.9.1