zwl
2026-03-20 a5e0d72c0a71f795e56690879a560ce715fa6313
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入库响应,barcode={},stationId={},requestId={}", barcode, sourceStaNo, requestId);
                    return;
                }
                if (response != null) {
                    // 存储响应结果,设置60秒超时
                    redisUtil.set(responseKey, response, 60);
@@ -172,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();
    }
@@ -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("异步上报堆垛机DB110状态异常,crnNo={},indices={}", crnNo, JSON.toJSONString(indices), e);
        } finally {
            if (crnNo != null) {
                redisUtil.del(RedisKeyType.REPORT_CRN_DB110_STATUS_LIMIT.key + crnNo);
            }
        }
    }
    // 上报堆垛机DB110状态数据
    public void reportCrnDb110Status(Integer crnNo, List<Integer> indices) {
        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
@@ -453,6 +495,12 @@
                        News.info("请求WMS堆垛机状态上报接口成功!!!url:{};request:{};response:{}", 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堆垛机状态上报接口失败,接口返回Code异常!!!url:{};request:{};response:{}",
                                wmsUrl + wmsSystemCrnStatusUrl, JSON.toJSONString(locMast.getBarcode()), response);
                    }