package com.ynxbd.common.helper.lis; import com.ynxbd.common.helper.ProperHelper; import com.ynxbd.common.helper.common.ErrorHelper; import com.ynxbd.common.helper.common.FileHelper; import com.ynxbd.common.helper.common.SoapHelper; import com.ynxbd.common.result.JsonResult; import com.ynxbd.common.result.JsonResultEnum; import lombok.extern.slf4j.Slf4j; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.Node; import java.util.HashMap; import java.util.List; import java.util.Map; @Slf4j public class RMLisHelper { // 请求地址 final private static String LIS_SOAP_URL; final private static Boolean IS_LOG_RESP; static { ProperHelper config = new ProperHelper().read("webservice.properties"); String url = config.getString("lis.url"); Boolean unifiedEntrance = config.getBoolean("lis.unifiedEntrance",false); IS_LOG_RESP = config.getBoolean("lis.is_log_resp",false); if (url == null) { LIS_SOAP_URL = null; log.error("Lis配置文件读取失败"); } else if(unifiedEntrance==false){ LIS_SOAP_URL = "http://" + url + "/LisReportServics.asmx?wsdl"; }else { LIS_SOAP_URL = "http://" + url + "/LisReportServics.asmx?UnifiedEntrance"; } } /** * webService请求工具类(枚举版) * * @param params 发送的参数 * @return 响应的xml数据 */ public static String getResponseXml(String method, Map params) { if (params == null) { log.info("params is null"); return null; } String result; try { long begTime = System.currentTimeMillis(); // 开始时间 String responseXml = SoapHelper.post("RMLis", LIS_SOAP_URL, null, "" + "" + "" + "" + method + "" + "1" + "" + SoapHelper.requestParams("RMLis", params) + "]]>" + "" ); long endTime = System.currentTimeMillis(); // 结束时间 String takeTime = (endTime - begTime) + "ms"; // 耗时 if (responseXml == null) { log.info("RMLis 请求无响应-耗时:[{}]", takeTime); return null; } //解析响应消息,使用SAXReader对象 org.dom4j.Document document = DocumentHelper.parseText(responseXml); if (document == null) { log.info("RMLis响应内容解析失败-耗时:[{}]-返回xml={}", takeTime, responseXml); return null; } Element rootElement = document.getRootElement(); List nodes = rootElement.selectNodes("//soap:Body"); Element element = (Element) nodes.get(0); Element unifiedEntranceResponse = element.element("UnifiedEntranceResponse"); if (unifiedEntranceResponse == null) { log.info("RMLis响应内容解析失败1-耗时:[{}]", takeTime); return null; } Element unifiedEntranceResult = unifiedEntranceResponse.element("UnifiedEntranceResult"); if (unifiedEntranceResult == null) { log.info("RMLis响应内容解析失败2-耗时:[{}]", takeTime); return null; } result = unifiedEntranceResult.getText(); if (result.length() > 500) { if(IS_LOG_RESP){ log.info("RMLis请求成功-耗时:[{}]-返回xml={}", takeTime,result); } log.info("RMLis请求成功-耗时:[{}]", takeTime); } else { log.info("RMLis请求成功-耗时:[{}]-返回xml={}", takeTime, result); } return result; } catch (DocumentException e) { ErrorHelper.println(e); } return null; } /** * xml响应数据组装成为JSON数据 * * @return 封装好的对象 */ public static JsonResult getJsonResult(String method, Map params) { String responseXml = getResponseXml(method, params); return JsonResult.xmlToBean(responseXml, JsonResultEnum.SYS_RM_LIS); } /** * xml响应数据组装成为JSON数据 * * @return 封装好的对象 */ public static JsonResult getJsonResult(String method, JsonResult.MapParams params) { Map requestParams = new HashMap<>(); if (params != null) { params.setParams(requestParams); } return getJsonResult(method, requestParams); } }