package com.fzzy.push.gd2020.v2;
|
|
import com.fzzy.api.data.AuthToken;
|
import com.fzzy.api.entity.Api1202;
|
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.cxf.endpoint.Client;
|
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
|
|
import javax.xml.namespace.QName;
|
|
/**
|
* @Desc: 入库数据接口
|
* @author: Andy
|
* @update-time: 2022/10/29
|
*/
|
@Slf4j
|
public class InStorageWebService {
|
|
public static InStorageWebService newInstance() {
|
return new InStorageWebService();
|
}
|
|
/**
|
* 入库-数据接口 -xml报文
|
*/
|
public String xml_webService = "<?xml version=\"1.0\" encoding=\"utf8\"?><root><row id=\"storeroom_instore\"><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>";
|
|
/**
|
* @Desc: 入库-数据接口
|
*/
|
public InvokeResult webService(AuthToken authToken, ApiConfs conf, Api1202 data) {
|
InvokeResult invokeResult = new InvokeResult();
|
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
|
|
String url = conf.getApiUrl() + "/inStorageWebService?wsdl"; // 填写调用入库数据接口服务
|
String method = "saveInStorageRecord"; // 填写入库数据方法名
|
|
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(Api1202 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()));//粮食性质
|
xmlStr = xmlStr.replace("{amount}", GDUtils.formatNum(data.getMz()));//数量
|
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);//业务单号
|
xmlStr = xmlStr.replace("{company_code}", GDUtils.formatStr(data.getLdd()));//粮权所属企业
|
xmlStr = xmlStr.replace("{level_code}", "");//粮食等级 可以为空
|
|
return xmlStr;
|
}
|
|
}
|