|
|
package com.docus.bgts.service;
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.docus.bgts.entity.AfCollectTask;
|
|
|
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.facade.IAfCollectTaskService;
|
|
|
import com.docus.bgts.facade.IBgtsService;
|
|
|
import com.docus.bgts.utils.FileUtils;
|
|
|
import com.docus.bgts.utils.HttpUtils;
|
|
|
import com.docus.bgts.utils.JAXDynamicClientFactory;
|
|
|
import com.docus.bgts.utils.XmlUtils;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.apache.cxf.endpoint.Client;
|
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentHelper;
|
|
|
import org.dom4j.Element;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class BgtsServiceImpl implements IBgtsService {
|
|
|
@Value("${ws.url}")
|
|
|
private String wsUrl;
|
|
|
@Value("${ws.localMethod}")
|
|
|
private String wsLocalMethod;
|
|
|
|
|
|
@Autowired
|
|
|
IAfCollectTaskService afCollectTaskService;
|
|
|
|
|
|
@Override
|
|
|
public void collect(String empId) throws Exception {
|
|
|
//通过empId获取报告单号集合
|
|
|
List<String[]> exams = getExamNo(empId);
|
|
|
//通过报告单号集合采集
|
|
|
collectExams(exams, empId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void collectByExamNo(String emamNo, String empId) throws Exception {
|
|
|
String[] strings = new String[2];
|
|
|
//通过报告单号和系统id查询任务表
|
|
|
String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid"));
|
|
|
AfCollectTask afCollectTask = afCollectTaskService.getOne(new QueryWrapper<AfCollectTask>().eq("C1", emamNo).eq("sysflag", collectorid));
|
|
|
strings[0] = emamNo;
|
|
|
strings[1] = afCollectTask.getC2();
|
|
|
List<String[]> exams = new ArrayList<>();
|
|
|
exams.add(strings);
|
|
|
collectExams(exams, empId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过报告单号集合采集数据
|
|
|
*
|
|
|
* @param exams
|
|
|
* @param empId
|
|
|
*/
|
|
|
private void collectExams(List<String[]> exams, String empId) throws Exception {
|
|
|
//获取插入表数据
|
|
|
ReportDownDto reportDownDto = getUrlCreateReportDto(exams, empId);
|
|
|
//插入文件af_collect_task表数据
|
|
|
afCollectTaskService.insert(reportDownDto);
|
|
|
// reportDownDto.setTaskid(id);
|
|
|
//调用上传接口
|
|
|
Map<String, Object> headMap = new HashMap<>();
|
|
|
headMap.put("Content-Type", "application/json");
|
|
|
String post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class));
|
|
|
Map resMap = JSON.parseObject(post, Map.class);
|
|
|
System.out.println(resMap);
|
|
|
if (String.valueOf(resMap.get("code")).equals("500")) {
|
|
|
throw new RuntimeException(String.valueOf(resMap.get("msg")));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取图片url,病返回插入表对象
|
|
|
*
|
|
|
* @param exams
|
|
|
* @param empId
|
|
|
* @return
|
|
|
*/
|
|
|
private ReportDownDto getUrlCreateReportDto(List<String[]> exams, String empId) throws Exception {
|
|
|
ReportDownDto reportDownDto = new ReportDownDto();
|
|
|
ReportDownPatientDto reportDownPatientDto = new ReportDownPatientDto();
|
|
|
reportDownPatientDto.setJzh(empId);
|
|
|
reportDownDto.setPatient(reportDownPatientDto);
|
|
|
String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid"));
|
|
|
String assortid = String.valueOf(FileUtils.getJsonByName("assortid"));
|
|
|
reportDownDto.setAssortid(assortid);
|
|
|
reportDownDto.setCollectorid(collectorid);
|
|
|
List<ReportDownScanFileDto> reportDownScanFileDtos = new ArrayList<>();
|
|
|
ReportDownScanFileDto reportDownScanFileDto;
|
|
|
int filesource = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filesource")));
|
|
|
int filestoragetype = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filestoragetype")));
|
|
|
for (String[] exam : exams) {
|
|
|
reportDownScanFileDto = getScanByExam(exam);
|
|
|
reportDownScanFileDto.setFilesource(filesource);
|
|
|
reportDownScanFileDto.setFilestoragetype(filestoragetype);
|
|
|
reportDownScanFileDtos.add(reportDownScanFileDto);
|
|
|
}
|
|
|
reportDownDto.setScanfiles(reportDownScanFileDtos);
|
|
|
return reportDownDto;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建ReportDownScanFileDto对象 通过报告单号
|
|
|
*
|
|
|
* @param exam
|
|
|
* @return
|
|
|
*/
|
|
|
private ReportDownScanFileDto getScanByExam(String[] exam) throws Exception {
|
|
|
ReportDownScanFileDto reportDownScanFileDto = new ReportDownScanFileDto();
|
|
|
reportDownScanFileDto.setSerialnum(exam[0]);
|
|
|
reportDownScanFileDto.setFiletitle(exam[1]);
|
|
|
// 1、创建document对象
|
|
|
Document document = DocumentHelper.createDocument();
|
|
|
// Element request = document.addElement("Request");
|
|
|
// Element msg = request.addElement("Msg");
|
|
|
// msg.addElement("EXAM_NO").setText(exam[0]);
|
|
|
List<String> bgtsDetailParam = (List<String>) FileUtils.getJsonByName("bgtsDetailParam");
|
|
|
Element request = null;
|
|
|
for (int i = 0; i < bgtsDetailParam.size(); i++) {
|
|
|
if (i == 0) {
|
|
|
request = document.addElement(bgtsDetailParam.get(i));
|
|
|
} else {
|
|
|
request = request.addElement(bgtsDetailParam.get(i));
|
|
|
}
|
|
|
}
|
|
|
request.setText(exam[0]);
|
|
|
String resXml = invokeWs(document.asXML());
|
|
|
//解析XML
|
|
|
XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(resXml.getBytes("UTF-8")));
|
|
|
// List<String> dis = new ArrayList<>();
|
|
|
// dis.add("MsgInfo");
|
|
|
// dis.add("Msg");
|
|
|
// dis.add("ReportInfo");
|
|
|
List<String> dis = (List<String>) FileUtils.getJsonByName("bgtsDetailRespon");
|
|
|
//数据所在节点
|
|
|
Element element = xmlUtils.getElement(dis);
|
|
|
reportDownScanFileDto.setDownurl(element.element(String.valueOf(FileUtils.getJsonByName("pdfUrl"))) == null ? "" : element.element(String.valueOf(FileUtils.getJsonByName("pdfUrl"))).getText());
|
|
|
return reportDownScanFileDto;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过empId获取报告单号集合
|
|
|
*
|
|
|
* @param empId
|
|
|
* @return
|
|
|
*/
|
|
|
private List<String[]> getExamNo(String empId) throws Exception {
|
|
|
List<String[]> exams = new ArrayList<>();
|
|
|
// 1、创建document对象
|
|
|
Document document = DocumentHelper.createDocument();
|
|
|
// Element request = document.addElement("Request");
|
|
|
// Element msg = request.addElement("Msg");
|
|
|
// msg.addElement("EMPI_ID").setText(empId);
|
|
|
List<String> bgtsParam = (List<String>) FileUtils.getJsonByName("bgtsParam");
|
|
|
Element request = null;
|
|
|
for (int i = 0; i < bgtsParam.size(); i++) {
|
|
|
if (i == 0) {
|
|
|
request = document.addElement(bgtsParam.get(i));
|
|
|
} else {
|
|
|
request = request.addElement(bgtsParam.get(i));
|
|
|
}
|
|
|
}
|
|
|
request.setText(empId);
|
|
|
String resXml = invokeWs(document.asXML());
|
|
|
//解析XML
|
|
|
XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(resXml.getBytes("UTF-8")));
|
|
|
// List<String> dis = new ArrayList<>();
|
|
|
// dis.add("MsgInfo");
|
|
|
// dis.add("Msg");
|
|
|
List<String> dis = (List<String>) FileUtils.getJsonByName("bgtsRespon");
|
|
|
//数据所在节点
|
|
|
Element element = xmlUtils.getElement(dis);
|
|
|
List<Element> examInfos = element.elements("ExamInfo");
|
|
|
Element examNo;
|
|
|
String[] key;
|
|
|
for (Element examInfo : examInfos) {
|
|
|
key = new String[2];
|
|
|
examNo = examInfo.element(String.valueOf(FileUtils.getJsonByName("examNo")));
|
|
|
if (examNo != null) {
|
|
|
key[0] = examNo.getText();
|
|
|
}
|
|
|
Element examItemInfo = examInfo.element("ExamItemInfo");
|
|
|
if (examItemInfo != null) {
|
|
|
key[1] = examItemInfo.element(String.valueOf(FileUtils.getJsonByName("examItemName"))).getText();
|
|
|
}
|
|
|
exams.add(key);
|
|
|
}
|
|
|
return exams;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 调用web service
|
|
|
* @param xml
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public String invokeWs(String xml) throws Exception {
|
|
|
// Object[] object = new Object[]{xml};//请求参数
|
|
|
// org.apache.axis.client.Service service = new org.apache.axis.client.Service();
|
|
|
// Call call = (Call) service.createCall();
|
|
|
// call.setTargetEndpointAddress(wsUrl);// 远程调用路径
|
|
|
// // 调用的命名空间和方法名
|
|
|
//// call.setOperationName(new QName(wsNamespaceUrl, wsLocalMethod));
|
|
|
// call.setOperationName(wsLocalMethod);
|
|
|
// call.setUseSOAPAction(true);
|
|
|
//// call.setSOAPActionURI(wsNamespaceUrl + "pushSurveyReport");
|
|
|
// call.addParameter("arg0", XMLType.XSD_STRING, ParameterMode.IN);
|
|
|
// call.setReturnType(XMLType.XSD_STRING);// 返回值类型:String
|
|
|
// call.setTimeout(100000);//超时
|
|
|
// String result = (String) call.invoke(object);// 远程调用
|
|
|
// System.out.println(result);
|
|
|
|
|
|
JAXDynamicClientFactory dcf = JAXDynamicClientFactory.newInstance();
|
|
|
Client client = dcf.createClient(wsUrl);
|
|
|
Object[] objects = client.invoke(wsLocalMethod,xml);
|
|
|
String str = objects[0].toString();
|
|
|
System.out.println(str);
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|