From 9a8018c3fbc94f99d5d184c8cb1ef23d7366cea0 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 29 四月 2026 17:02:38 +0800
Subject: [PATCH] #堆垛机任务执行优先级修改
---
src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java | 159 ++++++++++++++++++++++++++++++----------------------
1 files changed, 92 insertions(+), 67 deletions(-)
diff --git a/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java b/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
index b4090f5..d53cf22 100644
--- a/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
@@ -37,15 +37,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
+import java.util.*;
@Component
public class CrnOperateProcessUtils {
@@ -74,13 +66,6 @@
private MainProcessTaskSubmitter mainProcessTaskSubmitter;
private static final String CRN_OUT_REQUIRE_STATION_OUT_ENABLE_CONFIG = "crnOutRequireStationOutEnable";
-
- public synchronized void crnIoExecute() {
- List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<>());
- for (BasCrnp basCrnp : basCrnps) {
- crnIoExecute(basCrnp);
- }
- }
public void crnIoExecute(BasCrnp basCrnp) {
if (basCrnp == null || basCrnp.getCrnNo() == null) {
@@ -156,10 +141,10 @@
WrkStsType.NEW_OUTBOUND.sts,
WrkStsType.NEW_LOC_MOVE.sts));
taskQueue.sort(Comparator.comparingInt((WrkMast wrkMast) -> resolveTaskTypeRank(wrkMast, lastIo))
- .thenComparingInt(this::resolveBatchOutboundRank)
- .thenComparingInt(this::resolveBatchSeqOrder)
.thenComparingDouble(this::resolveTaskIoPri)
.thenComparingLong(this::resolveTaskQueueTime)
+ .thenComparingInt(this::resolveBatchOutboundRank)
+ .thenComparingInt(this::resolveBatchSeqOrder)
.thenComparingInt(this::resolveTaskQueueNo));
for (WrkMast wrkMast : taskQueue) {
@@ -170,7 +155,7 @@
if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.INBOUND_STATION_RUN_COMPLETE.sts) {
boolean result = this.crnExecuteInPlanner(currentCrn, crnThread, wrkMast);
if (result) {
- crnProtocol.setLastIo("O");
+ crnProtocol.setLastIo("I");
return;
}
continue;
@@ -179,7 +164,7 @@
if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.NEW_OUTBOUND.sts) {
boolean result = this.crnExecuteOutPlanner(currentCrn, crnThread, wrkMast);
if (result) {
- crnProtocol.setLastIo("I");
+ crnProtocol.setLastIo("O");
return;
}
continue;
@@ -384,7 +369,7 @@
return false;
}
- if (isOutboundStationTaskLimitReached()) {
+ if (isConveyorStationTaskLimitReached()) {
return false;
}
@@ -395,6 +380,12 @@
}
if (!allowBatchOutboundExecute(wrkMast, true)) {
+ return false;
+ }
+
+ //妫�鏌ユ槸鍚︿负鍑哄簱妯″紡
+ if(!checkOutTargetStationIoMode(wrkMast)) {
+ News.taskInfo(wrkMast.getWrkNo(), "鍫嗗灈鏈�:{} 浠诲姟:{}绂佹鎵ц锛屽嚭搴撶珯:{} 涓嶅浜庡嚭搴撴ā寮�", basCrnp.getCrnNo(), wrkMast.getWrkNo(), wrkMast.getStaNo());
return false;
}
@@ -595,15 +586,17 @@
return false;
}
- private boolean isOutboundStationTaskLimitReached() {
- int stationMaxTaskCount = getSystemConfigInt("stationMaxTaskCountLimit", 30);
- if (stationMaxTaskCount <= 0) {
+ private boolean isConveyorStationTaskLimitReached() {
+ int conveyorStationTaskLimit = getSystemConfigInt("conveyorStationTaskLimit", 30);
+ if (conveyorStationTaskLimit <= 0) {
return false;
}
int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
- if (currentStationTaskCount >= stationMaxTaskCount) {
- News.warn("杈撻�佺珯鐐逛换鍔℃暟閲忚揪鍒颁笂闄愶紝宸插仠姝换鍔′笅鍙戙�傚綋鍓嶄换鍔℃暟={}锛屼笂闄�={}", currentStationTaskCount, stationMaxTaskCount);
+ if (currentStationTaskCount >= conveyorStationTaskLimit) {
+ News.warn("杈撻�佺珯鐐逛换鍔℃暟閲忚揪鍒颁笂闄愶紝宸插仠姝换鍔′笅鍙戙�傚綋鍓嶄换鍔℃暟={}锛屼笂闄�={}",
+ currentStationTaskCount,
+ conveyorStationTaskLimit);
return true;
}
return false;
@@ -625,6 +618,36 @@
currentStationTaskCount,
basStation.getOutTaskLimit());
return true;
+ }
+ return false;
+ }
+
+ //妫�鏌ユ槸鍚︿负鍑哄簱妯″紡
+ private boolean checkOutTargetStationIoMode(WrkMast wrkMast) {
+ if (wrkMast == null || wrkMast.getStaNo() == null) {
+ return false;
+ }
+ BasStation basStation = basStationService.getById(wrkMast.getStaNo());
+ if (basStation == null) {
+ return false;
+ }
+
+ StationThread targetStationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
+ if (targetStationThread == null) {
+ return false;
+ }
+
+ StationProtocol targetStationProtocol = targetStationThread.getStatusMap().get(wrkMast.getStaNo());
+ if (targetStationProtocol == null) {
+ return false;
+ }
+
+ if (targetStationProtocol.getIoMode() == null) {
+ return false;
+ }
+
+ if (targetStationProtocol.getIoMode() == 2) {
+ return true;//鍑哄簱妯″紡
}
return false;
}
@@ -668,14 +691,6 @@
return defaultValue;
}
- //鍫嗗灈鏈轰换鍔℃墽琛屽畬鎴�
- public synchronized void crnIoExecuteFinish() {
- List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<>());
- for (BasCrnp basCrnp : basCrnps) {
- crnIoExecuteFinish(basCrnp);
- }
- }
-
public void crnIoExecuteFinish(BasCrnp basCrnp) {
if (basCrnp == null || basCrnp.getCrnNo() == null) {
return;
@@ -705,43 +720,53 @@
return;
}
- Long updateWrkSts = null;
- Date now = new Date();
- if(wrkMast.getWrkSts() == WrkStsType.INBOUND_RUN.sts){
- updateWrkSts = WrkStsType.COMPLETE_INBOUND.sts;
- notifyUtils.notify(String.valueOf(SlaveType.Crn), crnProtocol.getCrnNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.CRN_IN_TASK_COMPLETE, null);
- }else if(wrkMast.getWrkSts() == WrkStsType.OUTBOUND_RUN.sts){
- updateWrkSts = WrkStsType.OUTBOUND_RUN_COMPLETE.sts;
- notifyUtils.notify(String.valueOf(SlaveType.Crn), crnProtocol.getCrnNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.CRN_OUT_TASK_COMPLETE, null);
- }else if(wrkMast.getWrkSts() == WrkStsType.LOC_MOVE_RUN.sts){
- updateWrkSts = WrkStsType.COMPLETE_LOC_MOVE.sts;
- notifyUtils.notify(String.valueOf(SlaveType.Crn), crnProtocol.getCrnNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.CRN_TRANSFER_TASK_COMPLETE, null);
- }else if(wrkMast.getWrkSts() == WrkStsType.CRN_MOVE_RUN.sts){
- updateWrkSts = WrkStsType.COMPLETE_CRN_MOVE.sts;
- }else{
- News.error("鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗗伐浣滅姸鎬佸紓甯搞�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
+ String ownerLockKey = RedisKeyType.CRN_IO_EXECUTE_FINISH_OWNER_LOCK.key + wrkMast.getWrkNo();
+ String ownerLockToken = UUID.randomUUID().toString();
+ if (!redisUtil.trySetStringIfAbsent(ownerLockKey, ownerLockToken, 10)) {
return;
}
+ try {
+ wrkMast = wrkMastService.selectByWorkNo(crnProtocol.getTaskNo());
+ if (wrkMast == null) {
+ News.error("鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗘湭鎵惧埌宸ヤ綔妗c�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
+ return;
+ }
- wrkMast.setWrkSts(updateWrkSts);
- wrkMast.setSystemMsg("");
- wrkMast.setIoTime(now);
- wrkMast.setModiTime(now);
- if (wrkMastService.updateById(wrkMast)) {
- wrkAnalysisService.markCraneComplete(wrkMast, now, updateWrkSts);
- CrnCommand resetCommand = crnThread.getResetCommand(crnProtocol.getTaskNo(), crnProtocol.getCrnNo());
- MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, resetCommand));
- News.info("鍫嗗灈鏈轰换鍔$姸鎬佹洿鏂版垚鍔燂紝鍫嗗灈鏈哄彿={}锛屽伐浣滃彿={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
+ Long currentWrkSts = wrkMast.getWrkSts();
+ Long updateWrkSts = null;
+ Date now = new Date();
+ if(currentWrkSts == WrkStsType.INBOUND_RUN.sts){
+ updateWrkSts = WrkStsType.COMPLETE_INBOUND.sts;
+ notifyUtils.notify(String.valueOf(SlaveType.Crn), crnProtocol.getCrnNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.CRN_IN_TASK_COMPLETE, null);
+ }else if(currentWrkSts == WrkStsType.OUTBOUND_RUN.sts){
+ updateWrkSts = WrkStsType.OUTBOUND_RUN_COMPLETE.sts;
+ notifyUtils.notify(String.valueOf(SlaveType.Crn), crnProtocol.getCrnNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.CRN_OUT_TASK_COMPLETE, null);
+ }else if(currentWrkSts == WrkStsType.LOC_MOVE_RUN.sts){
+ updateWrkSts = WrkStsType.COMPLETE_LOC_MOVE.sts;
+ notifyUtils.notify(String.valueOf(SlaveType.Crn), crnProtocol.getCrnNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.CRN_TRANSFER_TASK_COMPLETE, null);
+ }else if(currentWrkSts == WrkStsType.CRN_MOVE_RUN.sts){
+ updateWrkSts = WrkStsType.COMPLETE_CRN_MOVE.sts;
+ }else{
+ News.error("鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗗伐浣滅姸鎬佸紓甯搞�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
+ return;
+ }
+
+ if (wrkMastService.updateWrkStsByWrkNoAndCurrentWrkSts(wrkMast.getWrkNo(), updateWrkSts, currentWrkSts) > 0) {
+ wrkMast.setWrkSts(updateWrkSts);
+ wrkMast.setSystemMsg("");
+ wrkMast.setIoTime(now);
+ wrkMast.setModiTime(now);
+ wrkAnalysisService.markCraneComplete(wrkMast, now, updateWrkSts);
+ CrnCommand resetCommand = crnThread.getResetCommand(crnProtocol.getTaskNo(), crnProtocol.getCrnNo());
+ MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, resetCommand));
+ News.info("鍫嗗灈鏈轰换鍔$姸鎬佹洿鏂版垚鍔燂紝鍫嗗灈鏈哄彿={}锛屽伐浣滃彿={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
+ redisUtil.set(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo(), "lock",10);
+ } else {
+ News.info("鍫嗗灈鏈哄畬鎴愮‘璁よ烦杩囷紝浠诲姟鐘舵�佸凡鍙樺寲銆傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
+ }
+ } finally {
+ redisUtil.compareAndDelete(ownerLockKey, ownerLockToken);
}
-
- redisUtil.set(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo(), "lock",10);
- }
- }
-
- public synchronized void plannerExecute() {
- List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<>());
- for (BasCrnp basCrnp : basCrnps) {
- plannerExecute(basCrnp);
}
}
--
Gitblit v1.9.1