|
|
@ -1,43 +1,106 @@ |
|
|
package com.hxhq.business.utils.pdf.template.sp; |
|
|
package com.hxhq.business.utils.pdf.template.sp; |
|
|
|
|
|
|
|
|
|
|
|
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.dto.mjy.DetailDto; |
|
|
import com.hxhq.business.utils.pdf.PdfBaseUtil; |
|
|
import com.hxhq.business.utils.pdf.PdfBaseUtil; |
|
|
|
|
|
import com.hxhq.common.core.utils.StringUtils; |
|
|
import com.hxhq.common.security.utils.SecurityUtils; |
|
|
import com.hxhq.common.security.utils.SecurityUtils; |
|
|
import com.hxhq.system.api.model.LoginUser; |
|
|
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.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.util.LinkedHashMap; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 色谱001 |
|
|
* 色谱001 |
|
|
|
|
|
* |
|
|
* @author tanfei |
|
|
* @author tanfei |
|
|
*/ |
|
|
*/ |
|
|
public class Sp001 { |
|
|
|
|
|
|
|
|
public class Sp001 { |
|
|
private static final Logger logger = LoggerFactory.getLogger(Sp001.class.getName()); |
|
|
private static final Logger logger = LoggerFactory.getLogger(Sp001.class.getName()); |
|
|
|
|
|
|
|
|
/**导出 |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 导出 |
|
|
|
|
|
* |
|
|
|
|
|
* @param studyFormFill |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
public static String exportDetail(String localFilePath) { |
|
|
|
|
|
|
|
|
public String exportDetail(StudyFormFill studyFormFill, List<StudyFormFillQmxx> studyFormFillQmxxList, List<StudyFormFillJcgj> studyFormFillJcgjList, String localFilePath) { |
|
|
Document document = null; |
|
|
Document document = null; |
|
|
FileOutputStream fos = null; |
|
|
FileOutputStream fos = null; |
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
String filePath = PdfBaseUtil.getFilePath(localFilePath); |
|
|
String filePath = PdfBaseUtil.getFilePath(localFilePath); |
|
|
try { |
|
|
try { |
|
|
String sign="华西海圻"; |
|
|
|
|
|
LoginUser loginUser=SecurityUtils.getLoginUser(); |
|
|
|
|
|
if(loginUser!=null){ |
|
|
|
|
|
sign=loginUser.getSysUser().getNickName(); |
|
|
|
|
|
} |
|
|
|
|
|
document=PdfBaseUtil.init(document,fos,filePath,sign,"华西海圻"); |
|
|
|
|
|
Map<String, String> formData = new LinkedHashMap<>(); |
|
|
|
|
|
formData.put("姓名","张三"); |
|
|
|
|
|
formData.put("性别", "男"); |
|
|
|
|
|
formData.put("手机","15882062878"); |
|
|
|
|
|
// 生成table |
|
|
|
|
|
PdfBaseUtil.addFormTableColumns(document, formData,3); |
|
|
|
|
|
|
|
|
String sign = "华西海圻"; |
|
|
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|
|
|
|
|
if (loginUser != null) { |
|
|
|
|
|
sign = loginUser.getSysUser().getNickName(); |
|
|
|
|
|
} |
|
|
|
|
|
document = PdfBaseUtil.init(document, fos, filePath, sign + sdf.format(new Date()), studyFormFill.getBdmc()); |
|
|
|
|
|
// 基本信息 |
|
|
|
|
|
|
|
|
|
|
|
JSONObject bdnr = JSONObject.parseObject(studyFormFill.getBdnr()); |
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "试验基本信息", 10, true); |
|
|
|
|
|
Map<String, String> formData1 = new LinkedHashMap<>(); |
|
|
|
|
|
formData1.put("试验名称", studyFormFill.getStudyMc()); |
|
|
|
|
|
formData1.put("试验编号", studyFormFill.getStudySn()); |
|
|
|
|
|
formData1.put("方法编号", bdnr.getString("methodCode")); |
|
|
|
|
|
formData1.put("版本号", bdnr.getString("methodCode")); |
|
|
|
|
|
PdfBaseUtil.addFormTableColumns(document, formData1, 2); |
|
|
|
|
|
|
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "试验配置条件", 10, true); |
|
|
|
|
|
Map<String, String> formData2 = new LinkedHashMap<>(); |
|
|
|
|
|
formData2.put("预填", bdnr.getString("pre") + (StringUtils.isNoneBlank(bdnr.getString("preOther")) ? bdnr.getString("preOther") : "")); |
|
|
|
|
|
formData2.put("实际", bdnr.getString("act") + (StringUtils.isNoneBlank(bdnr.getString("actOther")) ? bdnr.getString("actOther") : "")); |
|
|
|
|
|
PdfBaseUtil.addFormTableColumns(document, formData2, 2); |
|
|
|
|
|
|
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "配置时间", 10, true); |
|
|
|
|
|
Map<String, String> formData3 = new LinkedHashMap<>(); |
|
|
|
|
|
formData3.put("开始时间", studyFormFill.getStartDate() != null ? sdf.format(studyFormFill.getStartDate()) : ""); |
|
|
|
|
|
formData3.put("结束时间", studyFormFill.getEndDate() != null ? sdf.format(studyFormFill.getEndDate()) : ""); |
|
|
|
|
|
PdfBaseUtil.addFormTableColumns(document, formData3, 2); |
|
|
|
|
|
|
|
|
|
|
|
// 签名信息 |
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "试验试剂信息", 10, true); |
|
|
|
|
|
addResource(document, studyFormFill.getResource()); |
|
|
|
|
|
|
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "仪器使用信息", 10, true); |
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "存储条件", 10, true); |
|
|
|
|
|
Map<String, String> formData4 = new LinkedHashMap<>(); |
|
|
|
|
|
formData4.put("存储条件",bdnr.getString("storageCondition")+ (StringUtils.isNoneBlank(bdnr.getString("storageConditionOther")) ? bdnr.getString("storageConditionOther") : "")); |
|
|
|
|
|
PdfBaseUtil.addFormTableColumns(document, formData4, 1); |
|
|
|
|
|
|
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "操作步骤", 10, true); |
|
|
|
|
|
Map<String, String> formData5 = new LinkedHashMap<>(); |
|
|
|
|
|
formData5.put("目标溶液名称", bdnr.getString("targetName")); |
|
|
|
|
|
formData5.put("目标溶液编号", bdnr.getString("targetCode")+bdnr.getString("targetCodeSn")); |
|
|
|
|
|
formData5.put("目标溶液预计浓度", bdnr.getString("targetPreConcentration")+bdnr.getString("targetPreConcentrationUnit")); |
|
|
|
|
|
formData5.put("目标溶液实际浓度", bdnr.getString("targetActConcentration")+bdnr.getString("targetPreConcentrationUnit")); |
|
|
|
|
|
formData5.put("目标溶液预计体积", bdnr.getString("targetPreVolume")+bdnr.getString("targetPreVolumeUnit")); |
|
|
|
|
|
formData5.put("目标溶液实际体积", bdnr.getString("targetActVolume")+bdnr.getString("targetActVolumeUnit")); |
|
|
|
|
|
formData5.put("有效周期", bdnr.getString("effectivePeriod")+bdnr.getString("effectivePeriodUnit")); |
|
|
|
|
|
formData5.put("失效日", bdnr.getString("sxrq")); |
|
|
|
|
|
PdfBaseUtil.addFormTableColumns(document, formData5, 2); |
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "备注"+(StringUtils.isNoneBlank(bdnr.getString("remark")) ? ":"+bdnr.getString("remark") : ""), 10, false); |
|
|
|
|
|
|
|
|
|
|
|
// 签名信息 |
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "签名信息", 10, true); |
|
|
|
|
|
addQmxx(document, studyFormFillQmxxList); |
|
|
|
|
|
//稽查轨迹 |
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "稽查轨迹", 10, true); |
|
|
|
|
|
addJcgj(document, studyFormFillJcgjList); |
|
|
logger.info("生成成功:{}", filePath); |
|
|
logger.info("生成成功:{}", filePath); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("生成失败", e); |
|
|
logger.error("生成失败", e); |
|
|
@ -57,4 +120,129 @@ public class Sp001 { |
|
|
return filePath; |
|
|
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); |
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
// 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 = {"试剂名称", "编号", "批号", "浓度/含量/纯度","来源","失效日"}; |
|
|
|
|
|
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 { |
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
// 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 = {"签名人", "签名意义", "签名时间", "备注原因"}; |
|
|
|
|
|
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(sdf.format(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 { |
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
for (StudyFormFillJcgj jcgj : studyFormFillJcgjList) { |
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, sdf.format(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) { |
|
|
|
|
|
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("备注:" + jcgj.getRemark()); |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isNoneBlank(jcgj.getRemark())) { |
|
|
|
|
|
result.add("签名人:" + jcgj.getQmrMc()); |
|
|
|
|
|
} |
|
|
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, result.toString(), 10, false); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |