diff --git a/src/main/java/com/emr/controller/templateSearch/TemplateSearchController.java b/src/main/java/com/emr/controller/templateSearch/TemplateSearchController.java index ecbef32..508bc06 100644 --- a/src/main/java/com/emr/controller/templateSearch/TemplateSearchController.java +++ b/src/main/java/com/emr/controller/templateSearch/TemplateSearchController.java @@ -1130,7 +1130,7 @@ public class TemplateSearchController { @OptionalLog(module = "下载图片转换pdf压缩包", methods = "病案查询页面") @RequestMapping(value = "downloadBloodZip", produces = {"text/json;charset=UTF-8"}, method = RequestMethod.POST) @ResponseBody - public void downloadBloodZip(HttpServletResponse response, String patientIds, String flag) { + public void downloadBloodZip(HttpServletResponse response, String patientIds, String flag, String dataSource) { if (StringUtils.isNoneBlank(patientIds)) { try { @@ -1150,9 +1150,12 @@ public class TemplateSearchController { if (scanPathVo.getPatientId().equals(patinetId)) { vo.setName(scanPathVo.getName()); vo.setInpatientNo(scanPathVo.getInpatientNo()); + vo.setSubjectNo(scanPathVo.getSubjectNo()); String disDate = scanPathVo.getDisDate(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - vo.setDisDate(sdf.parse(disDate)); + if(!ObjectUtils.isEmpty(disDate)){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + vo.setDisDate(sdf.parse(disDate)); + } String fileRealPath = scanPathVo.getFileRealPath(); if (StringUtils.isNoneBlank(fileRealPath) && new File(fileRealPath).exists()) { filePaths.add(fileRealPath); @@ -1165,7 +1168,7 @@ public class TemplateSearchController { } } String zipName = "档案pdf压缩包"; - downloadPdfZip(response, zipName, list); + downloadPdfZip(response, zipName, list, dataSource); } } catch (Exception e) { ExceptionPrintUtil.printException(e); @@ -1335,64 +1338,48 @@ public class TemplateSearchController { //封装下载pdf压缩包方法 - private void downloadPdfZip(HttpServletResponse response, String zipName, Set list) { + private void downloadPdfZip(HttpServletResponse response, String zipName, Set list, String dataSource) throws UnsupportedEncodingException { response.reset(); response.setContentType("application/zip;charset=UTF-8"); - ZipOutputStream zos = null; - BufferedOutputStream bos = null; - ByteArrayOutputStream out = null; - BufferedInputStream bis = null; - try { - zipName = java.net.URLEncoder.encode(zipName, "UTF-8"); - response.setHeader("Content-Disposition", "attachment;filename=" + zipName + "(" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + ").zip"); - zos = new ZipOutputStream(response.getOutputStream()); - bos = new BufferedOutputStream(zos); + zipName = java.net.URLEncoder.encode(zipName, "UTF-8"); + response.setHeader("Content-Disposition", "attachment;filename=" + zipName + "(" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + ").zip"); + String filePdfName = ""; + try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())){ EmrPdfWaterSet emrPdfWaterSet = pdfWaterSetMapper.selectByPrimaryKey(1); SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd"); for (ScanPathForPatientListVo vo : list) { - String disDate = ""; - if (null != vo.getDisDate()) { + String disDate = "无"; + if (!ObjectUtils.isEmpty(vo.getDisDate())) { disDate = fmt.format(vo.getDisDate()); } List scanPathList = vo.getScanPathList(); - //每个文件名 - String fileName = vo.getInpatientNo().trim() + "-" + vo.getName().trim() + "-" + disDate.trim() + "_" + fmt.format(new Date()); - zos.putNextEntry(new ZipEntry(fileName + ".pdf")); - //合成pdf - out = new ByteArrayOutputStream(); - img2PdfUtil.imageToPdfToBuffOut(out, scanPathList, emrPdfWaterSet); - byte[] file = out.toByteArray(); //这个zip文件的字节 - bis = new BufferedInputStream(new ByteArrayInputStream(file)); - //输出 - int len = 0; - byte[] buf = new byte[1024 * 1024]; - while ((len = bis.read(buf, 0, buf.length)) != -1) { - bos.write(buf, 0, len); + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + //每个文件名 + String inpatientNo = ObjectUtils.isEmpty(vo.getInpatientNo()) ? "无" : vo.getInpatientNo().trim(); + String name = ObjectUtils.isEmpty(vo.getName()) ? "无" : vo.getName().trim(); + if("3".equals(dataSource)){ + //药学楼 + filePdfName = vo.getSubjectNo().trim() + "-" + name + "_" + fmt.format(new Date()); + }else{ + filePdfName = inpatientNo + "-" + name + "-" + disDate.trim() + "_" + fmt.format(new Date()); + } + String fileName = hospitaInfo + "_" + filePdfName; + zos.putNextEntry(new ZipEntry(fileName + ".pdf")); + //合成pdf + img2PdfUtil.imageToPdfToBuffOut(out, scanPathList, emrPdfWaterSet); + try (BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(out.toByteArray()))) { + //输出 + int len = 0; + byte[] buf = new byte[1024 * 1024]; + while ((len = bis.read(buf, 0, buf.length)) != -1) { + zos.write(buf, 0, len); + } + } } - bis.close(); // 及时关闭流,避免资源泄露 - out.reset(); } } catch (Exception e) { ExceptionPrintUtil.printException(e); e.printStackTrace(); - } finally { - try { - if (null != bos) { - bos.flush(); - bos.close(); - } - if (null != bis) { - bis.close(); - } - out.flush(); - out.close(); - if (null != zos) { - zos.flush(); - zos.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } } } @@ -1560,8 +1547,8 @@ public class TemplateSearchController { JSONObject jsonObject= (JSONObject) JSONObject.toJSON(scanPathVo); List patientInfoList = Arrays.asList(patientInfo.split(",")); for (String list:patientInfoList){ - String contents = jsonObject.getString(list).trim(); - if (list.equals("disDate")){ + String contents = ObjectUtils.isEmpty(jsonObject.getString(list)) ? "无" : jsonObject.getString(list).trim(); + if ("disDate".equals(list) && !ObjectUtils.isEmpty(jsonObject.getString(list))){ String dateString = jsonObject.getString(list); SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat targetFormat = new SimpleDateFormat("yyyyMMdd"); diff --git a/src/main/java/com/emr/vo/commomSearch/ScanPathForPatientListVo.java b/src/main/java/com/emr/vo/commomSearch/ScanPathForPatientListVo.java index 6cdc4af..10d3806 100644 --- a/src/main/java/com/emr/vo/commomSearch/ScanPathForPatientListVo.java +++ b/src/main/java/com/emr/vo/commomSearch/ScanPathForPatientListVo.java @@ -12,6 +12,15 @@ public class ScanPathForPatientListVo { private Date disDate; + private String subjectNo; + + public String getSubjectNo() { + return subjectNo; + } + + public void setSubjectNo(String subjectNo) { + this.subjectNo = subjectNo; + } public Date getDisDate() { return disDate; } diff --git a/src/main/java/com/emr/vo/commomSearch/ScanPathVo.java b/src/main/java/com/emr/vo/commomSearch/ScanPathVo.java index d9125e5..1abdce1 100644 --- a/src/main/java/com/emr/vo/commomSearch/ScanPathVo.java +++ b/src/main/java/com/emr/vo/commomSearch/ScanPathVo.java @@ -31,6 +31,16 @@ public class ScanPathVo { private String assortName; + private String subjectNo; + + public String getSubjectNo() { + return subjectNo; + } + + public void setSubjectNo(String subjectNo) { + this.subjectNo = subjectNo; + } + public String getAssortName() { return assortName; } diff --git a/src/main/resources/mapper/commomSearch/ScanPathMapper.xml b/src/main/resources/mapper/commomSearch/ScanPathMapper.xml index cfa96f9..62f231d 100644 --- a/src/main/resources/mapper/commomSearch/ScanPathMapper.xml +++ b/src/main/resources/mapper/commomSearch/ScanPathMapper.xml @@ -9,6 +9,7 @@ +