#
Junjie
2026-01-15 34b2641f4a039d4e1dcf8f4a93dd7928616c4b11
src/main/java/com/zy/core/utils/WmsOperateUtils.java
@@ -52,11 +52,9 @@
    @Autowired
    private BasStationService basStationService;
    @Autowired
    private StationOperateProcessUtils stationOperateProcessUtils;
    @Autowired
    private RedisUtil redisUtil;
    //申请入库任务
    // 申请入库任务
    public synchronized String applyInTask(String barcode, Integer sourceStaNo, Integer locType1) {
        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
        if (systemConfigMapObj == null) {
@@ -72,19 +70,8 @@
        }
        String wmsSystemInUrl = systemConfigMap.get("wmsSystemInUrl");
        if(wmsSystemInUrl == null){
        if (wmsSystemInUrl == null) {
            News.error("未配置WMS入库接口地址,配置文件Code编码:wmsSystemInUrl");
            return null;
        }
        int conveyorStationTaskLimit = 30;
        String conveyorStationTaskLimitStr = systemConfigMap.get("conveyorStationTaskLimit");
        if(conveyorStationTaskLimitStr != null){
            conveyorStationTaskLimit = Integer.parseInt(conveyorStationTaskLimitStr);
        }
        int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
        if (currentStationTaskCount > conveyorStationTaskLimit) {
            News.error("输送站点任务已达到上限,上限值:{},站点任务数:{}", conveyorStationTaskLimit, currentStationTaskCount);
            return null;
        }
@@ -92,14 +79,15 @@
        String response = null;
        int result = 0;
        try {
            BasStation basStation = basStationService.selectOne(new EntityWrapper<BasStation>().eq("station_id", sourceStaNo));
            if(basStation == null){
            BasStation basStation = basStationService
                    .selectOne(new EntityWrapper<BasStation>().eq("station_id", sourceStaNo));
            if (basStation == null) {
                News.error("站点{}不存在", sourceStaNo);
                return null;
            }
            String stationNo = String.valueOf(sourceStaNo);
            if(!Cools.isEmpty(basStation.getStationAlias())){
            if (!Cools.isEmpty(basStation.getStationAlias())) {
                stationNo = basStation.getStationAlias();
            }
@@ -112,22 +100,26 @@
                    .setUri(wmsUrl)
                    .setPath(wmsSystemInUrl)
                    .setJson(JSON.toJSONString(requestParam))
                    .setTimeout(360, TimeUnit.SECONDS)
                    .setTimeout(30, TimeUnit.SECONDS)
                    .build()
                    .doPost();
            if (response != null) {
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.getInteger("code") == 200) {
                    result = 1;
                    News.info("请求WMS入库接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
                }else {
                    News.info("请求WMS入库接口失败,接口返回Code异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
                    News.info("请求WMS入库接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl,
                            JSON.toJSONString(requestParam), response);
                } else {
                    News.info("请求WMS入库接口失败,接口返回Code异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl,
                            JSON.toJSONString(requestParam), response);
                }
            }else {
                News.info("请求WMS入库接口失败,接口未响应!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
            } else {
                News.info("请求WMS入库接口失败,接口未响应!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl,
                        JSON.toJSONString(requestParam), response);
            }
        } catch (Exception e) {
            News.error("请求WMS入库接口异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response, e);
            News.error("请求WMS入库接口异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl,
                    JSON.toJSONString(requestParam), response, e);
        } finally {
            HttpRequestLog httpRequestLog = new HttpRequestLog();
            httpRequestLog.setName(wmsUrl + wmsSystemInUrl);
@@ -140,7 +132,81 @@
        return response;
    }
    //申请任务重新分配库位
    /**
     * 异步申请入库任务 - 非阻塞版本
     * 将请求提交到线程池异步执行,结果存储到Redis中
     *
     * @param barcode     托盘码
     * @param sourceStaNo 站点编号
     * @param locType1    托盘高度
     */
    public void applyInTaskAsync(String barcode, Integer sourceStaNo, Integer locType1) {
        String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + sourceStaNo;
        String responseKey = RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + barcode + "_" + sourceStaNo;
        // 检查是否已有请求在进行中
        Object existingRequest = redisUtil.get(requestKey);
        if (existingRequest != null) {
            return; // 已有请求在进行中,跳过
        }
        // 标记请求进行中,设置60秒超时
        redisUtil.set(requestKey, "processing", 60);
        // 提交异步任务
        new Thread(() -> {
            try {
                String response = applyInTask(barcode, sourceStaNo, locType1);
                if (response != null) {
                    // 存储响应结果,设置60秒超时
                    redisUtil.set(responseKey, response, 60);
                    News.info("异步WMS入库请求完成,barcode={},stationId={},response={}", barcode, sourceStaNo, response);
                } else {
                    // 请求失败,存储失败标记
                    redisUtil.set(responseKey, "FAILED", 10);
                    News.error("异步WMS入库请求失败,barcode={},stationId={}", barcode, sourceStaNo);
                }
            } catch (Exception e) {
                News.error("异步WMS入库请求异常,barcode={},stationId={},error={}", barcode, sourceStaNo, e.getMessage());
                redisUtil.set(responseKey, "ERROR:" + e.getMessage(), 10);
            } finally {
                // 清除请求进行中标记
                redisUtil.del(requestKey);
            }
        }).start();
    }
    /**
     * 查询异步入库任务请求结果
     *
     * @param barcode   托盘码
     * @param stationId 站点编号
     * @return 响应结果,null表示还未完成或未找到
     */
    public String queryAsyncInTaskResponse(String barcode, Integer stationId) {
        String responseKey = RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + barcode + "_" + stationId;
        Object response = redisUtil.get(responseKey);
        if (response != null) {
            // 获取后删除,避免重复处理
            redisUtil.del(responseKey);
            return response.toString();
        }
        return null;
    }
    /**
     * 检查是否有异步请求正在进行中
     *
     * @param barcode   托盘码
     * @param stationId 站点编号
     * @return true表示正在请求中
     */
    public boolean isAsyncRequestInProgress(String barcode, Integer stationId) {
        String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + stationId;
        return redisUtil.get(requestKey) != null;
    }
    // 申请任务重新分配库位
    public synchronized String applyReassignTaskLocNo(Integer taskNo, Integer stationId) {
        String wmsUrl = null;
        Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
@@ -154,7 +220,8 @@
        }
        String wmsSystemReassignInTaskUrl = null;
        Config wmsSystemReassignInTaskUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemReassignInTaskUrl"));
        Config wmsSystemReassignInTaskUrlConfig = configService
                .selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemReassignInTaskUrl"));
        if (wmsSystemReassignInTaskUrlConfig != null) {
            wmsSystemReassignInTaskUrl = wmsSystemReassignInTaskUrlConfig.getValue();
        }
@@ -190,22 +257,26 @@
                    .setUri(wmsUrl)
                    .setPath(wmsSystemReassignInTaskUrl)
                    .setJson(JSON.toJSONString(requestParam))
                    .setTimeout(360, TimeUnit.SECONDS)
                    .setTimeout(30, TimeUnit.SECONDS)
                    .build()
                    .doPost();
            if (response != null) {
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.getInteger("code") == 200) {
                    result = 1;
                    News.info("请求申请任务重新分配入库接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
                    News.info("请求申请任务重新分配入库接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemReassignInTaskUrl,
                            JSON.toJSONString(requestParam), response);
                } else {
                    News.info("请求申请任务重新分配入库接口失败,接口返回Code异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
                    News.info("请求申请任务重新分配入库接口失败,接口返回Code异常!!!url:{};request:{};response:{}",
                            wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
                }
            } else {
                News.info("请求申请任务重新分配入库接口失败,接口未响应!!!url:{};request:{};response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
                News.info("请求申请任务重新分配入库接口失败,接口未响应!!!url:{};request:{};response:{}", wmsUrl + wmsSystemReassignInTaskUrl,
                        JSON.toJSONString(requestParam), response);
            }
        } catch (Exception e) {
            News.error("请求申请任务重新分配入库接口异常!!!url:{};request:{}; response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response, e);
            News.error("请求申请任务重新分配入库接口异常!!!url:{};request:{}; response:{}", wmsUrl + wmsSystemReassignInTaskUrl,
                    JSON.toJSONString(requestParam), response, e);
        } finally {
            HttpRequestLog httpRequestLog = new HttpRequestLog();
            httpRequestLog.setName(wmsUrl + wmsSystemReassignInTaskUrl);
@@ -218,7 +289,7 @@
        return response;
    }
    //申请在库库位更换库位
    // 申请在库库位更换库位
    public synchronized String applyChangeLocNo(String locNo) {
        String wmsUrl = null;
        Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
@@ -232,12 +303,13 @@
        }
        String wmsSystemChangeLocNoUrl = null;
        Config wmsSystemChangeLocNoUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemChangeLocNoUrl"));
        Config wmsSystemChangeLocNoUrlConfig = configService
                .selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemChangeLocNoUrl"));
        if (wmsSystemChangeLocNoUrlConfig != null) {
            wmsSystemChangeLocNoUrl = wmsSystemChangeLocNoUrlConfig.getValue();
        }
        if(wmsSystemChangeLocNoUrl == null){
        if (wmsSystemChangeLocNoUrl == null) {
            News.error("未配置申请在库库位更换库位接口地址,配置文件Code编码:wmsSystemChangeLocNoUrl");
            return null;
        }
@@ -259,7 +331,8 @@
                crnRows.addAll(list);
            }
        } else if (findCrnNoResult.getCrnType().equals(SlaveType.DualCrn)) {
            BasDualCrnp basDualCrnp = basDualCrnpService.selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", crnNo));
            BasDualCrnp basDualCrnp = basDualCrnpService
                    .selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", crnNo));
            if (basDualCrnp == null) {
                return null;
            }
@@ -267,7 +340,7 @@
            for (List<Integer> list : rowList) {
                crnRows.addAll(list);
            }
        }else {
        } else {
            throw new CoolException("未知设备类型");
        }
@@ -282,7 +355,7 @@
                    .setUri(wmsUrl)
                    .setPath(wmsSystemChangeLocNoUrl)
                    .setJson(JSON.toJSONString(requestParam))
                    .setTimeout(360, TimeUnit.SECONDS)
                    .setTimeout(30, TimeUnit.SECONDS)
                    .build()
                    .doPost();
@@ -290,15 +363,19 @@
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.getInteger("code") == 200) {
                    result = 1;
                    News.info("请求WMS申请更换库位接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
                }else {
                    News.info("请求WMS申请更换库位接口失败,接口返回Code异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
                    News.info("请求WMS申请更换库位接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemChangeLocNoUrl,
                            JSON.toJSONString(requestParam), response);
                } else {
                    News.info("请求WMS申请更换库位接口失败,接口返回Code异常!!!url:{};request:{};response:{}",
                            wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
                }
            }else {
                News.info("请求WMS申请更换库位接口失败,接口未响应!!!url:{};request:{};response:{}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
            } else {
                News.info("请求WMS申请更换库位接口失败,接口未响应!!!url:{};request:{};response:{}", wmsUrl + wmsSystemChangeLocNoUrl,
                        JSON.toJSONString(requestParam), response);
            }
        } catch (Exception e) {
            News.error("请求WMS申请更换库位接口异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response, e);
            News.error("请求WMS申请更换库位接口异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemChangeLocNoUrl,
                    JSON.toJSONString(requestParam), response, e);
        } finally {
            HttpRequestLog httpRequestLog = new HttpRequestLog();
            httpRequestLog.setName(wmsUrl + wmsSystemChangeLocNoUrl);