自动化立体仓库 - WMS系统
ZY
2025-05-14 c22b7331c0d215ba4b2e4b503d22dae853540290
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.zy.asrs.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.DocType;
import com.zy.asrs.entity.Order;
import com.zy.asrs.entity.OrderDetl;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.OrderService;
import com.zy.asrs.service.ReportToThirdService;
import com.zy.common.utils.Synchro;
import com.zy.nc.SendUtil;
import com.zy.nc.entity.NccSaleXsfhmxWms;
import com.zy.nc.util.NcResultMessage;
import com.zy.nc.vo.SaleOutBodyVO;
import com.zy.nc.vo.SaleOutHeadVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
@Slf4j
public class ReportToThirdServiceImpl implements ReportToThirdService {
 
    @Autowired
    private ApiLogService apiLogService;
 
    @Autowired
    private OrderService orderService;
 
    @Value("${NYNC.ip}")
    private String nyncIp;
 
    @Value("${NYNC.port}")
    private String port;
 
    @Value("${NYNC.saveRefDelivery}")
    private String saveRefDelivery;
 
 
    @Override
    public void report(Order order, List<OrderDetl> orderDetls, DocType docType) {
        Boolean http = false;
        NcResultMessage response = null;
        try {
            switch (order.getDocType().toString()) {
                case "35":
                    //组装对象数据
                    Map<String, Object> data = new HashMap<String, Object>();
                    SaleOutHeadVO saleOutHeadVO = new SaleOutHeadVO();
                    saleOutHeadVO.setPk_org("FYT");
                    saleOutHeadVO.setCwarehouseid("610101");
                    SaleOutBodyVO saleOutBodyVO = null;
                    List<SaleOutBodyVO> saleOutBodyVOList = new ArrayList<>();
                    for (OrderDetl orderDetl : orderDetls) {
                        saleOutBodyVO = new SaleOutBodyVO();
                        String remark = orderDetl.getRemark();
                        if (!Cools.isEmpty(remark)) {
                            NccSaleXsfhmxWms nccSaleXsfhmxWms = JSONObject.parseObject(remark, NccSaleXsfhmxWms.class);
                            saleOutBodyVO.setCsourcetype("4331-01");
                            saleOutBodyVO.setCsourcebillbid(nccSaleXsfhmxWms.getCdeliverybid());
                            saleOutBodyVO.setCsourcebillhid(nccSaleXsfhmxWms.getCdeliveryid());
                            saleOutHeadVO.setVdef2(nccSaleXsfhmxWms.getVdef2());
                            saleOutHeadVO.setVdef3(nccSaleXsfhmxWms.getVdef3());
                            saleOutHeadVO.setVdef4(nccSaleXsfhmxWms.getVdef4());
                            saleOutHeadVO.setVdef7(nccSaleXsfhmxWms.getVdef7());
                            saleOutHeadVO.setVdef8(nccSaleXsfhmxWms.getVdef8());
                            saleOutHeadVO.setVdef13(nccSaleXsfhmxWms.getVdef13());
                            saleOutHeadVO.setVdef14(nccSaleXsfhmxWms.getVdef14());
                        }
                        saleOutBodyVO.setNnum(orderDetl.getQty());
                        saleOutBodyVOList.add(saleOutBodyVO);
                    }
                    data.put("SaleOutHeadVO", saleOutHeadVO);
                    data.put("SaleOutBodyVO", saleOutBodyVOList);
                    //发送请求
                    response = SendUtil.sendDataToNc(SendUtil.token, nyncIp + ":" + port, saveRefDelivery, JSONObject.toJSONString(data));
                    if (!Cools.isEmpty(response) && response.isSuccess()) {
                        log.info("response:{}", response);
                        http = true;
                    }
                    break;
                case "产成品入库":
                    break;
                case "辅料采购入库":
                    break;
                case "辅料及成品转库":
                    break;
                case "自动包装入库":
                    break;
                case "内部调拨":
                    break;
                default:
                    break;
            }
            if (http) {
                // 修改订单状态 4.完成 ===>> 6.已上报
                if (!orderService.updateSettle(order.getId(), 6L, null)) {
                    throw new CoolException("服务器内部错误,请联系管理员");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new CoolException("调用接口报错,请联系管理员");
        } finally {
            reportApiLog(response, order.getDocType$(), nyncIp, saveRefDelivery);
        }
 
    }
 
    private Boolean reportApiLog(Object data, String docType, String url, String path) {
        String response = "";
        boolean success = false;
        apiLogService.save(
                docType,
                url + path,
                null,
                "127.0.0.1",
                JSON.toJSONString(data),
                response,
                success
        );
        return false;
    }
}