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/StationOperateProcessUtils.java |   74 ++++++++++++++++++++++---------------
 1 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
index fca1f0d..0f90d81 100644
--- a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -36,7 +36,7 @@
 @Component
 public class StationOperateProcessUtils {
     private static final int LOOP_LOAD_RESERVE_EXPIRE_SECONDS = 120;
-    private static final int OUT_ORDER_DISPATCH_LIMIT_SECONDS = 10;
+    private static final int OUT_ORDER_DISPATCH_LIMIT_SECONDS = 2;
     private static final int STATION_IDLE_RECOVER_SECONDS = 10;
     private static final int STATION_IDLE_RECOVER_LIMIT_SECONDS = 10;
     private static final int STATION_IDLE_TRACK_EXPIRE_SECONDS = 60 * 60;
@@ -312,39 +312,45 @@
             for (WrkMast wrkMast : wrkMasts) {
                 Integer wrkNo = wrkMast.getWrkNo();
                 Integer targetStaNo = wrkMast.getStaNo();
+                if (wrkNo == null || targetStaNo == null) {
+                    continue;
+                }
 
                 boolean complete = false;
+                Integer targetDeviceNo = null;
                 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 (stationProtocol.getTaskNo().equals(wrkNo)) {
-                    complete = true;
+                if (basStation != null) {
+                    targetDeviceNo = basStation.getDeviceNo();
+                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
+                    if (stationThread != null) {
+                        Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
+                        StationProtocol stationProtocol = statusMap.get(basStation.getStationId());
+                        if (stationProtocol != null && wrkNo.equals(stationProtocol.getTaskNo())) {
+                            complete = true;
+                        }
+                    }
                 }
 
                 if (complete) {
-                    wrkMast.setWrkSts(WrkStsType.STATION_RUN_COMPLETE.sts);
-                    wrkMast.setIoTime(new Date());
-                    wrkMastService.updateById(wrkMast);
-                    notifyUtils.notify(String.valueOf(SlaveType.Devp), basStation.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);
+                    completeStationRunTask(wrkMast, targetDeviceNo);
                 }
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
+    }
+
+    private void completeStationRunTask(WrkMast wrkMast, Integer deviceNo) {
+        if (wrkMast == null || wrkMast.getWrkNo() == null) {
+            return;
+        }
+        wrkMast.setWrkSts(WrkStsType.STATION_RUN_COMPLETE.sts);
+        wrkMast.setIoTime(new Date());
+        wrkMastService.updateById(wrkMast);
+        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);
     }
 
     // 妫�娴嬩换鍔¤浆瀹屾垚
@@ -580,6 +586,19 @@
         return countCurrentStationTask();
     }
 
+    public synchronized int getCurrentOutboundTaskCountByTargetStation(Integer stationId) {
+        if (stationId == null) {
+            return 0;
+        }
+        return (int) wrkMastService.count(new QueryWrapper<WrkMast>()
+                .eq("io_type", WrkIoType.OUT.id)
+                .eq("sta_no", stationId)
+                .in("wrk_sts",
+                        WrkStsType.OUTBOUND_RUN.sts,
+                        WrkStsType.OUTBOUND_RUN_COMPLETE.sts,
+                        WrkStsType.STATION_RUN.sts));
+    }
+
     // 妫�娴嬪嚭搴撴帓搴�
     public synchronized void checkStationOutOrder() {
         List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<BasDevp>());
@@ -753,11 +772,7 @@
         if (!Objects.equals(dispatchStationId, wrkMast.getStaNo())
                 && isCurrentOutOrderStation(currentStationId, outOrderStationIds)
                 && isWatchingCircleArrival(wrkMast.getWrkNo(), currentStationId)) {
-            Integer circleTarget = resolveNextCircleOrderTarget(currentStationId, outOrderStationIds);
-            if (circleTarget == null) {
-                return null;
-            }
-            return new OutOrderDispatchDecision(circleTarget, true);
+            return new OutOrderDispatchDecision(dispatchStationId, true);
         }
         return new OutOrderDispatchDecision(dispatchStationId, false);
     }
@@ -802,8 +817,7 @@
         if (seq == null) {
             toTarget = currentBatchSeq.equals(wrkMast.getBatchSeq());
         } else {
-            toTarget = Integer.valueOf(seq + 1).equals(wrkMast.getBatchSeq())
-                    && currentBatchSeq.equals(wrkMast.getBatchSeq());
+            toTarget = Integer.valueOf(seq + 1).equals(wrkMast.getBatchSeq());
         }
         if (toTarget) {
             if (hasReachableOutReleaseSlot(currentStationId, wrkMast.getStaNo())) {

--
Gitblit v1.9.1