提交 | 用户 | 时间
|
df1f2b
|
1 |
package com.jcdm.main.webservice.service; |
懒 |
2 |
|
|
3 |
|
131e8c
|
4 |
import cn.hutool.core.util.ObjectUtil; |
W |
5 |
import cn.hutool.core.util.StrUtil; |
df1f2b
|
6 |
import cn.hutool.json.JSONObject; |
55b0cb
|
7 |
import com.fasterxml.jackson.core.JsonProcessingException; |
懒 |
8 |
import com.fasterxml.jackson.databind.JsonNode; |
|
9 |
import com.fasterxml.jackson.databind.ObjectMapper; |
df1f2b
|
10 |
import com.google.gson.Gson; |
懒 |
11 |
import com.google.gson.JsonObject; |
131e8c
|
12 |
import com.jcdm.common.exception.ServiceException; |
df1f2b
|
13 |
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; |
懒 |
14 |
import com.jcdm.main.da.opcuaconfig.init.BeanUtils; |
|
15 |
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; |
|
16 |
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; |
|
17 |
import com.jcdm.main.om.workReport.service.IOmWorkReportService; |
|
18 |
import com.jcdm.main.webservice.domain.Item; |
|
19 |
import com.jcdm.main.webservice.domain.ItemList; |
|
20 |
import org.apache.commons.httpclient.HttpClient; |
|
21 |
import org.apache.commons.httpclient.UsernamePasswordCredentials; |
|
22 |
import org.apache.commons.httpclient.auth.AuthScope; |
|
23 |
import org.apache.commons.httpclient.methods.PostMethod; |
|
24 |
import org.apache.commons.httpclient.methods.RequestEntity; |
|
25 |
import org.apache.commons.httpclient.methods.StringRequestEntity; |
|
26 |
import org.apache.commons.io.IOUtils; |
|
27 |
import com.jcdm.main.om.productionOrde.*; |
b4ff0d
|
28 |
import org.slf4j.Logger; |
W |
29 |
import org.slf4j.LoggerFactory; |
df1f2b
|
30 |
import org.springframework.beans.factory.annotation.Autowired; |
懒 |
31 |
import org.springframework.web.bind.annotation.RestController; |
|
32 |
|
|
33 |
import javax.swing.border.Border; |
51b05b
|
34 |
import java.io.*; |
W |
35 |
import java.nio.charset.StandardCharsets; |
df1f2b
|
36 |
import java.util.List; |
懒 |
37 |
|
|
38 |
public class ReceivingServices { |
b4ff0d
|
39 |
|
W |
40 |
private static final Logger logger = LoggerFactory.getLogger("sys-user"); |
df1f2b
|
41 |
@Autowired |
懒 |
42 |
// private static IOmProductionOrdeInfoService omProductionOrdeInfoService; |
|
43 |
private static IOmProductionOrdeInfoService omProductionOrdeInfoService = BeanUtils.getBean(IOmProductionOrdeInfoService.class); |
|
44 |
|
131e8c
|
45 |
public static final String ProductionPlanInformationUrl = "http://popappdb.cfmoto.com.cn:50100/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_MES&receiverParty=&receiverService=&interface=SI_ZPP_CF_MES_005_SYN_OUT&interfaceNamespace=http%3A%2F%2Fcfmoto.com%2Fxi%2FMES"; |
W |
46 |
// public static final String ProductionPlanInformationUrl = "http://podqapp.cfmoto.com.cn:50200/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_MES&receiverParty=&receiverService=&interface=SI_ZPP_CF_MES_005_SYN_OUT&interfaceNamespace=http://cfmoto.com/xi/MES"; |
df1f2b
|
47 |
|
懒 |
48 |
public static void main(String[] args) throws Exception { |
|
49 |
// getInterfaceInformationXml(ProductionPlanInformationUrl,getProductionPlanInformationXml("A0055577")); |
|
50 |
// test1(); |
|
51 |
|
282556
|
52 |
// String serviceUrl = "http://podqapp.cfmoto.com.cn:50100/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_MES&receiverParty=&receiverService=&interface=SI_ZPP_CF_MES_005_SYN_OUT&interfaceNamespace=http://cfmoto.com/xi/MES"; |
Y |
53 |
// String serviceUrl = "http://podqapp.cfmoto.com.cn:50100/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_MES&receiverParty=&receiverService=&interface=SI_ZPP_CF_BC_001_SYN_OUT&interfaceNamespace=http://cfmoto.com/xi/MES"; |
55b0cb
|
54 |
//// String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\n" + |
懒 |
55 |
//// " <soapenv:Header/>\n" + |
|
56 |
//// " <soapenv:Body>\n" + |
|
57 |
//// " <urn:ZPP_CF_MES_005>\n" + |
|
58 |
//// " <!--Optional:-->\n" + |
|
59 |
//// " <IV_WERKS>1000</IV_WERKS>\n" + |
|
60 |
//// " <!--Optional:-->\n" + |
|
61 |
//// " <IV_ZSCTZD>A0055577</IV_ZSCTZD>\n" + |
|
62 |
//// " </urn:ZPP_CF_MES_005>\n" + |
|
63 |
//// " </soapenv:Body>\n" + |
|
64 |
//// "</soapenv:Envelope>"; |
df1f2b
|
65 |
// String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\n" + |
懒 |
66 |
// " <soapenv:Header/>\n" + |
|
67 |
// " <soapenv:Body>\n" + |
55b0cb
|
68 |
// " <urn:ZPP_BC_001>\n" + |
懒 |
69 |
// " <IV_AUFNR>000010569212</IV_AUFNR>\n" + |
|
70 |
// " <IV_VORNR>0010</IV_VORNR>\n" + |
|
71 |
// " <IV_LMNGA>1</IV_LMNGA>\n" + |
|
72 |
// " <IV_XMNGA>0</IV_XMNGA> \n" + |
|
73 |
// " <IV_STATU>1</IV_STATU> \n" + |
|
74 |
// " </urn:ZPP_BC_001>\n" + |
df1f2b
|
75 |
// " </soapenv:Body>\n" + |
懒 |
76 |
// "</soapenv:Envelope>"; |
|
77 |
// // HttpClient发送SOAP请求 |
|
78 |
// int timeout = 10000; |
|
79 |
// HttpClient client = new HttpClient(); |
|
80 |
// //如果需要用户名密码验证;不需要验证登录则不需要以下4行 |
|
81 |
// String username = "POMESUSER"; |
|
82 |
// String password = "12345tgb"; |
|
83 |
// UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); |
|
84 |
// client.getState().setCredentials(AuthScope.ANY, creds); |
|
85 |
// |
|
86 |
// PostMethod postMethod = new PostMethod(serviceUrl); |
|
87 |
// // 设置连接超时 |
|
88 |
// client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); |
|
89 |
// // 设置读取时间超时 |
|
90 |
// client.getHttpConnectionManager().getParams().setSoTimeout(timeout); |
|
91 |
// // 然后把Soap请求数据添加到PostMethod中 |
|
92 |
// RequestEntity requestEntity = new StringRequestEntity(content, "text/xml", "UTF-8"); |
|
93 |
// |
|
94 |
// // 设置请求头部,否则可能会报 “no SOAPAction header” 的错误 |
|
95 |
// postMethod.setRequestHeader("SOAPAction", ""); |
|
96 |
// // 设置请求体 |
|
97 |
// postMethod.setRequestEntity(requestEntity); |
|
98 |
// int status = client.executeMethod(postMethod); |
|
99 |
// |
|
100 |
// if (status == 200) {// 成功 |
|
101 |
// InputStream is = postMethod.getResponseBodyAsStream(); |
|
102 |
// // 获取请求结果字符串 |
|
103 |
// String result = IOUtils.toString(is); |
55b0cb
|
104 |
//// String jsonStr = xmlToJSON2(result); |
懒 |
105 |
//// Gson gson = new Gson(); |
|
106 |
//// // 将json字符串转换成对象 |
|
107 |
//// ItemList itemList = gson.fromJson(jsonStr, ItemList.class); |
df1f2b
|
108 |
// System.out.println("返回结果:" + result); |
懒 |
109 |
// } else { |
|
110 |
// System.out.println("错误代码:" + status + ":" + postMethod.getResponseBodyAsString()); |
|
111 |
// } |
|
112 |
} |
|
113 |
|
131e8c
|
114 |
public static void insertWebserviceData(String factory,String str) { |
W |
115 |
String result = getInterfaceInformationXml(ProductionPlanInformationUrl, getProductionPlanInformationXml(factory,str)); |
b4ff0d
|
116 |
logger.info("messageLocation1,"+result); |
df1f2b
|
117 |
String jsonStr = xmlToJSON2(result); |
b4ff0d
|
118 |
logger.info("messageLocation5,"+jsonStr); |
131e8c
|
119 |
if (StrUtil.isNotBlank(jsonStr)){ |
W |
120 |
if (!jsonStr.contains("[") && !jsonStr.contains("]")){ |
|
121 |
StringBuilder stringBuilder = new StringBuilder(jsonStr); |
|
122 |
stringBuilder.insert(8,"["); |
|
123 |
stringBuilder.insert(jsonStr.length(),"]"); |
|
124 |
jsonStr = stringBuilder.toString(); |
b4ff0d
|
125 |
logger.info("messageLocation6,"+jsonStr); |
131e8c
|
126 |
} |
W |
127 |
Gson gson = new Gson(); |
|
128 |
// 将json字符串转换成对象 |
|
129 |
ItemList itemList = gson.fromJson(jsonStr, ItemList.class); |
b4ff0d
|
130 |
if (ObjectUtil.isNotNull(itemList)){ |
W |
131 |
logger.info("messageLocation7,"+ itemList); |
|
132 |
} |
131e8c
|
133 |
for (Item item : itemList.getItem()) { |
b4ff0d
|
134 |
logger.info("messageLocation8,"+item); |
131e8c
|
135 |
OmProductionOrdeInfo ordeInfo = new OmProductionOrdeInfo(); |
W |
136 |
ordeInfo.setWorkshopCode(item.getWERKS()); |
|
137 |
ordeInfo.setProductCode(item.getPLNBEZ()); |
|
138 |
ordeInfo.setProductName(item.getMAKTX()); |
|
139 |
ordeInfo.setLineCode(item.getFEVOR()); |
|
140 |
ordeInfo.setWorkOrderNo(item.getAUFNR()); |
|
141 |
ordeInfo.setPlanQty((long) Double.parseDouble(item.getPSMNG())); |
|
142 |
ordeInfo.setProductionNotice(item.getZSCTZD()); |
|
143 |
ordeInfo.setTypeZ(item.getFERTH()); |
|
144 |
ordeInfo.setCreateUser(item.getZUSER()); |
|
145 |
//ordeInfo.setCreateTime(item.getZDATE()); |
|
146 |
ordeInfo.setDemandDate(item.getGSTRP());//开工日期 |
|
147 |
omProductionOrdeInfoService.insertOmProductionOrdeInfo(ordeInfo); |
|
148 |
} |
|
149 |
} else { |
|
150 |
throw new ServiceException("未接收到数据,请检查"); |
df1f2b
|
151 |
} |
131e8c
|
152 |
|
df1f2b
|
153 |
} |
懒 |
154 |
|
|
155 |
public static String getInterfaceInformationXml(String url,String xml){ |
|
156 |
int timeout = 10000; |
|
157 |
HttpClient client = new HttpClient(); |
|
158 |
//如果需要用户名密码验证;不需要验证登录则不需要以下4行 |
|
159 |
String username = "POMESUSER"; |
|
160 |
String password = "12345tgb"; |
|
161 |
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); |
|
162 |
client.getState().setCredentials(AuthScope.ANY, creds); |
|
163 |
|
|
164 |
PostMethod postMethod = new PostMethod(url); |
|
165 |
// 设置连接超时 |
|
166 |
client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); |
|
167 |
// 设置读取时间超时 |
|
168 |
client.getHttpConnectionManager().getParams().setSoTimeout(timeout); |
|
169 |
// 然后把Soap请求数据添加到PostMethod中 |
|
170 |
RequestEntity requestEntity = null; |
|
171 |
try { |
|
172 |
requestEntity = new StringRequestEntity(xml, "text/xml", "UTF-8"); |
|
173 |
} catch (UnsupportedEncodingException e) { |
|
174 |
throw new RuntimeException(e); |
|
175 |
} |
|
176 |
|
|
177 |
// 设置请求头部,否则可能会报 “no SOAPAction header” 的错误 |
51b05b
|
178 |
postMethod.setRequestHeader("SOAPAction", "application/x-www-form-urlencoded; charset=UTF-8"); |
df1f2b
|
179 |
// 设置请求体 |
懒 |
180 |
postMethod.setRequestEntity(requestEntity); |
|
181 |
int status = 0; |
|
182 |
try { |
|
183 |
status = client.executeMethod(postMethod); |
|
184 |
} catch (IOException e) { |
b4ff0d
|
185 |
logger.info("errorLocation1,"+e); |
df1f2b
|
186 |
throw new RuntimeException(e); |
懒 |
187 |
} |
|
188 |
if (status == 200) {// 成功 |
|
189 |
InputStream is = null; |
|
190 |
// 获取请求结果字符串 |
|
191 |
String result = null; |
|
192 |
try { |
51b05b
|
193 |
result = postMethod.getResponseBodyAsString(); |
W |
194 |
logger.info("二次输出流333333,{}",result); |
df1f2b
|
195 |
return result; |
懒 |
196 |
} catch (IOException e) { |
51b05b
|
197 |
logger.info("errorLocation2,"+e); |
df1f2b
|
198 |
throw new RuntimeException(e); |
懒 |
199 |
} |
|
200 |
} |
|
201 |
return "接口调用错误"; |
|
202 |
} |
|
203 |
|
131e8c
|
204 |
public static String getProductionPlanInformationXml(String factory,String planNo){ |
df1f2b
|
205 |
String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\n" + |
懒 |
206 |
" <soapenv:Header/>\n" + |
|
207 |
" <soapenv:Body>\n" + |
|
208 |
" <urn:ZPP_CF_MES_005>\n" + |
|
209 |
" <!--Optional:-->\n" + |
131e8c
|
210 |
" <IV_WERKS>"+factory+"</IV_WERKS>\n" + |
df1f2b
|
211 |
" <!--Optional:-->\n" + |
131e8c
|
212 |
" <IV_ZSCTZD>"+planNo+"</IV_ZSCTZD>\n" + |
df1f2b
|
213 |
" </urn:ZPP_CF_MES_005>\n" + |
懒 |
214 |
" </soapenv:Body>\n" + |
|
215 |
"</soapenv:Envelope>"; |
|
216 |
return content; |
|
217 |
} |
|
218 |
|
|
219 |
/** |
|
220 |
* 方式--贰 |
|
221 |
* 使用hutool工具包中的工具转化 |
|
222 |
* @param xmlStr |
|
223 |
* @return |
|
224 |
*/ |
|
225 |
public static String xmlToJSON2(String xmlStr){ |
|
226 |
JSONObject jsonObject1 = cn.hutool.json.XML.toJSONObject(xmlStr, true); |
131e8c
|
227 |
String data = new String(); |
df1f2b
|
228 |
Gson gson = new Gson(); |
懒 |
229 |
JsonObject jsonObject2 = gson.fromJson(jsonObject1.toString(), JsonObject.class); |
131e8c
|
230 |
JsonObject result = jsonObject2 |
df1f2b
|
231 |
.getAsJsonObject("SOAP:Envelope") |
懒 |
232 |
.getAsJsonObject("SOAP:Body") |
131e8c
|
233 |
.getAsJsonObject("n0:ZPP_CF_MES_005.Response"); |
W |
234 |
if (ObjectUtil.isNotNull(result)){ |
b4ff0d
|
235 |
logger.info("messageLocation2,"+result); |
131e8c
|
236 |
String string = result.get("EV_MESSAGE").toString(); |
cd403c
|
237 |
// if (string.contains("查询成功")){ |
W |
238 |
// logger.info("messageLocation3,"+string); |
|
239 |
// JsonObject etData = jsonObject2 |
|
240 |
// .getAsJsonObject("SOAP:Envelope") |
|
241 |
// .getAsJsonObject("SOAP:Body") |
|
242 |
// .getAsJsonObject("n0:ZPP_CF_MES_005.Response") |
|
243 |
// .getAsJsonObject("ET_DATA"); |
|
244 |
// data = etData.toString(); |
|
245 |
// logger.info("messageLocation4,"+data); |
|
246 |
// } |
|
247 |
logger.info("messageLocation3,"+string); |
|
248 |
JsonObject etData = jsonObject2 |
|
249 |
.getAsJsonObject("SOAP:Envelope") |
|
250 |
.getAsJsonObject("SOAP:Body") |
|
251 |
.getAsJsonObject("n0:ZPP_CF_MES_005.Response") |
|
252 |
.getAsJsonObject("ET_DATA"); |
|
253 |
data = etData.toString(); |
|
254 |
logger.info("messageLocation4,"+data); |
131e8c
|
255 |
} |
W |
256 |
|
|
257 |
return data; |
df1f2b
|
258 |
} |
5030f3
|
259 |
/** |
Y |
260 |
* 方式--贰 |
|
261 |
* 使用hutool工具包中的工具转化 |
|
262 |
* @param xmlStr |
|
263 |
* @return |
|
264 |
*/ |
|
265 |
public static String xmlToJSON1(String xmlStr){ |
|
266 |
String status = ""; |
|
267 |
if(xmlStr.contains("EV_MESSAGE")){ |
|
268 |
JSONObject jsonObject1 = cn.hutool.json.XML.toJSONObject(xmlStr, true); |
|
269 |
|
|
270 |
ObjectMapper objectMapper = new ObjectMapper(); |
|
271 |
JsonNode rootNode = null; |
|
272 |
try { |
|
273 |
rootNode = objectMapper.readTree(String.valueOf(jsonObject1)); |
|
274 |
} catch (JsonProcessingException e) { |
|
275 |
throw new RuntimeException(e); |
|
276 |
} |
|
277 |
String evStatus = rootNode |
|
278 |
.path("SOAP:Envelope") |
|
279 |
.path("SOAP:Body") |
|
280 |
.path("n0:ZPP_BC_001.Response") |
|
281 |
.path("EV_MESSAGE") |
|
282 |
.asText(); |
|
283 |
status = evStatus; |
|
284 |
} |
|
285 |
return status; |
|
286 |
} |
df1f2b
|
287 |
|
55b0cb
|
288 |
/** |
懒 |
289 |
* 方式--贰 |
|
290 |
* 使用hutool工具包中的工具转化 |
|
291 |
* @param xmlStr |
|
292 |
* @return |
|
293 |
*/ |
|
294 |
public static String xmlToJSON3(String xmlStr){ |
|
295 |
String status = ""; |
|
296 |
if(xmlStr.contains("EV_STATUS")){ |
|
297 |
JSONObject jsonObject1 = cn.hutool.json.XML.toJSONObject(xmlStr, true); |
|
298 |
|
|
299 |
ObjectMapper objectMapper = new ObjectMapper(); |
|
300 |
JsonNode rootNode = null; |
|
301 |
try { |
|
302 |
rootNode = objectMapper.readTree(String.valueOf(jsonObject1)); |
|
303 |
} catch (JsonProcessingException e) { |
|
304 |
throw new RuntimeException(e); |
|
305 |
} |
|
306 |
String evStatus = rootNode |
|
307 |
.path("SOAP:Envelope") |
|
308 |
.path("SOAP:Body") |
|
309 |
.path("n0:ZPP_BC_001.Response") |
|
310 |
.path("EV_STATUS") |
|
311 |
.asText(); |
|
312 |
status = evStatus; |
|
313 |
} |
|
314 |
return status; |
|
315 |
} |
|
316 |
|
df1f2b
|
317 |
} |