From a3c98aa10a202b36d596755ac0721af379f9b366 Mon Sep 17 00:00:00 2001 From: "15881625488@163.com" <15881625488@163.com> Date: Mon, 19 Jan 2026 17:14:12 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A[=E6=A8=A1=E6=9D=BF=E7=AE=A1?= =?UTF-8?q?=E7=90=86]=E5=AF=BC=E5=87=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/pdf/template/TemplateBaseUtil.java | 97 +++++++++----- .../hxhq/business/utils/pdf/template/sp/SP001.java | 28 ++--- .../hxhq/business/utils/pdf/template/sp/SP002.java | 139 --------------------- 3 files changed, 71 insertions(+), 193 deletions(-) delete mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/sp/SP002.java diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/TemplateBaseUtil.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/TemplateBaseUtil.java index 68a85ba..9597c6f 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/TemplateBaseUtil.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/TemplateBaseUtil.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.hxhq.business.domain.StudyFormFill; import com.hxhq.business.domain.StudyFormFillJcgj; import com.hxhq.business.domain.StudyFormFillQmxx; import com.hxhq.business.utils.lang.TemplateUtil; @@ -30,6 +31,28 @@ public class TemplateBaseUtil { private static final Logger logger = LoggerFactory.getLogger(TemplateBaseUtil.class.getName()); public static String language = "zh"; + + /** + * 试验信息 + * 试验名称,试验编号,方法编号,版本号 + * @param document + * @param studyFormFill + * @param bdnr + * @param lang + * @throws IOException + * @throws DocumentException + */ + public static void addStudyInfo(Document document, StudyFormFill studyFormFill, JSONObject bdnr, String lang) throws IOException, DocumentException { + language = lang; + PdfBaseUtil.addUnderlinedTitle(document, getName("试验基本信息"), 10, true); + Map formData1 = new LinkedHashMap<>(); + formData1.put(getName("试验名称"), studyFormFill.getStudyMc()); + formData1.put(getName("试验编号"), studyFormFill.getStudySn()); + formData1.put(getName("方法编号"), (StringUtils.isNoneBlank(bdnr.getString("methodCode")) ? bdnr.getString("methodCode") : "")); + formData1.put(getName("版本号"), (StringUtils.isNoneBlank(bdnr.getString("methodCode")) ? bdnr.getString("methodCode") : "")); + PdfBaseUtil.addFormTableColumns(document, formData1, 2); + } + /** * 试验试剂信息 * @@ -41,6 +64,7 @@ public class TemplateBaseUtil { public static void addResource(Document document, String resource, String lang) throws IOException, DocumentException { // [{"mc":"布洛芬","bh":"BLF260115-0014","ph":"","nd":"18ng/mL","source":"ELN配制","ndz":18,"nddw":"ng/mL","kc":1190,"kcdw":"3","syl":"4","syldw":"3","yxzq":360,"yxzqdw":"days"}] language = lang; + PdfBaseUtil.addUnderlinedTitle(document, getName("试验试剂信息"), 10, true); // 9. 表头 BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font headerFont = new Font(bfChinese, 10, Font.NORMAL); @@ -88,6 +112,7 @@ public class TemplateBaseUtil { */ public static void addInstrument(Document document, String instrument, String lang) throws IOException, DocumentException { language = lang; + PdfBaseUtil.addUnderlinedTitle(document, getName("仪器使用信息"), 10, true); // 9. 表头 BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font headerFont = new Font(bfChinese, 10, Font.NORMAL); @@ -136,6 +161,7 @@ public class TemplateBaseUtil { */ public static void addQmxx(Document document, List studyFormFillQmxxList, String lang) throws IOException, DocumentException { language = lang; + PdfBaseUtil.addUnderlinedTitle(document, getName("签名信息"), 10, true); // 9. 表头 BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font headerFont = new Font(bfChinese, 10, Font.NORMAL); @@ -150,7 +176,7 @@ public class TemplateBaseUtil { cell.setPadding(8); table.addCell(cell); } - if(studyFormFillQmxxList.size()>0){ + if (studyFormFillQmxxList.size() > 0) { int rowNum = 0; for (StudyFormFillQmxx studyFormFillQmxx : studyFormFillQmxxList) { // 交替行颜色 @@ -160,7 +186,7 @@ public class TemplateBaseUtil { table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); } table.addCell(PdfBaseUtil.createCell(studyFormFillQmxx.getQmrMc(), contentFont)); - table.addCell(PdfBaseUtil.createCell("en".equals(language)?studyFormFillQmxx.getQmyyEn():studyFormFillQmxx.getQmyy(), contentFont)); + table.addCell(PdfBaseUtil.createCell("en".equals(language) ? studyFormFillQmxx.getQmyyEn() : studyFormFillQmxx.getQmyy(), contentFont)); table.addCell(PdfBaseUtil.createCell(PdfExportUtil.parseDateToStr(studyFormFillQmxx.getCreateTime()), contentFont)); table.addCell(PdfBaseUtil.createCell(studyFormFillQmxx.getRemark(), contentFont)); rowNum++; @@ -177,45 +203,50 @@ public class TemplateBaseUtil { * @throws IOException * @throws DocumentException */ - public static void addJcgj(Document document, List studyFormFillJcgjList, String lang) throws IOException, DocumentException { + public static void addJcgj(Document document, List studyFormFillJcgjList, Integer jcgjlx, String lang) throws IOException, DocumentException { language = lang; - for (StudyFormFillJcgj jcgj : studyFormFillJcgjList) { - StringJoiner result = new StringJoiner(", "); - if ("en".equals(lang)) { - PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime()) + " " + jcgj.getJcmcEn(), 10, false); - if (StringUtils.isNoneBlank(jcgj.getJcnrEn())) { - ObjectMapper mapper = new ObjectMapper(); - JsonNode jsonArray = mapper.readTree(jcgj.getJcnrEn()); - for (JsonNode node : jsonArray) { - if (node.get("name") != null) { - String name = node.get("name").asText(); - String value = node.get("value") != null ? node.get("value").asText() : ""; - result.add(name + ":" + value); + Integer jcgjlxMark = 999; + if (!jcgjlx.equals(jcgjlxMark)) { + PdfBaseUtil.addUnderlinedTitle(document, getName("稽查轨迹"), 10, true); + TemplateBaseUtil.addJcgj(document, studyFormFillJcgjList, jcgjlxMark, language); + for (StudyFormFillJcgj jcgj : studyFormFillJcgjList) { + StringJoiner result = new StringJoiner(", "); + if ("en".equals(lang)) { + PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime()) + " " + jcgj.getJcmcEn(), 10, false); + if (StringUtils.isNoneBlank(jcgj.getJcnrEn())) { + ObjectMapper mapper = new ObjectMapper(); + JsonNode jsonArray = mapper.readTree(jcgj.getJcnrEn()); + for (JsonNode node : jsonArray) { + if (node.get("name") != null) { + String name = node.get("name").asText(); + String value = node.get("value") != null ? node.get("value").asText() : ""; + result.add(name + ":" + value); + } } } - } - }else{ - PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime()) + " " + jcgj.getJcmc(), 10, false); - if (StringUtils.isNoneBlank(jcgj.getJcnr())) { - ObjectMapper mapper = new ObjectMapper(); - JsonNode jsonArray = mapper.readTree(jcgj.getJcnr()); - for (JsonNode node : jsonArray) { - if (node.get("name") != null) { - String name = node.get("name").asText(); - String value = node.get("value") != null ? node.get("value").asText() : ""; - result.add(name + ":" + value); + } else { + PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime()) + " " + jcgj.getJcmc(), 10, false); + if (StringUtils.isNoneBlank(jcgj.getJcnr())) { + ObjectMapper mapper = new ObjectMapper(); + JsonNode jsonArray = mapper.readTree(jcgj.getJcnr()); + for (JsonNode node : jsonArray) { + if (node.get("name") != null) { + String name = node.get("name").asText(); + String value = node.get("value") != null ? node.get("value").asText() : ""; + result.add(name + ":" + value); + } } } } - } - if (StringUtils.isNoneBlank(jcgj.getRemark())) { - result.add(getName("备注") + ":" + jcgj.getRemark()); - } - if (StringUtils.isNoneBlank(jcgj.getQmrMc())) { - result.add(getName("签名人") + ":" + jcgj.getQmrMc()); + if (StringUtils.isNoneBlank(jcgj.getRemark())) { + result.add(getName("备注") + ":" + jcgj.getRemark()); + } + if (StringUtils.isNoneBlank(jcgj.getQmrMc())) { + result.add(getName("签名人") + ":" + jcgj.getQmrMc()); + } + PdfBaseUtil.addUnderlinedTitle(document, result.toString(), 10, false); } - PdfBaseUtil.addUnderlinedTitle(document, result.toString(), 10, false); } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/sp/SP001.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/sp/SP001.java index bc15768..37cf33c 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/sp/SP001.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/sp/SP001.java @@ -36,7 +36,7 @@ public class SP001 { language = lang; Document document = null; FileOutputStream fos = null; - String filePath = PdfBaseUtil.getFilePath(localFilePath,"SP001"); + String filePath = PdfBaseUtil.getFilePath(localFilePath,"Template"); try { String sign = "hxhq"; LoginUser loginUser = SecurityUtils.getLoginUser(); @@ -44,16 +44,9 @@ public class SP001 { sign = loginUser.getSysUser().getNickName(); } document = PdfBaseUtil.init(document, fos, filePath, sign +PdfExportUtil.parseDateToStr(new Date()), "en".equals(language)?studyFormFill.getTemplateMcEn():studyFormFill.getTemplateMc(),false); - // 基本信息 - JSONObject bdnr = JSONObject.parseObject(studyFormFill.getBdnr()); - PdfBaseUtil.addUnderlinedTitle(document, getName("试验基本信息"), 10, true); - Map formData1 = new LinkedHashMap<>(); - formData1.put(getName("试验名称"), studyFormFill.getStudyMc()); - formData1.put(getName("试验编号"), studyFormFill.getStudySn()); - formData1.put(getName("方法编号"), (StringUtils.isNoneBlank(bdnr.getString("methodCode"))? bdnr.getString("methodCode"):"")); - formData1.put(getName("版本号"), (StringUtils.isNoneBlank(bdnr.getString("methodCode"))? bdnr.getString("methodCode"):"")); - PdfBaseUtil.addFormTableColumns(document, formData1, 2); + //试验基本信息 + TemplateBaseUtil.addStudyInfo( document, studyFormFill, bdnr, lang); PdfBaseUtil.addUnderlinedTitle(document, getName("试验配置条件"), 10, true); Map formData2 = new LinkedHashMap<>(); @@ -67,11 +60,9 @@ public class SP001 { formData3.put(getName("结束时间"), studyFormFill.getEndDate() != null ? PdfExportUtil.parseDateToStr(studyFormFill.getEndDate()) : ""); PdfBaseUtil.addFormTableColumns(document, formData3, 2); - // 签名信息 - PdfBaseUtil.addUnderlinedTitle(document, getName("试验试剂信息"), 10, true); + // 试验试剂信息 TemplateBaseUtil.addResource(document, studyFormFill.getResource(),language); - - PdfBaseUtil.addUnderlinedTitle(document, getName("仪器使用信息"), 10, true); + //仪器使用信息 TemplateBaseUtil.addInstrument(document, "",language); PdfBaseUtil.addUnderlinedTitle(document, getName("存储条件"), 10, true); @@ -93,15 +84,10 @@ public class SP001 { PdfBaseUtil.addFormTableColumns(document, formData5, 2); PdfBaseUtil.addUnderlinedTitle(document, getName("备注") + ":" +(StringUtils.isNoneBlank(bdnr.getString("remark")) ? bdnr.getString("remark") : ""), 10, false); - // 签名信息 - PdfBaseUtil.addUnderlinedTitle(document, getName("签名信息"), 10, true); + //签名信息 TemplateBaseUtil.addQmxx(document, studyFormFillQmxxList,language); //稽查轨迹 - Integer jcgjlxMark=999; - if(!jcgjlx.equals(jcgjlxMark)){ - PdfBaseUtil.addUnderlinedTitle(document, getName("稽查轨迹"), 10, true); - TemplateBaseUtil.addJcgj(document, studyFormFillJcgjList,language); - } + TemplateBaseUtil.addJcgj(document, studyFormFillJcgjList,jcgjlx,language); logger.info("生成成功:{}", filePath); } catch (Exception e) { logger.error("生成失败", e); diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/sp/SP002.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/sp/SP002.java deleted file mode 100644 index 34e7965..0000000 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/sp/SP002.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.hxhq.business.utils.pdf.template.sp; - -import com.alibaba.fastjson2.JSONObject; -import com.hxhq.business.domain.StudyFormFill; -import com.hxhq.business.domain.StudyFormFillJcgj; -import com.hxhq.business.domain.StudyFormFillQmxx; -import com.hxhq.business.utils.pdf.PdfBaseUtil; -import com.hxhq.business.utils.pdf.PdfExportUtil; -import com.hxhq.business.utils.pdf.template.TemplateBaseUtil; -import com.hxhq.common.core.utils.StringUtils; -import com.hxhq.common.security.utils.SecurityUtils; -import com.hxhq.system.api.model.LoginUser; -import com.itextpdf.text.Document; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * 色谱-生物样品分析溶液配制表 - * - * @author tanfei - */ -public class SP002 { - private static final Logger logger = LoggerFactory.getLogger(SP002.class.getName()); - public String language = "zh"; - - /** - * 导出 - * - * @param studyFormFill - * @return - */ - public String exportDetail(StudyFormFill studyFormFill, List studyFormFillQmxxList, List studyFormFillJcgjList, String lang,Integer jcgjlx, String localFilePath) { - language = lang; - Document document = null; - FileOutputStream fos = null; - String filePath = PdfBaseUtil.getFilePath(localFilePath,"SP001"); - try { - String sign = "hxhq"; - LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null) { - sign = loginUser.getSysUser().getNickName(); - } - document = PdfBaseUtil.init(document, fos, filePath, sign +PdfExportUtil.parseDateToStr(new Date()), "en".equals(language)?studyFormFill.getTemplateMcEn():studyFormFill.getTemplateMc(),false); - // 基本信息 - - JSONObject bdnr = JSONObject.parseObject(studyFormFill.getBdnr()); - PdfBaseUtil.addUnderlinedTitle(document, getName("试验基本信息"), 10, true); - Map formData1 = new LinkedHashMap<>(); - formData1.put(getName("试验名称"), studyFormFill.getStudyMc()); - formData1.put(getName("试验编号"), studyFormFill.getStudySn()); - formData1.put(getName("方法编号"), (StringUtils.isNoneBlank(bdnr.getString("methodCode"))? bdnr.getString("methodCode"):"")); - formData1.put(getName("版本号"), (StringUtils.isNoneBlank(bdnr.getString("methodCode"))? bdnr.getString("methodCode"):"")); - PdfBaseUtil.addFormTableColumns(document, formData1, 2); - - PdfBaseUtil.addUnderlinedTitle(document, getName("试验配置条件"), 10, true); - Map formData2 = new LinkedHashMap<>(); - formData2.put(getName("预填"),(StringUtils.isNoneBlank(bdnr.getString("pre"))? bdnr.getString("pre"):"") + (StringUtils.isNoneBlank(bdnr.getString("preOther")) ? bdnr.getString("preOther") : "")); - formData2.put(getName("实际"),(StringUtils.isNoneBlank(bdnr.getString("act"))? bdnr.getString("act"):"") + (StringUtils.isNoneBlank(bdnr.getString("actOther")) ? bdnr.getString("actOther") : "")); - PdfBaseUtil.addFormTableColumns(document, formData2, 2); - - PdfBaseUtil.addUnderlinedTitle(document, getName("配置时间"), 10, true); - Map formData3 = new LinkedHashMap<>(); - formData3.put(getName("开始时间"), studyFormFill.getStartDate() != null ? PdfExportUtil.parseDateToStr(studyFormFill.getStartDate()) : ""); - formData3.put(getName("结束时间"), studyFormFill.getEndDate() != null ? PdfExportUtil.parseDateToStr(studyFormFill.getEndDate()) : ""); - PdfBaseUtil.addFormTableColumns(document, formData3, 2); - - // 签名信息 - PdfBaseUtil.addUnderlinedTitle(document, getName("试验试剂信息"), 10, true); - TemplateBaseUtil.addResource(document, studyFormFill.getResource(),language); - - PdfBaseUtil.addUnderlinedTitle(document, getName("仪器使用信息"), 10, true); - TemplateBaseUtil.addInstrument(document, "",language); - - PdfBaseUtil.addUnderlinedTitle(document, getName("存储条件"), 10, true); - - Map formData4 = new LinkedHashMap<>(); - formData4.put(getName("存储条件"), bdnr.getString("storageCondition") + (StringUtils.isNoneBlank(bdnr.getString("storageConditionOther")) ? bdnr.getString("storageConditionOther") : "")); - PdfBaseUtil.addFormTableColumns(document, formData4, 1); - - PdfBaseUtil.addUnderlinedTitle(document, getName("操作步骤"), 10, true); - Map formData5 = new LinkedHashMap<>(); - formData5.put(getName("目标溶液名称"), bdnr.getString("targetName")); - formData5.put(getName("目标溶液编号"), bdnr.getString("targetCode") + bdnr.getString("targetCodeSn")); - formData5.put(getName("目标溶液预计浓度"), bdnr.getString("targetPreConcentration") + bdnr.getString("targetPreConcentrationUnit")); - formData5.put(getName("目标溶液实际浓度"), bdnr.getString("targetActConcentration") + bdnr.getString("targetPreConcentrationUnit")); - formData5.put(getName("目标溶液预计体积"), bdnr.getString("targetPreVolume") + bdnr.getString("targetPreVolumeUnit")); - formData5.put(getName("目标溶液实际体积"), bdnr.getString("targetActVolume") + bdnr.getString("targetActVolumeUnit")); - formData5.put(getName("有效周期"), bdnr.getString("effectivePeriod") + bdnr.getString("effectivePeriodUnit")); - formData5.put(getName("失效日"), bdnr.getString("expireDate")); - PdfBaseUtil.addFormTableColumns(document, formData5, 2); - PdfBaseUtil.addUnderlinedTitle(document, getName("备注") + ":" +(StringUtils.isNoneBlank(bdnr.getString("remark")) ? bdnr.getString("remark") : ""), 10, false); - - // 签名信息 - PdfBaseUtil.addUnderlinedTitle(document, getName("签名信息"), 10, true); - TemplateBaseUtil.addQmxx(document, studyFormFillQmxxList,language); - //稽查轨迹 - Integer jcgjlxMark=999; - if(!jcgjlx.equals(jcgjlxMark)){ - PdfBaseUtil.addUnderlinedTitle(document, getName("稽查轨迹"), 10, true); - TemplateBaseUtil.addJcgj(document, studyFormFillJcgjList,language); - } - logger.info("生成成功:{}", filePath); - } catch (Exception e) { - logger.error("生成失败", e); - throw new RuntimeException("生成失败: " + e.getMessage()); - } finally { - if (document != null) { - document.close(); - } - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - logger.error("关闭文件流失败", e); - } - } - } - return filePath; - } - - - /** - * 获取名称 - * - * @param name - * @return - */ - public String getName(String name) { - return TemplateBaseUtil.getNameByLanguage(name,language); - } - -}