追溯报表页面样式调整

tags/yfai-mes-ext-v1.0
jun 10 months ago
parent 5db1430759
commit 73350ef0b9

@ -24,7 +24,6 @@ import cn.estsh.i3plus.pojo.mes.model.report.MesTraceabilityReportModel;
import cn.estsh.i3plus.pojo.mes.repository.*;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import cn.estsh.impp.framework.boot.util.ResultBean;
import com.itextpdf.text.DocumentException;
import jodd.util.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -189,8 +188,8 @@ public class MesYfReportServiceImpl implements IMesYfReportService {
//生成PDF文件并上传
try {
mesTraceabilityReportModel.setUrl(MesTraceabilityTemp.getMesTraceabilityTemp(mesTraceabilityReportModel));
} catch (IOException | DocumentException e) {
MesException.throwMesBusiException("生成PDF文件失败");
} catch (IOException e) {
MesException.throwMesBusiException("删除文件:生成PDF文件失败");
}
mesTraceabilityReportModelList.add(mesTraceabilityReportModel);
}

@ -1,5 +1,6 @@
package cn.estsh.i3plus.ext.mes.apiservice.utils;
import cn.estsh.i3plus.ext.mes.apiservice.unit.exception.MesException;
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCellScanMonitorLog;
@ -11,7 +12,6 @@ import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.obs.services.model.PutObjectResult;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
@ -20,44 +20,54 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import static cn.estsh.i3plus.ext.mes.apiservice.dbinterface.WmsSAPDbQuery.lz;
public class MesTraceabilityTemp {
public static String getMesTraceabilityTemp(MesTraceabilityReportModel mesTraceabilityReportModel) throws DocumentException, IOException {
Document document = new Document();
public static String getMesTraceabilityTemp(MesTraceabilityReportModel mesTraceabilityReportModel) throws IOException {
String url = "";
File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "追溯报表orgPdf" + mesTraceabilityReportModel.getProductSn() + "-" + mesTraceabilityReportModel.getPartNo() + ".PDF");
File destFile = null;
try {
Document document = new Document(PageSize.A4);
//本地地址
//BaseFont bfChinese = BaseFont.createFont("C:\\Windows\\Fonts\\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
BaseFont bfChinese = BaseFont.createFont(MesCommonConstant.FONDS_TEMP_PATH + "SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//标题字体
Font titleFont = new Font(bfChinese, 12, Font.NORMAL);
titleFont.setColor(new BaseColor(84, 132, 216));
//白色字体
Font whiteFont = new Font(bfChinese, 8, Font.NORMAL);
whiteFont.setColor(BaseColor.WHITE);
Font valueFont = new Font(bfChinese, 8, Font.NORMAL);
valueFont.setColor(new BaseColor(78, 103, 100));
//表格上面部分的字体
Font topValueFont = new Font(bfChinese, 8, Font.NORMAL);
topValueFont.setColor(new BaseColor(0, 0, 0));
//表格字体
Font tableValueFont = new Font(bfChinese, 8, Font.NORMAL);
tableValueFont.setColor(new BaseColor(0, 0, 0));
//设备
Font equFont = new Font(bfChinese, 8, Font.NORMAL);
equFont.setColor(new BaseColor(196, 222, 249));
Font titleFont = new Font(bfChinese, 24, Font.NORMAL);
titleFont.setColor(new BaseColor(84, 132, 216));
//蓝色背景色
BaseColor backgroundColor = new BaseColor(84, 132, 216);
File file = new File(System.getProperty("java.io.tmpdir") + File.separator + mesTraceabilityReportModel.getProductSn() + "-" + mesTraceabilityReportModel.getPartNo() + "追溯报表.PDF");
//创建临时文件
file.createNewFile();
PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
//标题
Paragraph title = new Paragraph();
title.setFont(titleFont);
title.add(lz("追溯报表"));
document.add(title);
//最上面内容
PdfPTable table0 = new PdfPTable(20);
//设置间距
table0.setSpacingBefore(30);
table0.setSpacingBefore(15);
table0.setWidths(new float[]{5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f});
table0.setWidthPercentage(100);
PdfPCell totalCell00 = new PdfPCell(new Paragraph(lz("追溯报表"), titleFont));
totalCell00.setColspan(20);
totalCell00.setBorderColor(BaseColor.WHITE);
totalCell00.setFixedHeight(50f);
table0.addCell(totalCell00);
PdfPCell totalCell0 = new PdfPCell(new Paragraph(lz("工厂") + ":", whiteFont));
totalCell0.setHorizontalAlignment(Element.ALIGN_LEFT);
@ -70,7 +80,7 @@ public class MesTraceabilityTemp {
totalCell0.setBorderColor(BaseColor.WHITE);
table0.addCell(totalCell0);
PdfPCell totalCell01 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getOrganizeCode(), valueFont));
PdfPCell totalCell01 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getOrganizeCode(), topValueFont));
totalCell01.setHorizontalAlignment(Element.ALIGN_LEFT);
totalCell01.setVerticalAlignment(Element.ALIGN_MIDDLE);
totalCell01.setPaddingBottom(3);
@ -91,7 +101,7 @@ public class MesTraceabilityTemp {
totalCell02.setColspan(5);
table0.addCell(totalCell02);
PdfPCell totalCell03 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProductSn(), valueFont));
PdfPCell totalCell03 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProductSn(), topValueFont));
totalCell03.setHorizontalAlignment(Element.ALIGN_LEFT);
totalCell03.setVerticalAlignment(Element.ALIGN_MIDDLE);
totalCell03.setBorder(Rectangle.NO_BORDER);
@ -112,7 +122,7 @@ public class MesTraceabilityTemp {
totalCell04.setColspan(5);
table0.addCell(totalCell04);
PdfPCell totalCell05 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getWorkCenterCode(), valueFont));
PdfPCell totalCell05 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getWorkCenterCode(), topValueFont));
totalCell05.setHorizontalAlignment(Element.ALIGN_LEFT);
totalCell05.setVerticalAlignment(Element.ALIGN_MIDDLE);
totalCell05.setBorder(Rectangle.NO_BORDER);
@ -133,7 +143,7 @@ public class MesTraceabilityTemp {
totalCell06.setColspan(5);
table0.addCell(totalCell06);
PdfPCell totalCell07 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getPartNo(), valueFont));
PdfPCell totalCell07 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getPartNo(), topValueFont));
totalCell07.setHorizontalAlignment(Element.ALIGN_LEFT);
totalCell07.setVerticalAlignment(Element.ALIGN_MIDDLE);
totalCell07.setBorder(Rectangle.NO_BORDER);
@ -145,10 +155,15 @@ public class MesTraceabilityTemp {
document.add(table0);
Paragraph divider = new Paragraph();
divider.setFont(titleFont);
//divider.add(new Chunk("\n"));换行
divider.add("———————————————————————————————————————————");
document.add(divider);
//最上面内容
PdfPTable tableTop2 = new PdfPTable(20);
//设置间距
tableTop2.setSpacingBefore(10);
tableTop2.setSpacingBefore(5);
tableTop2.setWidths(new float[]{5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f});
tableTop2.setWidthPercentage(100);
@ -164,7 +179,7 @@ public class MesTraceabilityTemp {
tableTop2Cell00.setColspan(5);
tableTop2.addCell(tableTop2Cell00);
PdfPCell tableTop2Cell01 = new PdfPCell(new Paragraph(MesExtEnumUtil.TRACEABILITY_REPORT_PROD_TYPE.valueOfDescription(mesTraceabilityReportModel.getProdType()), valueFont));
PdfPCell tableTop2Cell01 = new PdfPCell(new Paragraph(MesExtEnumUtil.TRACEABILITY_REPORT_PROD_TYPE.valueOfDescription(mesTraceabilityReportModel.getProdType()), topValueFont));
tableTop2Cell01.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell01.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell01.setBorder(Rectangle.NO_BORDER);
@ -174,7 +189,7 @@ public class MesTraceabilityTemp {
tableTop2Cell01.setColspan(5);
tableTop2.addCell(tableTop2Cell01);
PdfPCell tableTop2Cell02 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell02 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell02.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell02.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell02.setPaddingBottom(3);
@ -184,7 +199,7 @@ public class MesTraceabilityTemp {
tableTop2Cell02.setColspan(5);
tableTop2.addCell(tableTop2Cell02);
PdfPCell tableTop2Cell03 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell03 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell03.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell03.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell03.setBorder(Rectangle.NO_BORDER);
@ -206,7 +221,7 @@ public class MesTraceabilityTemp {
tableTop2Cell10.setColspan(5);
tableTop2.addCell(tableTop2Cell10);
PdfPCell tableTop2Cell11 = new PdfPCell(new Paragraph(MesExtEnumUtil.PRODUCE_SN_STATUS.valueOfDescription(mesTraceabilityReportModel.getSnStatus()), valueFont));
PdfPCell tableTop2Cell11 = new PdfPCell(new Paragraph(MesExtEnumUtil.PRODUCE_SN_STATUS.valueOfDescription(mesTraceabilityReportModel.getSnStatus()), topValueFont));
tableTop2Cell11.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell11.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell11.setBorder(Rectangle.NO_BORDER);
@ -216,7 +231,7 @@ public class MesTraceabilityTemp {
tableTop2Cell11.setColspan(5);
tableTop2.addCell(tableTop2Cell11);
PdfPCell tableTop2Cell12 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell12 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell12.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell12.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell12.setPaddingBottom(3);
@ -226,7 +241,7 @@ public class MesTraceabilityTemp {
tableTop2Cell12.setColspan(5);
tableTop2.addCell(tableTop2Cell12);
PdfPCell tableTop2Cell14 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell14 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell14.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell14.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell14.setBorder(Rectangle.NO_BORDER);
@ -248,7 +263,7 @@ public class MesTraceabilityTemp {
tableTop2Cell20.setColspan(5);
tableTop2.addCell(tableTop2Cell20);
PdfPCell tableTop2Cell21 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProduceBegin(), valueFont));
PdfPCell tableTop2Cell21 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProduceBegin(), topValueFont));
tableTop2Cell21.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell21.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell21.setBorder(Rectangle.NO_BORDER);
@ -258,7 +273,7 @@ public class MesTraceabilityTemp {
tableTop2Cell21.setColspan(5);
tableTop2.addCell(tableTop2Cell21);
PdfPCell tableTop2Cell22 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell22 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell22.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell22.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell22.setPaddingBottom(3);
@ -268,7 +283,7 @@ public class MesTraceabilityTemp {
tableTop2Cell22.setColspan(5);
tableTop2.addCell(tableTop2Cell22);
PdfPCell tableTop2Cell24 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell24 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell24.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell24.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell24.setBorder(Rectangle.NO_BORDER);
@ -290,7 +305,7 @@ public class MesTraceabilityTemp {
tableTop2Cell30.setColspan(5);
tableTop2.addCell(tableTop2Cell30);
PdfPCell tableTop2Cell31 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProduceEnd(), valueFont));
PdfPCell tableTop2Cell31 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProduceEnd(), topValueFont));
tableTop2Cell31.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell31.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell31.setBorder(Rectangle.NO_BORDER);
@ -300,7 +315,7 @@ public class MesTraceabilityTemp {
tableTop2Cell31.setColspan(5);
tableTop2.addCell(tableTop2Cell31);
PdfPCell tableTop2Cell32 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell32 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell32.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell32.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell32.setPaddingBottom(3);
@ -310,7 +325,7 @@ public class MesTraceabilityTemp {
tableTop2Cell32.setColspan(5);
tableTop2.addCell(tableTop2Cell32);
PdfPCell tableTop2Cell34 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell34 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell34.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell34.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell34.setBorder(Rectangle.NO_BORDER);
@ -333,7 +348,7 @@ public class MesTraceabilityTemp {
tableTop2Cell40.setColspan(5);
tableTop2.addCell(tableTop2Cell40);
PdfPCell tableTop2Cell41 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getDurationStr(), valueFont));
PdfPCell tableTop2Cell41 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getDurationStr(), topValueFont));
tableTop2Cell41.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell41.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell41.setBorder(Rectangle.NO_BORDER);
@ -343,7 +358,7 @@ public class MesTraceabilityTemp {
tableTop2Cell41.setColspan(5);
tableTop2.addCell(tableTop2Cell41);
PdfPCell tableTop2Cell42 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell42 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell42.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell42.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell42.setPaddingBottom(3);
@ -353,7 +368,7 @@ public class MesTraceabilityTemp {
tableTop2Cell42.setColspan(5);
tableTop2.addCell(tableTop2Cell42);
PdfPCell tableTop2Cell44 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell44 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell44.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell44.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell44.setBorder(Rectangle.NO_BORDER);
@ -376,7 +391,7 @@ public class MesTraceabilityTemp {
tableTop2Cell50.setColspan(5);
tableTop2.addCell(tableTop2Cell50);
PdfPCell tableTop2Cell51 = new PdfPCell(new Paragraph(MesExtEnumUtil.PRODUCE_SN_STATUS.valueOfDescription(mesTraceabilityReportModel.getProdStatus()), valueFont));
PdfPCell tableTop2Cell51 = new PdfPCell(new Paragraph(MesExtEnumUtil.PRODUCE_SN_STATUS.valueOfDescription(mesTraceabilityReportModel.getProdStatus()), topValueFont));
tableTop2Cell51.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell51.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell51.setBorder(Rectangle.NO_BORDER);
@ -386,7 +401,7 @@ public class MesTraceabilityTemp {
tableTop2Cell51.setColspan(5);
tableTop2.addCell(tableTop2Cell51);
PdfPCell tableTop2Cell52 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell52 = new PdfPCell(new Paragraph("", whiteFont));
tableTop2Cell52.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell52.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell52.setPaddingBottom(3);
@ -396,7 +411,7 @@ public class MesTraceabilityTemp {
tableTop2Cell52.setColspan(5);
tableTop2.addCell(tableTop2Cell52);
PdfPCell tableTop2Cell53 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell53 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell53.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell53.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell53.setBorder(Rectangle.NO_BORDER);
@ -406,7 +421,6 @@ public class MesTraceabilityTemp {
tableTop2Cell53.setColspan(5);
tableTop2.addCell(tableTop2Cell53);
//托盘条码
PdfPCell tableTop2Cell60 = new PdfPCell(new Paragraph(lz("托盘条码") + ":", whiteFont));
tableTop2Cell60.setHorizontalAlignment(Element.ALIGN_LEFT);
@ -419,7 +433,7 @@ public class MesTraceabilityTemp {
tableTop2Cell60.setColspan(5);
tableTop2.addCell(tableTop2Cell60);
PdfPCell tableTop2Cell61 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell61 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell61.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell61.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell61.setBorder(Rectangle.NO_BORDER);
@ -429,7 +443,7 @@ public class MesTraceabilityTemp {
tableTop2Cell61.setColspan(5);
tableTop2.addCell(tableTop2Cell61);
PdfPCell tableTop2Cell62 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell62 = new PdfPCell(new Paragraph("", whiteFont));
tableTop2Cell62.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell62.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell62.setPaddingBottom(3);
@ -439,7 +453,7 @@ public class MesTraceabilityTemp {
tableTop2Cell62.setColspan(5);
tableTop2.addCell(tableTop2Cell62);
PdfPCell tableTop2Cell63 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell tableTop2Cell63 = new PdfPCell(new Paragraph("", topValueFont));
tableTop2Cell63.setHorizontalAlignment(Element.ALIGN_LEFT);
tableTop2Cell63.setVerticalAlignment(Element.ALIGN_MIDDLE);
tableTop2Cell63.setBorder(Rectangle.NO_BORDER);
@ -462,7 +476,7 @@ public class MesTraceabilityTemp {
PdfPCell equCell01 = new PdfPCell(new Paragraph(lz("设备/工艺"), whiteFont));
equCell01.setBackgroundColor(backgroundColor);
equCell01.setHorizontalAlignment(Element.ALIGN_CENTER);
equCell01.setHorizontalAlignment(Element.ALIGN_MIDDLE);
equCell01.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell01.setPaddingBottom(3);
equCell01.setPaddingTop(1);
equCell01.setColspan(1);
@ -471,7 +485,7 @@ public class MesTraceabilityTemp {
PdfPCell equCell02 = new PdfPCell(new Paragraph(lz("工艺开始时间"), whiteFont));
equCell02.setBackgroundColor(backgroundColor);
equCell02.setHorizontalAlignment(Element.ALIGN_CENTER);
equCell02.setHorizontalAlignment(Element.ALIGN_MIDDLE);
equCell02.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell02.setPaddingBottom(3);
equCell02.setPaddingTop(1);
equCell02.setColspan(1);
@ -480,7 +494,7 @@ public class MesTraceabilityTemp {
PdfPCell equCell03 = new PdfPCell(new Paragraph(lz("工艺结束时间"), whiteFont));
equCell03.setBackgroundColor(backgroundColor);
equCell03.setHorizontalAlignment(Element.ALIGN_CENTER);
equCell03.setHorizontalAlignment(Element.ALIGN_MIDDLE);
equCell03.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell03.setPaddingBottom(3);
equCell03.setPaddingTop(1);
equCell03.setColspan(1);
@ -489,7 +503,7 @@ public class MesTraceabilityTemp {
PdfPCell equCell04 = new PdfPCell(new Paragraph(lz("托盘条码"), whiteFont));
equCell04.setBackgroundColor(backgroundColor);
equCell04.setHorizontalAlignment(Element.ALIGN_CENTER);
equCell04.setHorizontalAlignment(Element.ALIGN_MIDDLE);
equCell04.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell04.setPaddingBottom(3);
equCell04.setPaddingTop(1);
equCell04.setColspan(1);
@ -514,63 +528,64 @@ public class MesTraceabilityTemp {
equtable.addCell(equCell06);
// 构建每一列
PdfPCell equCell00 = new PdfPCell(new Paragraph(dataModel.getEquipmentCode(), valueFont));
PdfPCell equCell00 = new PdfPCell(new Paragraph(dataModel.getEquipmentCode(), tableValueFont));
equCell00.setHorizontalAlignment(Element.ALIGN_LEFT);
equCell00.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell00.setColspan(7);
equtable.addCell(equCell00);
PdfPCell equCell11 = new PdfPCell(new Paragraph(dataModel.getCraftCode(), valueFont));
PdfPCell equCell11 = new PdfPCell(new Paragraph(dataModel.getCraftCode(), tableValueFont));
equCell11.setHorizontalAlignment(Element.ALIGN_CENTER);
equCell11.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell11.setPaddingBottom(3);
equCell11.setPaddingTop(1);
equtable.addCell(equCell11);
PdfPCell equCell21 = new PdfPCell(new Paragraph(dataModel.getStartDateTime(), valueFont));
PdfPCell equCell21 = new PdfPCell(new Paragraph(dataModel.getStartDateTime(), tableValueFont));
equCell21.setHorizontalAlignment(Element.ALIGN_CENTER);
equCell21.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell21.setPaddingBottom(3);
equCell21.setPaddingTop(1);
equtable.addCell(equCell21);
PdfPCell equCell31 = new PdfPCell(new Paragraph(dataModel.getCompleteDateTime(), valueFont));
PdfPCell equCell31 = new PdfPCell(new Paragraph(dataModel.getCompleteDateTime(), tableValueFont));
equCell31.setHorizontalAlignment(Element.ALIGN_CENTER);
equCell31.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell31.setPaddingBottom(3);
equCell31.setPaddingTop(1);
equtable.addCell(equCell31);
PdfPCell equCell41 = new PdfPCell(new Paragraph(dataModel.getTrayNo(), valueFont));
PdfPCell equCell41 = new PdfPCell(new Paragraph(dataModel.getTrayNo(), tableValueFont));
equCell41.setHorizontalAlignment(Element.ALIGN_CENTER);
equCell41.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell41.setPaddingBottom(3);
equCell41.setPaddingTop(1);
equtable.addCell(equCell41);
PdfPCell equCell51 = new PdfPCell(new Paragraph(dataModel.getDurationStr(), valueFont));
PdfPCell equCell51 = new PdfPCell(new Paragraph(dataModel.getDurationStr(), tableValueFont));
equCell51.setHorizontalAlignment(Element.ALIGN_CENTER);
equCell51.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell51.setPaddingBottom(3);
equCell51.setPaddingTop(1);
equtable.addCell(equCell51);
PdfPCell equCell61 = new PdfPCell(new Paragraph(CommonEnumUtil.VALID == dataModel.getIsComplete() ? "OK" : "NO", valueFont));
PdfPCell equCell61 = new PdfPCell(new Paragraph(CommonEnumUtil.VALID == dataModel.getIsComplete() ? "OK" : "NO", tableValueFont));
equCell61.setHorizontalAlignment(Element.ALIGN_CENTER);
equCell61.setVerticalAlignment(Element.ALIGN_MIDDLE);
equCell61.setPaddingBottom(3);
equCell61.setPaddingTop(1);
equtable.addCell(equCell61);
int index = 0;
if (!CollectionUtils.isEmpty(dataModel.getMesWorkCellScanMonitorLogs())) {
for (MesWorkCellScanMonitorLog log : dataModel.getMesWorkCellScanMonitorLogs()) {
// 构建每一列
PdfPCell equcontentCell00 = new PdfPCell(new Paragraph("", valueFont));
PdfPCell equcontentCell00 = new PdfPCell(new Paragraph("", tableValueFont));
equcontentCell00.setHorizontalAlignment(Element.ALIGN_LEFT);
equcontentCell00.setBorder(Rectangle.NO_BORDER);
equcontentCell00.setColspan(1);
equtable.addCell(equcontentCell00);
if(!CollectionUtils.isEmpty(dataModel.getMesWorkCellScanMonitorLogs())){
for (MesWorkCellScanMonitorLog log : dataModel.getMesWorkCellScanMonitorLogs()) {
PdfPCell equcontentCell11 = new PdfPCell(new Paragraph(log.getMessage(), valueFont));
PdfPCell equcontentCell11 = new PdfPCell(new Paragraph(log.getMessage(), tableValueFont));
equcontentCell11.setHorizontalAlignment(Element.ALIGN_CENTER);
equcontentCell11.setVerticalAlignment(Element.ALIGN_MIDDLE);
equcontentCell11.setPaddingBottom(3);
@ -585,7 +600,7 @@ public class MesTraceabilityTemp {
equcontentCell11.setColspan(4);
equtable.addCell(equcontentCell11);
PdfPCell equcontentCell21 = new PdfPCell(new Paragraph(log.getScanInfo(), valueFont));
PdfPCell equcontentCell21 = new PdfPCell(new Paragraph(log.getScanInfo(), tableValueFont));
equcontentCell21.setHorizontalAlignment(Element.ALIGN_CENTER);
equcontentCell21.setVerticalAlignment(Element.ALIGN_MIDDLE);
equcontentCell21.setPaddingBottom(3);
@ -601,7 +616,14 @@ public class MesTraceabilityTemp {
index++;
}
} else {
PdfPCell equcontentCell11 = new PdfPCell(new Paragraph(" ", valueFont));
// 构建每一列
PdfPCell equcontentCell00 = new PdfPCell(new Paragraph("", tableValueFont));
equcontentCell00.setHorizontalAlignment(Element.ALIGN_LEFT);
equcontentCell00.setBorder(Rectangle.NO_BORDER);
equcontentCell00.setColspan(1);
equtable.addCell(equcontentCell00);
PdfPCell equcontentCell11 = new PdfPCell(new Paragraph(" ", tableValueFont));
equcontentCell11.setHorizontalAlignment(Element.ALIGN_CENTER);
equcontentCell11.setVerticalAlignment(Element.ALIGN_MIDDLE);
equcontentCell11.setPaddingBottom(3);
@ -615,11 +637,18 @@ public class MesTraceabilityTemp {
}
// 关闭文档
document.close();
//添加分页
destFile = new File(PageNumPdfPageEvent.addPageNum(file.getPath(), file.getPath().replace("追溯报表orgPdf", "追溯报表")));
//文件上传
PutObjectResult result = HuaWeiOBSUtil.putObjectByMultipartFile(MesCommonConstant.OBS_BUCKET_NAME, file.getName(), convert(file));
url = HuaWeiOBSUtil.putObjectByMultipartFile(MesCommonConstant.OBS_BUCKET_NAME, destFile.getName(), convert(destFile)).getObjectUrl();
} catch (DocumentException | IOException e) {
MesException.throwMesBusiException("生成PDF文件失败");
} finally {
//删除文件
file.deleteOnExit();
return result.getObjectUrl();
Files.deleteIfExists(destFile.toPath());
Files.deleteIfExists(file.toPath());
}
return url;
}
public static MultipartFile convert(File file) throws IOException {

@ -0,0 +1,101 @@
package cn.estsh.i3plus.ext.mes.apiservice.utils;
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.mes.apiservice.util.DateUtil;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @Description : pdf
* @Reference :
* @Author : junsheng.li
* @CreateDate 2024/7/2 17:05
* @Modify:
**/
public class PageNumPdfPageEvent extends PdfPageEventHelper {
static int totalPages = 0;
@Override
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte pdfContent = writer.getDirectContent();
pdfContent.saveState();
pdfContent.beginText();
try {
int footerFontSize = 11;
//BaseFont baseFont = BaseFont.createFont("C:\\Windows\\Fonts\\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
BaseFont baseFont = BaseFont.createFont(MesCommonConstant.FONDS_TEMP_PATH + "SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font fontDetail = new Font(baseFont, footerFontSize, Font.NORMAL);
pdfContent.setFontAndSize(baseFont, footerFontSize);
/*-----------------------------添加页码-------------------------------*/
//页脚的页码 展示
String footerNum = String.format("%d", writer.getPageNumber()) + "/" + totalPages;
Phrase phrase = new Phrase(footerNum, fontDetail);
//页码 纵坐标
float y = document.bottom(-20);
//页码 横轴 坐标 居右
float pageX = document.right() - 20;
//添加文本内容,进行展示页码
ColumnText.showTextAligned(pdfContent, footerFontSize, phrase, pageX, y, 0);
/*-----------------------------添加创建时间-------------------------------*/
Phrase creatTimePhrase = new Phrase("" + DateUtil.formatDateApp(), fontDetail);
//页码 横轴 坐标 居右
float createTimeX = (document.left() + document.right()) / 2 - 100;
ColumnText.showTextAligned(pdfContent, footerFontSize, creatTimePhrase, createTimeX, y, 0);
pdfContent.endText();
pdfContent.restoreState();
} catch (DocumentException | IOException e) {
e.printStackTrace();
}
}
public static String addPageNum(String orgPdfPath, String outputPdfPath) {
Document document = null;
PdfReader reader = null;
PdfWriter write = null;
try {
FileOutputStream fos = new FileOutputStream(outputPdfPath);
document = new Document(PageSize.A4);
write = PdfWriter.getInstance(document, fos);
write.setPageEvent(new PageNumPdfPageEvent());
document.open();
PdfContentByte pdfContent = write.getDirectContent();
reader = new PdfReader(orgPdfPath);
//总页数
totalPages = reader.getNumberOfPages();
for (int i = 1; i <= totalPages; i++) {
document.newPage();
write.setPageEmpty(false);
PdfImportedPage page = write.getImportedPage(reader, i);
pdfContent.addTemplate(page, 0, 0);
}
} catch (DocumentException | IOException e) {
e.printStackTrace();
} finally {
assert document != null;
document.close();
assert reader != null;
reader.close();
write.close();
}
return outputPdfPath;
}
}
Loading…
Cancel
Save