dbs
2024-12-12 83e0034ab5f729afeb2c25e328d63fda31ff01e1
src/main/java/com/itstyle/mdm/utils/MdmApiUtils.java
@@ -1,5 +1,7 @@
package com.itstyle.mdm.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.itstyle.mdm.entity.HttpClientResult;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
@@ -154,6 +156,77 @@
        }
    }
    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"));
            JSONObject tmp2=new JSONObject();
            tmp2.put("Code",rowObject.getString("code"));
            JSONObject tmp3=new JSONObject();
            tmp3.put("Name",rowObject.getString("name"));
            JSONObject tmp4=new JSONObject();
            tmp4.put("Specification",rowObject.getString("specification"));
            JSONObject tmp5=new JSONObject();
            tmp5.put("UnitName",rowObject.getString("unitName"));
            JSONObject tmp6=new JSONObject();
            tmp6.put("TypeCode",rowObject.getString("typeCode"));
            JSONObject tmp7=new JSONObject();
            tmp7.put("SpecificationDisplayName",rowObject.getString("specificationDisplayName"));
            JSONObject tmp8=new JSONObject();
            tmp8.put("SupplierName",rowObject.getString("supplierName"));
            mesResDetail.add(tmp1);
            mesResDetail.add(tmp2);
            mesResDetail.add(tmp3);
            mesResDetail.add(tmp4);
            mesResDetail.add(tmp5);
            mesResDetail.add(tmp6);
            mesResDetail.add(tmp7);
            mesResDetail.add(tmp8);
        }
        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);
        //第三步:给httpPost设置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: 获得响应结果
     *