You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					140 lines
				
				5.1 KiB
			
		
		
			
		
	
	
					140 lines
				
				5.1 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								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<String, Object> 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,
							 | 
						||
| 
								 | 
							
								                    "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ruim=\"http://www.ruimei.com.cn\">" +
							 | 
						||
| 
								 | 
							
								                            "<soapenv:Header/>" +
							 | 
						||
| 
								 | 
							
								                            "<soapenv:Body><ruim:UnifiedEntrance>" +
							 | 
						||
| 
								 | 
							
								                            "<ruim:methodName>" + method + "</ruim:methodName>" +
							 | 
						||
| 
								 | 
							
								                            "<ruim:parameterType>1</ruim:parameterType>" +
							 | 
						||
| 
								 | 
							
								                            "<ruim:parameterValue><![CDATA[<Request>" + SoapHelper.requestParams("RMLis", params) + "</Request>]]></ruim:parameterValue>" +
							 | 
						||
| 
								 | 
							
								                            "</ruim:UnifiedEntrance></soapenv:Body></soapenv:Envelope>"
							 | 
						||
| 
								 | 
							
								            );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            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<Node> 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<String, Object> 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<String, Object> requestParams = new HashMap<>();
							 | 
						||
| 
								 | 
							
								        if (params != null) {
							 | 
						||
| 
								 | 
							
								            params.setParams(requestParams);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        return getJsonResult(method, requestParams);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								}
							 |