From 65fd58ba961fb0f9d6680361f9ba7ab1226dadb2 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期日, 22 三月 2026 15:43:12 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java |   90 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java b/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
index 52cc748..ee1b8f6 100644
--- a/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
@@ -64,6 +64,8 @@
     @Autowired
     private StationOperateProcessUtils stationOperateProcessUtils;
 
+    private static final String CRN_OUT_REQUIRE_STATION_OUT_ENABLE_CONFIG = "crnOutRequireStationOutEnable";
+
     public synchronized void crnIoExecute() {
         Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
         if (systemConfigMapObj != null) {
@@ -374,7 +376,7 @@
                     continue;
                 }
 
-                if (!stationProtocol.isOutEnable()) {
+                if (isRequireOutboundStationOutEnable() && !stationProtocol.isOutEnable()) {
                     News.taskInfo(wrkMast.getWrkNo(), "鏀捐揣绔欑偣:{} 娌℃湁鍙嚭淇″彿", stationObjModel.getStationId());
                     continue;
                 }
@@ -565,7 +567,7 @@
                 continue;
             }
 
-            if (!stationProtocol.isOutEnable()) {
+            if (isRequireOutboundStationOutEnable() && !stationProtocol.isOutEnable()) {
                 News.taskInfo(wrkMast.getWrkNo(), "鏀捐揣绔欑偣:{} 娌℃湁鍙嚭淇″彿", stationObjModel.getStationId());
                 continue;
             }
@@ -645,6 +647,24 @@
             return true;
         }
 
+        List<WrkMast> unfinishedBatchWrkMasts = listUnfinishedBatchWrkMasts(wrkMast.getBatch());
+        if (hasMissingBatchSeq(unfinishedBatchWrkMasts)) {
+            News.taskInfo(wrkMast.getWrkNo(), "鎵规:{} 瀛樺湪鏈厤缃壒娆″簭鍙风殑鏈畬鎴愪换鍔★紝鏆備笉鍏佽鍫嗗灈鏈哄嚭搴�", wrkMast.getBatch());
+            return false;
+        }
+
+        if (!isWithinBatchExecuteWindow(wrkMast, unfinishedBatchWrkMasts, batchRunningLimit)) {
+            Integer windowStartSeq = unfinishedBatchWrkMasts.get(0).getBatchSeq();
+            Integer windowEndSeq = unfinishedBatchWrkMasts.get(Math.min(batchRunningLimit, unfinishedBatchWrkMasts.size()) - 1).getBatchSeq();
+            News.taskInfo(wrkMast.getWrkNo(),
+                    "鎵规:{} 褰撳墠涓ユ牸鎵ц绐楀彛搴忓彿涓篬{}-{}]锛屽綋鍓嶅簭鍙�={}锛屾殏涓嶅厑璁稿爢鍨涙満鍑哄簱",
+                    wrkMast.getBatch(),
+                    windowStartSeq,
+                    windowEndSeq,
+                    wrkMast.getBatchSeq());
+            return false;
+        }
+
         long batchRunningCount = wrkMastService.count(new QueryWrapper<WrkMast>()
                 .eq("io_type", WrkIoType.OUT.id)
                 .eq("batch", wrkMast.getBatch())
@@ -658,6 +678,46 @@
         }
 
         return true;
+    }
+
+    private List<WrkMast> listUnfinishedBatchWrkMasts(String batch) {
+        if (Cools.isEmpty(batch)) {
+            return new ArrayList<>();
+        }
+        return wrkMastService.list(new QueryWrapper<WrkMast>()
+                .eq("io_type", WrkIoType.OUT.id)
+                .eq("batch", batch)
+                .notIn("wrk_sts",
+                        WrkStsType.COMPLETE_OUTBOUND.sts,
+                        WrkStsType.SETTLE_OUTBOUND.sts)
+                .orderByAsc("batch_seq")
+                .orderByAsc("wrk_no"));
+    }
+
+    private boolean hasMissingBatchSeq(List<WrkMast> wrkMasts) {
+        if (wrkMasts == null || wrkMasts.isEmpty()) {
+            return false;
+        }
+        for (WrkMast item : wrkMasts) {
+            if (item == null || Cools.isEmpty(item.getBatchSeq())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean isWithinBatchExecuteWindow(WrkMast wrkMast, List<WrkMast> unfinishedBatchWrkMasts, int batchRunningLimit) {
+        if (wrkMast == null || unfinishedBatchWrkMasts == null || unfinishedBatchWrkMasts.isEmpty()) {
+            return true;
+        }
+        int windowSize = Math.min(batchRunningLimit, unfinishedBatchWrkMasts.size());
+        for (int i = 0; i < windowSize; i++) {
+            WrkMast current = unfinishedBatchWrkMasts.get(i);
+            if (current != null && wrkMast.getWrkNo().equals(current.getWrkNo())) {
+                return true;
+            }
+        }
+        return false;
     }
 
     private boolean isOutboundStationTaskLimitReached() {
@@ -707,6 +767,32 @@
         }
     }
 
+    private boolean isRequireOutboundStationOutEnable() {
+        return getSystemConfigBoolean(CRN_OUT_REQUIRE_STATION_OUT_ENABLE_CONFIG, true);
+    }
+
+    private boolean getSystemConfigBoolean(String code, boolean defaultValue) {
+        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+        if (!(systemConfigMapObj instanceof Map)) {
+            return defaultValue;
+        }
+        try {
+            Object value = ((Map<?, ?>) systemConfigMapObj).get(code);
+            if (value == null) {
+                return defaultValue;
+            }
+            String text = String.valueOf(value).trim();
+            if ("Y".equalsIgnoreCase(text) || "true".equalsIgnoreCase(text) || "1".equals(text)) {
+                return true;
+            }
+            if ("N".equalsIgnoreCase(text) || "false".equalsIgnoreCase(text) || "0".equals(text)) {
+                return false;
+            }
+        } catch (Exception ignore) {
+        }
+        return defaultValue;
+    }
+
     private synchronized boolean crnExecuteLocTransfer(BasCrnp basCrnp, CrnThread crnThread) {
         CrnProtocol crnProtocol = crnThread.getStatus();
         if(crnProtocol == null){

--
Gitblit v1.9.1