czt
2025-03-18 451f8ceb451519c029a0bcd0373b7b493e6265fc
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
package com.fzzy.push.gd2020.v2;
 
import com.fzzy.api.data.AuthToken;
import com.fzzy.api.entity.Api1205;
import com.fzzy.api.entity.ApiConfs;
import com.fzzy.push.gd2020.GDResult;
import com.fzzy.push.gd2020.GDUtils;
import com.fzzy.push.gd2020.InvokeResult;
import com.fzzy.push.gd2020.JaxbUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
 
import javax.xml.namespace.QName;
 
/**
 * @Desc: 出库数据接口
 * @author: Andy
 * @update-time: 2022/10/30
 */
@Slf4j
public class OutStorageWebService {
 
    public static OutStorageWebService newInstance() {
        return new OutStorageWebService();
    }
 
 
    public String xml_webService = "<?xml version=\"1.0\" encoding=\"utf8\"?><root><row id=\"storeroom_outstore\"><depot_code desc=\"库点代码\" type=\"varchar\" length=\"50\" requir=\"必填\">{depot_code}</depot_code><kind_code desc=\"粮食品种\" type=\"varchar\" length=\"50\" requir=\"必填\">{kind_code}</kind_code><property_code desc=\"粮食性质\" type=\"varchar\" length=\"50\" requir=\"必填\">{property_code}</property_code><amount desc=\"数量\" type=\"decimal\" length=\"12\" requir=\"必填\">{amount}</amount><store_date desc=\"业务日期\" type=\"varchar\" length=\"19\" requir=\"必填\">{store_date}</store_date><business_code desc=\"业务单号\" type=\"varchar\" length=\"30\" requir=\"必填\">{business_code}</business_code><company_code desc=\"粮权所属企业\" type=\"varchar\" length=\"50\" requir=\"必填\">{company_code}</company_code><level_code desc=\"粮食等级\" type=\"varchar\" length=\"50\" requir=\"可选\">{level_code}</level_code></row></root>";
 
 
    public InvokeResult webservice(AuthToken authToken, ApiConfs conf, Api1205 data) {
        InvokeResult invokeResult = new InvokeResult();
 
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
 
        String url = conf.getApiUrl() + "/outStorageWebService?wsdl"; // 填写调用出库数据接口服务
        String method = "saveOutStorageRecord"; // 填写出库数据方法名
 
        String nameSpace = "http://service.sljt.com"; // 填写调用省平台命名空间
        Thread.currentThread().setContextClassLoader(cl);
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient(url);
        QName name = new QName(nameSpace, method);
        Object[] objects;
 
        try {
 
            String xmlStr = webServiceXml(data);// 获取接口的输入报文,根据需要填写相应的报文
 
            log.debug("------xmlStr--{}", xmlStr);
 
 
            objects = client.invoke(name, new Object[]{authToken.getToken(), xmlStr});
 
            log.debug("-----------返回信息---{}", objects[0].toString());
 
            invokeResult = JaxbUtil.converyToJavaBean(objects[0].toString(), InvokeResult.class);
 
        } catch (Exception e) {
            log.error("----执行异常----{}", e);
            invokeResult.setCode(GDResult.CODE_500.getCode());
            invokeResult.setData("后端服务执行异常:+" + e.getMessage());
            return invokeResult;
        }
 
        return invokeResult;
    }
 
 
    /**
     * 报文获取--替换数据
     *
     * @param data
     * @return
     */
    public String webServiceXml(Api1205 data) {
        String xmlStr = xml_webService;
        xmlStr = xmlStr.replace("{depot_code}", GDUtils.formatStr(data.getKqdm()));//库点代码
        xmlStr = xmlStr.replace("{kind_code}", GDUtils.formatStr(data.getLspzdm()));//粮食品种
        xmlStr = xmlStr.replace("{property_code}", GDUtils.formatStr(data.getLsxzdm()));//粮食性质
        double amount = data.getJz();
        if (amount > 0) {//转换为吨
            amount = amount / 1000;
        }
        xmlStr = xmlStr.replace("{amount}", GDUtils.formatNum(amount));//出库数量 吨
        xmlStr = xmlStr.replace("{store_date}", GDUtils.formatDate(data.getYwrq(), "yyyy-MM-dd"));//业务日期
 
        // 库点代码+日期+三个顺序号,01为入库,如:52940000109020200417001
        String bizCode = data.getKqdm() + "01" + data.getBizId().substring(4);
        xmlStr = xmlStr.replace("{business_code}", bizCode);//业务单号
 
        //企业代码,库区代码前18位
        String companyCode = data.getKqdm().substring(0, 18);
        xmlStr = xmlStr.replace("{company_code}", companyCode);// 粮权所属企业
        xmlStr = xmlStr.replace("{level_code}", GDUtils.formatStr(data.getLsdjdm()));//粮食等级
        return xmlStr;
    }
 
 
}