自动化立体仓库 - WMS系统
zhou zhou
2025-12-30 0eab67f624c2b3349002860b408942265a076b9e
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
package com.zy.asrs.task.handler;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.DocTypeService;
import com.zy.asrs.service.OrderDetlPakinService;
import com.zy.asrs.service.OrderPakinService;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.common.constant.ApiInterfaceConstant;
import com.zy.common.constant.MesConstant;
import com.zy.common.model.MesPakinParam;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * Created by vincent on 2020/7/7
 */
@Slf4j
@Service
public class OrderPakinSyncHandler extends AbstractHandler<String> {
 
    @Autowired
    private OrderPakinService orderPakinService;
    @Autowired
    private OrderDetlPakinService orderDetlPakinService;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private DocTypeService docTypeService;
 
 
    @Transactional
    public ReturnT<String> startOrderReport(OrderPakin order) {
 
        DocType docType = docTypeService.selectById(order.getDocType());
        if (null == docType) {
            log.error("未找到对应的DocType,订单号:{},单据类型:{}", order.getOrderNo(), order.getDocType());
            return FAIL.setMsg("未找到对应的单据类型:" + order.getOrderNo());
        }
 
        ErpReportDto param = new ErpReportDto();
        param.setOrderDetails(new ArrayList<>());
        List<OrderDetlPakin> orderDetls = orderDetlPakinService.selectByOrderId(order.getId());
        for (OrderDetlPakin orderDetl : orderDetls) {
            param.getOrderDetails().add(new ErpReportDto.DetlDto(orderDetl.getMatnr(),orderDetl.getQty()));
        }
        param.setOrderNo(order.getOrderNo());
 
        String response = "";
        boolean success = false;
        ReturnT<String> result = SUCCESS;
        try {
            response = new HttpHandler.Builder()
                    .setUri(ApiInterfaceConstant.ERP_IP)
                    .setPath(ApiInterfaceConstant.PAKIN_PATH)
                    .setJson(JSON.toJSONString(param))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getInteger("code").equals(200)) {
                // 修改订单状态 4.完成 ===>> 6.已上报
                orderPakinService.updateSettle(order.getId(), 6L, null);
                success = true;
            } else {
                log.error("入库完成上报erp失败!url:{};request:{};response:{}", ApiInterfaceConstant.ERP_IP + ApiInterfaceConstant.PAKIN_PATH, JSON.toJSONString(param), response);
                throw new CoolException("入库完成上报erp失败");
            }
        } catch (Exception e) {
            log.error("入库完成上报erp异常", e);
            result = FAIL.setMsg("入库完成上报异常:" + e.getMessage());
        } finally {
            try {
                // 保存接口日志
                apiLogService.save(
                        "入库完成上报",
                        ApiInterfaceConstant.ERP_IP + ApiInterfaceConstant.PAKIN_PATH,
                        null,
                        "127.0.0.1",
                        JSON.toJSONString(param),
                        response,
                        success
                );
            } catch (Exception e) {
                log.error("入库保存接口日志异常", e);
            }
        }
 
        return result;
    }
 
}