diff --git a/src/main/java/com/docus/server/rpc/YdZyyPacsService.java b/src/main/java/com/docus/server/rpc/YdZyyPacsService.java new file mode 100644 index 0000000..459e1b0 --- /dev/null +++ b/src/main/java/com/docus/server/rpc/YdZyyPacsService.java @@ -0,0 +1,16 @@ +package com.docus.server.rpc; + +/** + * @author YongBin Wen + * @date 2024/9/14 16:53 + */ +public interface YdZyyPacsService { + /** + * 获取 pacs 报告 + * @date 2024/9/14 16:59 + * @author YongBin Wen + * @param remark 文件唯一值 + * @return 图片base64 + */ + String getJpgReportBase64(String remark); +} diff --git a/src/main/java/com/docus/server/rpc/impl/YdZyyPacsServiceImpl.java b/src/main/java/com/docus/server/rpc/impl/YdZyyPacsServiceImpl.java new file mode 100644 index 0000000..319d350 --- /dev/null +++ b/src/main/java/com/docus/server/rpc/impl/YdZyyPacsServiceImpl.java @@ -0,0 +1,132 @@ +package com.docus.server.rpc.impl; + +import com.docus.server.rpc.YdZyyPacsService; +import com.docus.server.util.XmlUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; +import org.w3c.dom.Node; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; + +/** + * @author YongBin Wen + * @date 2024/9/14 16:53 + */ +@Component +@Slf4j +public class YdZyyPacsServiceImpl implements YdZyyPacsService { + + + @Override + public String getJpgReportBase64(String remark) { + String wsUrl = "http://10.10.100.106:8011/PACS_WS.asmx"; + String method = "GetStudyReportPreview"; + String param = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " dfXML\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 32" + remark + "JPG300D:\\CTTESTTRUE\n" + + " ]]>\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + try { + // 服务器地址 + URL url = new URL(wsUrl); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + // 拼接soap + byte[] buf = param.getBytes(StandardCharsets.UTF_8); + // 设置报头 + conn.setRequestProperty("Content-Length", String.valueOf(buf.length)); + conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); + conn.setRequestProperty("soapActionString", method); + conn.setRequestMethod("POST"); + conn.setDoOutput(true); + conn.setDoInput(true); + + OutputStream out = conn.getOutputStream(); + out.write(buf); + out.close(); + // 获取响应状态码 + int code = conn.getResponseCode(); + StringBuilder respXml = new StringBuilder(); + if (code == HttpStatus.OK.value()) { + InputStream is = conn.getInputStream(); + byte[] b = new byte[1024]; + int len; + while ((len = is.read(b)) != -1) { + String s = new String(b, 0, len, StandardCharsets.UTF_8); + respXml.append(s); + } + is.close(); + } + return parsePacsBase64(respXml.toString()); + } catch (Exception ex) { + log.error("英德中医院获取pacs报告出现异常,参数:" + param + ",异常信息:" + ex.getMessage(), ex); + return null; + } + } + + private static String parsePacsBase64(String soapResult) { + String startStr = ""; + String endStr = ""; + int start = soapResult.indexOf(startStr); + int end = soapResult.indexOf(endStr) + endStr.length(); + soapResult = soapResult.substring(start, end); + soapResult = soapResult.replace("<", "<"); + soapResult = soapResult.replace(">", ">"); + XmlUtil xmlUtil = XmlUtil.of(soapResult); + Node errorCodeNode = xmlUtil.getNode("/GetStudyReportPreviewResult/iErrorCode"); + if ("0".equals(errorCodeNode.getTextContent())) { + Node fileBase64Node = xmlUtil.getNode("/GetStudyReportPreviewResult/sResultValue/string/FileBase64"); + if (fileBase64Node != null) { + return fileBase64Node.getTextContent(); + } + } + return null; + } + + public static void main(String[] args) { + String result = "\n" + + "\n" + + "\t\n" + + "\t\t\n" + + "\t\t\t\n" + + "\t\t\t\tdfXML\n" + + "\t\t\t\t0\n" + + "\t\t\t\t执行成功\n" + + "\t\t\t\t0\n" + + "\t\t\t\t\n" + + "\t\t\t\t\t<ImageType>JPG</ImageType>\n" + + "<ImageDPI>300</ImageDPI>\n" + + "<FileName>D:\\CTTEST\\PACS_REPORT_IMAGE_2018935_202409141634352881.JPG</FileName>\n" + + "<ImageSize>0</ImageSize>\n" + + "<Md5Value></Md5Value>\n" + + "<FileBase64>/9j/4AAQSkZJRgABAQEAYABgAAtLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3oAKKKKACiiigAooooAKKKKAP/Z</FileBase64>\n" + + "\n" + + "\t\t\t\t\n" + + "\t\t\t\n" + + "\t\t\n" + + "\t\n" + + ""; + System.out.println(parsePacsBase64(result)); + } +} diff --git a/src/main/java/com/docus/server/ydzyy/controller/ApiController.java b/src/main/java/com/docus/server/ydzyy/controller/ApiController.java new file mode 100644 index 0000000..ef0304f --- /dev/null +++ b/src/main/java/com/docus/server/ydzyy/controller/ApiController.java @@ -0,0 +1,30 @@ +package com.docus.server.ydzyy.controller; + + +import com.docus.infrastructure.web.api.CommonResult; +import com.docus.server.rpc.YdZyyPacsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * api测试类 + */ +@RestController +@RequestMapping("/ydzyyApi") +public class ApiController { + @Autowired + private YdZyyPacsService pacsService; + + /** + * 测试 + */ + @GetMapping("/pacs/xml") + public CommonResult lisXmlTest(@RequestParam(name = "remark") String remark) { + String base64 = pacsService.getJpgReportBase64(remark); + return CommonResult.success(base64); + } + +} diff --git a/src/main/java/com/docus/server/ydzyy/job/PacsCollectJob.java b/src/main/java/com/docus/server/ydzyy/job/PacsCollectJob.java index 4eaf651..6ee371c 100644 --- a/src/main/java/com/docus/server/ydzyy/job/PacsCollectJob.java +++ b/src/main/java/com/docus/server/ydzyy/job/PacsCollectJob.java @@ -8,6 +8,7 @@ import com.docus.server.archive.entity.AfCollectTask; import com.docus.server.archive.entity.TBasic; import com.docus.server.archive.mapper.TBasicMapper; import com.docus.server.rpc.DownPlatformService; +import com.docus.server.rpc.YdZyyPacsService; import com.docus.server.rpc.dto.ReportDownDto; import com.docus.server.rpc.dto.ReportDownPatientDto; import com.docus.server.rpc.dto.ReportDownScanFileDto; @@ -47,6 +48,9 @@ public class PacsCollectJob { @Resource private IdService idService; + @Resource + private YdZyyPacsService ydZyyPacsService; + @XxlJob("Ydzyy-CollectPacsByModifyTime") public void collectPacsByModifyTime() { @@ -118,21 +122,55 @@ public class PacsCollectJob { @XxlJob("Ydzyy-CollectPacsByFailedTask") public void collectPacsByFailedTask() { - + String collectorId = "3"; + String assortId = "AC2C8F4A88884DC894630302C61C6A07"; + List notReCollectState = Arrays.asList("3", "4"); log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>英德中医院pacs任务补偿job,开始任务!"); try { LocalDate startDate = LocalDate.now().plusMonths(-3); String startDateStr = startDate + " 00:00:00"; - String collectorId = "3"; List patientIds = tBasicMapper.findFailedTaskPatId(collectorId, startDateStr); log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>英德中医院pacs任务补偿job,查询创建时间>={} 失败的任务患者数量:{} 个。", startDateStr, patientIds); if (Func.isEmpty(patientIds)) { return; } - List tBasicList = tBasicMapper.getTbasicByPatientIds(patientIds); - for (TBasic tBasic : tBasicList) { - collectPacs(tBasic); + // 失败重采不从视图,从接口获取 +// List tBasicList = tBasicMapper.getTbasicByPatientIds(patientIds); +// for (TBasic tBasic : tBasicList) { +// collectPacs(tBasic); +// } + for (String patientId : patientIds) { + ReportDownPatientDto patient = new ReportDownPatientDto(); + patient.setPatientid(patientId); + ReportDownDto reportDownDto = new ReportDownDto(); + reportDownDto.setAssortid(assortId); + reportDownDto.setCollectorid(collectorId); + reportDownDto.setIp("java-collect-pacs"); + reportDownDto.setPatient(patient); + List tasks = tBasicMapper.getCollectTaskByPatAndSource(patientId, collectorId); + List reCollectTask = tasks.stream().filter(task -> !notReCollectState.contains(task.getState())).collect(Collectors.toList()); + for (AfCollectTask task : reCollectTask) { + String remark = task.getC1(); + String base64 = ydZyyPacsService.getJpgReportBase64(remark); + if (Func.isBlank(base64)) { + log.info("remark:{} 获取pacs图片报告base64失败!", remark); + continue; + } + ReportDownScanFileDto reportDownScanFileDto = new ReportDownScanFileDto(); + reportDownScanFileDto.setDownurl(base64); + reportDownScanFileDto.setFiletitle(task.getC6()); + reportDownScanFileDto.setSerialnum(remark); + reportDownScanFileDto.setFilesource(1); + reportDownScanFileDto.setFiletype(2); + reportDownScanFileDto.setFilestoragetype(1); + reportDownScanFileDto.setTaskid(task.getId()); + List scanFiles = Collections.singletonList(reportDownScanFileDto); + reportDownDto.setScanfiles(scanFiles); + downPlatformService.report(reportDownDto); + + } } + } catch (Exception ex) { log.error(">>>>>>>>>>>>>>>>>>>>>>>>>>>英德中医院pacs任务补偿job出现异常,结束任务!" + ex.getMessage(), ex); }