#
zwl
2026-02-09 ad79ba405b2d1ac96423f88f4e8a76c584b9d38a
src/main/java/com/zy/core/utils/WmsOperateUtils.java
@@ -5,24 +5,24 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.BasDualCrnp;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.HttpRequestLog;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.BasDualCrnpService;
import com.zy.asrs.service.BasStationService;
import com.zy.asrs.service.HttpRequestLogService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.service.impl.LocMastServiceImpl;
import com.zy.asrs.utils.Utils;
import com.zy.common.entity.FindCrnNoResult;
import com.zy.common.service.CommonService;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.cache.MessageQueue;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.Task;
import com.zy.core.model.command.CrnCommand;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -53,14 +53,17 @@
    private BasStationService basStationService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private LocMastServiceImpl locMastService;
    // 申请入库任务
    public synchronized String applyInTask(String barcode, Integer sourceStaNo, Integer locType1) {
    public synchronized String applyInTask(String barcode, Integer sourceStaNo, Integer locType1,Double weight) {
        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
        if (systemConfigMapObj == null) {
            News.error("系统Config缓存失效");
            return null;
        }
        HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
        String wmsUrl = systemConfigMap.get("wmsSystemUri");
@@ -95,6 +98,8 @@
            requestParam.put("sourceStaNo", stationNo);
            requestParam.put("locType1", locType1);
            requestParam.put("row", Utils.getInTaskEnableRow(sourceStaNo));
            requestParam.put("ioType",1);
            requestParam.put("weight", weight);
            response = new HttpHandler.Builder()
                    .setUri(wmsUrl)
@@ -134,13 +139,12 @@
    /**
     * 异步申请入库任务 - 非阻塞版本
     * 将请求提交到线程池异步执行,结果存储到Redis中
     * 
     * @param barcode     托盘码
     * @param sourceStaNo 站点编号
     * @param locType1    托盘高度
     */
    public void applyInTaskAsync(String barcode, Integer sourceStaNo, Integer locType1) {
    public void applyInTaskAsync(String barcode, Integer sourceStaNo, Integer locType1,Double weight) {
        String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + sourceStaNo;
        String responseKey = RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + barcode + "_" + sourceStaNo;
@@ -156,18 +160,18 @@
        // 提交异步任务
        new Thread(() -> {
            try {
                String response = applyInTask(barcode, sourceStaNo, locType1);
                String response = applyInTask(barcode, sourceStaNo, locType1,weight);
                if (response != null) {
                    // 存储响应结果,设置60秒超时
                    redisUtil.set(responseKey, response, 60);
                    News.info("异步WMS入库请求完成,barcode={},stationId={},response={}", barcode, sourceStaNo, response);
                    News.info("异步WMS入库请求完成,barcode={},stationId={},response={},weight={}", barcode, sourceStaNo, response,weight);
                } else {
                    // 请求失败,存储失败标记
                    redisUtil.set(responseKey, "FAILED", 10);
                    News.error("异步WMS入库请求失败,barcode={},stationId={}", barcode, sourceStaNo);
                    News.error("异步WMS入库请求失败,barcode={},stationId={},weight={}", barcode, sourceStaNo,weight);
                }
            } catch (Exception e) {
                News.error("异步WMS入库请求异常,barcode={},stationId={},error={}", barcode, sourceStaNo, e.getMessage());
                News.error("异步WMS入库请求异常,barcode={},stationId={},error={},weight={}", barcode, sourceStaNo, e.getMessage(),weight);
                redisUtil.set(responseKey, "ERROR:" + e.getMessage(), 10);
            } finally {
                // 清除请求进行中标记
@@ -388,4 +392,87 @@
        return response;
    }
    // 上报堆垛机DB110状态数据
    public void reportCrnDb110Status(Integer crnNo, List<Integer> indices) {
        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
        if (systemConfigMapObj == null) {
            News.error("系统Config缓存失效");
            return;
        }
        HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
        String wmsUrl = systemConfigMap.get("wmsSystemUri");
        if (wmsUrl == null) {
            News.error("未配置WMS系统URI,配置文件Code编码:wmsSystemUri");
            return;
        }
        String wmsSystemCrnStatusUrl = systemConfigMap.get("wmsSystemCrnStatusUrl");
        if (wmsSystemCrnStatusUrl == null) {
            News.error("未配置WMS堆垛机状态上报接口地址,配置文件Code编码:wmsSystemCrnStatusUrl");
            return;
        }
        String response = null;
        int result = 0;
        BasCrnp crnNo1 = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
        if (crnNo1 == null) {
            return;
        }
        // 根据indices下标从crnNo1的arr数组中取出对应值
        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())) {
                News.info("没有查询到该库位或者没有找到该库位对应托盘码 :{}", split[idx]);
                CrnCommand command = new CrnCommand();
                command.setLocNo(locMast.getLocNo());
                command.setIndex(idx);
                command.setValue((short)0);
                MessageQueue.offer(SlaveType.Crn, crnNo, new Task(5, command));
                continue;
            }
            try {
                response = new HttpHandler.Builder()
                        .setUri(wmsUrl)
                        .setPath(wmsSystemCrnStatusUrl)
                        .setJson(locMast.getBarcode())
                        .setTimeout(30, TimeUnit.SECONDS)
                        .build()
                        .doPost();
                if (response != null) {
                    JSONObject jsonObject = JSON.parseObject(response);
                    if (jsonObject.getInteger("code") == 200) {
                        result = 1;
                        CrnCommand command = new CrnCommand();
                        command.setLocNo(locMast.getLocNo());
                        command.setIndex(idx);
                        command.setValue((short)2);
                        MessageQueue.offer(SlaveType.Crn, crnNo, new Task(5, command));
                        News.info("请求WMS堆垛机状态上报接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemCrnStatusUrl,
                                JSON.toJSONString(locMast.getBarcode()), response);
                    } else {
                        News.info("请求WMS堆垛机状态上报接口失败,接口返回Code异常!!!url:{};request:{};response:{}",
                                wmsUrl + wmsSystemCrnStatusUrl, JSON.toJSONString(locMast.getBarcode()), response);
                    }
                } else {
                    News.info("请求WMS堆垛机状态上报接口失败,接口未响应!!!url:{};request:{};response:{}", wmsUrl + wmsSystemCrnStatusUrl,
                            JSON.toJSONString(locMast.getBarcode()), response);
                }
            } catch (Exception e) {
                News.error("请求WMS堆垛机状态上报接口异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemCrnStatusUrl,
                        JSON.toJSONString(locMast.getBarcode()), response, e);
            } finally {
                HttpRequestLog httpRequestLog = new HttpRequestLog();
                httpRequestLog.setName(wmsUrl + wmsSystemCrnStatusUrl);
                httpRequestLog.setRequest(JSON.toJSONString(locMast.getBarcode()));
                httpRequestLog.setResponse(response);
                httpRequestLog.setCreateTime(new Date());
                httpRequestLog.setResult(result);
                httpRequestLogService.insert(httpRequestLog);
            }
        }
    }
}