From a5e0d72c0a71f795e56690879a560ce715fa6313 Mon Sep 17 00:00:00 2001
From: zwl <1051256694@qq.com>
Date: 星期五, 20 三月 2026 08:54:01 +0800
Subject: [PATCH] 入库口强制入库确认后还会退回一次,才可入库修复

---
 src/main/java/com/zy/core/utils/WmsOperateUtils.java |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/zy/core/utils/WmsOperateUtils.java b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
index 107733a..e28f5ce 100644
--- a/src/main/java/com/zy/core/utils/WmsOperateUtils.java
+++ b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
@@ -26,12 +26,14 @@
 import com.zy.system.entity.Config;
 import com.zy.system.service.ConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
 @Component
@@ -146,6 +148,7 @@
      */
     public void applyInTaskAsync(String barcode, Integer sourceStaNo, Integer locType1,Double weight) {
         String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + sourceStaNo;
+        String requestVersionKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST_VERSION.key + barcode + "_" + sourceStaNo;
         String responseKey = RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + barcode + "_" + sourceStaNo;
 
         // 妫�鏌ユ槸鍚﹀凡鏈夎姹傚湪杩涜涓�
@@ -154,13 +157,21 @@
             return; // 宸叉湁璇锋眰鍦ㄨ繘琛屼腑锛岃烦杩�
         }
 
-        // 鏍囪璇锋眰杩涜涓紝璁剧疆60绉掕秴鏃�
-        redisUtil.set(requestKey, "processing", 60);
+        String requestId = UUID.randomUUID().toString();
+        // 鏍囪璇锋眰杩涜涓紝璁板綍褰撳墠鏈�鏂拌姹傜増鏈紝鏃ц姹傛櫄鍒版椂涓嶅厑璁歌鐩栨柊缁撴灉
+        redisUtil.set(requestKey, requestId, 120);
+        redisUtil.set(requestVersionKey, requestId, 600);
+        redisUtil.del(responseKey);
 
         // 鎻愪氦寮傛浠诲姟
         new Thread(() -> {
             try {
                 String response = applyInTask(barcode, sourceStaNo, locType1,weight);
+                Object latestRequestVersion = redisUtil.get(requestVersionKey);
+                if (latestRequestVersion == null || !requestId.equals(latestRequestVersion.toString())) {
+                    News.info("蹇界暐杩囨湡寮傛WMS鍏ュ簱鍝嶅簲锛宐arcode={}锛宻tationId={}锛宺equestId={}", barcode, sourceStaNo, requestId);
+                    return;
+                }
                 if (response != null) {
                     // 瀛樺偍鍝嶅簲缁撴灉锛岃缃�60绉掕秴鏃�
                     redisUtil.set(responseKey, response, 60);
@@ -172,10 +183,16 @@
                 }
             } catch (Exception e) {
                 News.error("寮傛WMS鍏ュ簱璇锋眰寮傚父锛宐arcode={}锛宻tationId={}锛宔rror={},weight={}", barcode, sourceStaNo, e.getMessage(),weight);
-                redisUtil.set(responseKey, "ERROR:" + e.getMessage(), 10);
+                Object latestRequestVersion = redisUtil.get(requestVersionKey);
+                if (latestRequestVersion != null && requestId.equals(latestRequestVersion.toString())) {
+                    redisUtil.set(responseKey, "ERROR:" + e.getMessage(), 10);
+                }
             } finally {
                 // 娓呴櫎璇锋眰杩涜涓爣璁�
-                redisUtil.del(requestKey);
+                Object currentRequest = redisUtil.get(requestKey);
+                if (currentRequest != null && requestId.equals(currentRequest.toString())) {
+                    redisUtil.del(requestKey);
+                }
             }
         }).start();
     }
@@ -208,6 +225,15 @@
     public boolean isAsyncRequestInProgress(String barcode, Integer stationId) {
         String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + stationId;
         return redisUtil.get(requestKey) != null;
+    }
+
+    public void clearAsyncInTaskCache(String barcode, Integer stationId) {
+        String cacheSuffix = barcode + "_" + stationId;
+        redisUtil.del(
+                RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + cacheSuffix,
+                RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST_VERSION.key + cacheSuffix,
+                RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + cacheSuffix
+        );
     }
 
     // 鐢宠浠诲姟閲嶆柊鍒嗛厤搴撲綅
@@ -392,6 +418,22 @@
         return response;
     }
 
+    @Async
+    public void reportCrnDb110StatusAsync(Integer crnNo, List<Integer> indices) {
+        try {
+            if (crnNo == null || indices == null || indices.isEmpty()) {
+                return;
+            }
+            reportCrnDb110Status(crnNo, indices);
+        } catch (Exception e) {
+            News.error("寮傛涓婃姤鍫嗗灈鏈篋B110鐘舵�佸紓甯革紝crnNo={}锛宨ndices={}", crnNo, JSON.toJSONString(indices), e);
+        } finally {
+            if (crnNo != null) {
+                redisUtil.del(RedisKeyType.REPORT_CRN_DB110_STATUS_LIMIT.key + crnNo);
+            }
+        }
+    }
+
     // 涓婃姤鍫嗗灈鏈篋B110鐘舵�佹暟鎹�
     public void reportCrnDb110Status(Integer crnNo, List<Integer> indices) {
         Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
@@ -423,7 +465,7 @@
         String[] split = crnNo1.getArr().split(",");
         for (Integer idx : indices) {
             LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", split[idx]));
-            if (locMast == null||Cools.isEmpty(locMast.getBarcode())) {
+            if (locMast == null||Cools.isEmpty(locMast.getBarcode())||locMast.getLocSts().equals("O")) {
                 News.info("娌℃湁鏌ヨ鍒拌搴撲綅鎴栬�呮病鏈夋壘鍒拌搴撲綅瀵瑰簲鎵樼洏鐮� 锛歿}", split[idx]);
                 CrnCommand command = new CrnCommand();
                 command.setLocNo(locMast.getLocNo());
@@ -453,6 +495,12 @@
                         News.info("璇锋眰WMS鍫嗗灈鏈虹姸鎬佷笂鎶ユ帴鍙f垚鍔燂紒锛侊紒url锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemCrnStatusUrl,
                                 JSON.toJSONString(locMast.getBarcode()), response);
                     } else {
+                        result = 0;
+                        CrnCommand command = new CrnCommand();
+                        command.setLocNo(locMast.getLocNo());
+                        command.setIndex(idx);
+                        command.setValue((short)0);
+                        MessageQueue.offer(SlaveType.Crn, crnNo, new Task(5, command));
                         News.info("璇锋眰WMS鍫嗗灈鏈虹姸鎬佷笂鎶ユ帴鍙eけ璐ワ紝鎺ュ彛杩斿洖Code寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}",
                                 wmsUrl + wmsSystemCrnStatusUrl, JSON.toJSONString(locMast.getBarcode()), response);
                     }

--
Gitblit v1.9.1