| @ -1,5 +1,6 @@ | |||
| package com.hxhq.business.utils; | |||
| package com.hxhq.business.utils.lang; | |||
| import com.hxhq.business.utils.JctUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @ -1,258 +0,0 @@ | |||
| package com.hxhq.business.utils.pdf.template; | |||
| 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.*; | |||
| import com.hxhq.business.utils.TemplateUtil; | |||
| import com.hxhq.business.utils.pdf.PdfBaseUtil; | |||
| import com.hxhq.business.utils.pdf.PdfExportUtil; | |||
| 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.*; | |||
| 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; | |||
| import java.io.FileOutputStream; | |||
| import java.io.IOException; | |||
| import java.util.*; | |||
| import java.util.List; | |||
| /** | |||
| * 色谱-生物样品分析溶液配制表 | |||
| * | |||
| * @author tanfei | |||
| */ | |||
| public class SP001 { | |||
| private static final Logger logger = LoggerFactory.getLogger(SP001.class.getName()); | |||
| public String language = "zh"; | |||
| /** | |||
| * 导出 | |||
| * | |||
| * @param studyFormFill | |||
| * @return | |||
| */ | |||
| public String exportDetail(StudyFormFill studyFormFill,Template template, List<StudyFormFillQmxx> studyFormFillQmxxList, List<StudyFormFillJcgj> studyFormFillJcgjList, String lang, String localFilePath) { | |||
| language = lang; | |||
| Document document = null; | |||
| FileOutputStream fos = null; | |||
| String filePath = PdfBaseUtil.getFilePath(localFilePath); | |||
| 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)?template.getShowSn():template.getName()); | |||
| // 基本信息 | |||
| JSONObject bdnr = JSONObject.parseObject(studyFormFill.getBdnr()); | |||
| PdfBaseUtil.addUnderlinedTitle(document, getName("试验基本信息"), 10, true); | |||
| Map<String, String> formData1 = new LinkedHashMap<>(); | |||
| formData1.put(getName("试验名称"), studyFormFill.getStudyMc()); | |||
| formData1.put(getName("试验编号"), studyFormFill.getStudySn()); | |||
| formData1.put(getName("方法编号"), bdnr.getString("methodCode")); | |||
| formData1.put(getName("版本号"), bdnr.getString("methodCode")); | |||
| PdfBaseUtil.addFormTableColumns(document, formData1, 2); | |||
| PdfBaseUtil.addUnderlinedTitle(document, getName("试验配置条件"), 10, true); | |||
| Map<String, String> formData2 = new LinkedHashMap<>(); | |||
| formData2.put(getName("预填"), bdnr.getString("pre") + (StringUtils.isNoneBlank(bdnr.getString("preOther")) ? bdnr.getString("preOther") : "")); | |||
| formData2.put(getName("实际"), bdnr.getString("act") + (StringUtils.isNoneBlank(bdnr.getString("actOther")) ? bdnr.getString("actOther") : "")); | |||
| PdfBaseUtil.addFormTableColumns(document, formData2, 2); | |||
| PdfBaseUtil.addUnderlinedTitle(document, getName("配置时间"), 10, true); | |||
| Map<String, String> 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); | |||
| addResource(document, studyFormFill.getResource()); | |||
| PdfBaseUtil.addUnderlinedTitle(document, getName("仪器使用信息"), 10, true); | |||
| PdfBaseUtil.addUnderlinedTitle(document, getName("存储条件"), 10, true); | |||
| Map<String, String> 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<String, String> 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("sxrq")); | |||
| 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); | |||
| addQmxx(document, studyFormFillQmxxList); | |||
| //稽查轨迹 | |||
| PdfBaseUtil.addUnderlinedTitle(document, getName("稽查轨迹"), 10, true); | |||
| addJcgj(document, studyFormFillJcgjList); | |||
| 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 document | |||
| * @param resource | |||
| * @throws IOException | |||
| * @throws DocumentException | |||
| */ | |||
| public void addResource(Document document, String resource) 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"}] | |||
| if (StringUtils.isNoneBlank(resource)) { | |||
| JSONArray jsonArray = JSONArray.parseArray(resource); | |||
| // 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(6); | |||
| table.setWidthPercentage(100); | |||
| String[] headers = {getName("试剂名称"), getName("编号"), getName("批号"), getName("浓度/含量/纯度"), getName("来源"), getName("失效日")}; | |||
| for (String header : headers) { | |||
| PdfPCell cell = new PdfPCell(new Phrase(header, headerFont)); | |||
| cell.setHorizontalAlignment(Element.ALIGN_CENTER); | |||
| cell.setPadding(8); | |||
| cell.setBorderWidth(1); | |||
| table.addCell(cell); | |||
| } | |||
| int rowNum = 0; | |||
| for (int i = 0; i < jsonArray.size(); i++) { | |||
| JSONObject obj = jsonArray.getJSONObject(i); | |||
| // 交替行颜色 | |||
| if (rowNum % 2 == 0) { | |||
| table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); | |||
| } else { | |||
| table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); | |||
| } | |||
| table.addCell(PdfBaseUtil.createCell(obj.getString("mc"), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(obj.getString("bh"), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(obj.getString("ph"), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(obj.getString("nd"), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(obj.getString("source"), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(StringUtils.isNoneBlank(obj.getString("sxrq")) ? obj.getString("sxrq") : "", contentFont)); | |||
| rowNum++; | |||
| } | |||
| document.add(table); | |||
| } | |||
| } | |||
| /** | |||
| * 签名信息 | |||
| * | |||
| * @param document | |||
| * @param studyFormFillQmxxList | |||
| * @throws IOException | |||
| * @throws DocumentException | |||
| */ | |||
| public void addQmxx(Document document, List<StudyFormFillQmxx> studyFormFillQmxxList) throws IOException, DocumentException { | |||
| // 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); | |||
| cell.setBorderWidth(1); | |||
| table.addCell(cell); | |||
| } | |||
| int rowNum = 0; | |||
| for (StudyFormFillQmxx studyFormFillQmxx : studyFormFillQmxxList) { | |||
| // 交替行颜色 | |||
| if (rowNum % 2 == 0) { | |||
| table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); | |||
| } else { | |||
| table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); | |||
| } | |||
| table.addCell(PdfBaseUtil.createCell(studyFormFillQmxx.getQmrMc(), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(studyFormFillQmxx.getQmyy(), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(PdfExportUtil.parseDateToStr(studyFormFillQmxx.getCreateTime()), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(studyFormFillQmxx.getRemark(), contentFont)); | |||
| rowNum++; | |||
| } | |||
| document.add(table); | |||
| } | |||
| /** | |||
| * 稽查轨迹 | |||
| * | |||
| * @param document | |||
| * @param studyFormFillJcgjList | |||
| * @throws IOException | |||
| * @throws DocumentException | |||
| */ | |||
| public void addJcgj(Document document, List<StudyFormFillJcgj> studyFormFillJcgjList) throws IOException, DocumentException { | |||
| for (StudyFormFillJcgj jcgj : studyFormFillJcgjList) { | |||
| PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime()) + " " + jcgj.getJcmc(), 10, false); | |||
| StringJoiner result = new StringJoiner(", "); | |||
| 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.getRemark())) { | |||
| result.add(getName("签名人") + ":" + jcgj.getQmrMc()); | |||
| } | |||
| PdfBaseUtil.addUnderlinedTitle(document, result.toString(), 10, false); | |||
| } | |||
| } | |||
| /** | |||
| * 获取名称 | |||
| * | |||
| * @param name | |||
| * @return | |||
| */ | |||
| public String getName(String name) { | |||
| return "en".equals(language) ? TemplateUtil.getEn(name) : name; | |||
| } | |||
| } | |||
| @ -0,0 +1,242 @@ | |||
| package com.hxhq.business.utils.pdf.template; | |||
| 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.StudyFormFillJcgj; | |||
| import com.hxhq.business.domain.StudyFormFillQmxx; | |||
| import com.hxhq.business.utils.lang.TemplateUtil; | |||
| import com.hxhq.business.utils.pdf.PdfBaseUtil; | |||
| import com.hxhq.business.utils.pdf.PdfExportUtil; | |||
| import com.hxhq.common.core.utils.StringUtils; | |||
| 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; | |||
| import java.io.IOException; | |||
| import java.util.List; | |||
| import java.util.*; | |||
| /** | |||
| * 色谱-生物样品分析溶液配制表 | |||
| * | |||
| * @author tanfei | |||
| */ | |||
| public class TemplateBaseUtil { | |||
| private static final Logger logger = LoggerFactory.getLogger(TemplateBaseUtil.class.getName()); | |||
| public static String language = "zh"; | |||
| /** | |||
| * 试验试剂信息 | |||
| * | |||
| * @param document | |||
| * @param resource | |||
| * @throws IOException | |||
| * @throws DocumentException | |||
| */ | |||
| 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; | |||
| // 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(6); | |||
| table.setWidthPercentage(100); | |||
| String[] headers = {getName("试剂名称"), getName("编号"), 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 (StringUtils.isNoneBlank(resource)) { | |||
| JSONArray jsonArray = JSONArray.parseArray(resource); | |||
| int rowNum = 0; | |||
| for (int i = 0; i < jsonArray.size(); i++) { | |||
| JSONObject obj = jsonArray.getJSONObject(i); | |||
| // 交替行颜色 | |||
| if (rowNum % 2 == 0) { | |||
| table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); | |||
| } else { | |||
| table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); | |||
| } | |||
| table.addCell(PdfBaseUtil.createCell(obj.getString("mc"), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(obj.getString("bh"), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(obj.getString("ph"), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(obj.getString("nd"), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(obj.getString("source"), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(StringUtils.isNoneBlank(obj.getString("sxrq")) ? obj.getString("sxrq") : "", contentFont)); | |||
| rowNum++; | |||
| } | |||
| } | |||
| document.add(table); | |||
| } | |||
| /** | |||
| * 仪器使用信息 | |||
| * | |||
| * @param document | |||
| * @param instrument | |||
| * @throws IOException | |||
| * @throws DocumentException | |||
| */ | |||
| public static void addInstrument(Document document, String instrument, String lang) throws IOException, DocumentException { | |||
| language = lang; | |||
| // 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 (StringUtils.isNoneBlank(instrument)) { | |||
| // JSONArray jsonArray = JSONArray.parseArray(instrument); | |||
| // int rowNum = 0; | |||
| // for (int i = 0; i < jsonArray.size(); i++) { | |||
| // JSONObject obj = jsonArray.getJSONObject(i); | |||
| // // 交替行颜色 | |||
| // if (rowNum % 2 == 0) { | |||
| // table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); | |||
| // } else { | |||
| // table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); | |||
| // } | |||
| // table.addCell(PdfBaseUtil.createCell(obj.getString("mc"), contentFont)); | |||
| // table.addCell(PdfBaseUtil.createCell(obj.getString("bh"), contentFont)); | |||
| // table.addCell(PdfBaseUtil.createCell(obj.getString("ph"), contentFont)); | |||
| // table.addCell(PdfBaseUtil.createCell(obj.getString("nd"), contentFont)); | |||
| // table.addCell(PdfBaseUtil.createCell(obj.getString("source"), contentFont)); | |||
| // table.addCell(PdfBaseUtil.createCell(StringUtils.isNoneBlank(obj.getString("sxrq")) ? obj.getString("sxrq") : "", contentFont)); | |||
| // rowNum++; | |||
| // } | |||
| } | |||
| document.add(table); | |||
| } | |||
| /** | |||
| * 签名信息 | |||
| * | |||
| * @param document | |||
| * @param studyFormFillQmxxList | |||
| * @throws IOException | |||
| * @throws DocumentException | |||
| */ | |||
| public static void addQmxx(Document document, List<StudyFormFillQmxx> studyFormFillQmxxList, String lang) throws IOException, DocumentException { | |||
| language = lang; | |||
| // 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(studyFormFillQmxxList.size()>0){ | |||
| int rowNum = 0; | |||
| for (StudyFormFillQmxx studyFormFillQmxx : studyFormFillQmxxList) { | |||
| // 交替行颜色 | |||
| if (rowNum % 2 == 0) { | |||
| table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); | |||
| } else { | |||
| 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(PdfExportUtil.parseDateToStr(studyFormFillQmxx.getCreateTime()), contentFont)); | |||
| table.addCell(PdfBaseUtil.createCell(studyFormFillQmxx.getRemark(), contentFont)); | |||
| rowNum++; | |||
| } | |||
| } | |||
| document.add(table); | |||
| } | |||
| /** | |||
| * 稽查轨迹 | |||
| * | |||
| * @param document | |||
| * @param studyFormFillJcgjList | |||
| * @throws IOException | |||
| * @throws DocumentException | |||
| */ | |||
| public static void addJcgj(Document document, List<StudyFormFillJcgj> studyFormFillJcgjList, 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); | |||
| } | |||
| } | |||
| } | |||
| }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); | |||
| } | |||
| } | |||
| /** | |||
| * 获取名称 | |||
| * | |||
| * @param name | |||
| * @return | |||
| */ | |||
| public static String getNameByLanguage(String name, String lang) { | |||
| return "en".equals(lang) ? TemplateUtil.getEn(name) : name; | |||
| } | |||
| /** | |||
| * 获取名称 | |||
| * | |||
| * @param name | |||
| * @return | |||
| */ | |||
| public static String getName(String name) { | |||
| return "en".equals(language) ? TemplateUtil.getEn(name) : name; | |||
| } | |||
| } | |||
| @ -0,0 +1,135 @@ | |||
| package com.hxhq.business.utils.pdf.template.sp; | |||
| import com.alibaba.fastjson2.JSONObject; | |||
| import com.hxhq.business.domain.*; | |||
| 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.*; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import java.io.FileOutputStream; | |||
| import java.io.IOException; | |||
| import java.util.*; | |||
| import java.util.List; | |||
| /** | |||
| * 色谱-生物样品分析溶液配制表 | |||
| * | |||
| * @author tanfei | |||
| */ | |||
| public class SP001 { | |||
| private static final Logger logger = LoggerFactory.getLogger(SP001.class.getName()); | |||
| public String language = "zh"; | |||
| /** | |||
| * 导出 | |||
| * | |||
| * @param studyFormFill | |||
| * @return | |||
| */ | |||
| public String exportDetail(StudyFormFill studyFormFill, List<StudyFormFillQmxx> studyFormFillQmxxList, List<StudyFormFillJcgj> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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("sxrq")); | |||
| 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); | |||
| } | |||
| } | |||