From 9c094af56e63348c55adddeee00be696a0af78c4 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期六, 21 三月 2026 16:42:37 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java | 208 ++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 154 insertions(+), 54 deletions(-)
diff --git a/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java b/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
index 4c25c66..903d756 100644
--- a/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
@@ -8,10 +8,12 @@
import com.core.exception.CoolException;
import com.zy.asrs.domain.enums.NotifyMsgType;
import com.zy.asrs.domain.param.CreateLocMoveTaskParam;
+import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasCrnpService;
+import com.zy.asrs.service.BasStationService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.utils.NotifyUtils;
@@ -33,6 +35,8 @@
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.List;
@@ -47,6 +51,8 @@
private BasCrnpService basCrnpService;
@Autowired
private LocMastService locMastService;
+ @Autowired
+ private BasStationService basStationService;
@Autowired
private RedisUtil redisUtil;
@Autowired
@@ -73,23 +79,24 @@
//鍏ュ嚭搴� ===>> 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂
public synchronized void crnIoExecuteNormal() {
List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<>());
+ Map<Integer, BasCrnp> dispatchCrnMap = new HashMap<>();
+ Map<Integer, CrnThread> dispatchThreadMap = new HashMap<>();
+ Map<Integer, CrnProtocol> dispatchProtocolMap = new HashMap<>();
for (BasCrnp basCrnp : basCrnps) {
CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
- if(crnThread == null){
+ if (crnThread == null) {
continue;
}
CrnProtocol crnProtocol = crnThread.getStatus();
- if(crnProtocol == null){
+ if (crnProtocol == null) {
continue;
}
- List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>()
+ long runningCount = wrkMastService.count(new QueryWrapper<WrkMast>()
.eq("crn_no", basCrnp.getCrnNo())
- .in("wrk_sts", WrkStsType.INBOUND_RUN.sts, WrkStsType.OUTBOUND_RUN.sts, WrkStsType.LOC_MOVE_RUN.sts)
- .orderBy(true, false, "batch_seq")
- );
- if(!wrkMasts.isEmpty()){
+ .in("wrk_sts", WrkStsType.INBOUND_RUN.sts, WrkStsType.OUTBOUND_RUN.sts, WrkStsType.LOC_MOVE_RUN.sts));
+ if (runningCount > 0) {
continue;
}
@@ -105,47 +112,106 @@
if (clearLock != null) {
continue;
}
+ dispatchCrnMap.put(basCrnp.getCrnNo(), basCrnp);
+ dispatchThreadMap.put(basCrnp.getCrnNo(), crnThread);
+ dispatchProtocolMap.put(basCrnp.getCrnNo(), crnProtocol);
+ }
+ }
- // 濡傛灉鏈�杩戜竴娆℃槸鍏ュ簱妯″紡
- if (crnProtocol.getLastIo().equals("I")) {
- if (basCrnp.getInEnable().equals("Y")) {
- boolean result = this.crnExecuteIn(basCrnp, crnThread);// 鍏ュ簱
- crnProtocol.setLastIo("O");
- if (result) {
- break;
- }
- } else if (basCrnp.getOutEnable().equals("Y")) {
- boolean result = this.crnExecuteOut(basCrnp, crnThread);// 鍑哄簱
- crnProtocol.setLastIo("I");
- if (result) {
- break;
- }
- }
- }
- // 濡傛灉鏈�杩戜竴娆℃槸鍑哄簱妯″紡
- else if (crnProtocol.getLastIo().equals("O")) {
- if (basCrnp.getOutEnable().equals("Y")) {
- boolean result = this.crnExecuteOut(basCrnp, crnThread);// 鍑哄簱
- crnProtocol.setLastIo("I");
- if (result) {
- break;
- }
- } else if (basCrnp.getInEnable().equals("Y")) {
- boolean result = this.crnExecuteIn(basCrnp, crnThread);// 鍏ュ簱
- crnProtocol.setLastIo("O");
- if (result) {
- break;
- }
- }
- }
+ if (dispatchCrnMap.isEmpty()) {
+ return;
+ }
- //搴撲綅绉昏浆
- boolean transfer = this.crnExecuteLocTransfer(basCrnp, crnThread);
+ List<WrkMast> taskQueue = wrkMastService.list(new QueryWrapper<WrkMast>()
+ .in("crn_no", new ArrayList<>(dispatchCrnMap.keySet()))
+ .in("wrk_sts",
+ WrkStsType.INBOUND_DEVICE_RUN.sts,
+ WrkStsType.NEW_OUTBOUND.sts,
+ WrkStsType.NEW_LOC_MOVE.sts));
+ taskQueue.sort(Comparator
+ .comparingInt(this::resolveBatchOutboundRank)
+ .thenComparingInt(this::resolveBatchSeqOrder)
+ .thenComparingDouble(this::resolveTaskIoPri)
+ .thenComparingLong(this::resolveTaskQueueTime)
+ .thenComparingInt(this::resolveTaskQueueNo));
+
+ for (WrkMast wrkMast : taskQueue) {
+ if (wrkMast == null || wrkMast.getCrnNo() == null) {
+ continue;
+ }
+
+ Integer crnNo = wrkMast.getCrnNo();
+ BasCrnp basCrnp = dispatchCrnMap.get(crnNo);
+ CrnThread crnThread = dispatchThreadMap.get(crnNo);
+ CrnProtocol crnProtocol = dispatchProtocolMap.get(crnNo);
+ if (basCrnp == null || crnThread == null || crnProtocol == null) {
+ continue;
+ }
+
+ if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.INBOUND_DEVICE_RUN.sts) {
+ boolean result = this.crnExecuteInPlanner(basCrnp, crnThread, wrkMast);
+ if (result) {
+ crnProtocol.setLastIo("O");
+ return;
+ }
+ continue;
+ }
+
+ if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.NEW_OUTBOUND.sts) {
+ boolean result = this.crnExecuteOutPlanner(basCrnp, crnThread, wrkMast);
+ if (result) {
+ crnProtocol.setLastIo("I");
+ return;
+ }
+ continue;
+ }
+
+ if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.NEW_LOC_MOVE.sts) {
+ boolean transfer = this.crnExecuteMovePlanner(basCrnp, crnThread, wrkMast);
if (transfer) {
- break;
+ return;
}
}
}
+ }
+
+ private int resolveBatchOutboundRank(WrkMast wrkMast) {
+ return isBatchOutboundTask(wrkMast) ? 0 : 1;
+ }
+
+ private int resolveBatchSeqOrder(WrkMast wrkMast) {
+ if (!isBatchOutboundTask(wrkMast) || wrkMast.getBatchSeq() == null) {
+ return Integer.MAX_VALUE;
+ }
+ return wrkMast.getBatchSeq();
+ }
+
+ private double resolveTaskIoPri(WrkMast wrkMast) {
+ if (wrkMast == null || wrkMast.getIoPri() == null) {
+ return Double.MAX_VALUE;
+ }
+ return wrkMast.getIoPri();
+ }
+
+ private long resolveTaskQueueTime(WrkMast wrkMast) {
+ if (wrkMast == null) {
+ return Long.MAX_VALUE;
+ }
+ Date queueTime = wrkMast.getAppeTime() != null ? wrkMast.getAppeTime() : wrkMast.getIoTime();
+ return queueTime == null ? Long.MAX_VALUE : queueTime.getTime();
+ }
+
+ private int resolveTaskQueueNo(WrkMast wrkMast) {
+ if (wrkMast == null || wrkMast.getWrkNo() == null) {
+ return Integer.MAX_VALUE;
+ }
+ return wrkMast.getWrkNo();
+ }
+
+ private boolean isBatchOutboundTask(WrkMast wrkMast) {
+ return wrkMast != null
+ && Integer.valueOf(WrkIoType.OUT.id).equals(wrkMast.getIoType())
+ && !Cools.isEmpty(wrkMast.getBatch());
}
private synchronized boolean crnExecuteIn(BasCrnp basCrnp, CrnThread crnThread) {
@@ -265,18 +331,7 @@
return false;
}
- int stationMaxTaskCount = 30;
- Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
- if (systemConfigMapObj != null) {
- try {
- HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
- stationMaxTaskCount = Integer.parseInt(systemConfigMap.getOrDefault("stationMaxTaskCountLimit", "30"));
- } catch (Exception ignore) {}
- }
-
- int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
- if (stationMaxTaskCount > 0 && currentStationTaskCount >= stationMaxTaskCount) {
- News.warn("杈撻�佺珯鐐逛换鍔℃暟閲忚揪鍒颁笂闄愶紝宸插仠姝换鍔′笅鍙戙�傚綋鍓嶄换鍔℃暟={}锛屼笂闄�={}", currentStationTaskCount, stationMaxTaskCount);
+ if (isOutboundStationTaskLimitReached()) {
return false;
}
@@ -289,6 +344,9 @@
);
for (WrkMast wrkMast : wrkMasts) {
+ if (isOutboundTargetStationTaskLimitReached(wrkMast)) {
+ continue;
+ }
if (!allowBatchOutboundExecute(wrkMast)) {
continue;
}
@@ -469,7 +527,15 @@
return false;
}
+ if (isOutboundStationTaskLimitReached()) {
+ return false;
+ }
+
Integer crnNo = basCrnp.getCrnNo();
+
+ if (isOutboundTargetStationTaskLimitReached(wrkMast)) {
+ return false;
+ }
if (!allowBatchOutboundExecute(wrkMast)) {
return false;
@@ -594,6 +660,40 @@
return true;
}
+ private boolean isOutboundStationTaskLimitReached() {
+ int stationMaxTaskCount = getSystemConfigInt("stationMaxTaskCountLimit", 30);
+ if (stationMaxTaskCount <= 0) {
+ return false;
+ }
+
+ int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
+ if (currentStationTaskCount >= stationMaxTaskCount) {
+ News.warn("杈撻�佺珯鐐逛换鍔℃暟閲忚揪鍒颁笂闄愶紝宸插仠姝换鍔′笅鍙戙�傚綋鍓嶄换鍔℃暟={}锛屼笂闄�={}", currentStationTaskCount, stationMaxTaskCount);
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isOutboundTargetStationTaskLimitReached(WrkMast wrkMast) {
+ if (wrkMast == null || wrkMast.getStaNo() == null) {
+ return false;
+ }
+ BasStation basStation = basStationService.getById(wrkMast.getStaNo());
+ if (basStation == null || basStation.getOutTaskLimit() == null || basStation.getOutTaskLimit() < 0) {
+ return false;
+ }
+ int currentStationTaskCount = stationOperateProcessUtils.getCurrentOutboundTaskCountByTargetStation(wrkMast.getStaNo());
+ if (currentStationTaskCount >= basStation.getOutTaskLimit()) {
+ News.taskInfo(wrkMast.getWrkNo(),
+ "鐩爣鍑哄簱绔�:{} 宸茶揪鍑哄簱浠诲姟涓婇檺锛屽綋鍓�={}锛屼笂闄�={}",
+ wrkMast.getStaNo(),
+ currentStationTaskCount,
+ basStation.getOutTaskLimit());
+ return true;
+ }
+ return false;
+ }
+
private int getSystemConfigInt(String code, int defaultValue) {
Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
if (systemConfigMapObj == null) {
--
Gitblit v1.9.1