From 9906e6b188bf2c36dddc0d5adadbf02e69ea3e4b Mon Sep 17 00:00:00 2001 From: wujian <14790700720@163.com> Date: 星期五, 25 十月 2024 09:17:29 +0800 Subject: [PATCH] add -sap --- jcdm-main/src/main/java/com/jcdm/main/webservice/service/ReceivingServices.java | 148 +++++++++++++++++++++++++++++++++++++------------ 1 files changed, 111 insertions(+), 37 deletions(-) diff --git a/jcdm-main/src/main/java/com/jcdm/main/webservice/service/ReceivingServices.java b/jcdm-main/src/main/java/com/jcdm/main/webservice/service/ReceivingServices.java index e0c7c4a..abd05b1 100644 --- a/jcdm-main/src/main/java/com/jcdm/main/webservice/service/ReceivingServices.java +++ b/jcdm-main/src/main/java/com/jcdm/main/webservice/service/ReceivingServices.java @@ -1,12 +1,15 @@ package com.jcdm.main.webservice.service; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.JsonObject; +import com.jcdm.common.exception.ServiceException; import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; import com.jcdm.main.da.opcuaconfig.init.BeanUtils; import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; @@ -22,21 +25,25 @@ import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.io.IOUtils; import com.jcdm.main.om.productionOrde.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; import javax.swing.border.Border; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; +import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.List; public class ReceivingServices { + + private static final Logger logger = LoggerFactory.getLogger("sys-user"); @Autowired // private static IOmProductionOrdeInfoService omProductionOrdeInfoService; private static IOmProductionOrdeInfoService omProductionOrdeInfoService = BeanUtils.getBean(IOmProductionOrdeInfoService.class); - public static final String ProductionPlanInformationUrl = "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"; + 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"; +// 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"; public static void main(String[] args) throws Exception { // getInterfaceInformationXml(ProductionPlanInformationUrl,getProductionPlanInformationXml("A0055577")); @@ -104,26 +111,45 @@ // } } - public static void insertWebserviceData(String str) { - String result = getInterfaceInformationXml(ProductionPlanInformationUrl, getProductionPlanInformationXml(str)); + public static void insertWebserviceData(String factory,String str) { + String result = getInterfaceInformationXml(ProductionPlanInformationUrl, getProductionPlanInformationXml(factory,str)); + logger.info("messageLocation1,"+result); String jsonStr = xmlToJSON2(result); - Gson gson = new Gson(); - // 灏唈son瀛楃涓茶浆鎹㈡垚瀵硅薄 - ItemList itemList = gson.fromJson(jsonStr, ItemList.class); - for (Item item : itemList.getItem()) { - OmProductionOrdeInfo ordeInfo = new OmProductionOrdeInfo(); - ordeInfo.setProductCode(item.getPLNBEZ()); - ordeInfo.setProductName(item.getMAKTX()); - ordeInfo.setLineCode(item.getFEVOR()); - ordeInfo.setWorkOrderNo(item.getAUFNR()); - ordeInfo.setPlanQty((long) Double.parseDouble(item.getPSMNG())); - ordeInfo.setProductionNotice(item.getZSCTZD()); - ordeInfo.setTypeZ(item.getFERTH()); - ordeInfo.setCreateUser(item.getZUSER()); - //ordeInfo.setCreateTime(item.getZDATE()); - ordeInfo.setDemandDate(item.getGSTRP());//寮�宸ユ棩鏈� - omProductionOrdeInfoService.insertOmProductionOrdeInfo(ordeInfo); + logger.info("messageLocation5,"+jsonStr); + if (StrUtil.isNotBlank(jsonStr)){ + if (!jsonStr.contains("[") && !jsonStr.contains("]")){ + StringBuilder stringBuilder = new StringBuilder(jsonStr); + stringBuilder.insert(8,"["); + stringBuilder.insert(jsonStr.length(),"]"); + jsonStr = stringBuilder.toString(); + logger.info("messageLocation6,"+jsonStr); + } + Gson gson = new Gson(); + // 灏唈son瀛楃涓茶浆鎹㈡垚瀵硅薄 + ItemList itemList = gson.fromJson(jsonStr, ItemList.class); + if (ObjectUtil.isNotNull(itemList)){ + logger.info("messageLocation7,"+ itemList); + } + for (Item item : itemList.getItem()) { + logger.info("messageLocation8,"+item); + OmProductionOrdeInfo ordeInfo = new OmProductionOrdeInfo(); + ordeInfo.setWorkshopCode(item.getWERKS()); + ordeInfo.setProductCode(item.getPLNBEZ()); + ordeInfo.setProductName(item.getMAKTX()); + ordeInfo.setLineCode(item.getFEVOR()); + ordeInfo.setWorkOrderNo(item.getAUFNR()); + ordeInfo.setPlanQty((long) Double.parseDouble(item.getPSMNG())); + ordeInfo.setProductionNotice(item.getZSCTZD()); + ordeInfo.setTypeZ(item.getFERTH()); + ordeInfo.setCreateUser(item.getZUSER()); + //ordeInfo.setCreateTime(item.getZDATE()); + ordeInfo.setDemandDate(item.getGSTRP());//寮�宸ユ棩鏈� + omProductionOrdeInfoService.insertOmProductionOrdeInfo(ordeInfo); + } + } else { + throw new ServiceException("鏈帴鏀跺埌鏁版嵁锛岃妫�鏌�"); } + } public static String getInterfaceInformationXml(String url,String xml){ @@ -149,43 +175,41 @@ } // 璁剧疆璇锋眰澶撮儴锛屽惁鍒欏彲鑳戒細鎶� 鈥渘o SOAPAction header鈥� 鐨勯敊璇� - postMethod.setRequestHeader("SOAPAction", ""); + postMethod.setRequestHeader("SOAPAction", "application/x-www-form-urlencoded; charset=UTF-8"); // 璁剧疆璇锋眰浣� postMethod.setRequestEntity(requestEntity); int status = 0; try { status = client.executeMethod(postMethod); } catch (IOException e) { + logger.info("errorLocation1,"+e); throw new RuntimeException(e); } if (status == 200) {// 鎴愬姛 InputStream is = null; - try { - is = postMethod.getResponseBodyAsStream(); - } catch (IOException e) { - throw new RuntimeException(e); - } // 鑾峰彇璇锋眰缁撴灉瀛楃涓� String result = null; try { - result = IOUtils.toString(is); + result = postMethod.getResponseBodyAsString(); + logger.info("浜屾杈撳嚭娴�333333,{}",result); return result; } catch (IOException e) { + logger.info("errorLocation2,"+e); throw new RuntimeException(e); } } return "鎺ュ彛璋冪敤閿欒"; } - public static String getProductionPlanInformationXml(String str){ + public static String getProductionPlanInformationXml(String factory,String planNo){ String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\n" + " <soapenv:Header/>\n" + " <soapenv:Body>\n" + " <urn:ZPP_CF_MES_005>\n" + " <!--Optional:-->\n" + - " <IV_WERKS>1000</IV_WERKS>\n" + + " <IV_WERKS>"+factory+"</IV_WERKS>\n" + " <!--Optional:-->\n" + - " <IV_ZSCTZD>"+str+"</IV_ZSCTZD>\n" + + " <IV_ZSCTZD>"+planNo+"</IV_ZSCTZD>\n" + " </urn:ZPP_CF_MES_005>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>"; @@ -200,15 +224,65 @@ */ public static String xmlToJSON2(String xmlStr){ JSONObject jsonObject1 = cn.hutool.json.XML.toJSONObject(xmlStr, true); - + String data = new String(); Gson gson = new Gson(); JsonObject jsonObject2 = gson.fromJson(jsonObject1.toString(), JsonObject.class); - JsonObject etData = jsonObject2 + JsonObject result = jsonObject2 .getAsJsonObject("SOAP:Envelope") .getAsJsonObject("SOAP:Body") - .getAsJsonObject("n0:ZPP_CF_MES_005.Response") - .getAsJsonObject("ET_DATA"); - return etData.toString(); + .getAsJsonObject("n0:ZPP_CF_MES_005.Response"); + if (ObjectUtil.isNotNull(result)){ + logger.info("messageLocation2,"+result); + String string = result.get("EV_MESSAGE").toString(); +// if (string.contains("鏌ヨ鎴愬姛")){ +// logger.info("messageLocation3,"+string); +// JsonObject etData = jsonObject2 +// .getAsJsonObject("SOAP:Envelope") +// .getAsJsonObject("SOAP:Body") +// .getAsJsonObject("n0:ZPP_CF_MES_005.Response") +// .getAsJsonObject("ET_DATA"); +// data = etData.toString(); +// logger.info("messageLocation4,"+data); +// } + logger.info("messageLocation3,"+string); + JsonObject etData = jsonObject2 + .getAsJsonObject("SOAP:Envelope") + .getAsJsonObject("SOAP:Body") + .getAsJsonObject("n0:ZPP_CF_MES_005.Response") + .getAsJsonObject("ET_DATA"); + data = etData.toString(); + logger.info("messageLocation4,"+data); + } + + return data; + } + /** + * 鏂瑰紡--璐� + * 浣跨敤hutool宸ュ叿鍖呬腑鐨勫伐鍏疯浆鍖� + * @param xmlStr + * @return + */ + public static String xmlToJSON1(String xmlStr){ + String status = ""; + if(xmlStr.contains("EV_MESSAGE")){ + JSONObject jsonObject1 = cn.hutool.json.XML.toJSONObject(xmlStr, true); + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode rootNode = null; + try { + rootNode = objectMapper.readTree(String.valueOf(jsonObject1)); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + String evStatus = rootNode + .path("SOAP:Envelope") + .path("SOAP:Body") + .path("n0:ZPP_BC_001.Response") + .path("EV_MESSAGE") + .asText(); + status = evStatus; + } + return status; } /** -- Gitblit v1.9.3