From 22d513759f7b4b409433e3a39a17eb29084cb4e0 Mon Sep 17 00:00:00 2001 From: chen <2710907404@qq.com> Date: Tue, 18 Mar 2025 17:25:35 +0800 Subject: [PATCH] =?UTF-8?q?20250318=20=E6=9B=B4=E6=96=B0=201.=E5=B8=B8?= =?UTF-8?q?=E8=A7=84=E6=AF=92=E5=93=81=E6=A3=80=E9=AA=8C=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/InspectRecordServiceImpl.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) 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 f465f67..0ecff19 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 @@ -81,7 +81,7 @@ public class InspectRecordServiceImpl implements InspectRecordService { // Map map = this.invivoRecord(entrustInfo); return R.ok(this.createInVivoFile(entrustInfo, materialType), "生成成功!"); } - return null; + return R.ok(this.generateCommonDrugInpectRecord(entrustId)); } /** @@ -188,36 +188,36 @@ public class InspectRecordServiceImpl implements InspectRecordService { // 获取文件数据map Map data = this.invivoRecord(entrustInfo, materialType); // 调用模板生成检验记录 - ByteArrayOutputStream bos = new ByteArrayOutputStream(); String templatePath = ""; if (materialType.equals("毛发")) { templatePath = "/template" + "/贵阳生物样本毛发检验记录模板.docx"; } else { templatePath = "/template" + "/贵阳生物样本尿液检验记录模板.docx"; } + LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); + Configure config = Configure.builder(). + bind("dataDtos", policy).build(); + return buildDocFileAndUploadToOss(entrustInfo.getId(), templatePath, config, data); + } + + /** + * 根据委托信息、模板路径、配置和数据构建文档文件并上传到OSS + * + * @param entrustId 委托id + * @param templatePath 模板文件路径 + * @param config 配置信息 + * @param data 要填充到模板中的数据 + * @return 上传后的文件路径 + * @throws Exception 可能抛出的异常 + */ + private String buildDocFileAndUploadToOss(String entrustId, String templatePath, Configure config, Map data) throws Exception { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); ossFile.fileGet(templatePath, bos); byte[] templateArray = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(templateArray); bos.close(); - LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); - Configure config = Configure.builder(). - bind("dataDtos", policy).build(); - - XWPFTemplate template = XWPFTemplate.compile(bis, config).render( - new HashMap() {{ - put("entrustDepartment", data.get("entrustDepartment")); - put("deliver1Name", data.get("deliver1Name")); - put("deliver2Name", data.get("deliver2Name")); - put("year", data.get("year")); - put("month", data.get("month")); - put("day", data.get("day")); - put("instrumentName", data.get("instrumentName")); - put("referenceMaterialName", data.get("referenceMaterialName")); - put("reagentConsumableName", data.get("reagentConsumableName")); - put("dataDtos", data.get("dataDtos")); - }} - ); + XWPFTemplate template = XWPFTemplate.compile(bis, config).render(data); NiceXWPFDocument document = template.getXWPFDocument(); // XWPFTable table = document.getTables().get(3); @@ -233,7 +233,7 @@ public class InspectRecordServiceImpl implements InspectRecordService { ByteArrayInputStream fisWord = new ByteArrayInputStream(fosWord.toByteArray()); fosWord.close(); document.close(); - String path = TestRecordFileUrl.TEST_RECORD_CATALOGUE.getFileUrl() + "/" + entrustInfo.getId() + "/" + "贵阳生物样本检验记录.docx"; + String path = TestRecordFileUrl.TEST_RECORD_CATALOGUE.getFileUrl() + "/" + entrustId + "/" + "贵阳生物样本检验记录.docx"; ossFile.fileSave(path, fisWord); return path; } @@ -280,8 +280,13 @@ public class InspectRecordServiceImpl implements InspectRecordService { /** * 生成常规毒品的检验记录(贵阳禁毒) */ - public void generateCommonDrugInpectRecord(String entrustId) { + public String generateCommonDrugInpectRecord(String entrustId) throws Exception { Map docMap = buildCommonDrugDocMap(entrustId); + String templatePath = "/template" + "/贵阳禁毒常规毒品检验记录模板.docx"; + LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); + Configure config = Configure.builder(). + bind("dataDtos", policy).build(); + return buildDocFileAndUploadToOss(entrustId, templatePath, config, docMap); } /** @@ -343,7 +348,7 @@ public class InspectRecordServiceImpl implements InspectRecordService { .stream() .collect(Collectors.joining("、")); // 拼接筛查物名称 data.put("materialCharacterDesc", materialCharacterDesc); - data.put("ingredient", targetObjectStr); + data.put("materialIngredient", targetObjectStr); // 设置使用的标准物质和试剂 List references = testRecordReagentService.list(Wrappers.lambdaQuery()