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 8d144f2..e888ade 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,9 +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.domain.*; import com.hxhq.business.utils.lang.TemplateUtil; import com.hxhq.business.utils.pdf.PdfBaseUtil; import com.hxhq.business.utils.pdf.PdfExportUtil; @@ -138,7 +136,7 @@ public class TemplateBaseUtil { * @throws IOException * @throws DocumentException */ - public static void addQmxx(Document document, List studyFormFillQmxxList, String lang) throws IOException, DocumentException { + public static void addQmxxFill(Document document, List studyFormFillQmxxList, String lang) throws IOException, DocumentException { language = lang; PdfBaseUtil.addUnderlinedTitle(document, getName("签名信息"), 10, true); // 9. 表头 @@ -182,12 +180,11 @@ public class TemplateBaseUtil { * @throws IOException * @throws DocumentException */ - public static void addJcgj(Document document, List studyFormFillJcgjList, Integer jcgjlx, String lang) throws IOException, DocumentException { + public static void addJcgjFill(Document document, List studyFormFillJcgjList, Integer jcgjlx, String lang) throws IOException, DocumentException { language = lang; 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)) { @@ -229,6 +226,105 @@ public class TemplateBaseUtil { } } + + /** + * 签名信息 + * + * @param document + * @param studyFormPlanQmxxList + * @throws IOException + * @throws DocumentException + */ + public static void addQmxxPlan(Document document, List studyFormPlanQmxxList, 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); + Font contentFont = new Font(bfChinese, 10, Font.NORMAL); + // 8. 创建表格 + PdfPTable table = new PdfPTable(4); + table.setWidthPercentage(100); + String[] headers = {getName("签名人"), getName("签名意义"), getName("签名时间"), getName("备注原因")}; + for (String header : headers) { + PdfPCell cell = new PdfPCell(new Phrase(header, headerFont)); + cell.setHorizontalAlignment(Element.ALIGN_CENTER); + cell.setPadding(8); + table.addCell(cell); + } + if (studyFormPlanQmxxList.size() > 0) { + int rowNum = 0; + for (StudyFormPlanQmxx studyFormPlanQmxx : studyFormPlanQmxxList) { + // 交替行颜色 + if (rowNum % 2 == 0) { + table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); + } else { + table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); + } + table.addCell(PdfBaseUtil.createCell(studyFormPlanQmxx.getQmrMc(), contentFont)); + table.addCell(PdfBaseUtil.createCell("en".equals(language) ? studyFormPlanQmxx.getQmyyEn() : studyFormPlanQmxx.getQmyy(), contentFont)); + table.addCell(PdfBaseUtil.createCell(PdfExportUtil.parseDateToStr(studyFormPlanQmxx.getCreateTime()), contentFont)); + table.addCell(PdfBaseUtil.createCell(studyFormPlanQmxx.getRemark(), contentFont)); + rowNum++; + } + } + document.add(table); + } + + /** + * 稽查轨迹 + * + * @param document + * @param studyFormPlanJcgjList + * @throws IOException + * @throws DocumentException + */ + public static void addJcgjPlan(Document document, List studyFormPlanJcgjList, Integer jcgjlx, String lang) throws IOException, DocumentException { + language = lang; + Integer jcgjlxMark = 999; + if (!jcgjlx.equals(jcgjlxMark)) { + PdfBaseUtil.addUnderlinedTitle(document, getName("稽查轨迹"), 10, true); + for (StudyFormPlanJcgj jcgj : studyFormPlanJcgjList) { + 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); + } + } + } + } + + 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); + } + } + } + /** * 获取名称 * diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/gsp/SYWZPZJHB.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/gsp/SYWZPZJHB.java index b3bf4fc..0343c4c 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/gsp/SYWZPZJHB.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/gsp/SYWZPZJHB.java @@ -2,16 +2,19 @@ package com.hxhq.business.utils.pdf.template.gsp; import com.alibaba.fastjson2.JSONArray; 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.domain.StudyFormPlan; +import com.hxhq.business.domain.StudyFormPlanJcgj; +import com.hxhq.business.domain.StudyFormPlanQmxx; 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 com.itextpdf.text.*; +import com.itextpdf.text.pdf.BaseFont; +import com.itextpdf.text.pdf.PdfPCell; +import com.itextpdf.text.pdf.PdfPTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,38 +37,82 @@ public class SYWZPZJHB { /** * 导出 * - * @param studyFormFill + * @param studyFormPlan * @return */ - public String exportDetail(StudyFormFill studyFormFill, List studyFormFillQmxxList, List studyFormFillJcgjList, String lang,Integer jcgjlx, String localFilePath) { + public String exportDetail(StudyFormPlan studyFormPlan, List studyFormPlanQmxxList, List studyFormPlanJcgjList, String lang, Integer jcgjlx, String localFilePath) { language = lang; Document document = null; FileOutputStream fos = null; - String filePath = PdfBaseUtil.getFilePath(localFilePath,"Template"); + String filePath = PdfBaseUtil.getFilePath(localFilePath, "Template"); 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()), studyFormFill.getBdmc(),false); - JSONObject bdnr = JSONObject.parseObject(studyFormFill.getBdnr()); - JSONObject zdgxjl = JSONObject.parseObject(StringUtils.isNoneBlank(studyFormFill.getZdgxjl())?studyFormFill.getZdgxjl():"{}"); - JSONArray fhyjjl = JSONArray.parseArray(StringUtils.isNoneBlank(studyFormFill.getFhyjjl())?studyFormFill.getFhyjjl():"[]"); + document = PdfBaseUtil.init(document, fos, filePath, sign + PdfExportUtil.parseDateToStr(new Date()), studyFormPlan.getBdmc(), false); + JSONObject bdnr = JSONObject.parseObject(studyFormPlan.getBdnr()); + JSONObject zdgxjl = JSONObject.parseObject(StringUtils.isNoneBlank(studyFormPlan.getZdgxjl()) ? studyFormPlan.getZdgxjl() : "{}"); + JSONArray fhyjjl = JSONArray.parseArray(StringUtils.isNoneBlank(studyFormPlan.getFhyjjl()) ? studyFormPlan.getFhyjjl() : "[]"); //region 表单信息 //试验基本信息 PdfBaseUtil.addUnderlinedTitle(document, getName("试验基本信息"), 10, true); Map formData1 = new LinkedHashMap<>(); - formData1.put(getName("试验名称"), studyFormFill.getStudyMc()); - formData1.put(getName("试验编号"), studyFormFill.getStudySn()); - PdfBaseUtil.addFormTableColumns(document, formData1, 2); + formData1.put(getName("试验名称"), studyFormPlan.getStudyMc()); + formData1.put(getName("试验编号"), studyFormPlan.getStudySn()); + PdfBaseUtil.addFormTableColumns(document, formData1, 2); + PdfBaseUtil.addUnderlinedTitle(document, getName("计划信息"), 10, true); + Map formData2 = new LinkedHashMap<>(); + formData2.put(getName("领取时间"), (StringUtils.isNoneBlank(bdnr.getString("drawTime")) ? bdnr.getString("drawTime") : "") + TemplateBaseUtil.getCheck("_drawTime", zdgxjl) + TemplateBaseUtil.getFh("_drawTime", fhyjjl)); + formData2.put(getName("分析时间"), (StringUtils.isNoneBlank(bdnr.getString("analyzeTime")) ? bdnr.getString("analyzeTime") : "") + TemplateBaseUtil.getCheck("_analyzeTime", zdgxjl) + TemplateBaseUtil.getFh("_analyzeTime", fhyjjl)); + formData2.put(getName("试验物资"), (StringUtils.isNoneBlank(bdnr.getString("testSubstance")) ? bdnr.getString("testSubstance") : "") + TemplateBaseUtil.getCheck("_testSubstance", zdgxjl) + TemplateBaseUtil.getFh("_testSubstance", fhyjjl)); + formData2.put(getName("配置频率"), (StringUtils.isNoneBlank(bdnr.getString("configFrequency")) ? bdnr.getString("configFrequency") : "") + TemplateBaseUtil.getCheck("_configFrequency", zdgxjl) + TemplateBaseUtil.getFh("_configFrequency", fhyjjl)); + PdfBaseUtil.addFormTableColumns(document, formData2, 2); + // 9. 表头 + BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); + Font headerFont = new Font(bfChinese, 10, Font.NORMAL); + Font contentFont = new Font(bfChinese, 10, Font.NORMAL); + // 8. 创建表格 + PdfPTable table = new PdfPTable(3); + table.setWidthPercentage(100); + JSONObject headerSelectFields = JSONObject.parseObject(bdnr.getString("headerSelectFields")); + String[] headers = { + getName("给药剂量或组别"), + getName("配制浓度") + headerSelectFields.getString("preparationConcentrationUnit") + TemplateBaseUtil.getCheck("_preparationConcentrationUnit", zdgxjl) + TemplateBaseUtil.getFh("_preparationConcentrationUnit", fhyjjl), + getName("配制体积") + headerSelectFields.getString("preparationVolumeUnit") + TemplateBaseUtil.getCheck("_preparationVolumeUnit", zdgxjl) + TemplateBaseUtil.getFh("_preparationVolumeUnit", fhyjjl) + }; + for (String header : headers) { + PdfPCell cell = new PdfPCell(new Phrase(header, headerFont)); + cell.setHorizontalAlignment(Element.ALIGN_CENTER); + cell.setPadding(8); + table.addCell(cell); + } + JSONArray stepTableFormData = JSONArray.parseArray(bdnr.getString("stepTableFormData")); + if (stepTableFormData.size() > 0) { + for (int i = 0; i < stepTableFormData.size(); i++) { + JSONObject obj = stepTableFormData.getJSONObject(i); + int rowNum = 0; + // 交替行颜色 + if (rowNum % 2 == 0) { + table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); + } else { + table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); + } + table.addCell(PdfBaseUtil.createCell(obj.getString("startSolutionCode") + TemplateBaseUtil.getCheck("_startSolutionCode_"+(rowNum+1), zdgxjl) + TemplateBaseUtil.getFh("_startSolutionCode_"+(rowNum+1), fhyjjl), contentFont)); + table.addCell(PdfBaseUtil.createCell(obj.getString("preparationConcentration") + TemplateBaseUtil.getCheck("_preparationConcentration_"+(rowNum+1), zdgxjl) + TemplateBaseUtil.getFh("_preparationConcentration_"+(rowNum+1), fhyjjl), contentFont)); + table.addCell(PdfBaseUtil.createCell(obj.getString("preparationVolume") + TemplateBaseUtil.getCheck("_preparationVolume_"+(rowNum+1), zdgxjl) + TemplateBaseUtil.getFh("_preparationVolume_"+(rowNum+1), fhyjjl), contentFont)); + rowNum++; + } + } + document.add(table); //签名信息 - TemplateBaseUtil.addQmxx(document, studyFormFillQmxxList,language); + TemplateBaseUtil.addQmxxPlan(document, studyFormPlanQmxxList, language); //稽查轨迹 - TemplateBaseUtil.addJcgj(document, studyFormFillJcgjList,jcgjlx,language); + TemplateBaseUtil.addJcgjPlan(document,studyFormPlanJcgjList, jcgjlx, language); logger.info("生成成功:{}", filePath); } catch (Exception e) { logger.error("生成失败", e); @@ -93,7 +140,7 @@ public class SYWZPZJHB { * @return */ public String getName(String name) { - return TemplateBaseUtil.getNameByLanguage(name,language); + return TemplateBaseUtil.getNameByLanguage(name, language); } } 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 7717d91..07c3b1b 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 @@ -98,9 +98,9 @@ public class SP001 { //endregion //签名信息 - TemplateBaseUtil.addQmxx(document, studyFormFillQmxxList,language); + TemplateBaseUtil.addQmxxFill(document, studyFormFillQmxxList,language); //稽查轨迹 - TemplateBaseUtil.addJcgj(document, studyFormFillJcgjList,jcgjlx,language); + TemplateBaseUtil.addJcgjFill(document, studyFormFillJcgjList,jcgjlx,language); logger.info("生成成功:{}", filePath); } catch (Exception e) { logger.error("生成失败", e);