2/25 优化1.0

axxyy
wangwei 1 month ago
parent 189de7b247
commit af135d6b4e

@ -156,6 +156,21 @@
<artifactId>yb</artifactId>
<version>zephyr1.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.bouncycastle</groupId>-->
<!-- <artifactId>bcprov-jdk15to18</artifactId>-->

@ -30,7 +30,6 @@ import com.glxp.mipsdl.dao.inout.IoOrderDao;
import com.glxp.mipsdl.dao.inout.IoOrderDetailBizDao;
import com.glxp.mipsdl.dao.thrsys.*;
import com.glxp.mipsdl.entity.auth.AuthWarehouseEntity;
import com.glxp.mipsdl.entity.axxyy.PriceDict;
import com.glxp.mipsdl.entity.basic.BasicBussinessTypeEntity;
import com.glxp.mipsdl.entity.basic.BasicCorpEntity;
import com.glxp.mipsdl.entity.basic.BasicUdirelEntity;
@ -63,23 +62,40 @@ import com.glxp.mipsdl.thirddao.njxyy.ThrProductsMapper;
import com.glxp.mipsdl.thirddao.njxyy.ThrSickerMapper;
import com.glxp.mipsdl.util.*;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import okhttp3.*;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.annotation.Resource;
import javax.xml.bind.JAXBException;
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
;
import java.io.*;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.util.*;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Client
@ -142,29 +158,68 @@ public class AxxyyClient extends CommonHttpClient {
* @param methodName
* @return
*/
public String getMsgHeader(String methodName) {
public static String getMsgHeader(String methodName) {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<root>\n" +
"<serverName>" + methodName + "</serverName>\n" +
"<format>" + "xml" + "</format>\n" +
"<format>xml</format>\n" +
"<callOperator>" + "" + "</callOperator>\n" +
"<certificate>" + "ousrgPVbTpn7ckRUZWypfBR7tGWi2EINBp4vIHOS44V/jN3U5dD+5A==" + "</certificate>\n" +
"<certificate>ousrgPVbTpn7ckRUZWypfBR7tGWi2EINBp4vIHOS44V/jN3U5dD+5A==</certificate>\n" +
"</root>";
}
public String setFilter() {
public static String setFilter() {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<root>\n" +
// "<code>" + "" + "</code>\n" +
"<name>" + "红细胞寿命测定-呼气法" + "</name>\n" +
// "<spell>" + "" + "</spell>\n" +
// "<invalid>" + "" + "</invalid>\n" +
// "<subject>" + "" + "</subject>\n" +
"<code>" + "" + "</code>\n" +
"<name>红细胞寿命测定-呼气法</name>\n" +
"<spell>" + "" + "</spell>\n" +
"<invalid>" + "" + "</invalid>\n" +
"<subject>" + "" + "</subject>\n" +
"</root>";
}
private static String buildSoapRequest(String msgHeader, String msgBody) {
// 构建 SOAP 请求消息
// String soapRequestTemplate =
// "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:zys=\"http://www.zysoft.com.cn/\">\n" +
// "<soapenv:Header/>\n" +
// " <soapenv:Body>\n" +
// " <zys:CallInterface>\n" +
// " <zys:msgHeader><![CDATA[%s]]></zys:msgHeader>\n" +
// " <zys:msgBody><![CDATA[%s]]></zys:msgBody>\n" +
// " </zys:CallInterface>\n" +
// " </soapenv:Body>\n" +
// "</soapenv:Envelope>";
String soapRequestTemplate = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:zys=\"http://www.zysoft.com.cn/\">\n" +
"<soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <zys:CallInterface>\n" +
" <zys:msgHeader><![CDATA[<root>\n" +
" <serverName>getPriceDict</serverName>\n" +
" <format>xml</format>\n" +
" <callOperator></callOperator>\n" +
" <certificate>ousrgPVbTpn7ckRUZWypfBR7tGWi2EINBp4vIHOS44V/jN3U5dD+5A==</certificate>\n" +
" </root>]]>\n" +
"</zys:msgHeader>\n" +
"<zys:msgBody><![CDATA[\t\n" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<root>\n" +
"<name>红细胞寿命测定-呼气法</name>\n" +
"</root>]]>\n" +
"</zys:msgBody>\n" +
" </zys:CallInterface>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
// return String.format(soapRequestTemplate, msgHeader, msgBody);
return soapRequestTemplate;
}
/**
* ---(A001)
*
@ -957,74 +1012,109 @@ public class AxxyyClient extends CommonHttpClient {
@Override
public BaseResponse getBasicProject(DlThirdProjectRequest dlThirdProjectRequest) {
CtqyyRequest ctqyyRequest = new CtqyyRequest();
String getPriceDict = getMsgHeader("getPriceDict");
String s = setFilter();
log.error("DANGQIAN 请求头:::" + getPriceDict);
log.error("DANGQIAN 请求体:::" + s);
try {
String response = callInterface(getMsgHeader("getPriceDict"), setFilter());
System.out.println("Response: " + response);
} catch (Exception e) {
log.error("解析安溪县医院智业返回项目信息数据异常,返回结果:{}", e);
log.error("异常信息:{}", e);
e.printStackTrace();
// 发送请求
BaseResponse response = callInterface(getMsgHeader("getPriceDict"), setFilter());
// 记录日志
log.error("获取智业收费项目222: " + response);
// log.error("获取智业收费项目:::::: " + response);
}catch (Exception e){
log.error("获取智业收费项目失败" );
log.error("Response: " + e.getMessage());
}
return null;
}
private static final String WSDL_URL = "http://173.19.192.196:8882/OTHER/BtmsEntranceWs?wsdl";
public static String callInterface(String msgHeader, String msgBody) throws Exception {
URL url = new URL("http://173.19.192.196:8882/OTHER/BtmsEntranceWs?wsdl");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/xml");
connection.setDoOutput(true);
public BaseResponse callInterface(String msgHeader, String msgBody) {
String requestBody = "<request>\n" +
" <msgHeader>" + msgHeader + "</msgHeader>\n" +
" <msgBody>" + msgBody + "</msgBody>\n" +
"</request>";
try {
try (OutputStream os = connection.getOutputStream()) {
byte[] input = requestBody.getBytes("utf-8");
os.write(input, 0, input.length);
}
// 构建请求头
Map<String, String> headers = Map.of(
"Content-Type", "text/xml;charset=utf-8",
"SOAPAction","http://www.zysoft.com.cn/CallInterface"
int responseCode = connection.getResponseCode();
);
// 注意这里我们实际上是在构建一个表单体而不是直接发送XML或JSON
// 因此我们需要对msgHeader和msgBody进行URL编码并将它们作为表单字段发送
String postData = buildSoapRequest(null,null);
log.error("Response Code: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
// 读取响应
java.util.Scanner scanner = new java.util.Scanner(connection.getInputStream()).useDelimiter("\\A");
String response = scanner.hasNext() ? scanner.next() : "";
log.error("Response Body: " + response);
return scanner.hasNext() ? scanner.next() : "";
} else {
log.error("HTTP error code : " + responseCode);
throw new RuntimeException("HTTP error code : " + responseCode);
HttpRequest request = HttpRequest.post(WSDL_URL)
.addHeaders(headers)
.body(postData);
HttpResponse xmlResponse = request.execute();
String xml = xmlResponse.body();
// 假设 XML 解析到的 JSON 字符串部分
log.error("获取智业收费项目999:" + xml);
return ResultVOUtils.error(500, xml);
} catch (Exception e) {
log.error("获取智业收费项目失败===" + e.getMessage());
return ResultVOUtils.error(500, "获取智业收费项目失败===" + e.getMessage());
}
}
public static void main(String[] args) {
String soapXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><zys:CallInterfaceResponse xmlns:zys=\"http://www.zysoft.com.cn/\">" +
" <zys:payload>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;root&gt;&lt;code&gt;0&lt;/code&gt;&lt;data&gt;&lt;lists&gt;&lt;code&gt;023050000701&lt;/code&gt;&lt;name&gt;红细胞寿命测定-呼气法&lt;/name&gt;&lt;unit&gt;次&lt;/unit&gt;&lt;price&gt;245&lt;/price&gt;&lt;spell&gt;HXBSMCDHQF&lt;/spell&gt;&lt;valid&gt;Y&lt;/valid&gt;&lt;sequence&gt;&lt;/sequence&gt;&lt;std_code&gt;23050000701&lt;/std_code&gt;&lt;subject&gt;D&lt;/subject&gt;&lt;subjectname&gt;化验&lt;/subjectname&gt;&lt;dispreceipt&gt;FJ15&lt;/dispreceipt&gt;&lt;dispreceiptname&gt;化验费&lt;/dispreceiptname&gt;&lt;resireceipt&gt;FJ15&lt;/resireceipt&gt;&lt;resireceiptname&gt;化验费&lt;/resireceiptname&gt;&lt;starttime&gt;20190412000000&lt;/starttime&gt;&lt;stoptime&gt;&lt;/stoptime&gt;&lt;modifytime&gt;20190505170000&lt;/modifytime&gt;&lt;modifyoperator&gt;SYSTEM3&lt;/modifyoperator&gt;&lt;item_connotation&gt;红细胞寿命测定-呼气法&lt;/item_connotation&gt;&lt;except_content&gt;&lt;/except_content&gt;&lt;country_code&gt;002305000070000-23050000701&lt;/country_code&gt;&lt;org_stdcode&gt;&lt;/org_stdcode&gt;&lt;/lists&gt;&lt;/data&gt;&lt;/root&gt;</zys:payload>" +
"</zys:CallInterfaceResponse></soapenv:Body></soapenv:Envelope>";
try {
// 提取 <zys:payload> 中的内容
int payloadStart = soapXml.indexOf("<zys:payload>") + "<zys:payload>".length();
int payloadEnd = soapXml.indexOf("</zys:payload>");
String escapedXml = soapXml.substring(payloadStart, payloadEnd);
// 处理转义字符
String unescapedXml = StringEscapeUtils.unescapeXml(escapedXml);
// 解析 XML
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(unescapedXml)));
// 转换为字符串
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(writer));
String standardXml = writer.toString();
// 处理空标签,将 <tag/> 替换为 <tag></tag>
Pattern pattern = Pattern.compile("<([^/][^>]*)\\s*/>");
Matcher matcher = pattern.matcher(standardXml);
String resultXml = matcher.replaceAll("<$1></$1>");
// 输出标准 XML
System.out.println(resultXml);
} catch (ParserConfigurationException | SAXException | TransformerException | IOException e) {
e.printStackTrace();
}
}
private static String formatXML(Document doc) throws TransformerException {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
// public String parserResult(String response) {
// if (response.contains("<root")) {
// try {
// JAXBUtil.unmarshalAndGetResult()
// Document document = DocumentHelper.parseText(response);
// String message = document.getRootElement().element("message").getText();
// return message;
// } catch (DocumentException e) {
// log.info("解析安溪县医院智业接口返回结果异常, 返回结果:{}", response);
// log.error("异常信息:", e);
// }
// }
// return response;
// }
DOMSource source = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
transformer.transform(source, result);
return writer.toString();
}
}

Loading…
Cancel
Save