feat:湖里HIS接口对接

hlfyyy
chenhc 3 months ago
parent 1b354e3d33
commit 191b608b5f

@ -90,8 +90,10 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.xml.namespace.QName;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@ -1326,12 +1328,12 @@ public class HlfyyyClient extends CommonHttpClient {
BaseResponse<String> baseResponseA = callInterface(zaZyRequest.getMsgHeader(), zaZyRequest.getMsgBody());
String response = parserResult((String) baseResponseA.getData());
if (StrUtil.isNotBlank(response)) {
if (baseResponseA != null) {
try {
BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
if (baseResponse.getCode() == 20000) {
String thirdBillNo = String.valueOf(baseResponse.getData());
if (baseResponseA.getCode() == 20000) {
String thirdBillNo = String.valueOf(baseResponseA.getData());
orderEntity.setThirdBillNo(thirdBillNo);
orderEntity.setExportStatus(1); //提交成功
uploadLog.setStatus(2);
@ -1342,16 +1344,16 @@ public class HlfyyyClient extends CommonHttpClient {
return ResultVOUtils.success("提交成功");
}
uploadLog.setStatus(3);
uploadLog.setResult("提交失败,错误信息:" + baseResponse.getMessage());
uploadLog.setResult("提交失败,错误信息:" + baseResponseA.getMessage());
orderEntity.setExportStatus(2); //上传失败
orderDao.updateById(orderEntity);
orderUploadLogDao.insert(uploadLog);
return baseResponse;
return baseResponseA;
} catch (Exception e) {
log.error("解析提交到智业单据返回结果异常,结果信息:{}", response);
log.error("解析提交到智业单据返回结果异常,结果信息:{}", baseResponseA);
log.error("异常信息:{}", e);
uploadLog.setStatus(3);
uploadLog.setResult("提交失败,错误信息:" + response);
uploadLog.setResult("提交失败,错误信息:" + baseResponseA);
orderEntity.setExportStatus(2); //上传失败
orderDao.updateById(orderEntity);
orderUploadLogDao.insert(uploadLog);
@ -2469,63 +2471,54 @@ public class HlfyyyClient extends CommonHttpClient {
// WebService地址
private static final String METHOD_NAME = "CallInterface";
private static final String WSDL_URL = "http://192.168.158.208:8152/ZoesoftHipService.asmx?WSDL";
private static final String WSDL_URL = "http://192.168.158.208:8152/ZoesoftHipService.asmx/CallInterface";
public BaseResponse callInterface(String msgHeader, String msgBody) {
public BaseResponse callInterface(String msgHeader, String msgBody) {
try {
// // 先将JSON字符串转为Map
// Map<String, Object> map = JSONUtil.toBean(msgBody, Map.class);
// // 遍历Map将所有值转换为字符串
// map.replaceAll((key, value) -> value == null? null : value.toString());
// // 再将转换后的Map转回JSON字符串此时所有值都已是字符串类型
// msgBody = JSONUtil.toJsonStr(map);
String xml = "\n" +
"<soap:Envelope\n" +
" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
" xmlns:pm=\"http://www.zoesoft.com.cn/\">\n" +
" <soap:Body>\n" +
" <pm:CallInterface>\n" +
" <msgHeader>\n" +
" <?xmlversion=\"1.0\"encoding=\"utf-8\"?>\n" +
" <root>\n" +
" <serverName>saveBuyApplyInfo</serverName>\n" +
" <format>xml</format>\n" +
" </root>\n" +
" </msgHeader>\n" +
" <msgBody>\n" +
msgBody +
"\n" +
" </msgBody>\n" +
" </pm:CallInterface>\n" +
" </soap:Body>\n" +
"</soap:Envelope>";
log.error("msgHeader:" + msgHeader);
log.error("msgBody:" + msgBody);
log.error("xml:" + xml);
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "text/xml;charset=UTF-8");
headers.put("SOAPAction", "http://www.zoesoft.com.cn/HIPMessageServerTransit");
HttpRequest request = HttpRequest.post(WSDL_URL)
.addHeaders(headers)
.body(xml);
HttpResponse response = request.execute();
log.error("response:" + response);
log.error("response.body():" + response.body());
// 构建请求头
Map<String, String> headers = Map.of(
"Content-Type", "application/x-www-form-urlencoded"
);
return ResultVOUtils.success(response.body());
// 构建POST数据
msgHeader = "<root><serverName>saveBuyApplyInfo</serverName><format>xml</format></root>";
} catch (Exception e) {
log.error("上传智业单据错误==="+e.getMessage());
return ResultVOUtils.error(500,"上传智业单据错误==="+e.getMessage());
}
// 注意这里我们实际上是在构建一个表单体而不是直接发送XML或JSON
// 因此我们需要对msgHeader和msgBody进行URL编码并将它们作为表单字段发送
String postData = String.format("msgHeader=%s&msgBody=%s",
URLEncoder.encode(msgHeader, "UTF-8"),
URLEncoder.encode(msgBody, "UTF-8")
);
HttpRequest request = HttpRequest.post(WSDL_URL)
.addHeaders(headers)
.body(postData);
HttpResponse xmlResponse = request.execute();
log.error("response:" + xmlResponse);
String xml = xmlResponse.body();
// 假设 XML 解析到的 JSON 字符串部分
String jsonStr ="{" + xml.substring(xml.indexOf("{") + 1, xml.lastIndexOf("}")) + "}" ;
log.error("jsonStr:" + jsonStr);
JSONObject jsonObject = JSON.parseObject(jsonStr);
// 提取并打印retCode、retMsg和output的值
String retCode = jsonObject.getString("retCode");
String retMsg = jsonObject.getString("retMsg");
String output = jsonObject.getString("output");
if ("0".equals(retCode)) {
return ResultVOUtils.success(retMsg);
}
return ResultVOUtils.error(500, retMsg);
} catch (Exception e) {
log.error("上传智业单据错误===" + e.getMessage());
return ResultVOUtils.error(500, "上传智业单据错误===" + e.getMessage());
}
}
}
}

Loading…
Cancel
Save