From cc5b5daacf92ac5601370c50463237b34b7ba78f Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 02 四月 2026 18:57:54 +0800
Subject: [PATCH] #预调度堆垛机2
---
src/main/java/com/zy/asrs/task/InboundCrnMoveDispatchScheduler.java | 112 +++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 78 insertions(+), 34 deletions(-)
diff --git a/src/main/java/com/zy/asrs/task/InboundCrnMoveDispatchScheduler.java b/src/main/java/com/zy/asrs/task/InboundCrnMoveDispatchScheduler.java
index f2e7139..fcb9863 100644
--- a/src/main/java/com/zy/asrs/task/InboundCrnMoveDispatchScheduler.java
+++ b/src/main/java/com/zy/asrs/task/InboundCrnMoveDispatchScheduler.java
@@ -18,16 +18,19 @@
import com.zy.core.enums.WrkStsType;
import com.zy.core.model.StationObjModel;
import com.zy.core.model.protocol.StationProtocol;
-import com.zy.core.move.StationMoveCoordinator;
-import com.zy.core.move.StationMoveSession;
import com.zy.core.thread.StationThread;
import com.zy.core.utils.CrnOperateProcessUtils;
+import com.zy.common.utils.RedisUtil;
+import com.zy.core.enums.RedisKeyType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.stream.Collectors;
@Component
public class InboundCrnMoveDispatchScheduler {
@@ -37,20 +40,20 @@
private final CommonService commonService;
private final BasCrnpService basCrnpService;
private final CrnOperateProcessUtils crnOperateProcessUtils;
- private final StationMoveCoordinator stationMoveCoordinator;
+ private final RedisUtil redisUtil;
public InboundCrnMoveDispatchScheduler(WrkMastService wrkMastService,
BasStationService basStationService,
CommonService commonService,
BasCrnpService basCrnpService,
CrnOperateProcessUtils crnOperateProcessUtils,
- StationMoveCoordinator stationMoveCoordinator) {
+ RedisUtil redisUtil) {
this.wrkMastService = wrkMastService;
this.basStationService = basStationService;
this.commonService = commonService;
this.basCrnpService = basCrnpService;
this.crnOperateProcessUtils = crnOperateProcessUtils;
- this.stationMoveCoordinator = stationMoveCoordinator;
+ this.redisUtil = redisUtil;
}
@Scheduled(fixedDelay = 1000L)
@@ -108,25 +111,15 @@
return;
}
- // 鍚屽爢鍨涙満娌℃湁鏈畬鎴愬嚭搴撲换鍔℃椂锛屼紭鍏堢洿鎺ュ埌褰撳墠鍏ュ簱浠诲姟鍙栬揣浣嶇瓑寰呫��
- if (!hasPendingOutboundTask(crnNo)) {
+ // 鍚屽爢鍨涙満娌℃湁闇�瑕佸弬涓庡綋鍓嶈皟搴﹀垽鏂殑鍑哄簱浠诲姟鏃讹紝浼樺厛鐩存帴鍒板綋鍓嶅叆搴撲换鍔″彇璐т綅绛夊緟銆�
+ if (!hasBlockingOutboundTask(crnNo)) {
boolean dispatched = crnOperateProcessUtils.dispatchCrnMove(crnNo, inboundPickupLocNo);
if (dispatched) {
News.info("妫�娴嬪埌浠呮湁鍏ュ簱浠诲姟锛屽凡瑙﹀彂鍫嗗灈鏈虹洿鎺ョЩ鍔ㄥ埌鍏ュ簱浠诲姟鍙栬揣浣嶇瓑寰咃紝宸ヤ綔鍙�={}锛屽爢鍨涙満鍙�={}锛屽彇璐т綅={}",
wrkMast.getWrkNo(), crnNo, inboundPickupLocNo);
}
- return;
- }
-
- StationMoveSession session = stationMoveCoordinator == null ? null : stationMoveCoordinator.loadSession(wrkMast.getWrkNo());
- if (!isInboundCrnMoveDispatchWindow(wrkMast, session)) {
- return;
- }
-
- boolean dispatched = crnOperateProcessUtils.dispatchCrnMove(crnNo, inboundPickupLocNo);
- if (dispatched) {
- News.info("鍏ュ簱浠诲姟鍗冲皢鍒拌揪鍙栬揣浣嶏紝宸茶Е鍙戝爢鍨涙満棰勭Щ杞︼紝宸ヤ綔鍙�={}锛屽爢鍨涙満鍙�={}锛屽彇璐т綅={}",
- wrkMast.getWrkNo(), crnNo, inboundPickupLocNo);
+ } else {
+ News.taskInfo(wrkMast.getWrkNo(), "褰撳墠瀛樺湪闃诲鍏ュ簱棰勭Щ杞︾殑鍑哄簱浠诲姟锛屾殏涓嶈Е鍙戝爢鍨涙満棰勭Щ杞�");
}
}
@@ -146,11 +139,11 @@
return null;
}
- private boolean hasPendingOutboundTask(Integer crnNo) {
+ private boolean hasBlockingOutboundTask(Integer crnNo) {
if (crnNo == null) {
return false;
}
- return wrkMastService.count(new QueryWrapper<WrkMast>()
+ List<WrkMast> pendingOutboundTasks = wrkMastService.list(new QueryWrapper<WrkMast>()
.eq("crn_no", crnNo)
.eq("io_type", WrkIoType.OUT.id)
.in("wrk_sts",
@@ -159,27 +152,78 @@
WrkStsType.OUTBOUND_RUN_COMPLETE.sts,
WrkStsType.STATION_RUN.sts,
WrkStsType.STATION_RUN_COMPLETE.sts,
- WrkStsType.OUTBOUND_MANUAL.sts)) > 0;
+ WrkStsType.OUTBOUND_MANUAL.sts)
+ .orderByAsc("wrk_no"));
+ if (pendingOutboundTasks == null || pendingOutboundTasks.isEmpty()) {
+ return false;
+ }
+
+ // 闈炴壒娆′换鍔℃垨缂哄皯鎵规搴忓彿鐨勪换鍔′粛鎸夊師閫昏緫澶勭悊锛岄伩鍏嶆斁瀹藉埌鏃犳硶纭鎵ц椤哄簭鐨勫嚭搴撲换鍔°��
+ boolean hasNonBatchTask = pendingOutboundTasks.stream().anyMatch(task -> !isBatchTaskWithSeq(task));
+ if (hasNonBatchTask) {
+ return true;
+ }
+
+ return pendingOutboundTasks.stream()
+ .filter(this::isBatchTaskWithSeq)
+ .filter(task -> isWithinCurrentBatchExecuteWindow(task, pendingOutboundTasks))
+ .filter(this::isCrnMoveBlockingOutboundTask)
+ .findAny()
+ .isPresent();
}
- private boolean isInboundCrnMoveDispatchWindow(WrkMast wrkMast, StationMoveSession session) {
- if (wrkMast == null || session == null || !session.isActive() || wrkMast.getStaNo() == null) {
+ private boolean isBatchTaskWithSeq(WrkMast wrkMast) {
+ return wrkMast != null
+ && Objects.equals(wrkMast.getIoType(), WrkIoType.OUT.id)
+ && !Cools.isEmpty(wrkMast.getBatch())
+ && wrkMast.getBatchSeq() != null;
+ }
+
+ private boolean isCrnMoveBlockingOutboundTask(WrkMast wrkMast) {
+ if (wrkMast == null || wrkMast.getWrkSts() == null) {
return false;
}
- List<Integer> fullPathStationIds = session.getFullPathStationIds();
- Integer currentStationId = session.getCurrentStationId();
- if (fullPathStationIds == null || fullPathStationIds.isEmpty() || currentStationId == null) {
+ return Objects.equals(wrkMast.getWrkSts(), WrkStsType.NEW_OUTBOUND.sts)
+ || Objects.equals(wrkMast.getWrkSts(), WrkStsType.OUTBOUND_RUN.sts)
+ || Objects.equals(wrkMast.getWrkSts(), WrkStsType.OUTBOUND_MANUAL.sts);
+ }
+
+ private boolean isWithinCurrentBatchExecuteWindow(WrkMast wrkMast, List<WrkMast> pendingOutboundTasks) {
+ if (!isBatchTaskWithSeq(wrkMast) || pendingOutboundTasks == null || pendingOutboundTasks.isEmpty()) {
return false;
}
- int currentIndex = fullPathStationIds.lastIndexOf(currentStationId);
- if (currentIndex < 0 || currentIndex >= fullPathStationIds.size() - 1) {
+ int batchRunningLimit = getSystemConfigInt("crnOutBatchRunningLimit", 5);
+ if (batchRunningLimit <= 0) {
+ return true;
+ }
+ List<WrkMast> sameBatchTasks = pendingOutboundTasks.stream()
+ .filter(this::isBatchTaskWithSeq)
+ .filter(task -> Objects.equals(task.getBatch(), wrkMast.getBatch()))
+ .sorted(Comparator.comparing(WrkMast::getBatchSeq).thenComparing(WrkMast::getWrkNo))
+ .collect(Collectors.toList());
+ if (sameBatchTasks.isEmpty()) {
return false;
}
- int remainingStationCount = fullPathStationIds.size() - currentIndex - 1;
- if (remainingStationCount != 1) {
- return false;
+ int windowSize = Math.min(batchRunningLimit, sameBatchTasks.size());
+ for (int i = 0; i < windowSize; i++) {
+ WrkMast current = sameBatchTasks.get(i);
+ if (current != null && Objects.equals(current.getWrkNo(), wrkMast.getWrkNo())) {
+ return true;
+ }
}
- Integer nextStationId = fullPathStationIds.get(currentIndex + 1);
- return Objects.equals(nextStationId, wrkMast.getStaNo());
+ return false;
+ }
+
+ private int getSystemConfigInt(String code, int defaultValue) {
+ Object systemConfigMapObj = redisUtil == null ? null : redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+ if (!(systemConfigMapObj instanceof HashMap)) {
+ return defaultValue;
+ }
+ try {
+ HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+ return Integer.parseInt(systemConfigMap.getOrDefault(code, String.valueOf(defaultValue)));
+ } catch (Exception ignore) {
+ return defaultValue;
+ }
}
}
--
Gitblit v1.9.1