添加http调用webservice

3.2.4.44
wyb 2 years ago
parent 6ad9353f2a
commit 12538de7b0

@ -0,0 +1,60 @@
package com.docus.server.report.client;
import com.docus.core.util.Func;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
* http webservice
*/
public class HttpWsClient {
private static final Logger logger = LoggerFactory.getLogger(HttpWsClient.class);
public static String send(String wsdlUrl, Map<String, String> requestProperty, String param) {
try {
byte[] paramBytes = param.getBytes(StandardCharsets.UTF_8);
URL url = new URL(wsdlUrl);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestProperty("Content-Length", String.valueOf(paramBytes.length));
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
// 额外的一些请求信息
if (Func.isNotEmpty(requestProperty)) {
for (Map.Entry<String, String> entry : requestProperty.entrySet()) {
httpConn.setRequestProperty(entry.getKey(), entry.getValue());
}
}
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setConnectTimeout(60000);
// 输入内容
OutputStream outputStream = httpConn.getOutputStream();
outputStream.write(paramBytes);
outputStream.flush();
outputStream.close();
// 获取返回内容
InputStreamReader inputStreamReader = new InputStreamReader(httpConn.getInputStream());
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder stringBuilder = new StringBuilder();
String str = null;
while ((str = bufferedReader.readLine()) != null) {
stringBuilder.append(str).append("\n");
}
bufferedReader.close();
inputStreamReader.close();
return stringBuilder.toString();
} catch (Exception ex) {
logger.error("wsdl"+wsdlUrl+", ext requestProperty:"+requestProperty+", param:"+param,ex);
return null;
}
}
}

