From cd04aa8b887e82ec664e42f0bc353c079be1d2c5 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 27 四月 2026 17:57:19 +0800
Subject: [PATCH] fix: filter auto tune out station limits

---
 src/main/java/com/zy/core/utils/StationOperateProcessUtils.java |  123 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
index ff51a4d..75e9350 100644
--- a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -1,16 +1,24 @@
 package com.zy.core.utils;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zy.asrs.entity.BasCrnp;
 import com.zy.asrs.entity.BasDevp;
 import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.utils.Utils;
 import com.zy.asrs.service.*;
+import com.zy.common.service.CommonService;
+import com.zy.common.utils.RedisUtil;
 import com.zy.core.News;
 import com.zy.core.cache.SlaveConnection;
+import com.zy.core.dispatch.StationCommandDispatcher;
+import com.zy.core.enums.RedisKeyType;
 import com.zy.core.enums.SlaveType;
+import com.zy.core.enums.StationCommandType;
 import com.zy.core.enums.WrkIoType;
 import com.zy.core.enums.WrkStsType;
 import com.zy.core.model.StationObjModel;
+import com.zy.core.model.command.StationCommand;
 import com.zy.core.model.protocol.StationProtocol;
 import com.zy.core.task.MainProcessLane;
 import com.zy.core.task.MainProcessTaskSubmitter;
@@ -30,6 +38,8 @@
 
 @Component
 public class StationOperateProcessUtils {
+    private static final String STATION_COMMAND_SOURCE = "station-operate-process";
+
     @Autowired
     private WrkMastService wrkMastService;
     @Autowired
@@ -52,10 +62,106 @@
     private StationOutboundDecisionSupport stationOutboundDecisionSupport;
     @Autowired
     private BasCrnpService basCrnpService;
+    @Autowired
+    private CommonService commonService;
+    @Autowired
+    private RedisUtil redisUtil;
+    @Autowired
+    private StationCommandDispatcher stationCommandDispatcher;
+
+    public void submitStationEnableInTasks(long minIntervalMs) {
+        submitStationEnableInTasks(MainProcessLane.STATION_ENABLE_IN, minIntervalMs);
+    }
+
+    public void submitStationEnableInTasks(MainProcessLane lane,
+                                           long minIntervalMs) {
+        List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>());
+        for (BasDevp basDevp : basDevps) {
+            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
+            if (stationThread == null) {
+                continue;
+            }
+            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
+            if (stationMap == null || stationMap.isEmpty()) {
+                continue;
+            }
+            for (StationObjModel stationObjModel : basDevp.getInStationList$()) {
+                Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId();
+                if (stationId == null || !stationMap.containsKey(stationId)) {
+                    continue;
+                }
+                mainProcessTaskSubmitter.submitKeyedSerialTask(
+                        lane,
+                        stationId,
+                        "stationEnableInExecute",
+                        minIntervalMs,
+                        () -> stationEnableInExecute(basDevp, stationObjModel)
+                );
+            }
+        }
+    }
 
     // 鎵ц鍗曚釜绔欑偣鐨勫叆搴撲换鍔′笅鍙�
     public void stationInExecute(BasDevp basDevp, StationObjModel stationObjModel) {
         stationRegularDispatchProcessor.stationInExecute(basDevp, stationObjModel);
+    }
+
+    // 鎵ц鍗曚釜绔欑偣鐨勫惎鍔ㄥ叆搴撲笅鍙�
+    public void stationEnableInExecute(BasDevp basDevp, StationObjModel stationObjModel) {
+        if (basDevp == null || stationObjModel == null || stationObjModel.getStationId() == null) {
+            return;
+        }
+
+        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
+        if (stationThread == null) {
+            return;
+        }
+
+        Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
+        if (stationMap == null || stationMap.isEmpty()) {
+            return;
+        }
+
+        Integer stationId = stationObjModel.getStationId();
+        if (!stationMap.containsKey(stationId)) {
+            return;
+        }
+
+        StationProtocol stationProtocol = stationMap.get(stationId);
+        if (stationProtocol == null) {
+            return;
+        }
+
+        Object lock = redisUtil.get(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId);
+        if (lock != null) {
+            return;
+        }
+
+        if (!stationProtocol.isAutoing()
+                || !stationProtocol.isLoading()
+                || stationProtocol.getTaskNo() != 0
+                || !stationProtocol.isEnableIn()) {
+            return;
+        }
+
+        Integer barcodeStationId = stationObjModel.getBarcodeStation() == null ? null : stationObjModel.getBarcodeStation().getStationId();
+        if (barcodeStationId == null) {
+            return;
+        }
+
+        StationCommand command = stationThread.getCommand(
+                StationCommandType.MOVE,
+                commonService.getWorkNo(WrkIoType.ENABLE_IN.id),
+                stationId,
+                barcodeStationId,
+                0
+        );
+        stationCommandDispatcher.dispatch(basDevp.getDevpNo(), command, STATION_COMMAND_SOURCE, "enable-in");
+        Utils.precomputeInTaskEnableRow(barcodeStationId);
+        redisUtil.set(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 15);
+        // 鍚姩鍏ュ簱鏃跺垹闄ら��鍥炴帶鍒秌ey锛屽厑璁稿悗缁紓甯告椂鍐嶆鐢熸垚閫�鍥炲懡浠�
+        redisUtil.del(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + barcodeStationId);
+        News.info("{}绔欑偣鍚姩鍏ュ簱鎴愬姛锛屾暟鎹寘:{}", stationId, JSON.toJSONString(command));
     }
 
     // 鎵ц鍗曚釜鍑哄簱浠诲姟瀵瑰簲鐨勮緭閫佺珯鐐逛笅鍙�
