You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

349 lines
14 KiB
Java

4 years ago
package com.docus.bgts.handler;
import com.alibaba.fastjson.JSON;
import com.docus.bgts.entity.*;
4 years ago
import com.docus.bgts.enums.Codes;
import com.docus.bgts.facade.IAfCollectTaskService;
import com.docus.bgts.facade.IMrReportErrorService;
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.commons.lang3.StringUtils;
4 years ago
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
4 years ago
import org.springframework.beans.factory.annotation.Autowired;
import javax.jws.WebService;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
4 years ago
import java.io.UnsupportedEncodingException;
import java.util.*;
4 years ago
@WebService
public class TBasicWebService implements ITBasicWebService {
@Autowired
IAfCollectTaskService afCollectTaskService;
@Autowired
IMrReportErrorService mrReportErrorService;
private final Logger logger = LoggerFactory.getLogger(getClass());
4 years ago
private Element getElementFromString(String s) {
SAXReader builder = new SAXReader();
Document doc = null;
Element element = null;
try {
doc = builder.read(new StringReader(s));
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (doc != null) {
element = doc.getRootElement();
}
return element;
}
@Override
public String pushSurveyReport(String xml) {
try {
logger.info("报告推送入参:" + xml);
// 1、创建document对象
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + xml;
//解析XML
XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(xml.getBytes("UTF-8")));
//获取数据存在的节点节点
Element elementRoot = xmlUtils.getMsgElement();
//key
String serialnmnKey = String.valueOf(FileUtils.getJsonByName("serialnum"));
String filetitleKey = String.valueOf(FileUtils.getJsonByName("filetitle"));
String downurlKey = String.valueOf(FileUtils.getJsonByName("downurl"));
// 获取患者主索引号
String empId = String.valueOf(FileUtils.getJsonByName(Codes.EMP_ID.getMessage()));
//判断是否为撤销
String isJudge = String.valueOf(FileUtils.getJsonByName("isJudge"));
if (StringUtils.isBlank(isJudge) || isJudge.equals("0")) {
} else {
//获取撤回路径
List<String> judgeDirectory = (List<String>) FileUtils.getJsonByName("judgeDirectory");
Element current = xmlUtils.getElement(judgeDirectory);
//获取撤回标签
String judgeIndex = String.valueOf(FileUtils.getJsonByName("judgeIndex"));
Element judgeIndexElement = current.element(judgeIndex);
if (judgeIndexElement == null || StringUtils.isBlank(judgeIndexElement.getText()) || (!judgeIndexElement.getText().equals("1"))) {
logger.info("------新增/修改------");
} else if (judgeIndexElement.getText().equals("1")) {
logger.info("---------撤回--------");
CanlcelDto canlcelDto = new CanlcelDto();
String serialnum = String.valueOf(FileUtils.getJsonByName("serialnum"));
String serialnumElement = getElementText(elementRoot, serialnum.split(","));
canlcelDto.setSerialnum(serialnumElement);
//调用上传服务撤销功能
afCollectTaskService.invokeRepoalFile(canlcelDto);
logger.info("----------当前操作完成--------------");
return ResultUtils.success().asXML();
}
}
Map<String, Object> headMap = new HashMap<>();
headMap.put("Content-Type", "application/json");
ReportDownDto reportDownDto;
4 years ago
ReportDownScanFileDto reportDownScanFileDto;
ReportDownPatientDto reportDownPatientDto;
//临时资料存储
String serialnum;
String filetitle;
String downurl;
String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid"));
String assortid = getAssortid(elementRoot);
reportDownDto = new ReportDownDto();
reportDownDto.setCollectorid(collectorid);
reportDownDto.setAssortid(assortid);
//获取基本数据信息
List<ReportDownScanFileDto> reportDownDtoArr = new ArrayList<>();
reportDownPatientDto = new ReportDownPatientDto();
//获取jzh
String empIdText = getElementText(elementRoot, empId.split(","));
4 years ago
reportDownPatientDto.setJzh(empIdText);
logger.info("患者主索引号:" + empIdText);
reportDownDto.setPatient(reportDownPatientDto);
List<Element> elementList = xmlUtils.getJsonByName(elementRoot);
for (Element element : elementList) {
filetitle = getElementText(element, filetitleKey.split(","));
downurl = getElementText(element, downurlKey.split(","));
4 years ago
downurl = handleDownUrl(downurl);
//获取采集流水号
serialnum = getElementText(element, serialnmnKey.split(","));
4 years ago
reportDownScanFileDto = new ReportDownScanFileDto();
reportDownScanFileDto.setDownurl(downurl);
reportDownScanFileDto.setFiletitle(filetitle);
reportDownScanFileDto.setSerialnum(serialnum);
reportDownScanFileDto.setFilesource(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filesource"))));
reportDownScanFileDto.setFilestoragetype(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filestoragetype"))));
//判断是否为base64
if (reportDownScanFileDto.getDownurl().length() > 200) {
reportDownScanFileDto.setFiletype(2);
}
reportDownDtoArr.add(reportDownScanFileDto);
}
if (reportDownDtoArr.size() <= 0) {
throw new RuntimeException("不存在必要的基本信息");
} else {
reportDownDto.setScanfiles(reportDownDtoArr);
}
//插入文件af_collect_task表数据
afCollectTaskService.insert(reportDownDto);
String post = "";
logger.info("--------执行上传功能----------");
Map params = JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class);
if (reportDownDto.getScanfiles().get(0).getFiletype() == 1) {
logger.info("上传参数:" + params);
}
4 years ago
post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, params);
// String post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), map, headMap);
if (StringUtils.isBlank(post)) {
logger.info("--------上传时出现错误,可能是文件服务没有启动----------");
throw new RuntimeException("上传时出现错误,可能是文件服务没有启动");
}
Map resMap = JSON.parseObject(post, Map.class);
if (String.valueOf(resMap.get("code")).equals("500")) {
throw new RuntimeException(String.valueOf(resMap.get("msg")));
} else {
logger.info("----------执行成功-----------");
4 years ago
return ResultUtils.success().asXML();
}
} catch (RuntimeException e) {
e.printStackTrace();
mrReportErrorService.insert(xml);
return ResultUtils.fail(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
mrReportErrorService.insert(xml);
return ResultUtils.fail(e.getMessage());
}
}
4 years ago
/**
*
*
* @param downurl
* @return
*/
private String handleDownUrl(String downurl) {
String url = "";
try {
XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(downurl.getBytes("UTF-8")));
if (null != xmlUtils) {
url=downurl;
List<String> urlReplaces=(List<String>) FileUtils.getJsonByName("urlReplace");
for (String urlReplace : urlReplaces) {
url = url.replaceAll(urlReplace, "");
}
return url;
}
} catch (Exception e) {
}
return "";
4 years ago
}
4 years ago
@Override
public String EmrDocumentArchive(String xml) {
return pushSurveyReport(xml);
}
@Override
public String EmrDocumentArchiveCancel(String xml) {
4 years ago
try {
logger.info("--------------撤销接收到xml--------------");
logger.info(xml);
//解析xml并提取CanlcelDto对象
CanlcelDto canlcelDto = getCanlCelDtoByXml(xml);
//调用上传服务撤销功能
afCollectTaskService.invokeRepoalFile(canlcelDto);
logger.info("--------------撤销操作完成-------------");
return ResultUtils.success().asXML();
} catch (RuntimeException e) {
logger.info("发送错误:" + e.getMessage());
mrReportErrorService.insert(xml);
4 years ago
e.printStackTrace();
4 years ago
return ResultUtils.fail(e.getMessage());
} catch (Exception e) {
logger.info("发送错误:" + e.getMessage());
e.printStackTrace();
mrReportErrorService.insert(xml);
return ResultUtils.fail(e.getMessage());
}
}
/**
* xmlCanlcelDto
*
* @param xml
* @return
*/
4 years ago
private CanlcelDto getCanlCelDtoByXml(String xml) throws UnsupportedEncodingException {
XmlUtils xmlUtils = null;
try {
xmlUtils = new XmlUtils(new ByteArrayInputStream(xml.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
}
4 years ago
//采集流水号所在位置目录
List<String> repealDirectory = (List<String>) FileUtils.getJsonByName("repealDirectory");
Element element = xmlUtils.getElement(repealDirectory);
String repealSerialnum = String.valueOf(FileUtils.getJsonByName("repealSerialnum"));
Element repealSerialnumElement = element.element(repealSerialnum);
CanlcelDto canlcelDto = new CanlcelDto();
if (null == repealSerialnumElement || StringUtils.isBlank(repealSerialnumElement.getText())) {
throw new RuntimeException(repealSerialnum + "标签必须有值");
} else {
String serialnum = repealSerialnumElement.getText();
logger.info("当前流水号为:" + serialnum);
canlcelDto.setSerialnum(serialnum);
}
return canlcelDto;
}
4 years ago
/**
* key
*
* @param element
* @param args
* @return
*/
private String getElementText(Element element, String[] args) {
String resText = "";
Element byElement = (Element) element.clone();
4 years ago
Element byElement1 = null;
4 years ago
String[] split;
for (String arg : args) {
split = arg.split("&");
if (split.length > 1) {
for (String spi : split) {
if (byElement1 == null) {
byElement1 = byElement.element(spi);
} else {
byElement1 = byElement1.element(spi);
}
4 years ago
if (byElement1 != null && StringUtils.isNotBlank(byElement1.getText())) {
4 years ago
break;
} else {
byElement1 = null;
4 years ago
}
}
} else {
if (byElement1 == null) {
byElement1 = byElement.element(arg);
} else {
byElement1 = byElement1.element(arg);
}
4 years ago
}
4 years ago
if (byElement1 != null) {
resText = byElement1.getText();
4 years ago
} else {
break;
}
}
if (StringUtils.isBlank(resText)) {
throw new RuntimeException(args[args.length - 1] + "的值不能为空");
}
4 years ago
return resText;
}
4 years ago
/**
* id
4 years ago
*
* @return
*/
private String getAssortid(Element element) {
4 years ago
String assortId = String.valueOf(FileUtils.getJsonByName("assortid"));
if (StringUtils.isBlank(assortId)) {
String assortIdKey = String.valueOf(FileUtils.getJsonByName("assortidParamKey"));
if (StringUtils.isBlank(assortIdKey)) {
assortId = "";
} else {
assortId = element.element(assortIdKey).getText();
}
String myAssortId = afCollectTaskService.getAssortIdByAssortId(assortId);
if (StringUtils.isBlank(myAssortId)) {
myAssortId = afCollectTaskService.getAssortIdByAssortName(assortId);
if (StringUtils.isBlank(myAssortId)) {
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
ZdAssort zdAssort = new ZdAssort();
zdAssort.setAssortName(assortId);
zdAssort.setAssortId(uuid);
zdAssort.setEffective(1);
afCollectTaskService.insertZdAssort(zdAssort);
assortId = uuid;
} else {
assortId = myAssortId;
}
} else {
assortId = myAssortId;
}
4 years ago
}
return assortId;
}
}