#
Junjie
12 小时以前 f5e49b2c04137fdc88c453cbe5d190cf7daab079
src/main/java/com/zy/core/utils/WmsOperateUtils.java
@@ -1,20 +1,24 @@
package com.zy.core.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.HttpRequestLog;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.BasDualCrnpService;
import com.zy.asrs.service.HttpRequestLogService;
import com.zy.asrs.service.WrkMastService;
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.core.News;
import com.zy.core.enums.SlaveType;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,6 +43,8 @@
    private CommonService commonService;
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private BasDualCrnpService basDualCrnpService;
    //申请入库任务
    public synchronized String applyInTask(String barcode, Integer sourceStaNo, Integer locType1) {
@@ -66,11 +72,12 @@
        HashMap<String, Object> requestParam = new HashMap<>();
        String response = null;
        int result = 0;
        try {
            requestParam.put("barcode", barcode);
            requestParam.put("sourceStaNo", sourceStaNo);
            requestParam.put("locType1", locType1);
            requestParam.put("row", Utils.getInTaskEnableRow());
            requestParam.put("row", Utils.getInTaskEnableRow(sourceStaNo));
            response = new HttpHandler.Builder()
                    .setUri(wmsUrl)
@@ -79,7 +86,17 @@
                    .setTimeout(360, TimeUnit.SECONDS)
                    .build()
                    .doPost();
            News.info("请求WMS入库接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
            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);
                }
            }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);
        } finally {
@@ -88,13 +105,14 @@
            httpRequestLog.setRequest(JSON.toJSONString(requestParam));
            httpRequestLog.setResponse(response);
            httpRequestLog.setCreateTime(new Date());
            httpRequestLog.setResult(result);
            httpRequestLogService.insert(httpRequestLog);
        }
        return response;
    }
    //申请任务重新分配库位
    public synchronized String applyReassignTaskLocNo(Integer taskNo) {
    public synchronized String applyReassignTaskLocNo(Integer taskNo, Integer stationId) {
        String wmsUrl = null;
        Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
        if (wmsSystemUriConfig != null) {
@@ -112,7 +130,7 @@
            wmsSystemReassignInTaskUrl = wmsSystemReassignInTaskUrlConfig.getValue();
        }
        if(wmsSystemReassignInTaskUrl == null){
        if (wmsSystemReassignInTaskUrl == null) {
            News.error("未配置WMS任务重新分配入库库位接口地址,配置文件Code编码:wmsSystemReassignInTaskUrl");
            return null;
        }
@@ -125,9 +143,19 @@
        HashMap<String, Object> requestParam = new HashMap<>();
        String response = null;
        int result = 0;
        try {
            List<Integer> excludeCrnList = new ArrayList<>();
            List<Integer> excludeDualCrnList = new ArrayList<>();
            if (!Cools.isEmpty(wrkMast.getCrnNo())) {
                excludeCrnList.add(wrkMast.getCrnNo());
            }
            if (!Cools.isEmpty(wrkMast.getDualCrnNo())) {
                excludeDualCrnList.add(wrkMast.getDualCrnNo());
            }
            requestParam.put("taskNo", wrkMast.getWmsWrkNo());
            requestParam.put("row", Utils.getInTaskEnableRow(new ArrayList<>(wrkMast.getCrnNo())));
            requestParam.put("row", Utils.getInTaskEnableRow(stationId, excludeCrnList, excludeDualCrnList, false));
            response = new HttpHandler.Builder()
                    .setUri(wmsUrl)
@@ -136,7 +164,17 @@
                    .setTimeout(360, TimeUnit.SECONDS)
                    .build()
                    .doPost();
            News.info("请求申请任务重新分配入库接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
            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);
                } else {
                    News.info("请求申请任务重新分配入库接口失败,接口返回Code异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
                }
            } else {
                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);
        } finally {
@@ -145,6 +183,7 @@
            httpRequestLog.setRequest(JSON.toJSONString(requestParam));
            httpRequestLog.setResponse(response);
            httpRequestLog.setCreateTime(new Date());
            httpRequestLog.setResult(result);
            httpRequestLogService.insert(httpRequestLog);
        }
        return response;
@@ -174,23 +213,38 @@
            return null;
        }
        Integer crnNo = commonService.findCrnNoByLocNo(locNo);
        if (crnNo == null) {
        FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
        if (findCrnNoResult == null) {
            return null;
        }
        BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
        if (basCrnp == null) {
            return null;
        }
        Integer crnNo = findCrnNoResult.getCrnNo();
        List<Integer> crnRows = new ArrayList<>();
        List<List<Integer>> rowList = basCrnp.getControlRows$();
        for (List<Integer> list : rowList) {
            crnRows.addAll(list);
        if (findCrnNoResult.getCrnType().equals(SlaveType.Crn)) {
            BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
            if (basCrnp == null) {
                return null;
            }
            List<List<Integer>> rowList = basCrnp.getControlRows$();
            for (List<Integer> list : rowList) {
                crnRows.addAll(list);
            }
        } else if (findCrnNoResult.getCrnType().equals(SlaveType.DualCrn)) {
            BasDualCrnp basDualCrnp = basDualCrnpService.selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", crnNo));
            if (basDualCrnp == null) {
                return null;
            }
            List<List<Integer>> rowList = basDualCrnp.getControlRows$();
            for (List<Integer> list : rowList) {
                crnRows.addAll(list);
            }
        }else {
            throw new CoolException("未知设备类型");
        }
        HashMap<String, Object> requestParam = new HashMap<>();
        String response = null;
        int result = 0;
        try {
            requestParam.put("locNo", locNo);
            requestParam.put("row", crnRows);
@@ -202,9 +256,18 @@
                    .setTimeout(360, TimeUnit.SECONDS)
                    .build()
                    .doPost();
            News.info("请求WMS申请更换库位接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
            return response;
            if (response != null) {
                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);
                }
            }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);
        } finally {
@@ -213,9 +276,10 @@
            httpRequestLog.setRequest(JSON.toJSONString(requestParam));
            httpRequestLog.setResponse(response);
            httpRequestLog.setCreateTime(new Date());
            httpRequestLog.setResult(result);
            httpRequestLogService.insert(httpRequestLog);
        }
        return null;
        return response;
    }
}