@@ -94,9 +200,24 @@
         if (wrkMast == null) {
             return;
         }
+        if (!Objects.equals(wrkMast.getStaNo(), stationObjModel.getStationId())) {
+            News.info("鍏ュ簱绔欑偣鍒拌揪鎵弿蹇界暐锛屽伐浣滃彿={}锛屾壂鎻忕珯鐐�={}锛屼换鍔$洰鏍囩珯={}锛屽師鍥�=target_mismatch",
+                    wrkMast.getWrkNo(), stationObjModel.getStationId(), wrkMast.getStaNo());
+            return;
+        }
+        if (!Objects.equals(wrkMast.getWrkSts(), WrkStsType.INBOUND_STATION_RUN.sts)) {
+            News.info("鍏ュ簱绔欑偣鍒拌揪鎵弿蹇界暐锛屽伐浣滃彿={}锛屾壂鎻忕珯鐐�={}锛屼换鍔$姸鎬�={}锛屽師鍥�=wrk_sts_mismatch",
+                    wrkMast.getWrkNo(), stationObjModel.getStationId(), wrkMast.getWrkSts());
+            return;
+        }
+        News.info("鍏ュ簱绔欑偣鍒拌揪鎵弿鍛戒腑锛屽伐浣滃彿={}锛屾壂鎻忕珯鐐�={}锛岀洰鏍囩珯={}锛岀珯鐐箃askNo={}锛屽噯澶囪浆鐘舵��3",
+                wrkMast.getWrkNo(), stationObjModel.getStationId(), wrkMast.getStaNo(), stationProtocol.getTaskNo());
         boolean updated = wrkAnalysisService.completeInboundStationRun(wrkMast, new Date());
         if (updated) {
-            News.info("鍏ュ簱绔欑偣鍒拌揪鎵弿鍛戒腑锛屽伐浣滃彿={}锛岀洰鏍囩珯={}", wrkMast.getWrkNo(), wrkMast.getStaNo());
+            News.info("鍏ュ簱绔欑偣鍒拌揪鎵弿瀹屾垚锛屽伐浣滃彿={}锛岀洰鏍囩珯={}锛岀粨鏋�=updated_to_3", wrkMast.getWrkNo(), wrkMast.getStaNo());
+        }
+        else {
+            News.info("鍏ュ簱绔欑偣鍒拌揪鎵弿缁撴潫锛屽伐浣滃彿={}锛岀洰鏍囩珯={}锛岀粨鏋�=skip_update", wrkMast.getWrkNo(), wrkMast.getStaNo());
         }
     }
 

--
Gitblit v1.9.1