@ -8,7 +8,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.namespace.QName;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -22,22 +21,22 @@ public class JaxWsDynamicClient {
private static final Map<String, Client> CLIENT_MAP=new ConcurrentHashMap<>();
private static final Logger logger= LoggerFactory.getLogger(JaxWsDynamicClient.class);
public static String send(String wsdlUrl,String namespaceUri,String operationName,Object[] params){
public static String send(String wsdlUrl,String namespaceUri,String operationName,Object param){
try {
Client client = getClient(wsdlUrl);
Object[] result;
if (namespaceUri == null || namespaceUri.isEmpty()) {
result = client.invoke(operationName, params);
result = client.invoke(operationName, param);
} else {
QName qName = new QName(namespaceUri, operationName);
result = client.invoke(qName, params);
result = client.invoke(qName, param);
}
if (result == null || result[0] == null) {
return null;
}
return String.valueOf(result[0]);
} catch (Exception ex) {
logger.error("wsdlUrl" + wsdlUrl + " operationName" + operationName + "params:" + Arrays.toString(params) + " 调用失败了!", ex);
logger.error("wsdlUrl" + wsdlUrl + " operationName" + operationName + "param:" + param + " 调用失败了!", ex);
return null;
}
}

@ -65,8 +65,8 @@ public class ReportJob {
LocalDateTime now = LocalDateTime.now();
log.info("LIS检验报告报告查询 任务开始了");
// 定义查基础数据 入院时间 开始结束
AfJobTime afJobTime= getJobTimeByJobType(jobType);
String queryBasicAdmissStartDate =afJobTime.getUpdateTime();
AfJobTime afJobTime = getJobTimeByJobType(jobType);
String queryBasicAdmissStartDate = afJobTime.getUpdateTime();
String queryBasicAdmissEndDate = now.toString();
// 查询基础数据定义 分页
int offset = 0;
@ -113,8 +113,8 @@ public class ReportJob {
LocalDateTime now = LocalDateTime.now();
log.info("检查报告报告查询 任务开始了");
// 定义查基础数据 入院时间 开始结束
AfJobTime afJobTime= getJobTimeByJobType(jobType);
String queryBasicAdmissStartDate =afJobTime.getUpdateTime();
AfJobTime afJobTime = getJobTimeByJobType(jobType);
String queryBasicAdmissStartDate = afJobTime.getUpdateTime();
String queryBasicAdmissEndDate = now.toString();
// 查询基础数据定义 分页
int offset = 0;
@ -169,25 +169,25 @@ public class ReportJob {
private List<ReportDto> getInspectReportDtoListBySdRyReportPatientId(String sdRyReportPatientId, TBasic tBasic) {
try {
List<ReportDto> reportDtos = new ArrayList<>();
int pageNum=1;
final int pageSize=10;
boolean loopCondition=true;
int pageNum = 1;
final int pageSize = 5;
boolean loopCondition = true;
do {
String requestParam = organizationQuerySdRyInspectReportParam(sdRyReportPatientId, tBasic,pageNum,pageSize);
String requestParam = organizationQuerySdRyInspectReportParam(sdRyReportPatientId, tBasic, pageNum, pageSize);
String url = organizationQuerySdRyInspectReportUrl(sdRyReportQueryConfig.getReportQueryInspectUrl());
log.info("查询检查报告请求地址:{} ,请求body参数:{}", url, requestParam);
String respBody= this.sendPost(url,requestParam);
String respBody = this.sendPost(url, requestParam);
log.info("查询检查报告请求成功,响应参数:{}", respBody);
List<ReportDto> reportDtoList=parseQuerySdRyInspectReport(respBody,tBasic);
if(reportDtoList.isEmpty()){
List<ReportDto> reportDtoList = parseQuerySdRyInspectReport(respBody, tBasic);
if (reportDtoList.isEmpty()) {
break;
}
if(reportDtoList.size()<pageSize){
loopCondition=false;
if (reportDtoList.size() < pageSize) {
loopCondition = false;
}
reportDtos.addAll(reportDtoList);
pageNum++;
}while (loopCondition);
} while (loopCondition);
return reportDtos;
} catch (Exception ex) {
log.error("查询检查报告出错啦!", ex);
@ -205,51 +205,52 @@ public class ReportJob {
private String organizationQuerySdRyInspectReportParam(String sdRyReportPatientId, TBasic tBasic, int pageNum, int pageSize) {
boolean isPage = true;
String orgCode="4560886379";
String orgCode = "4560886379";
Date admissDate = tBasic.getAdmissDate();
if(admissDate==null){
throw new BaseException("patientId"+tBasic.getPatientId()+"的入院时间为空");
if (admissDate == null) {
throw new BaseException("patientId" + tBasic.getPatientId() + "的入院时间为空");
}
Instant instant = admissDate.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDate admissLocalDate = instant.atZone(zoneId).toLocalDate();
LocalDate endTimeLocalDate = admissLocalDate.plusDays(1);
LocalDate startTimeLocalDate = admissLocalDate.plusDays(-3);
String startTime=startTimeLocalDate+" 00:00:00";
String endTime=endTimeLocalDate+" 00:00:00";
String startTime = startTimeLocalDate + " 00:00:00";
String endTime = endTimeLocalDate + " 00:00:00";
HashMap<Object, Object> map = new HashMap<>(7);
map.put("isPage",isPage);
map.put("pageNo",pageNum);
map.put("pageSize",pageSize);
map.put("OrgCode",orgCode);
map.put("StartTime",startTime);
map.put("EndTime",endTime);
map.put("PatientId",sdRyReportPatientId);
map.put("isPage", isPage);
map.put("pageNo", pageNum);
map.put("pageSize", pageSize);
map.put("OrgCode", orgCode);
map.put("StartTime", startTime);
map.put("EndTime", endTime);
map.put("PatientId", sdRyReportPatientId);
map.put("PatentTypeCode", "1");
return Func.toJson(map);
}
private List<ReportDto> parseQuerySdRyInspectReport(String respBody, TBasic tBasic) {
private List<ReportDto> parseQuerySdRyInspectReport(String respBody, TBasic tBasic) {
JSONObject jsonObject = Func.readJson(respBody, JSONObject.class);
Object resultCode = jsonObject.get("ResultCode");
String successCode="0";
if(!successCode.equals(String.valueOf(resultCode))){
String successCode = "0";
if (!successCode.equals(String.valueOf(resultCode))) {
return new ArrayList<>();
}
try {
Object data = jsonObject.get("data");
String dataJsonStr = Func.toJson(data);
// 是否是json object ,因为返回的如果是 [] 则不会识别为jsonObject
List<ReportDto> reportDtoList = new ArrayList<>();
if( Func.isJsonObject(dataJsonStr)){
List<ReportDto> reportDtoList = new ArrayList<>();
if (Func.isJsonObject(dataJsonStr)) {
JSONObject dataJsonObject = Func.readJson(dataJsonStr, JSONObject.class);
Object result = dataJsonObject.get("result");
String resultJsonStr = Func.toJson(result);
List<JSONObject> reportObjectList = Func.parseJsonArray(resultJsonStr, JSONObject.class);
if(Func.isNotEmpty(reportObjectList)){
if (Func.isNotEmpty(reportObjectList)) {
for (JSONObject reportObject : reportObjectList) {
// 检查报告号
String examReportSn =String.valueOf( reportObject.get("EXAM_REPORT_SN"));
String examReportSn = String.valueOf(reportObject.get("EXAM_REPORT_SN"));
// 申请单号
String requestSn = String.valueOf(reportObject.get("REQUEST_SN"));
// pdf地址
@ -263,7 +264,7 @@ public class ReportJob {
reportDto.setAdmisstimes(tBasic.getAdmissTimes());
reportDto.setInpatientNo(tBasic.getInpatientNo());
// 确定报告唯一 报告单号+申请单号
reportDto.setSerialnum(examReportSn+requestSn);
reportDto.setSerialnum(examReportSn + requestSn);
reportDto.setFileTitle(reportName);
reportDto.setDownUrl(pdfUrl);
reportDto.setAssortId(sdRyReportQueryConfig.getReportQueryInspectAssortId());
@ -275,36 +276,37 @@ public class ReportJob {
}
}
return reportDtoList;
}catch (Exception ex){
log.error(ex.getMessage(),ex);
return new ArrayList<>();
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
return new ArrayList<>();
}
}
private String sendPost(String url,String body){
private String sendPost(String url, String body) {
HttpRequest post = HttpUtil.createPost(url);
post.timeout(60 * 1000);
post.header("Content-Type", "application/json; charset=utf-8");
post.body(body);
HttpResponse response = post.execute();
return response.body();
return response.body();
}
/**
* job
*
* @param jobType job
* @return job 1801-01-01 00:00:00
*/
private AfJobTime getJobTimeByJobType(String jobType){
private AfJobTime getJobTimeByJobType(String jobType) {
AfJobTime afJobTime = afJobTimeMapper.getAfJobTimeByJobType(jobType);
// 定义查基础数据 入院时间 开始结束
String startTime = "1801-01-01 00:00:00";
if (afJobTime ==null) {
if (afJobTime == null) {
afJobTime = new AfJobTime();
afJobTime.setJobType(jobType);
afJobTime.setUpdateTime(startTime);
}
if(Func.isBlank(afJobTime.getUpdateTime())){
if (Func.isBlank(afJobTime.getUpdateTime())) {
afJobTime.setUpdateTime(startTime);
}
return afJobTime;
@ -330,11 +332,11 @@ public class ReportJob {
private List<ReportDto> getLisReportDtoListBySdRyReportPatientId(String sdRyReportPatientId, TBasic tBasic) {
try {
List<ReportDto> reportDtos = new ArrayList<>();
int pageNum=1;
final int pageSize=10;
boolean loopCondition=true;
int pageNum = 1;
final int pageSize = 5;
boolean loopCondition = true;
do {
String requestParam = organizationQuerySdRyLisReportParam(sdRyReportPatientId, tBasic,pageNum,pageSize);
String requestParam = organizationQuerySdRyLisReportParam(sdRyReportPatientId, tBasic, pageNum, pageSize);
String url = organizationQuerySdRyLisReportUrl(sdRyReportQueryConfig.getReportQueryLisUrl());
log.info("查询Lis报告请求地址{} ,请求body参数:{}", url, requestParam);
HttpRequest post = HttpUtil.createPost(url);
@ -344,16 +346,16 @@ public class ReportJob {
HttpResponse response = post.execute();
String respBody = response.body();
log.info("查询Lis报告请求成功,响应参数:{}", respBody);
List<ReportDto> reportDtoList=parseQuerySdRyLisReport(respBody,tBasic);
if(reportDtoList.isEmpty()){
List<ReportDto> reportDtoList = parseQuerySdRyLisReport(respBody, tBasic);
if (reportDtoList.isEmpty()) {
break;
}
if(reportDtoList.size()<pageSize){
loopCondition=false;
if (reportDtoList.size() < pageSize) {
loopCondition = false;
}
reportDtos.addAll(reportDtoList);
pageNum++;
}while (loopCondition);
} while (loopCondition);
return reportDtos;
} catch (Exception ex) {
log.error("查询Lis报告出错啦", ex);
@ -361,27 +363,27 @@ public class ReportJob {
}
}
private List<ReportDto> parseQuerySdRyLisReport(String respBody, TBasic tBasic) {
private List<ReportDto> parseQuerySdRyLisReport(String respBody, TBasic tBasic) {
JSONObject jsonObject = Func.readJson(respBody, JSONObject.class);
Object resultCode = jsonObject.get("ResultCode");
String successCode="0";
if(!successCode.equals(String.valueOf(resultCode))){
String successCode = "0";
if (!successCode.equals(String.valueOf(resultCode))) {
return new ArrayList<>();
}
try {
Object data = jsonObject.get("data");
String dataJsonStr = Func.toJson(data);
// 是否是json object ,因为返回的如果是 [] 则不会识别为jsonObject
List<ReportDto> reportDtoList = new ArrayList<>();
if( Func.isJsonObject(dataJsonStr)){
List<ReportDto> reportDtoList = new ArrayList<>();
if (Func.isJsonObject(dataJsonStr)) {
JSONObject dataJsonObject = Func.readJson(dataJsonStr, JSONObject.class);
Object result = dataJsonObject.get("result");
String resultJsonStr = Func.toJson(result);
List<JSONObject> reportObjectList = Func.parseJsonArray(resultJsonStr, JSONObject.class);
if(Func.isNotEmpty(reportObjectList)){
if (Func.isNotEmpty(reportObjectList)) {
for (JSONObject reportObject : reportObjectList) {
// 检验报告号
String labReportSn =String.valueOf( reportObject.get("LAB_REPORT_SN"));
String labReportSn = String.valueOf(reportObject.get("LAB_REPORT_SN"));
// 申请单号
String requestSn = String.valueOf(reportObject.get("REQUEST_SN"));
// pdf地址
@ -395,7 +397,7 @@ public class ReportJob {
reportDto.setAdmisstimes(tBasic.getAdmissTimes());
reportDto.setInpatientNo(tBasic.getInpatientNo());
// 确定报告唯一 报告单号+申请单号
reportDto.setSerialnum(labReportSn+requestSn);
reportDto.setSerialnum(labReportSn + requestSn);
reportDto.setFileTitle(reportTypeName);
reportDto.setDownUrl(pdfUrl);
reportDto.setAssortId(sdRyReportQueryConfig.getReportQueryLisAssortId());
@ -407,9 +409,9 @@ public class ReportJob {
}
}
return reportDtoList;
}catch (Exception ex){
log.error(ex.getMessage(),ex);
return new ArrayList<>();
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
return new ArrayList<>();
}
}
@ -423,27 +425,28 @@ public class ReportJob {
private String organizationQuerySdRyLisReportParam(String sdRyReportPatientId, TBasic tBasic, int pageNum, int pageSize) {
boolean isPage = true;
String orgCode="4560886379";
String orgCode = "4560886379";
Date admissDate = tBasic.getAdmissDate();
if(admissDate==null){
throw new BaseException("patientId"+tBasic.getPatientId()+"的入院时间为空");
if (admissDate == null) {
throw new BaseException("patientId" + tBasic.getPatientId() + "的入院时间为空");
}
Instant instant = admissDate.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDate admissLocalDate = instant.atZone(zoneId).toLocalDate();
LocalDate endTimeLocalDate = admissLocalDate.plusDays(1);
LocalDate startTimeLocalDate = admissLocalDate.plusDays(-3);
String startTime=startTimeLocalDate+" 00:00:00";
String endTime=endTimeLocalDate+" 00:00:00";
String startTime = startTimeLocalDate + " 00:00:00";
String endTime = endTimeLocalDate + " 00:00:00";
HashMap<Object, Object> map = new HashMap<>(7);
map.put("isPage",isPage);
map.put("pageNo",pageNum);
map.put("pageSize",pageSize);
map.put("OrgCode",orgCode);
map.put("StartTime",startTime);
map.put("EndTime",endTime);
map.put("PatientId",sdRyReportPatientId);
map.put("isPage", isPage);
map.put("pageNo", pageNum);
map.put("pageSize", pageSize);
map.put("OrgCode", orgCode);
map.put("StartTime", startTime);
map.put("EndTime", endTime);
map.put("PatientId", sdRyReportPatientId);
map.put("PatentTypeCode", "1");
return Func.toJson(map);
}
@ -460,11 +463,11 @@ public class ReportJob {
return new ArrayList<>();
}
String param = organizationQuerySdRyReportIndexParam(sDryIndex);
String[] params = {param};
String namespaceUri = sdRyReportQueryConfig.getQueryReportIndexWsdlNamespaceUri();
String wsdlAddr = sdRyReportQueryConfig.getQueryReportIndexWsdlAddr();
String operationName = sdRyReportQueryConfig.getQueryReportIndexWsdlOperationName();
String result = JaxWsDynamicClient.send(wsdlAddr, namespaceUri, operationName, params);
String result = JaxWsDynamicClient.send(wsdlAddr, namespaceUri, operationName, param);
log.info("查询顺德人医患者交叉索引数据,返回值:{}", result);
if (result == null) {
return new ArrayList<>();

Loading…
Cancel
Save