zwl
2026-03-20 a5e0d72c0a71f795e56690879a560ce715fa6313
入库口强制入库确认后还会退回一次,才可入库修复
3个文件已修改
35 ■■■■ 已修改文件
src/main/java/com/zy/core/enums/RedisKeyType.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/plugin/NormalProcess.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/utils/WmsOperateUtils.java 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/enums/RedisKeyType.java
@@ -52,6 +52,7 @@
    CURRENT_CIRCLE_TASK_CRN_NO("current_circle_task_crn_no_"),
    ASYNC_WMS_IN_TASK_REQUEST("async_wms_in_task_request_"),
    ASYNC_WMS_IN_TASK_REQUEST_VERSION("async_wms_in_task_request_version_"),
    ASYNC_WMS_IN_TASK_RESPONSE("async_wms_in_task_response_"),
    AI_CHAT_HISTORY("ai_chat_history_"),
    AI_CHAT_META("ai_chat_meta_"),
src/main/java/com/zy/core/plugin/NormalProcess.java
@@ -210,6 +210,7 @@
                                StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO,
                                        9991, 1015, 1013, 0);
                                MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                                wmsOperateUtils.clearAsyncInTaskCache(barcode, stationIdVal);
                                // 接口返回非200,重新发起请求
                                News.error("WMS入库接口返回非200,重新发起请求,barcode={},stationId={},response={}", barcode,
                                        stationIdVal, response);
src/main/java/com/zy/core/utils/WmsOperateUtils.java
@@ -33,6 +33,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Component
@@ -147,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;
        // 检查是否已有请求在进行中
@@ -155,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入库响应,barcode={},stationId={},requestId={}", barcode, sourceStaNo, requestId);
                    return;
                }
                if (response != null) {
                    // 存储响应结果,设置60秒超时
                    redisUtil.set(responseKey, response, 60);
@@ -173,10 +183,16 @@
                }
            } catch (Exception e) {
                News.error("异步WMS入库请求异常,barcode={},stationId={},error={},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();
    }
@@ -211,6 +227,15 @@
        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
        );
    }
    // 申请任务重新分配库位
    public synchronized String applyReassignTaskLocNo(Integer taskNo, Integer stationId) {
        String wmsUrl = null;