From 73734f096b25cb3c350ddceec46e47f4de004b7d Mon Sep 17 00:00:00 2001
From: dbs <email0099@163.com>
Date: 星期一, 23 十二月 2024 16:34:16 +0800
Subject: [PATCH] 新增MES接口的解析处理。

---
 src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java |   71 +++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java b/src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java
index b3527ae..b6949c1 100644
--- a/src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java
+++ b/src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java
@@ -1,6 +1,10 @@
 package com.itstyle.mdm.utils;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
 import com.itstyle.mdm.entity.HttpClientResult;
+import com.itstyle.mdm.utils.model.SoapEnvelopeProduct;
 import org.apache.http.HttpStatus;
 import org.apache.http.NameValuePair;
 import org.apache.http.client.config.RequestConfig;
@@ -154,6 +158,73 @@
         }
     }
 
+    public static String getMesResponseJson(String xml){
+        return SoapEnvelopeProduct.getResJson(xml);
+    }
+    public static String getMesJson(String json){
+        JSONObject mesResJson=new JSONObject();
+        JSONObject jsonobj=JSONObject.parseObject(json);
+        JSONArray jsonArray = jsonobj.getJSONArray("records");
+        JSONArray mesResDetail=new JSONArray();
+        for(int i=0;i<jsonArray.size();i++){
+            JSONObject rowObject = jsonArray.getJSONObject(i);
+            JSONObject tmp1=new JSONObject();
+            tmp1.put("Tgcoriginalcode",rowObject.getString("tgctwoclasscode"));
+
+            tmp1.put("Code",rowObject.getString("code"));
+
+            tmp1.put("Name",rowObject.getString("name"));
+
+            tmp1.put("Specification",rowObject.getString("specification"));
+
+            tmp1.put("UnitName",rowObject.getString("unitName"));
+
+            tmp1.put("TypeCode",rowObject.getString("typeCode"));
+
+            tmp1.put("SpecificationDisplayName",rowObject.getString("specificationDisplayName"));
+
+            tmp1.put("SupplierName",rowObject.getString("supplierName"));
+            mesResDetail.add(tmp1);
+        }
+        mesResJson.put("Records",mesResDetail);
+        return mesResJson.toJSONString();
+    }
+    public static String getMesSoapBody(String json){
+        return "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
+                "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\n" +
+                "  <soap12:Body>\n" +
+                "    <ReceiveTCG xmlns=\"http://www.hitachi.com/HITPHAMS\">\n" +
+                "      <JsonStr><![CDATA["+json+"]]></JsonStr>\n" +
+                "    </ReceiveTCG>\n" +
+                "  </soap12:Body>\n" +
+                "</soap12:Envelope>";
+    }
+    public static HttpClientResult doPostXmlJson(String url, String xmlStr) throws Exception{
+        // 鍒涘缓httpClient瀵硅薄
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+
+        //绗簩姝ワ細鍒涘缓httpPost瀵硅薄
+        HttpPost httpPost = new HttpPost(url);
+        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(CONNECT_TIMEOUT).setSocketTimeout(SOCKET_TIMEOUT).build();
+        httpPost.setConfig(requestConfig);
+        //绗笁姝ワ細缁檋ttpPost璁剧疆JSON鏍煎紡鐨勫弬鏁�
+        StringEntity requestEntity = new StringEntity(xmlStr,"utf-8");
+        requestEntity.setContentEncoding("UTF-8");
+        httpPost.setHeader("Content-type", "application/soap+xml; charset=utf-8");
+        httpPost.setEntity(requestEntity);
+
+        // 鍒涘缓httpResponse瀵硅薄
+        CloseableHttpResponse httpResponse = null;
+
+        try {
+            // 鎵ц璇锋眰骞惰幏寰楀搷搴旂粨鏋�
+            return getHttpClientResult(httpResponse, httpClient, httpPost);
+        } finally {
+            // 閲婃斁璧勬簮
+            release(httpResponse, httpClient);
+        }
+    }
+
     /**
      * Description: 鑾峰緱鍝嶅簲缁撴灉
      *

--
Gitblit v1.8.0