From b3fc1ed1e1f4ed79765530c7564715eb6d6a9be4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=B5=B7=E8=88=AA?=
<11918452+yang-haihang@user.noreply.gitee.com>
Date: Thu, 27 Mar 2025 10:37:48 +0800
Subject: [PATCH] update
---
dlp-drugtesting-biz/pom.xml | 5 +++
.../controller/TestRecordController.java | 9 +++-
.../service/InspectRecordService.java | 8 +++-
.../impl/InspectRecordServiceImpl.java | 42 ++++++++++++++++---
4 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/dlp-drugtesting-biz/pom.xml b/dlp-drugtesting-biz/pom.xml
index df7b4ea..745686f 100644
--- a/dlp-drugtesting-biz/pom.xml
+++ b/dlp-drugtesting-biz/pom.xml
@@ -187,6 +187,11 @@
poi-ooxml-full
5.2.3
+
+
+ org.springframework
+ spring-test
+
diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordController.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordController.java
index 54e5353..6adadd7 100644
--- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordController.java
+++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/controller/TestRecordController.java
@@ -222,8 +222,13 @@ public class TestRecordController {
@ApiOperation("生成检验记录-贵阳禁毒")
@GetMapping("/inspectionRecord")
- public R inspectionRecord(String entrustId, String materialType) throws Exception {
- return inspectRecordService.buildInspectionRecord(entrustId, materialType);
+ public R inspectionRecord(String businessId, String materialType) throws Exception {
+ return inspectRecordService.buildInspectionRecord(businessId, materialType);
}
+ @ApiOperation("预览检验记录-贵阳禁毒")
+ @GetMapping("/previewRecord")
+ public void previewRecord(String businessId, String materialType, HttpServletResponse response) throws Exception {
+ inspectRecordService.previewInspectionRecord(businessId, materialType, response);
+ }
}
diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/InspectRecordService.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/InspectRecordService.java
index bb77c4f..083abb5 100644
--- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/InspectRecordService.java
+++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/InspectRecordService.java
@@ -2,6 +2,8 @@ package digital.laboratory.platform.inspection.service;
import digital.laboratory.platform.common.core.util.R;
+import javax.servlet.http.HttpServletResponse;
+
/**
* @author ChenJiangBao
* @version 1.0
@@ -12,9 +14,11 @@ public interface InspectRecordService {
/**
* 生成检验记录-贵阳禁毒
- * @param entrustId 委托id
+ * @param businessId 委托id
* @return
* @throws Exception
*/
- R buildInspectionRecord(String entrustId, String materialType) throws Exception;
+ R buildInspectionRecord(String businessId, String materialType) throws Exception;
+
+ void previewInspectionRecord(String businessId, String materialType, HttpServletResponse servletResponse) throws Exception;
}
diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java
index a531c82..9aadd1f 100644
--- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java
+++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java
@@ -1,6 +1,6 @@
package digital.laboratory.platform.inspection.service.impl;
-
import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@@ -10,6 +10,7 @@ import com.deepoove.poi.config.Configure;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.deepoove.poi.xwpf.NiceXWPFDocument;
import digital.laboratory.platform.common.core.util.R;
+import digital.laboratory.platform.common.feign.RemoteWord2PDFService;
import digital.laboratory.platform.common.oss.service.OssFile;
import digital.laboratory.platform.inspection.dto.TestRecordSampleDataDocDTO;
import digital.laboratory.platform.inspection.entity.TestRecordInstrument;
@@ -27,11 +28,14 @@ import digital.laboratory.platform.inspetion.api.entity.TargetObject;
import digital.laboratory.platform.inspetion.api.entity.TestRecord;
import digital.laboratory.platform.sys.entity.Drug;
import digital.laboratory.platform.sys.enums.entrust.EntrustBiologyType;
+import feign.Response;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.springframework.beans.BeanUtils;
+import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.util.*;
import java.util.function.Function;
@@ -70,24 +74,50 @@ public class InspectRecordServiceImpl implements InspectRecordService {
@Resource
private TestRecordSampledataExpandService testRecordSampledataExpandService;
+ @Resource
+ private RemoteWord2PDFService remoteWord2PDFService;
+
/**
* 生成检验记录-贵阳禁毒
*
- * @param entrustId 委托id
+ * @param businessId 委托id
* @param materialType 标注当前委托的检材是尿液还是毛发
* @return
* @throws Exception
*/
@Override
- public R buildInspectionRecord(String entrustId, String materialType) throws Exception {
- EntrustInfo entrustInfo = entrustInfoService.getById(entrustId);
+ public R buildInspectionRecord(String businessId, String materialType) throws Exception {
+ EntrustInfo entrustInfo = entrustInfoService.getById(businessId);
if (entrustInfo == null) {
return R.ok(false, "委托信息不存在!");
}
if (entrustInfo.getBusinessType().equals(BusinessType.BOINT_CASE.getBusinessType())) {
return R.ok(this.buildInVivoDocFile(entrustInfo, materialType), "生成成功!");
}
- return R.ok(this.generateCommonDrugInpectRecord(entrustId));
+ return R.ok(this.generateCommonDrugInpectRecord(businessId));
+ }
+
+ @Override
+ public void previewInspectionRecord(String businessId, String materialType, HttpServletResponse servletResponse) throws Exception {
+
+ String path = (String) this.buildInspectionRecord(businessId, materialType).getData();
+ java.io.ByteArrayOutputStream fosWord = new java.io.ByteArrayOutputStream();
+ ossFile.fileGet(path, fosWord);
+ ByteArrayInputStream fisWord = new ByteArrayInputStream(fosWord.toByteArray());
+ fosWord.close();
+ // 转换临时目录中的 word 文档为 PDF
+ MockMultipartFile mockMultipartFile = new MockMultipartFile("file", "检验记录" + ".docx", "image/jpg", fisWord);
+ String pdfFilePath = path.substring(0, path.lastIndexOf(".")) + ".pdf";
+ Response response = remoteWord2PDFService.word2pdf(mockMultipartFile);
+ fisWord.close();
+ org.apache.commons.io.output.ByteArrayOutputStream outPDF = new org.apache.commons.io.output.ByteArrayOutputStream();
+ IoUtil.copy(response.body().asInputStream(), outPDF, IoUtil.DEFAULT_MIDDLE_BUFFER_SIZE);
+ ByteArrayInputStream isPDF = new ByteArrayInputStream(outPDF.toByteArray());
+ outPDF.close();
+ ossFile.fileSave(pdfFilePath, isPDF);
+ isPDF.close();
+ ossFile.fileGet(pdfFilePath, servletResponse.getOutputStream());
+ System.out.println(String.format("转换为 PDF 结束"));
}
/**
@@ -363,7 +393,7 @@ public class InspectRecordServiceImpl implements InspectRecordService {
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
Configure config = Configure.builder().
bind("dataDtos", policy)
- .build();
+ .build();
return buildDocFileAndUploadToOss(entrustId, templatePath, config, docMap);
}