Browse Source

fix:[试验管理]填报表单导出

master
15881625488@163.com 3 months ago
parent
commit
d044d7ad62
10 changed files with 291 additions and 146 deletions
  1. +1
    -1
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudyFormFillController.java
  2. +7
    -1
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudyFormFillJcgjServiceImpl.java
  3. +1
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/GyzjJcnrUtil.java
  4. +2
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/MjyJcnrUtil.java
  5. +3
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/TemplateUtil.java
  6. +12
    -8
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/PdfBaseUtil.java
  7. +3
    -2
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/resource/Dosage.java
  8. +3
    -2
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/resource/Drug.java
  9. +12
    -132
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/SP001.java
  10. +247
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/TemplateBaseUtil.java

+ 1
- 1
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudyFormFillController.java View File

@ -100,7 +100,7 @@ public class StudyFormFillController extends BaseController {
StudyFormFillQmxx studyFormFillQmxx = new StudyFormFillQmxx();
studyFormFillQmxx.setFormId(form.getFormId());
List<StudyFormFillQmxx> studyFormFillQmxxList = studyFormFillQmxxService.queryList(studyFormFillQmxx);
StudyFormFill studyFormFill=studyFormFillService.getById(form.getFormId());
StudyFormFill studyFormFill=studyFormFillService.queryInfo(form.getFormId());
Template template=templateService.getById(studyFormFill.getTemplateId());
if(template!=null){
return AjaxResult.success(localFilePrefix + PdfExportUtil.export(

+ 7
- 1
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudyFormFillJcgjServiceImpl.java View File

@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hxhq.business.domain.GyzjJcgj;
import com.hxhq.business.domain.StudyFormPreJcgj;
import com.hxhq.business.enums.zykgl.JcgjlxEnum;
import com.hxhq.business.utils.StudyFormUtil;
import com.hxhq.business.utils.JctUtil;
import com.hxhq.business.utils.StudyFormUtil;
@ -44,7 +45,12 @@ public class StudyFormFillJcgjServiceImpl extends ServiceImpl
}
queryWrapper.eq("form_id",studyFormFillJcgj.getFormId());
if(studyFormFillJcgj.getJcgjlx()!=null&&studyFormFillJcgj.getJcgjlx().intValue()>0){
queryWrapper.eq("jcgjlx",studyFormFillJcgj.getJcgjlx());
Integer jcgjlxExport=999;
if(studyFormFillJcgj.getJcgjlx().intValue()==jcgjlxExport){
queryWrapper.notIn("jcgjlx", JcgjlxEnum.xg.getValue());
}else{
queryWrapper.eq("jcgjlx",studyFormFillJcgj.getJcgjlx());
}
}
if (StringUtils.isNoneBlank(studyFormFillJcgj.getJcmc())) {
queryWrapper.and(p -> p.like("`jcmc`", studyFormFillJcgj.getJcmc())

+ 1
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/GyzjJcnrUtil.java View File

@ -96,6 +96,7 @@ public class GyzjJcnrUtil {
mapLang.put("领取发放","Distribution");
mapLang.put("存储","Storage");
mapLang.put("取出","Take Out");
mapLang.put("给药制剂详情","Dose Information");
mapLang.put("表单名称","Preset Name");
mapLang.put("锁定发放记录","Lock Record");

+ 2
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/MjyJcnrUtil.java View File

@ -98,6 +98,8 @@ public class MjyJcnrUtil {
mapLang.put("解锁发放记录","Unlock Record");
mapLang.put("麻精药入库","Controlled Drug Check-in");
mapLang.put("目的","Purpose");
mapLang.put("麻精药详情","Drug Information");
mapLang.put("入库位置","入库位置");
mapLang.put("入库条件","入库条件");
mapLang.put("减少量","减少量");

+ 3
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/TemplateUtil.java View File

@ -67,6 +67,9 @@ public class TemplateUtil {
mapLang.put("签名时间","Date");
mapLang.put("备注原因","Comment/Reason");
}
public static void main(String[] args) {

+ 12
- 8
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/PdfBaseUtil.java View File

@ -107,7 +107,7 @@ public class PdfBaseUtil {
* @param filePath
* @param signText
*/
public static Document init(Document document, FileOutputStream fos, String filePath, String signText, String headerText) {
public static Document init(Document document, FileOutputStream fos, String filePath, String signText, String headerText,Boolean showHaderLine) {
try {
// 创建PDF文档 设置文档边距避免内容遮挡页眉页脚
// 顶部边距为页眉留出空间
@ -125,11 +125,11 @@ public class PdfBaseUtil {
fos = new FileOutputStream(filePath);
PdfWriter writer = PdfWriter.getInstance(document, fos);
// 设置页面事件每页添加文字页眉
writer.setPageEvent(new PdfBaseUtil.TextHeaderEvent(signText, headerText));
writer.setPageEvent(new PdfBaseUtil.TextHeaderEvent(signText, headerText,showHaderLine));
// 5. 设置PDF属性
document.addTitle("华西海圻");
document.addAuthor("华西海圻");
document.addCreator("华西海圻");
document.addTitle("hxhq");
document.addAuthor("hxhq");
document.addCreator("hxhq");
document.addCreationDate();
document.open();
return document;
@ -234,11 +234,13 @@ public class PdfBaseUtil {
private String signText;
private String headerText;
private BaseFont baseFont;
private Boolean showHaderLine=true;
private int totalPages = 0;
private PdfTemplate total;
public TextHeaderEvent(String signText, String headerText) throws Exception {
public TextHeaderEvent(String signText, String headerText,Boolean showHaderLine) throws Exception {
try {
this.showHaderLine = showHaderLine;
this.signText = signText;
this.headerText = headerText;
// 创建字体支持中文
@ -350,8 +352,10 @@ public class PdfBaseUtil {
canvas.showText(headerText);
canvas.endText();
// 添加页眉分隔线可选
addHeaderLine(canvas, pageWidth, textY - 10);
if(showHaderLine){
// 添加页眉分隔线可选
addHeaderLine(canvas, pageWidth, textY - 10);
}
}
} catch (Exception e) {

+ 3
- 2
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/resource/Dosage.java View File

@ -48,7 +48,7 @@ public class Dosage {
if (loginUser != null) {
sign = loginUser.getSysUser().getNickName();
}
document = PdfBaseUtil.init(document, fos, filePath, sign + PdfExportUtil.parseDateToStr(new Date()), null);
document = PdfBaseUtil.init(document, fos, filePath, sign + PdfExportUtil.parseDateToStr(new Date()), getName("麻精药详情"),false);
// 基本信息
PdfBaseUtil.addUnderlinedTitle(document, getName("基本信息"), 10, true);
Map<String, String> formData1 = new LinkedHashMap<>();
@ -149,9 +149,9 @@ public class Dosage {
*/
public void addJcgj(Document document, List<GyzjJcgj> gyzjJcgjList, String lang) throws IOException, DocumentException {
for (GyzjJcgj jcgj : gyzjJcgjList) {
PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime())+ " " + getName(jcgj.getJcmc()), 10, false);
StringJoiner result = new StringJoiner(", ");
if ("en".equals(lang)) {
PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime())+ " " + getName(jcgj.getJcnrEn()), 10, false);
if (StringUtils.isNoneBlank(jcgj.getJcnrEn())) {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonArray = mapper.readTree(jcgj.getJcnrEn());
@ -165,6 +165,7 @@ public class Dosage {
}
} else {
if (StringUtils.isNoneBlank(jcgj.getJcnr())) {
PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime())+ " " + getName(jcgj.getJcmc()), 10, false);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonArray = mapper.readTree(jcgj.getJcnr());
for (JsonNode node : jsonArray) {

+ 3
- 2
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/resource/Drug.java View File

@ -47,7 +47,7 @@ public class Drug {
if (loginUser != null) {
sign = loginUser.getSysUser().getNickName();
}
document = PdfBaseUtil.init(document, fos, filePath, sign + PdfExportUtil.parseDateToStr(new Date()), null);
document = PdfBaseUtil.init(document, fos, filePath, sign + PdfExportUtil.parseDateToStr(new Date()), getName("麻精药详情"),false);
// 基本信息
PdfBaseUtil.addUnderlinedTitle(document, getName("基本信息"), 10, true);
Map<String, String> formData1 = new LinkedHashMap<>();
@ -148,9 +148,9 @@ public class Drug {
*/
public void addJcgj(Document document, List<MjyJcgj> mjyJcgjList, String lang) throws IOException, DocumentException {
for (MjyJcgj jcgj : mjyJcgjList) {
PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime())+ " " + getName(jcgj.getJcmc()), 10, false);
StringJoiner result = new StringJoiner(", ");
if ("en".equals(lang)) {
PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime())+ " " + getName(jcgj.getJcnrEn()), 10, false);
if (StringUtils.isNoneBlank(jcgj.getJcnrEn())) {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonArray = mapper.readTree(jcgj.getJcnrEn());
@ -163,6 +163,7 @@ public class Drug {
}
}
} else {
PdfBaseUtil.addUnderlinedTitle(document, PdfExportUtil.parseDateToStr(jcgj.getCreateTime())+ " " + getName(jcgj.getJcmc()), 10, false);
if (StringUtils.isNoneBlank(jcgj.getJcnr())) {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonArray = mapper.readTree(jcgj.getJcnr());

+ 12
- 132
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/SP001.java View File

@ -49,7 +49,7 @@ public class SP001 {
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());
document = PdfBaseUtil.init(document, fos, filePath, sign +PdfExportUtil.parseDateToStr(new Date()), "en".equals(language)?template.getShowSn():template.getName(),false);
// 基本信息
JSONObject bdnr = JSONObject.parseObject(studyFormFill.getBdnr());
@ -57,14 +57,14 @@ public class SP001 {
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"));
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("预填"), 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") : ""));
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);
@ -75,10 +75,13 @@ public class SP001 {
// 签名信息
PdfBaseUtil.addUnderlinedTitle(document, getName("试验试剂信息"), 10, true);
addResource(document, studyFormFill.getResource());
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);
@ -98,10 +101,10 @@ public class SP001 {
// 签名信息
PdfBaseUtil.addUnderlinedTitle(document, getName("签名信息"), 10, true);
addQmxx(document, studyFormFillQmxxList);
TemplateBaseUtil.addQmxx(document, studyFormFillQmxxList,language);
//稽查轨迹
PdfBaseUtil.addUnderlinedTitle(document, getName("稽查轨迹"), 10, true);
addJcgj(document, studyFormFillJcgjList);
TemplateBaseUtil.addJcgj(document, studyFormFillJcgjList,language);
logger.info("生成成功:{}", filePath);
} catch (Exception e) {
logger.error("生成失败", e);
@ -121,129 +124,6 @@ public class SP001 {
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);
}
}
/**
* 获取名称
@ -252,7 +132,7 @@ public class SP001 {
* @return
*/
public String getName(String name) {
return "en".equals(language) ? TemplateUtil.getEn(name) : name;
return TemplateBaseUtil.getNameByLanguage(name,language);
}
}

+ 247
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/pdf/template/TemplateBaseUtil.java View File

@ -0,0 +1,247 @@
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.StudyFormFill;
import com.hxhq.business.domain.StudyFormFillJcgj;
import com.hxhq.business.domain.StudyFormFillQmxx;
import com.hxhq.business.domain.Template;
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.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.getRemark())) {
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;
}
}

Loading…
Cancel
Save