自动化立体仓库 - WMS系统
pang.jiabao
5 天以前 d18505cc87fa30a5b202057bbcc4236986efc80a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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.OrderDetlPakout;
import com.zy.asrs.entity.OrderPakout;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.DocTypeService;
import com.zy.asrs.service.OrderDetlPakoutService;
import com.zy.asrs.service.OrderPakoutService;
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.List;
 
/**
 * Created by vincent on 2020/7/7
 */
@Slf4j
@Service
public class OrderPakoutSyncHandler extends AbstractHandler<String> {
 
    @Autowired
    private OrderPakoutService orderPakoutService;
    @Autowired
    private OrderDetlPakoutService orderDetlPakoutService;
    @Autowired
    private ApiLogService apiLogService;
 
    @Resource
    private LoadingConfigTimer loadingConfigTimer;
 
 
    @Transactional
    public void startOrderReport(OrderPakout order) {
 
        // 构造请求体
        JSONObject param = new JSONObject();
        param.put("orderNo", order.getOrderNo());
        List<OrderDetlPakout> orderDetls = orderDetlPakoutService.selectByOrderId(order.getId());
        JSONArray detl = new JSONArray();
        for (OrderDetlPakout orderDetlPakout : orderDetls) {
            JSONObject object = new JSONObject();
            object.put("matnr", orderDetlPakout.getMatnr());
            object.put("batch", orderDetlPakout.getBatch());
            object.put("anfme", orderDetlPakout.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.getErpOutReportPath();
        String nameSpaces = "出库单上报";
        try {
 
//            response = new HttpHandler.Builder()
//                    .setUri(loadingConfigTimer.getErpReportURL())
//                    .setPath(loadingConfigTimer.getErpOutReportPath())
//                    .setJson(requestJson)
//                    .build()
//                    .doPost();
//            JSONObject jsonObject = JSON.parseObject(response);
//            if (jsonObject.getString("code") != null && jsonObject.getString("code").equals("200")) {
                orderPakoutService.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);
            }
        }
    }
 
}