自动化立体仓库 - WMS系统
pang.jiabao
4 天以前 d18505cc87fa30a5b202057bbcc4236986efc80a
src/main/java/com/zy/asrs/task/handler/OrderPakinSyncHandler.java
@@ -1,5 +1,8 @@
package com.zy.asrs.task.handler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zy.asrs.entity.DocType;
import com.zy.asrs.entity.OrderDetlPakin;
import com.zy.asrs.entity.OrderPakin;
@@ -9,11 +12,15 @@
import com.zy.asrs.service.OrderPakinService;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.common.utils.HttpHandler;
import com.zy.system.timer.LoadingConfigTimer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
@@ -29,20 +36,70 @@
    private OrderDetlPakinService orderDetlPakinService;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private DocTypeService docTypeService;
    @Resource
    private LoadingConfigTimer loadingConfigTimer;
    @Transactional
    public ReturnT<String> startOrderReport(OrderPakin order) {
        DocType docType = docTypeService.selectById(order.getDocType());
        if (null == docType) {
            return SUCCESS;
        }
        long settle = 6L;
        List<OrderDetlPakin> orderDetls = orderDetlPakinService.selectByOrderId(order.getId());
    public void startOrderReport(OrderPakin order) {
        return SUCCESS;
        // 构造请求体
        JSONObject param = new JSONObject();
        param.put("orderNo", order.getOrderNo());
        List<OrderDetlPakin> orderDetls = orderDetlPakinService.selectByOrderId(order.getId());
        JSONArray detl = new JSONArray();
        for (OrderDetlPakin orderDetlPakin : orderDetls) {
            JSONObject object = new JSONObject();
            object.put("matnr", orderDetlPakin.getMatnr());
            object.put("batch", orderDetlPakin.getBatch());
            object.put("anfme", orderDetlPakin.getQty());
            detl.add(object);
        }
        param.put("matList", detl);
        String response = "";
        boolean success = false;
        String errorMsg = null;
        String requestJson = param.toJSONString();
        String url = loadingConfigTimer.getErpReportURL() + loadingConfigTimer.getErpInReportPath();
        String nameSpaces = "入库单上报";
        try {
//            response = new HttpHandler.Builder()
//                    .setUri(loadingConfigTimer.getErpReportURL())
//                    .setPath(loadingConfigTimer.getErpInReportPath())
//                    .setJson(requestJson)
//                    .build()
//                    .doPost();
//            JSONObject jsonObject = JSON.parseObject(response);
//            if (jsonObject.getString("code") != null && jsonObject.getString("code").equals("200")) {
                orderPakinService.updateSettle(order.getId(), 6L, null);
                log.info("入库单据上报成功,单据编号:{}", order.getOrderNo());
                success = true;
//            } else {
//                errorMsg = response;
//                log.error(nameSpaces + "调用外部接口失败,url:{},request:{},response:{}", url, requestJson, response);
//            }
        } catch (Exception e) {
            errorMsg = e.getMessage();
            log.error(nameSpaces + "调用外部接口异常,url:{},request:{},response:{}", url, requestJson, response, e);
        } finally {
            try {
                apiLogService.save(
                        nameSpaces,
                        url,
                        null,
                        "127.0.0.1",
                        requestJson,
                        response,
                        success,
                        errorMsg
                );
            } catch (Exception e) {
                log.error(nameSpaces + "保存接口日志失败", e);
            }
        }
    }
}