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               |    5 ++
 src/main/java/com/itstyle/mdm/utils/MdmUtils.java                  |    5 ++
 src/main/java/com/itstyle/mdm/utils/model/SoapEnvelopeProduct.java |   64 ++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java b/src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java
index 13f452b..b6949c1 100644
--- a/src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java
+++ b/src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java
@@ -2,7 +2,9 @@
 
 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;
@@ -156,6 +158,9 @@
         }
     }
 
+    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);
diff --git a/src/main/java/com/itstyle/mdm/utils/MdmUtils.java b/src/main/java/com/itstyle/mdm/utils/MdmUtils.java
index 4c43192..1bcceaa 100644
--- a/src/main/java/com/itstyle/mdm/utils/MdmUtils.java
+++ b/src/main/java/com/itstyle/mdm/utils/MdmUtils.java
@@ -158,6 +158,9 @@
 
                     //鍝嶅簲缁撴灉
                     String content = httpClientResult.getContent();
+                    if("MES绯荤粺".equals(sysName)){
+                        content = MdmApiUtils.getMesResponseJson(content);
+                    }
                     int code = httpClientResult.getCode();
                     if(200 == code){
                         //鎴愬姛
@@ -168,7 +171,7 @@
                     }
                 } catch (Exception e) {
                     e.printStackTrace();
-                    this.saveInterfaceLog(uuid,interfaceName,address,jsonParam,"{\"batchId\":\""+uuid+"\",\"msg\":\" 鎺ュ彛璋冪敤缃戠粶寮傚父锛侊紒锛� \"}");
+                    this.saveInterfaceLog(uuid,interfaceName,address,jsonParam,"{\"batchId\":\""+uuid+"\",\"msg\":\" 鎺ュ彛璋冪敤缃戠粶寮傚父锛侊紒锛�/"+e.getMessage()+"/ \"}");
                 }
 
             }
diff --git a/src/main/java/com/itstyle/mdm/utils/model/SoapEnvelopeProduct.java b/src/main/java/com/itstyle/mdm/utils/model/SoapEnvelopeProduct.java
new file mode 100644
index 0000000..b7d8731
--- /dev/null
+++ b/src/main/java/com/itstyle/mdm/utils/model/SoapEnvelopeProduct.java
@@ -0,0 +1,64 @@
+package com.itstyle.mdm.utils.model;
+
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+@JacksonXmlRootElement(localName = "soap:Envelope")
+public class SoapEnvelopeProduct {
+    @JacksonXmlProperty(localName = "Body")
+    private SoapBody body;
+
+    // getters and setters
+    public SoapBody getBody() {
+        return body;
+    }
+
+    public void setBody(SoapBody body) {
+        this.body = body;
+    }
+
+    public static String getResJson(String xml){
+        XmlMapper xmlMapper = new XmlMapper();
+        SoapEnvelopeProduct envelope = null;
+        String jsonStr="";
+        try {
+            envelope = xmlMapper.readValue(xml, SoapEnvelopeProduct.class);
+            jsonStr = envelope.getBody().getReceiveTCGResponse().getReceiveTCGResult().trim();
+        } catch (Exception e) {
+            jsonStr="{\"error\":\""+e.getMessage()+"\"}";
+        }
+        return jsonStr;
+    }
+}
+
+class SoapBody {
+    @JacksonXmlProperty(localName = "ReceiveTCGResponse")
+    @JacksonXmlElementWrapper(useWrapping = false)
+    private ReceiveTCGResponse receiveTCGResponse;
+
+    // getters and setters
+    public ReceiveTCGResponse getReceiveTCGResponse() {
+        return receiveTCGResponse;
+    }
+
+    public void setReceiveTCGResponse(ReceiveTCGResponse receiveTCGResponse) {
+        this.receiveTCGResponse = receiveTCGResponse;
+    }
+}
+
+@JacksonXmlRootElement(localName = "ReceiveTCGResponse", namespace = "http://www.hitachi.com/HITPHAMS")
+class ReceiveTCGResponse {
+    @JacksonXmlProperty(localName = "ReceiveTCGResult")
+    private String receiveTCGResult;
+
+    // getters and setters
+    public String getReceiveTCGResult() {
+        return receiveTCGResult;
+    }
+
+    public void setReceiveTCGResult(String receiveTCGResult) {
+        this.receiveTCGResult = receiveTCGResult;
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0