From 3441d5d4e8f06a97768ef4aec76f1161a77a52fe Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 13 四月 2026 16:30:26 +0800
Subject: [PATCH] #入库退回检查封装

---
 src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java |   83 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java b/src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java
index 0939a56..ab90be5 100644
--- a/src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java
+++ b/src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java
@@ -6,7 +6,9 @@
 import com.core.common.Cools;
 import com.zy.asrs.domain.param.CreateInTaskParam;
 import com.zy.asrs.entity.BasDevp;
+import com.zy.asrs.entity.WrkLastno;
 import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.service.WrkLastnoService;
 import com.zy.asrs.service.WrkMastService;
 import com.zy.common.model.StartupDto;
 import com.zy.common.service.CommonService;
@@ -52,6 +54,8 @@
     private MainProcessTaskSubmitter mainProcessTaskSubmitter;
     @Autowired
     private StationCommandDispatcher stationCommandDispatcher;
+    @Autowired
+    private WrkLastnoService wrkLastnoService;
 
     /**
      * 淇濈暀褰撳墠鎸夌珯鐐� lane 骞跺彂鐨勮兘鍔涳紝鍚屾椂鐢ㄤ竴涓畝鍗曡鏁伴伩鍏嶅苟鍙戠敓鎴愭妸绔欑偣浠诲姟鏁伴《绌夸笂闄愩��
@@ -61,6 +65,11 @@
     public void generate(StoreInTaskPolicy policy, BasDevp basDevp, StationObjModel stationObjModel) {
         try {
             if (!policy.isEnabled()) {
+                return;
+            }
+
+            StoreInTaskContext earlyContext = buildContext(basDevp, stationObjModel);
+            if (earlyContext == null || !handleErrorStationBack(earlyContext)) {
                 return;
             }
 
@@ -179,6 +188,80 @@
         }
     }
 
+    private boolean handleErrorStationBack(StoreInTaskContext context) {
+        StationProtocol stationProtocol = context.getStationProtocol();
+        if (stationProtocol == null) {
+            return false;
+        }
+
+        if (!stationProtocol.isAutoing()) {
+            return false;
+        }
+
+        if (!stationProtocol.isLoading()) {
+            return false;
+        }
+
+        if (stationProtocol.getError() <= 0) {
+            return true;
+        }
+
+        if (!stationProtocol.isInBarcodeError()) {
+            return true;
+        }
+
+        WrkLastno stationBackTaskRange = wrkLastnoService.getById(WrkIoType.STATION_BACK.id);
+        Integer currentTaskNo = stationProtocol.getTaskNo();
+        if (currentTaskNo != null
+                && currentTaskNo > 0
+                && stationBackTaskRange != null
+                && stationBackTaskRange.getsNo() != null
+                && stationBackTaskRange.geteNo() != null
+                && currentTaskNo >= stationBackTaskRange.getsNo()
+                && currentTaskNo <= stationBackTaskRange.geteNo()) {
+            News.info("鏉$爜绔欏凡澶勪簬閫�鍥炲伐浣滃彿鑼冨洿锛岃烦杩囬噸澶嶇敓鎴愰��鍥炲懡浠ゃ�俿tationId={}锛宼askNo={}锛宺ange=[{}, {}]",
+                    stationProtocol.getStationId(),
+                    currentTaskNo,
+                    stationBackTaskRange.getsNo(),
+                    stationBackTaskRange.geteNo());
+            return false;
+        }
+
+        StationObjModel backStation = context.getStationObjModel().getBackStation();
+        if (backStation == null || backStation.getStationId() == null) {
+            News.warn("鏉$爜绔欓��鍥炲け璐ワ紝閫�鍥炵珯鏈厤缃�俤eviceNo={}锛宻tationId={}",
+                    context.getBasDevp() == null ? null : context.getBasDevp().getDevpNo(),
+                    stationProtocol.getStationId());
+            return false;
+        }
+
+        if (stationProtocol.getTaskNo() != null
+                && stationProtocol.getTaskNo() > 0
+                && backStation.getStationId().equals(stationProtocol.getTargetStaNo())) {
+            return false;
+        }
+
+        Object lock = redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getStationId());
+        if (lock != null) {
+            return false;
+        }
+
+        StationCommand command = context.getStationThread().getCommand(StationCommandType.MOVE,
+                commonService.getWorkNo(WrkIoType.STATION_BACK.id),
+                context.getStationObjModel().getStationId(),
+                backStation.getStationId(), 0);
+        if (command == null) {
+            News.taskInfo(stationProtocol.getTaskNo(), "{}宸ヤ綔,鑾峰彇杈撻�佺嚎鍛戒护澶辫触", stationProtocol.getTaskNo());
+            return false;
+        }
+        stationCommandDispatcher.dispatch(context.getBasDevp().getDevpNo(), command, "store-in-task", "station-back");
+        News.info("{}鎵爜绔欏紓甯革紝宸查��鍥炶嚦{},鏉$爜绔欑姸鎬侊細{}", stationProtocol.getTaskNo(),
+                backStation.getStationId(), JSON.toJSONString(stationProtocol));
+        redisUtil.set(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getStationId(),
+                "lock", 60 * 60);
+        return false;
+    }
+
     private StoreInTaskContext buildContext(BasDevp basDevp, StationObjModel stationObjModel) {
         if (basDevp == null || stationObjModel == null || stationObjModel.getStationId() == null) {
             return null;

--
Gitblit v1.9.1