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 |   50 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/zy/core/utils/WmsOperateUtils.java b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
index 5d4c108..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);

--
Gitblit v1.9.1