@ -2,29 +2,45 @@ package com.docus.bgts.handler;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONObject ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.docus.bgts.entity.* ;
import com.docus.bgts.enums.Codes ;
import com.docus.bgts.facade.IAfCollectTaskService ;
import com.docus.bgts.facade.IMrReportErrorService ;
import com.docus.bgts.mapper.TBasicExtendMapper ;
import com.docus.bgts.mapper.TBasicMapper ;
import com.docus.bgts.mapper.TScanAssortMapper ;
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 com.sun.xml.internal.ws.util.xml.XmlUtil;
import org.apache.commons.lang3.CharEncoding ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.exception.ExceptionUtils ;
import org.dom4j.Document ;
import org.dom4j.DocumentException ;
import org.dom4j.Element ;
import org.dom4j.Namespace ;
import org.dom4j.io.SAXReader ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
import sun.misc.BASE64Decoder ;
import javax.jws.WebService ;
import java.io.ByteArrayInputStream ;
import java.io.StringReader ;
import java.io.UnsupportedEncodingException ;
import java.io.* ;
import java.nio.file.Files ;
import java.nio.file.Path ;
import java.nio.file.Paths ;
import java.text.SimpleDateFormat ;
import java.util.* ;
import java.util.concurrent.locks.Lock ;
import java.util.concurrent.locks.ReentrantLock ;
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
@WebService
public class TBasicWebService implements ITBasicWebService {
@ -35,6 +51,16 @@ public class TBasicWebService implements ITBasicWebService {
@Autowired
IMrReportErrorService mrReportErrorService ;
@Autowired
TBasicMapper tBasicMapper ;
@Autowired
TBasicExtendMapper tBasicExtendMapper ;
@Autowired
TScanAssortMapper tScanAssortMapper ;
// private Object lock = new Object();
private final Logger logger = LoggerFactory . getLogger ( getClass ( ) ) ;
@ -56,6 +82,7 @@ public class TBasicWebService implements ITBasicWebService {
@Override
public String pushSurveyReport ( String xml ) {
long l6 = System . currentTimeMillis ( ) ;
try {
logger . info ( "报告推送入参:" + xml ) ;
// 1、创建document对象
@ -63,13 +90,22 @@ public class TBasicWebService implements ITBasicWebService {
//解析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 nurseSubmitTime = String . valueOf ( FileUtils . getJsonByName ( "nurseSubmitTime" ) ) ;
String doctorSubmitTime = String . valueOf ( FileUtils . getJsonByName ( "doctorSubmitTime" ) ) ;
String examApplyDate = String . valueOf ( FileUtils . getJsonByName ( "examApplyDate" ) ) ;
String inPatientNo = String . valueOf ( FileUtils . getJsonByName ( "inPatientNo" ) ) ;
//电子病历排序时间
String sortingTimeKey = String . valueOf ( FileUtils . getJsonByName ( "sortingTime" ) ) ;
// 获取患者主索引号
String empId = String . valueOf ( FileUtils . getJsonByName ( Codes . EMP_ID . getMessage ( ) ) ) ;
//电子病历封存id
String seal = String . valueOf ( FileUtils . getJsonByName ( "sealId" ) ) ;
//判断是否为撤销
String isJudge = String . valueOf ( FileUtils . getJsonByName ( "isJudge" ) ) ;
if ( StringUtils . isBlank ( isJudge ) | | isJudge . equals ( "0" ) ) {
@ -85,14 +121,9 @@ public class TBasicWebService implements ITBasicWebService {
logger . info ( "------新增/修改------" ) ;
} else if ( judgeIndexElement . getText ( ) . equals ( "1" ) ) {
logger . info ( "---------撤回--------" ) ;
CanlcelDto canlcelDto = new CanlcelDto ( ) ;
String serialnum = String . valueOf ( FileUtils . getJsonByName ( "serialnum" ) ) ;
// Element serialnumElement = elementRoot.element(serialnum);
String serialnumElement = getElementText ( elementRoot , serialnum . split ( "," ) ) ; ;
// if (serialnumElement != null || StringUtils.isBlank(serialnumElement.getText())) {
// throw new RuntimeException("撤回操作时:" + serialnum + "标签不能为空!");
// }
String serialnumElement = getElementText ( elementRoot , serialnum . split ( "," ) ) ;
canlcelDto . setSerialnum ( serialnumElement ) ;
//调用上传服务撤销功能
afCollectTaskService . invokeRepoalFile ( canlcelDto ) ;
@ -111,7 +142,291 @@ public class TBasicWebService implements ITBasicWebService {
String serialnum ;
String filetitle ;
String downurl ;
String sortingTime ;
String assortid ;
String collectorid = String . valueOf ( FileUtils . getJsonByName ( "collectorid" ) ) ;
if ( collectorid . equals ( "1" ) ) {
assortid = String . valueOf ( FileUtils . getJsonByName ( "assortid" ) ) ;
} else {
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 ( "," ) ) ;
//获取封存id
String sealId = getElementTextCanBeEmpty ( elementRoot , seal . split ( "," ) ) ;
if ( null ! = sealId & & ! "" . equals ( sealId ) ) {
reportDownPatientDto . setJzh ( empIdText ) ;
reportDownPatientDto . setSealId ( sealId ) ;
logger . info ( "封存患者jzh : " + empIdText ) ;
reportDownDto . setPatient ( reportDownPatientDto ) ;
List < Element > elementList = xmlUtils . getJsonByName ( elementRoot ) ;
for ( Element element : elementList ) {
filetitle = getElementText ( element , filetitleKey . split ( "," ) ) ;
downurl = getElementText ( element , downurlKey . split ( "," ) ) ;
//downurl = handleDownUrl(downurl);
//添加护理提交时间
if ( collectorid . equals ( "1" ) ) {
nurseSubmitTime = getElementText ( element , nurseSubmitTime . split ( "," ) ) ;
afCollectTaskService . updateNurseSubmitTime ( reportDownDto , nurseSubmitTime ) ;
afCollectTaskService . insertNurseState ( reportDownDto , nurseSubmitTime ) ;
}
//获取电子病历排序时间
sortingTime = getElementTextCanBeEmpty ( element , sortingTimeKey . split ( "," ) ) ;
//获取采集流水号
serialnum = getElementText ( element , serialnmnKey . split ( "," ) ) ;
reportDownScanFileDto = new ReportDownScanFileDto ( ) ;
reportDownScanFileDto . setDownurl ( downurl ) ;
reportDownScanFileDto . setFiletitle ( filetitle ) ;
reportDownScanFileDto . setSerialnum ( serialnum ) ;
reportDownScanFileDto . setSortdate ( sortingTime ) ;
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 ) ;
}
afCollectTaskService . insertSeal ( reportDownDto ) ;
String post = "" ;
logger . info ( "--------执行上传功能----------" ) ;
Map params = JSON . parseObject ( JSON . toJSONString ( reportDownDto ) , Map . class ) ;
if ( reportDownDto . getScanfiles ( ) . get ( 0 ) . getFiletype ( ) = = 1 ) {
logger . info ( "封存id--" + reportDownDto . getPatient ( ) . getSealId ( ) + ": 上传参数:" + params ) ;
}
long l = System . currentTimeMillis ( ) ;
post = HttpUtils . post ( String . valueOf ( FileUtils . getJsonByName ( Codes . SEALUPLOAD . getMessage ( ) ) ) , headMap , params ) ;
long l1 = System . currentTimeMillis ( ) ;
logger . info ( "封存id--" + reportDownDto . getPatient ( ) . getSealId ( ) + "请求下载耗时----------" + ( l1 - l ) ) ;
if ( StringUtils . isBlank ( post ) ) {
logger . info ( "封存id--" + reportDownDto . getPatient ( ) . getSealId ( ) + "--------上传时出现错误,可能是文件服务没有启动----------" ) ;
throw new RuntimeException ( "封存id--" + reportDownDto . getPatient ( ) . getSealId ( ) + "上传时出现错误,可能是文件服务没有启动" ) ;
}
Map resMap = JSON . parseObject ( post , Map . class ) ;
long l7 = System . currentTimeMillis ( ) ;
logger . info ( "接口总耗时--------" + ( l7 - l6 ) ) ;
if ( String . valueOf ( resMap . get ( "code" ) ) . equals ( "500" ) ) {
logger . info ( "封存id--" + reportDownDto . getPatient ( ) . getSealId ( ) + "--------上传失败!" + resMap . get ( "msg" ) ) ;
throw new RuntimeException ( "封存id--" + reportDownDto . getPatient ( ) . getSealId ( ) + "上传失败:" + resMap . get ( "msg" ) ) ;
} else {
logger . info ( "----------执行成功-----------" ) ;
return ResultUtils . success ( ) . asXML ( ) ;
}
} else {
//病理没有就诊流水号的根据住院号和检查申请日期时间匹配患者
// String empIdText = getElementTextCanBeEmpty(elementRoot, empId.split(","));
// if (null==empIdText||empIdText.equals("")){
// String examApplyDates = getElementText(elementRoot, examApplyDate.split(","));
// String inPatientNos = getElementText(elementRoot, inPatientNo.split(","));
// empIdText = afCollectTaskService.selectJzh(inPatientNos, examApplyDates);
// if (null==empIdText){
// TBasic tBasic = afCollectTaskService.selectDisDateIsNull(inPatientNos);
// if (null!=tBasic){
// empIdText = tBasic.getJzh();
// }else {
// throw new RuntimeException("住院号未匹配到患者");
// }
// }
//
// }
// doctorSubmitTime = getElementText(elementRoot, doctorSubmitTime.split(","));
/ * *
* 删 除 电 子 病 历 数 据
* /
// long l2 = System.currentTimeMillis();
// String patientId = afCollectTaskService.getpatientIdByEmpId(empIdText);
// long l3 = System.currentTimeMillis();
// logger.info("查询patient_id耗时" + (l3 - l2));
// //删除af_downfile表数据
// long l4 = System.currentTimeMillis();
// int i = afCollectTaskService.deleteByPatientIdAndCollectorId(patientId, collectorid);
// long l5 = System.currentTimeMillis();
// logger.info("删除" + empIdText + "af_downfile表" + i + "条数据耗时-----" + (l5 - l4));
// //删除t_scan_assort表数据
// long l8 = System.currentTimeMillis();
// int i1 = afCollectTaskService.deleteByPatientIdAndAssortId(patientId, assortid);
// long l11 = System.currentTimeMillis();
// logger.info("删除" + empIdText + "t_scan_assort表" + i1 + "条数据耗时-----" + (l11 - l8));
// //删除af_collect_task表数据
// long l9 = System.currentTimeMillis();
// int i2 = afCollectTaskService.deleteByPatientIdAndSysFlag(patientId, collectorid);
// long l10 = System.currentTimeMillis();
// logger.info("删除" + empIdText + "af_collect_task表" + i2 + "条数据耗时-----" + (l10 - l9));
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 ( "," ) ) ;
//downurl = handleDownUrl(downurl);
//添加护理提交时间
if ( collectorid . equals ( "1" ) ) {
nurseSubmitTime = getElementText ( element , nurseSubmitTime . split ( "," ) ) ;
afCollectTaskService . updateNurseSubmitTime ( reportDownDto , nurseSubmitTime ) ;
afCollectTaskService . insertNurseState ( reportDownDto , nurseSubmitTime ) ;
}
//获取电子病历排序时间
// sortingTime = getElementTextCanBeEmpty(element, sortingTimeKey.split(","));
//获取采集流水号
serialnum = getElementText ( element , serialnmnKey . split ( "," ) ) ;
reportDownScanFileDto = new ReportDownScanFileDto ( ) ;
reportDownScanFileDto . setDownurl ( downurl ) ;
reportDownScanFileDto . setFiletitle ( filetitle ) ;
reportDownScanFileDto . setSerialnum ( serialnum ) ;
// reportDownScanFileDto.setSortdate(sortingTime);
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 ) ;
}
if ( collectorid . equals ( "22" ) ) {
//查询正式住院患者信息
TBasic tBasic = tBasicMapper . selectByjzh ( empIdText ) ;
if ( null ! = tBasic ) {
//查询预住院患者信息
TBasicExtend tBasicExtend = tBasicExtendMapper . selectByPatientId ( tBasic . getPatientId ( ) ) ;
if ( null ! = tBasicExtend ) {
TBasic tBasicPre = tBasicMapper . selectByjzh ( tBasicExtend . getPreJzh ( ) ) ;
if ( null ! = tBasicPre ) {
int pre = tScanAssortMapper . updateByPatientId ( tBasic . getPatientId ( ) , tBasicPre . getPatientId ( ) ) ;
if ( pre < = 0 ) {
logger . info ( "当前预住院没有文件!" ) ;
} else {
logger . info ( "本次预住院合并" + pre + "份报告" ) ;
}
} else {
logger . info ( "未查询到预住院患者信息!" ) ;
}
}
}
}
//插入医生提交时间
// afCollectTaskService.updateDoctorSubmitTime(reportDownDto, doctorSubmitTime);
//插入医生提交状态
// afCollectTaskService.insertDoctorState(reportDownDto, doctorSubmitTime);
//插入文件af_collect_task表数据
// synchronized (lock) {
// System.err.println(reportDownDto);
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 ( reportDownDto . getPatient ( ) . getJzh ( ) + ": 上传参数:" + params ) ;
}
long l = System . currentTimeMillis ( ) ;
post = HttpUtils . post ( String . valueOf ( FileUtils . getJsonByName ( Codes . UPLOAD . getMessage ( ) ) ) , headMap , params ) ;
long l1 = System . currentTimeMillis ( ) ;
logger . info ( "请求下载耗时----------" + ( l1 - l ) ) ;
// 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 ) ;
long l7 = System . currentTimeMillis ( ) ;
logger . info ( "接口总耗时--------" + ( l7 - l6 ) ) ;
if ( String . valueOf ( resMap . get ( "code" ) ) . equals ( "500" ) ) {
logger . info ( reportDownDto . getPatient ( ) . getJzh ( ) + "--------上传失败!" + resMap . get ( "msg" ) ) ;
throw new RuntimeException ( reportDownDto . getPatient ( ) . getJzh ( ) + "上传失败:" + resMap . get ( "msg" ) ) ;
} else {
logger . info ( "----------执行成功-----------" ) ;
return ResultUtils . success ( ) . asXML ( ) ;
}
}
} catch ( RuntimeException e ) {
e . printStackTrace ( ) ;
// mrReportErrorService.insert(xml);
logger . error ( e . getMessage ( ) ) ;
String stackTrace = ExceptionUtils . getStackTrace ( e ) ;
logger . info ( "错误信息----------" + stackTrace ) ;
return ResultUtils . fail ( e . getMessage ( ) ) ;
} catch ( Exception e ) {
// mrReportErrorService.insert(xml);
logger . error ( e . getMessage ( ) ) ;
String stackTrace = ExceptionUtils . getStackTrace ( e ) ;
logger . info ( "错误信息----------" + stackTrace ) ;
e . printStackTrace ( ) ;
return ResultUtils . fail ( e . getMessage ( ) ) ;
}
}
/ * *
* 肇 庆 门 急 诊 报 告 接 收
*
* @param xml
* @return
* /
@Override
public String outPatient ( String xml ) {
long l6 = System . currentTimeMillis ( ) ;
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 ( ) ) ) ;
Map < String , Object > headMap = new HashMap < > ( ) ;
headMap . put ( "Content-Type" , "application/json" ) ;
ReportDownDto reportDownDto ;
ReportDownScanFileDto reportDownScanFileDto ;
ReportDownPatientDto reportDownPatientDto ;
//临时资料存储
String serialnum ;
String filetitle ;
String downurl ;
// String sortingTime;
int filetype = Integer . parseInt ( String . valueOf ( FileUtils . getJsonByName ( "filetype" ) ) ) ;
String collectorid = String . valueOf ( FileUtils . getJsonByName ( "collectorid" ) ) ;
String assortid = getAssortid ( elementRoot ) ;
reportDownDto = new ReportDownDto ( ) ;
reportDownDto . setCollectorid ( collectorid ) ;
@ -126,17 +441,15 @@ public class TBasicWebService implements ITBasicWebService {
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 ( "," ) ) ;
downurl = handleDownUrl ( downurl ) ;
//获取采集流水号
serialnum = getElementText ( element , serialnmnKey . split ( "," ) ) ;
reportDownScanFileDto = new ReportDownScanFileDto ( ) ;
reportDownScanFileDto . setDownurl ( downurl );
reportDownScanFileDto . setDownurl ( downurl .substring ( 1 , downurl . length ( ) - 1 ) );
reportDownScanFileDto . setFiletitle ( filetitle ) ;
reportDownScanFileDto . setSerialnum ( serialnum ) ;
reportDownScanFileDto . setFiletype ( filetype ) ;
reportDownScanFileDto . setFilesource ( Integer . parseInt ( String . valueOf ( FileUtils . getJsonByName ( "filesource" ) ) ) ) ;
reportDownScanFileDto . setFilestoragetype ( Integer . parseInt ( String . valueOf ( FileUtils . getJsonByName ( "filestoragetype" ) ) ) ) ;
//判断是否为base64
@ -150,21 +463,28 @@ public class TBasicWebService implements ITBasicWebService {
} else {
reportDownDto . setScanfiles ( reportDownDtoArr ) ;
}
//插入文件af_collect_task表数据
afCollectTaskService . insert ( reportDownDto ) ;
// System.err.println(reportDownDto);
afCollectTaskService . insertOut ( reportDownDto ) ;
String post = "" ;
logger . info ( "--------执行上传功能----------" ) ;
Map params = JSON . parseObject ( JSON . toJSONString ( reportDownDto ) , Map . class ) ;
if ( reportDownDto . getScanfiles ( ) . get ( 0 ) . getFiletype ( ) = = 1 ) {
logger . info ( "上传参数:" + params ) ;
}
logger . info ( "上传参数:" + params ) ;
long l = System . currentTimeMillis ( ) ;
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);
long l1 = System . currentTimeMillis ( ) ;
logger . info ( "请求下载耗时----------" + ( l1 - l ) ) ;
if ( StringUtils . isBlank ( post ) ) {
logger . info ( "--------上传时出现错误,可能是文件服务没有启动----------" ) ;
throw new RuntimeException ( "上传时出现错误,可能是文件服务没有启动" ) ;
}
Map resMap = JSON . parseObject ( post , Map . class ) ;
long l7 = System . currentTimeMillis ( ) ;
logger . info ( "接口总耗时--------" + ( l7 - l6 ) ) ;
if ( String . valueOf ( resMap . get ( "code" ) ) . equals ( "500" ) ) {
throw new RuntimeException ( String . valueOf ( resMap . get ( "msg" ) ) ) ;
} else {
@ -173,11 +493,15 @@ public class TBasicWebService implements ITBasicWebService {
}
} catch ( RuntimeException e ) {
e . printStackTrace ( ) ;
mrReportErrorService . insert ( xml ) ;
logger . error ( e . getMessage ( ) ) ;
// String stackTrace = ExceptionUtils.getStackTrace(e);
// logger.info("错误信息----------"+stackTrace);
return ResultUtils . fail ( e . getMessage ( ) ) ;
} catch ( Exception e ) {
logger . error ( e . getMessage ( ) ) ;
// String stackTrace = ExceptionUtils.getStackTrace(e);
// logger.info("错误信息----------"+stackTrace);
e . printStackTrace ( ) ;
mrReportErrorService . insert ( xml ) ;
return ResultUtils . fail ( e . getMessage ( ) ) ;
}
}
@ -191,82 +515,52 @@ public class TBasicWebService implements ITBasicWebService {
private String handleDownUrl ( String downurl ) {
String url = "" ;
try {
XmlUtils xmlUtils = new XmlUtils ( new ByteArrayInputStream ( downurl . getBytes ( "UTF-8" ) ) ) ;
if ( null ! = xmlUtils ) {
url = downurl ;
url = downurl . replaceAll ( "<REST>" , "" ) ;
url = url . replaceAll ( "</REST>" , "" ) ;
url = url . replaceAll ( "<SQW>" , "" ) ;
url = url . replaceAll ( "</SQW>" , "" ) ;
}
} catch ( Exception e ) {
}
int pdfIndex = - 1 ;
int httpIndex = downurl . indexOf ( "http" ) ;
if ( httpIndex = = - 1 ) {
return downurl ;
}
if ( downurl . indexOf ( ".pdf" ) = = - 1 ) {
if ( downurl . indexOf ( ".PDF" ) = = - 1 ) {
if ( downurl . indexOf ( ".jpg" ) = = - 1 ) {
if ( downurl . indexOf ( ".JPG" ) = = - 1 ) {
if ( downurl . indexOf ( ".png" ) = = - 1 ) {
if ( downurl . indexOf ( ".PNG" ) = = - 1 ) {
return downurl ;
} else {
pdfIndex = downurl . indexOf ( ".PNG" ) + 4 ;
}
} else {
pdfIndex = downurl . indexOf ( ".png" ) + 4 ;
}
} else {
pdfIndex = downurl . indexOf ( ".JPG" ) + 4 ;
}
} else {
pdfIndex = downurl . indexOf ( ".jpg" ) + 4 ;
url = downurl ;
List < String > urlReplaces = ( List < String > ) FileUtils . getJsonByName ( "urlReplace" ) ;
for ( String urlReplace : urlReplaces ) {
url = url . replaceAll ( urlReplace , "" ) ;
}
} else {
pdfIndex = downurl . indexOf ( ".PDF" ) + 4 ;
return url ;
}
} else {
pdfIndex = downurl . indexOf ( ".pdf" ) + 4 ;
}
url = downurl . substring ( httpIndex , pdfIndex ) ;
return url ;
}
@Override
public String EmrDocumentArchive ( String xml ) {
return pushSurveyReport ( xml ) ;
}
@Override
public String EmrDocumentArchiveCancel ( String xml ) {
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 ) ;
e . printStackTrace ( ) ;
return ResultUtils . fail ( e . getMessage ( ) ) ;
} catch ( Exception e ) {
logger . info ( "发送错误:" + e . getMessage ( ) ) ;
e . printStackTrace ( ) ;
mrReportErrorService . insert ( xml ) ;
return ResultUtils . fail ( e . getMessage ( ) ) ;
}
return "" ;
}
// @Override
// public String EmrDocumentArchive(String xml) {
// return pushSurveyReport(xml);
// }
//
// @Override
// public String EmrDocumentArchiveCancel(String xml) {
// 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);
// e.printStackTrace();
// return ResultUtils.fail(e.getMessage());
// } catch (Exception e) {
// logger.info("发送错误:" + e.getMessage());
// e.printStackTrace();
// // mrReportErrorService.insert(xml);
// return ResultUtils.fail(e.getMessage());
// }
//
// }
/ * *
* 解 析 xml , 返 回 CanlcelDto 对 象
*
@ -344,6 +638,50 @@ public class TBasicWebService implements ITBasicWebService {
return resText ;
}
/ * *
* 获 取 key 内 容
*
* @param element
* @param args
* @return
* /
private String getElementTextCanBeEmpty ( Element element , String [ ] args ) {
String resText = "" ;
Element byElement = ( Element ) element . clone ( ) ;
Element byElement1 = null ;
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 ) ;
}
if ( byElement1 ! = null & & StringUtils . isNotBlank ( byElement1 . getText ( ) ) ) {
break ;
} else {
byElement1 = null ;
}
}
} else {
if ( byElement1 = = null ) {
byElement1 = byElement . element ( arg ) ;
} else {
byElement1 = byElement1 . element ( arg ) ;
}
}
if ( byElement1 ! = null ) {
resText = byElement1 . getText ( ) ;
} else {
break ;
}
}
return resText ;
}
/ * *
* 获 取 分 类 id
@ -380,4 +718,42 @@ public class TBasicWebService implements ITBasicWebService {
}
return assortId ;
}
public static void depdf ( ) {
// 存放pdf的base64
Path path = Paths . get ( "D:\\pdf.txt" ) ;
Stream < String > lines = null ;
try {
lines = Files . lines ( path ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
// 读取文件转换为String
String collect = lines . collect ( Collectors . joining ( System . lineSeparator ( ) ) ) ;
String encodedBytes = collect ;
BASE64Decoder decoder = new BASE64Decoder ( ) ;
byte [ ] decodedBytes = new byte [ 0 ] ;
try {
decodedBytes = decoder . decodeBuffer ( encodedBytes ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
File file = new File ( "D:\\newfile.pdf" ) ;
FileOutputStream fop = null ;
try {
fop = new FileOutputStream ( file ) ;
fop . write ( decodedBytes ) ;
fop . flush ( ) ;
fop . close ( ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
public static void main ( String [ ] args ) {
depdf ( ) ;
}
}