自动化立体仓库 - WMS系统
zhangc
2024-12-12 5dc8a9f9aba3310fd21cad9509635bb7ec2f007f
src/main/java/com/zy/asrs/task/handler/AgvWrkMastHandler.java
@@ -15,7 +15,6 @@
import com.zy.asrs.service.*;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.common.utils.HttpHandler;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,7 +24,6 @@
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Slf4j
@@ -113,6 +111,10 @@
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private FlowLogService flowLogService;
    @Autowired
    private ReportDataService reportDataService;
    @Transactional
    public ReturnT<String> completedPutWayWrk(AgvWrkMast agvWrkMast) {
@@ -700,9 +702,7 @@
    }
    private void reportMes(AgvWrkMast agvWrkMast, List<AgvWrkDetl> agvWrkDetls) {
        if (!flag) {
            return;
        }
        if (Cools.isEmpty(agvWrkDetls)) {
            return;
        }
@@ -714,16 +714,13 @@
                reportMesPakinOrder(agvWrkMast, agvWrkDetls);
            }
        }
        try {
            if (OUT_TYPE_List.contains(agvWrkMast.getIoType())) {
                reportMesPakoutOrder(agvWrkMast, agvWrkDetls);
            }
            if (MOVE_TYPE_List.contains(agvWrkMast.getIoType())) {
                generateMesParam(agvWrkMast, agvWrkDetls);
            }
        } catch (Exception e) {
            e.printStackTrace();
        if (OUT_TYPE_List.contains(agvWrkMast.getIoType())) {
            reportMesPakoutOrder(agvWrkMast, agvWrkDetls);
        }
        if (MOVE_TYPE_List.contains(agvWrkMast.getIoType())) {
            generateMesParam(agvWrkMast, agvWrkDetls);
        }
    }
@@ -846,17 +843,17 @@
    //获取mes token信息
    private Map<String, Object> getMesTokenInfo() {
        Map<String, String> param = new HashMap<>();
        param.put("appKey", appKey);
        param.put("appSecret", appSecret);
//        Map<String, String> param = new HashMap<>();
//        param.put("appKey", appKey);
//        param.put("appSecret", appSecret);
//
//        JSONObject jsonObject = doHttpRequest(param, null, "获取MesToken", getTokenUrl, getTokenPath, null, "127.0.0.1");
//
//        Map<String, Object> headParam = new HashMap<>();
//        headParam.put("X-AUTH", JSON.parseObject(jsonObject.get("data").toString()).get("appAccessToken").toString());
        JSONObject jsonObject = doHttpRequest(param, null, "获取MesToken", getTokenUrl, getTokenPath, null, "127.0.0.1");
        Map<String, Object> headParam = new HashMap<>();
        headParam.put("X-AUTH", JSON.parseObject(jsonObject.get("data").toString()).get("appAccessToken").toString());
        return headParam;
        //       return headParam;
        return null;
    }
    //根据楼层默认出库仓位
@@ -877,37 +874,45 @@
        return null;
    }
    private JSONObject doHttpRequest(Object requestParam, Map<String, Object> headParam, String namespace, String url, String path, String appkey, String ip) {
    private void doHttpRequest(Object requestParam, Map<String, Object> headParam, String namespace, String url, String path, String appkey, String ip) {
        //保证上报表
        ReportData reportData = new ReportData();
        reportData.setReportJson(JSONObject.toJSONString(requestParam));
        reportData.setMemo(namespace);
        reportData.setCreateTime(new Date());
        reportData.setReportType("MES");
        reportDataService.insert(reportData);
        String response = "";
        boolean success = false;
        try {
            response = new HttpHandler.Builder().setUri(url).setPath(path).setTimeout(30, TimeUnit.SECONDS).setHeaders(headParam).setJson(JSONObject.toJSONString(requestParam)).setHttps(true).build().doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (Cools.isEmpty(jsonObject.get("code")) || Integer.parseInt(jsonObject.get("code").toString()) != 200) {
                log.info("mes接口调用失败,返回信息:" + jsonObject);
                //TODO 张超
                throw new CoolException("mes接口调用失败,返回信息:" + jsonObject);
            }
            success = true;
            return jsonObject;
//            String succeed = jsonObject.get("succeed").toString();
//        String response = "";
//        boolean success = false;
//
//            int code = Cools.eq("0",succeed) ? 0 : 1;
//            if(code != 200){
//                throw new CoolException(jsonObject.get("dsc").toString());
//        try {
//            response = new HttpHandler.Builder().setUri(url).setPath(path).setTimeout(30, TimeUnit.SECONDS).setHeaders(headParam).setJson(JSONObject.toJSONString(requestParam)).setHttps(true).build().doPost();
//            JSONObject jsonObject = JSON.parseObject(response);
//
//            if (Cools.isEmpty(jsonObject.get("code")) || Integer.parseInt(jsonObject.get("code").toString()) != 200) {
//                log.info("mes接口调用失败,返回信息:" + jsonObject);
//                //TODO 张超
//                throw new CoolException("mes接口调用失败,返回信息:" + jsonObject);
//            }
//            success = true;
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new CoolException(e.getMessage());
        } finally {
            apiLogService.save(namespace, url + path, appkey, ip, JSON.toJSONString(JSONObject.toJSONString(requestParam)), response, success);
        }
//            return jsonObject;
//
////            String succeed = jsonObject.get("succeed").toString();
////
////            int code = Cools.eq("0",succeed) ? 0 : 1;
////            if(code != 200){
////                throw new CoolException(jsonObject.get("dsc").toString());
////            }
////            success = true;
//
//        } catch (Exception e) {
//            log.error(e.getMessage());
//            throw new CoolException(e.getMessage());
//        } finally {
//            apiLogService.save(namespace, url + path, appkey, ip, JSON.toJSONString(JSONObject.toJSONString(requestParam)), response, success);
//        }
    }