dbs
2024-12-23 73734f096b25cb3c350ddceec46e47f4de004b7d
新增MES接口的解析处理。
1个文件已添加
2个文件已修改
74 ■■■■■ 已修改文件
src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/itstyle/mdm/utils/MdmUtils.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/itstyle/mdm/utils/model/SoapEnvelopeProduct.java 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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);
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()+"/ \"}");
                }
            }
src/main/java/com/itstyle/mdm/utils/model/SoapEnvelopeProduct.java
New file
@@ -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;
    }
}