diff --git a/docus-webservice/src/main/java/com/docus/webservice/handler/TBasicWebService.java b/docus-webservice/src/main/java/com/docus/webservice/handler/TBasicWebService.java index b37aeb5..0614d8e 100644 --- a/docus-webservice/src/main/java/com/docus/webservice/handler/TBasicWebService.java +++ b/docus-webservice/src/main/java/com/docus/webservice/handler/TBasicWebService.java @@ -2,7 +2,6 @@ package com.docus.webservice.handler; import com.alibaba.fastjson.JSON; - import com.docus.webservice.dto.SelectColumn; import com.docus.webservice.entity.MrReportError; import com.docus.webservice.entity.TBasic; @@ -15,7 +14,6 @@ import com.docus.webservice.utils.XmlUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; - import javax.jws.WebService; import java.io.ByteArrayInputStream; import java.io.File; @@ -146,6 +144,7 @@ public class TBasicWebService implements ITBasicWebService { return ResultUtils.fail(selectColumn.getQualityColumn() + " 字段不能为空值"); } else { continue; + } } else { if (selectColumn.getTableName().equals("t_basic")) { @@ -181,6 +180,4 @@ public class TBasicWebService implements ITBasicWebService { } return ResultUtils.success().asXML(); } - - } diff --git a/docus-webservice/src/main/java/com/docus/webservice/run/RunServer.java b/docus-webservice/src/main/java/com/docus/webservice/run/RunServer.java deleted file mode 100644 index 03dc0d8..0000000 --- a/docus-webservice/src/main/java/com/docus/webservice/run/RunServer.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.docus.webservice.run; - -import com.docus.webservice.enums.Codes; -import com.docus.webservice.handler.TBasicWebService; -import org.springframework.stereotype.Component; - -import javax.xml.ws.Endpoint; - -/** - * 启动服务 - */ -public class RunServer { - - public void run() { - String address = "http://localhost:" + Codes.EXTERNAL.getCode()+"/" + Codes.EXTERNAL.getMessage(); - Endpoint.publish(address, new TBasicWebService()); - System.out.println("publish success..."); - System.out.println(address); - } - -} diff --git a/docus-ws-bgts/dataConfig/homeQualitySet.json b/docus-ws-bgts/dataConfig/homeQualitySet.json new file mode 100644 index 0000000..d1de953 --- /dev/null +++ b/docus-ws-bgts/dataConfig/homeQualitySet.json @@ -0,0 +1,27 @@ +{ + //唯一键目录结构数组,最高层为前面,最后一层为数据采集层,根节点不填 + "directory":["Msg","PatInfo"], + //患者主索引号 + "indexFlag":"jzh", + //采集流水号 + "serialnum":"PATHOLOGY_ONLY_NO", + //文件标题 + "filetitle":"EXAM_ITEM_NAME", + //下载地址 + "downurl":"IMAGE_URL", + //分类id + "assortid":"批复文件", + //系统id + "collectorid":"121212", + //采集类型(文件来源 1:采集器;2:扫描生产软件) + "filesource":0, + //下载类型(1:服务器本地;2:ftp服务器;3:共享文件夹) + "filestoragetype":0, + //上传接口 + "uploadConnector":"http://192.168.1.107:9291/api/downplatform/report", + //基本数据存放处,根节点不填,最后一层为基本信息存放标签 + "basicDirectory":["Msg","PatInfo"], + //可能存在存储基本数据不同情况的标签 + "doubleBasic":["TestItemInfo","BioTestInfo"], + +} \ No newline at end of file diff --git a/docus-ws-bgts/pom.xml b/docus-ws-bgts/pom.xml index f54b48f..f4cecf0 100644 --- a/docus-ws-bgts/pom.xml +++ b/docus-ws-bgts/pom.xml @@ -73,6 +73,21 @@ spring-boot-starter-test test + + org.apache.httpcomponents + httpcore + 4.4.5 + + + org.apache.httpcomponents + httpclient + 4.5.2 + + + org.apache.httpcomponents + httpmime + 4.4 + diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/entity/ReportDownDto.java b/docus-ws-bgts/src/main/java/com/docus/bgts/entity/ReportDownDto.java new file mode 100644 index 0000000..7b1ea47 --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/entity/ReportDownDto.java @@ -0,0 +1,21 @@ +package com.docus.bgts.entity; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class ReportDownDto { + @ApiModelProperty(value = "采集器id") + private String collectorid; + + @ApiModelProperty(value = "采集器ip") + private String ip; + + @ApiModelProperty(value = "文件信息") + private List scanfiles; + + private ReportDownPatientDto patient; + +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/entity/ReportDownPatientDto.java b/docus-ws-bgts/src/main/java/com/docus/bgts/entity/ReportDownPatientDto.java new file mode 100644 index 0000000..8509d86 --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/entity/ReportDownPatientDto.java @@ -0,0 +1,10 @@ +package com.docus.bgts.entity; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class ReportDownPatientDto { + @ApiModelProperty(value = "记帐号") + private String jzh; +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/entity/ReportDownScanFileDto.java b/docus-ws-bgts/src/main/java/com/docus/bgts/entity/ReportDownScanFileDto.java new file mode 100644 index 0000000..c45f597 --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/entity/ReportDownScanFileDto.java @@ -0,0 +1,23 @@ +package com.docus.bgts.entity; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class ReportDownScanFileDto { + @ApiModelProperty(value = "分类id") + private String assortid; + @ApiModelProperty(value = "文件标题") + private String filetitle; + @ApiModelProperty(value = "采集类型(文件来源 1:采集器;2:扫描生产软件)") + private int filesource; + @ApiModelProperty(value = "下载类型(1:服务器本地;2:ftp服务器;3:共享文件夹)") + private int filestoragetype; + @ApiModelProperty(value = "下载地址") + private String downurl; + @ApiModelProperty(value = "档案信息") + private String recordid; + @ApiModelProperty("采集流水号") + private String serialnum; + +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/enums/Codes.java b/docus-ws-bgts/src/main/java/com/docus/bgts/enums/Codes.java index 9f9b975..a31eb30 100644 --- a/docus-ws-bgts/src/main/java/com/docus/bgts/enums/Codes.java +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/enums/Codes.java @@ -17,11 +17,17 @@ public enum Codes { //web service返回描述部分 RET_CON("103","RetCon"), //web service 服务名 - EXTERNAL("9201","docus_tBasic_data"), + EXTERNAL("9202","201_P_WS_JYBGTS"), //静态文件存放位置 JSON_ADDRESS("999","\\dataConfig\\homeQualitySet.json"), //接收二级节点 MSG("201","Msg"), + //节点根 + DIRECTORY("1000","directory"), + //上传接口地址 + UPLOAD("0","uploadConnector"), + //患者主索引号 + EMP_ID("0","indexFlag"), //错误日志编号 ERROR_CODE("500","12"), //接收三级节点 diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/handler/ITBasicWebService.java b/docus-ws-bgts/src/main/java/com/docus/bgts/handler/ITBasicWebService.java index bccf620..47f035e 100644 --- a/docus-ws-bgts/src/main/java/com/docus/bgts/handler/ITBasicWebService.java +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/handler/ITBasicWebService.java @@ -1,10 +1,16 @@ package com.docus.bgts.handler; +import javax.jws.WebMethod; import javax.jws.WebService; @WebService public interface ITBasicWebService { - + /** + * 检验报告推送 + * @return + */ + @WebMethod + String pushSurveyReport(String xml); } diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/handler/TBasicWebService.java b/docus-ws-bgts/src/main/java/com/docus/bgts/handler/TBasicWebService.java index 8867e91..ebf58e9 100644 --- a/docus-ws-bgts/src/main/java/com/docus/bgts/handler/TBasicWebService.java +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/handler/TBasicWebService.java @@ -1,9 +1,95 @@ package com.docus.bgts.handler; +import com.alibaba.fastjson.JSON; +import com.docus.bgts.entity.ReportDownDto; +import com.docus.bgts.entity.ReportDownPatientDto; +import com.docus.bgts.entity.ReportDownScanFileDto; +import com.docus.bgts.enums.Codes; +import com.docus.bgts.utils.FileUtils; +import com.docus.bgts.utils.HttpUtils; +import com.docus.bgts.utils.ResultUtils; +import com.docus.bgts.utils.XmlUtils; +import org.apache.bcel.classfile.Code; +import org.dom4j.Element; + import javax.jws.WebService; +import java.io.ByteArrayInputStream; +import java.util.*; @WebService public class TBasicWebService implements ITBasicWebService { + @Override + public String pushSurveyReport(String xml) { + StringBuffer mesBuffer=new StringBuffer(); + try { + //解析XML + XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(xml.getBytes("UTF-8"))); + // 获取患者主索引号 + String empId = String.valueOf(FileUtils.getJsonByName(Codes.EMP_ID.getMessage())); + Map headMap = new HashMap<>(); + headMap.put("Content-Type", "application/json"); + ReportDownDto reportDownDto; + //获取根节点 + List elementList = xmlUtils.getJsonByName(); + //key + String serialnmnKey=String.valueOf(FileUtils.getJsonByName("serialnum")); + String filetitleKey=String.valueOf(FileUtils.getJsonByName("filetitle")); + String downurlKey=String.valueOf(FileUtils.getJsonByName("downurl")); + ReportDownScanFileDto reportDownScanFileDto; + ReportDownPatientDto reportDownPatientDto; + //临时资料存储 + String serialnum; + String filetitle; + String downurl; + String collectorid=String.valueOf(FileUtils.getJsonByName("collectorid")); + String assortid=String.valueOf(FileUtils.getJsonByName("assortid")); + reportDownDto = new ReportDownDto(); + reportDownDto.setCollectorid(collectorid); + reportDownDto.setIp("string"); + //获取基本数据信息 + List reportDownDtoArr=new ArrayList<>(); + reportDownPatientDto=new ReportDownPatientDto(); + reportDownPatientDto.setJzh(elementList.get(0).element(empId).getText()); + reportDownDto.setPatient(reportDownPatientDto); + for (Element element : elementList) { + serialnum=element.element(serialnmnKey).getText(); + filetitle=element.element(filetitleKey).getText(); + downurl=element.element(downurlKey).getText(); + + reportDownScanFileDto=new ReportDownScanFileDto(); + reportDownScanFileDto.setDownurl(downurl); + reportDownScanFileDto.setFiletitle(filetitle); + reportDownScanFileDto.setSerialnum(serialnum); + reportDownScanFileDto.setAssortid(assortid); + reportDownScanFileDto.setFilesource(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filesource")))); + reportDownScanFileDto.setFilestoragetype(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filestoragetype")))); + reportDownScanFileDto.setRecordid("临时医嘱"); + reportDownDtoArr.add(reportDownScanFileDto); + } + if(reportDownDtoArr.size()<=0){ + throw new RuntimeException("不存在必要的基本信息"); + }else { + reportDownDto.setScanfiles(reportDownDtoArr); + } + String post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class)); +// String post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), map, headMap); + Map resMap = JSON.parseObject(post, Map.class); + System.out.println(resMap); + if (String.valueOf(resMap.get("code")).equals("500")) { + return ResultUtils.fail(String.valueOf(resMap.get("msg"))); + } else { + return ResultUtils.success().asXML(); + } + } + catch (RuntimeException e){ + return ResultUtils.fail(e.getMessage()); + } + catch (Exception e) { + e.printStackTrace(); + } + + return ResultUtils.fail(); + } } diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/utils/FileUtils.java b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/FileUtils.java new file mode 100644 index 0000000..9995dbf --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/FileUtils.java @@ -0,0 +1,44 @@ +package com.docus.bgts.utils; + +import com.alibaba.fastjson.JSON; +import com.docus.bgts.enums.Codes; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class FileUtils { + /** + * 获取jar包所在位置 + * + * @return + */ + public static String currentPath() { + File dir = new File("."); + String currentpath = ""; + try { + currentpath = dir.getCanonicalPath(); + } catch (IOException e) { + e.printStackTrace(); + } + return currentpath; + } + + /** + * 获取静态文件中的内容 + * @param name + * @return + */ + public static Object getJsonByName(String name){ + //获取目录结构 + String path = FileUtils.currentPath(); + //解析json映射文件 + String json = JsonUtils.readJsonFile(path + Codes.JSON_ADDRESS.getMessage()); + Map jsonMap = JSON.parseObject(json, Map.class); + return jsonMap.get(name); + } + + + +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/utils/HttpUtils.java b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/HttpUtils.java new file mode 100644 index 0000000..470ebbd --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/HttpUtils.java @@ -0,0 +1,211 @@ +package com.docus.bgts.utils; + +import com.alibaba.fastjson.JSON; +import org.apache.http.HttpEntity; +import org.apache.http.NameValuePair; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.*; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Map; + +public class HttpUtils { + private static PoolingHttpClientConnectionManager cm; + private static String EMPTY_STR = ""; + private static String UTF_8 = "UTF-8"; + + private static void init() { + if (cm == null) { + cm = new PoolingHttpClientConnectionManager(); + cm.setMaxTotal(50);// 整个连接池最大连接数 + cm.setDefaultMaxPerRoute(5);// 每路由最大连接数,默认值是2 + } + } + + /** + * 通过连接池获取HttpClient + * + * @return + */ + private static CloseableHttpClient getHttpClient() { + init(); + return HttpClients.custom().setConnectionManager(cm).build(); + } + /** + * @param url + * @return + */ + public static String get(String url) { + HttpGet httpGet = new HttpGet(url); + return getResult(httpGet); + } + /** + * @param url、params + * @return + */ + public static String get(String url, Map params) throws URISyntaxException { + URIBuilder ub = new URIBuilder(); + ub.setPath(url); + + ArrayList pairs = covertParams2NVPS(params); + ub.setParameters(pairs); + + HttpGet httpGet = new HttpGet(ub.build()); + return getResult(httpGet); + } + /** + * @param url、headers、params + * @return + */ + public static String get(String url, Map headers, Map params) + throws URISyntaxException { + URIBuilder ub = new URIBuilder(); + ub.setPath(url); + + if (params != null) { + ArrayList pairs = covertParams2NVPS(params); + ub.setParameters(pairs); + } + + HttpGet httpGet = new HttpGet(ub.build()); + for (Map.Entry param : headers.entrySet()) { + httpGet.addHeader(param.getKey(), String.valueOf(param.getValue())); + } + return getResult(httpGet); + } + /** + * @param url + * @return + */ + public static String post(String url) { + HttpPost httpPost = new HttpPost(url); + return getResult(httpPost); + } + /** + * @param url、params + * @return + */ + public static String post(String url, Map params) throws UnsupportedEncodingException { + HttpPost httpPost = new HttpPost(url); + httpPost.setEntity(new UrlEncodedFormEntity(covertParams2NVPS(params), "utf-8"));//设置表单提交编码 + +// httpPost.setEntity(new StringEntity(JSON.toJSONString(params), ContentType.APPLICATION_FORM_URLENCODED)); + return getResult(httpPost); + } + + public static String post(String url, Object params, Map head) throws UnsupportedEncodingException { + HttpPost httpPost = new HttpPost(url); + System.out.println(params); + httpPost.setEntity(new StringEntity(params.toString()));//设置表单提交编码 + if (params != null) { + for (Map.Entry param : head.entrySet()) { + httpPost.addHeader(param.getKey(), String.valueOf(param.getValue())); + } + } +// httpPost.setEntity(new StringEntity(JSON.toJSONString(params), ContentType.APPLICATION_FORM_URLENCODED)); + return getResult(httpPost); + } + + private static ArrayList covertParams2NVPS(Map params) { + ArrayList pairs = new ArrayList(); + for (Map.Entry param : params.entrySet()) { + if (param.getValue() != null) { + pairs.add(new BasicNameValuePair(param.getKey(), param.getValue())); + } + } + + return pairs; + } + /** + * @param url、headers、params + * @return + */ + public static String post(String url, Map headers, Map params) + throws UnsupportedEncodingException { + HttpPost httpPost = new HttpPost(url); + System.out.println(params); + if (params != null) { + for (Map.Entry param : headers.entrySet()) { + httpPost.addHeader(param.getKey(), String.valueOf(param.getValue())); + } + } + + httpPost.setEntity(new StringEntity(JSON.toJSONString(params), ContentType.APPLICATION_JSON)); + + return getResult(httpPost); + } + + /** + * 处理Http请求 + * + * @param request + * @return + */ + private static String getResult(HttpRequestBase request) { + // CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpClient httpClient = getHttpClient(); + try { + CloseableHttpResponse response = httpClient.execute(request); + // response.getStatusLine().getStatusCode(); + HttpEntity entity = response.getEntity(); + if (entity != null) { + // long len = entity.getContentLength();// -1 表示长度未知 + String result = EntityUtils.toString(entity, UTF_8); + response.close(); + // httpClient.close(); + return result; + } + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + + } + + return EMPTY_STR; + } + + /** + * 处理Http请求 + * + * @param requestBuilder + * @return + */ + private static String getResult(RequestBuilder requestBuilder) { + // CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpClient httpClient = getHttpClient(); + try { + CloseableHttpResponse response = httpClient.execute(requestBuilder.build()); + // response.getStatusLine().getStatusCode(); + HttpEntity entity = response.getEntity(); + if (entity != null) { + // long len = entity.getContentLength();// -1 表示长度未知 + String result = EntityUtils.toString(entity, UTF_8); + response.close(); + // httpClient.close(); + return result; + } + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + + } + + return EMPTY_STR; + } +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/utils/XmlUtils.java b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/XmlUtils.java index c00f21f..dde93ed 100644 --- a/docus-ws-bgts/src/main/java/com/docus/bgts/utils/XmlUtils.java +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/XmlUtils.java @@ -1,6 +1,7 @@ package com.docus.bgts.utils; +import com.alibaba.fastjson.JSON; import com.docus.bgts.enums.Codes; import org.dom4j.Document; import org.dom4j.DocumentException; @@ -8,6 +9,9 @@ import org.dom4j.Element; import org.dom4j.io.SAXReader; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; public class XmlUtils { //定义解析器和文档对象 @@ -38,6 +42,74 @@ public class XmlUtils { } } + /** + * 动态获取节点内容 + * @return + */ + public String getElement(String name){ + //获取根节点 + Element root = document.getRootElement(); + Object directory = FileUtils.getJsonByName(Codes.DIRECTORY.getMessage()); + Element current=root; + if(directory==null){ + throw new RuntimeException("没有定义目录结构"); + } + List directoryArr=(List)directory; + for (String dire : directoryArr) { + current=current.element(dire); + } + return current.element(name)==null?"":current.element(name).getText(); + } + + /** + * 根据路径动态获取节点 + * @return + */ + public Element getElement(List directory){ + //获取根节点 + Element root = document.getRootElement(); + + Element current=root; + List directoryArr=directory; + for (String dire : directoryArr) { + current=current.element(dire); + } + if(current==null){ + throw new RuntimeException("未找到对应节点"); + } + return current; + } + + /** + * 返回存在的根节点 + */ + public List getJsonByName(){ + //获取目录结构 + String path = FileUtils.currentPath(); + //解析json映射文件 + String json = JsonUtils.readJsonFile(path + Codes.JSON_ADDRESS.getMessage()); + Map jsonMap = JSON.parseObject(json, Map.class); + //判断是否多条 + List basicArr= (List) jsonMap.get("doubleBasic"); + List directory= (List) jsonMap.get("basicDirectory"); + List elements=null; + Element root=this.getElement(directory); + for (String basic : basicArr) { + elements=root.elements(basic); + if(elements!=null&&elements.size()>0){ + break; + } + } + if(elements==null||elements.size()==0){ + //只有一条 + List rootDirectory= (List) jsonMap.get("directory"); + root = this.getElement(rootDirectory); + elements=new ArrayList<>(); + elements.add(root); + } + return elements; + } + /** * 根据节点名称获取内容 * diff --git a/docus-ws-bgts/src/main/resources/application.yml b/docus-ws-bgts/src/main/resources/application.yml index 620ec4e..24ba993 100644 --- a/docus-ws-bgts/src/main/resources/application.yml +++ b/docus-ws-bgts/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 9797 + port: 9301 mybatis-plus: configuration: