From 73350ef0b98255ce8b2944efae3755815b7ed686 Mon Sep 17 00:00:00 2001 From: jun Date: Tue, 2 Jul 2024 18:31:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=BD=E6=BA=AF=E6=8A=A5=E8=A1=A8=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/report/MesYfReportServiceImpl.java | 5 +- .../mes/apiservice/utils/MesTraceabilityTemp.java | 1205 ++++++++++---------- .../mes/apiservice/utils/PageNumPdfPageEvent.java | 101 ++ 3 files changed, 720 insertions(+), 591 deletions(-) create mode 100644 modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/PageNumPdfPageEvent.java diff --git a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/report/MesYfReportServiceImpl.java b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/report/MesYfReportServiceImpl.java index 8235734..9a32814 100644 --- a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/report/MesYfReportServiceImpl.java +++ b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/report/MesYfReportServiceImpl.java @@ -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); } diff --git a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/MesTraceabilityTemp.java b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/MesTraceabilityTemp.java index 17213dc..319be2f 100644 --- a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/MesTraceabilityTemp.java +++ b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/MesTraceabilityTemp.java @@ -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,606 +20,635 @@ 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(); - //本地地址 - //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 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 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(); - //最上面内容 - PdfPTable table0 = new PdfPTable(20); - //设置间距 - table0.setSpacingBefore(30); - 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); - totalCell0.setVerticalAlignment(Element.ALIGN_MIDDLE); - totalCell0.setPaddingBottom(3); - totalCell0.setPaddingTop(1); - totalCell0.setPaddingLeft(5); - totalCell0.setColspan(5); - totalCell0.setBackgroundColor(backgroundColor); - totalCell0.setBorderColor(BaseColor.WHITE); - table0.addCell(totalCell0); - - PdfPCell totalCell01 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getOrganizeCode(), valueFont)); - totalCell01.setHorizontalAlignment(Element.ALIGN_LEFT); - totalCell01.setVerticalAlignment(Element.ALIGN_MIDDLE); - totalCell01.setPaddingBottom(3); - totalCell01.setPaddingTop(1); - totalCell01.setPaddingLeft(5); - totalCell01.setBorder(Rectangle.NO_BORDER); - totalCell01.setColspan(5); - table0.addCell(totalCell01); - - PdfPCell totalCell02 = new PdfPCell(new Paragraph(lz("条码") + ":", whiteFont)); - totalCell02.setHorizontalAlignment(Element.ALIGN_LEFT); - totalCell02.setVerticalAlignment(Element.ALIGN_MIDDLE); - totalCell02.setPaddingBottom(3); - totalCell02.setPaddingTop(1); - totalCell02.setPaddingLeft(5); - totalCell02.setBackgroundColor(backgroundColor); - totalCell02.setBorderColor(BaseColor.WHITE); - totalCell02.setColspan(5); - table0.addCell(totalCell02); - - PdfPCell totalCell03 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProductSn(), valueFont)); - totalCell03.setHorizontalAlignment(Element.ALIGN_LEFT); - totalCell03.setVerticalAlignment(Element.ALIGN_MIDDLE); - totalCell03.setBorder(Rectangle.NO_BORDER); - totalCell03.setPaddingBottom(3); - totalCell03.setPaddingTop(1); - totalCell03.setPaddingLeft(5); - totalCell03.setColspan(5); - table0.addCell(totalCell03); - - PdfPCell totalCell04 = new PdfPCell(new Paragraph(lz("产线") + ":", whiteFont)); - totalCell04.setHorizontalAlignment(Element.ALIGN_LEFT); - totalCell04.setVerticalAlignment(Element.ALIGN_MIDDLE); - totalCell04.setPaddingBottom(3); - totalCell04.setPaddingTop(1); - totalCell04.setPaddingLeft(5); - totalCell04.setBackgroundColor(backgroundColor); - totalCell04.setBorderColor(BaseColor.WHITE); - totalCell04.setColspan(5); - table0.addCell(totalCell04); - - PdfPCell totalCell05 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getWorkCenterCode(), valueFont)); - totalCell05.setHorizontalAlignment(Element.ALIGN_LEFT); - totalCell05.setVerticalAlignment(Element.ALIGN_MIDDLE); - totalCell05.setBorder(Rectangle.NO_BORDER); - totalCell05.setPaddingBottom(3); - totalCell05.setPaddingTop(3); - totalCell05.setPaddingLeft(5); - totalCell05.setColspan(5); - table0.addCell(totalCell05); - - PdfPCell totalCell06 = new PdfPCell(new Paragraph(lz("零件号") + ":", whiteFont)); - totalCell06.setHorizontalAlignment(Element.ALIGN_LEFT); - totalCell06.setVerticalAlignment(Element.ALIGN_MIDDLE); - totalCell06.setPaddingBottom(3); - totalCell06.setPaddingTop(3); - totalCell06.setPaddingLeft(5); - totalCell06.setBackgroundColor(backgroundColor); - totalCell06.setBorderColor(BaseColor.WHITE); - totalCell06.setColspan(5); - table0.addCell(totalCell06); - - PdfPCell totalCell07 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getPartNo(), valueFont)); - totalCell07.setHorizontalAlignment(Element.ALIGN_LEFT); - totalCell07.setVerticalAlignment(Element.ALIGN_MIDDLE); - totalCell07.setBorder(Rectangle.NO_BORDER); - totalCell07.setPaddingBottom(3); - totalCell07.setPaddingTop(3); - totalCell07.setPaddingLeft(5); - totalCell07.setColspan(5); - table0.addCell(totalCell07); - - document.add(table0); - - //最上面内容 - PdfPTable tableTop2 = new PdfPTable(20); - //设置间距 - tableTop2.setSpacingBefore(10); - 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); - - //加工类型 - PdfPCell tableTop2Cell00 = new PdfPCell(new Paragraph(lz("加工类型") + ":", whiteFont)); - tableTop2Cell00.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell00.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell00.setPaddingBottom(3); - tableTop2Cell00.setPaddingTop(1); - tableTop2Cell00.setPaddingLeft(5); - tableTop2Cell00.setBackgroundColor(backgroundColor); - tableTop2Cell00.setBorderColor(BaseColor.WHITE); - tableTop2Cell00.setColspan(5); - tableTop2.addCell(tableTop2Cell00); - - PdfPCell tableTop2Cell01 = new PdfPCell(new Paragraph(MesExtEnumUtil.TRACEABILITY_REPORT_PROD_TYPE.valueOfDescription(mesTraceabilityReportModel.getProdType()), valueFont)); - tableTop2Cell01.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell01.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell01.setBorder(Rectangle.NO_BORDER); - tableTop2Cell01.setPaddingBottom(3); - tableTop2Cell01.setPaddingTop(1); - tableTop2Cell01.setPaddingLeft(5); - tableTop2Cell01.setColspan(5); - tableTop2.addCell(tableTop2Cell01); - - PdfPCell tableTop2Cell02 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell02.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell02.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell02.setPaddingBottom(3); - tableTop2Cell02.setPaddingTop(1); - tableTop2Cell02.setPaddingLeft(5); - tableTop2Cell02.setBorderColor(BaseColor.WHITE); - tableTop2Cell02.setColspan(5); - tableTop2.addCell(tableTop2Cell02); - - PdfPCell tableTop2Cell03 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell03.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell03.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell03.setBorder(Rectangle.NO_BORDER); - tableTop2Cell03.setPaddingBottom(3); - tableTop2Cell03.setPaddingTop(1); - tableTop2Cell03.setPaddingLeft(5); - tableTop2Cell03.setColspan(5); - tableTop2.addCell(tableTop2Cell03); - - //零件状态 - PdfPCell tableTop2Cell10 = new PdfPCell(new Paragraph(lz("零件状态") + ":", whiteFont)); - tableTop2Cell10.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell10.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell10.setBackgroundColor(backgroundColor); - tableTop2Cell10.setBorderColor(BaseColor.WHITE); - tableTop2Cell10.setPaddingBottom(3); - tableTop2Cell10.setPaddingTop(1); - tableTop2Cell10.setPaddingLeft(5); - tableTop2Cell10.setColspan(5); - tableTop2.addCell(tableTop2Cell10); - - PdfPCell tableTop2Cell11 = new PdfPCell(new Paragraph(MesExtEnumUtil.PRODUCE_SN_STATUS.valueOfDescription(mesTraceabilityReportModel.getSnStatus()), valueFont)); - tableTop2Cell11.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell11.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell11.setBorder(Rectangle.NO_BORDER); - tableTop2Cell11.setPaddingBottom(3); - tableTop2Cell11.setPaddingTop(1); - tableTop2Cell11.setPaddingLeft(5); - tableTop2Cell11.setColspan(5); - tableTop2.addCell(tableTop2Cell11); - - PdfPCell tableTop2Cell12 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell12.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell12.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell12.setPaddingBottom(3); - tableTop2Cell12.setPaddingTop(3); - tableTop2Cell12.setPaddingLeft(5); - tableTop2Cell12.setBorderColor(BaseColor.WHITE); - tableTop2Cell12.setColspan(5); - tableTop2.addCell(tableTop2Cell12); - - PdfPCell tableTop2Cell14 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell14.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell14.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell14.setBorder(Rectangle.NO_BORDER); - tableTop2Cell14.setPaddingBottom(3); - tableTop2Cell14.setPaddingTop(3); - tableTop2Cell14.setPaddingLeft(5); - tableTop2Cell14.setColspan(5); - tableTop2.addCell(tableTop2Cell14); - - //加工开始时间 - PdfPCell tableTop2Cell20 = new PdfPCell(new Paragraph(lz("加工开始时间") + ":", whiteFont)); - tableTop2Cell20.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell20.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell20.setBackgroundColor(backgroundColor); - tableTop2Cell20.setBorderColor(BaseColor.WHITE); - tableTop2Cell20.setPaddingBottom(3); - tableTop2Cell20.setPaddingTop(1); - tableTop2Cell20.setPaddingLeft(5); - tableTop2Cell20.setColspan(5); - tableTop2.addCell(tableTop2Cell20); - - PdfPCell tableTop2Cell21 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProduceBegin(), valueFont)); - tableTop2Cell21.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell21.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell21.setBorder(Rectangle.NO_BORDER); - tableTop2Cell21.setPaddingBottom(3); - tableTop2Cell21.setPaddingTop(1); - tableTop2Cell21.setPaddingLeft(5); - tableTop2Cell21.setColspan(5); - tableTop2.addCell(tableTop2Cell21); - - PdfPCell tableTop2Cell22 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell22.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell22.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell22.setPaddingBottom(3); - tableTop2Cell22.setPaddingTop(1); - tableTop2Cell22.setPaddingLeft(5); - tableTop2Cell22.setBorderColor(BaseColor.WHITE); - tableTop2Cell22.setColspan(5); - tableTop2.addCell(tableTop2Cell22); - - PdfPCell tableTop2Cell24 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell24.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell24.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell24.setBorder(Rectangle.NO_BORDER); - tableTop2Cell24.setPaddingBottom(3); - tableTop2Cell24.setPaddingTop(1); - tableTop2Cell24.setPaddingLeft(5); - tableTop2Cell24.setColspan(5); - tableTop2.addCell(tableTop2Cell24); - - //加工结束时间 - PdfPCell tableTop2Cell30 = new PdfPCell(new Paragraph(lz("加工结束时间") + ":", whiteFont)); - tableTop2Cell30.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell30.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell30.setBackgroundColor(backgroundColor); - tableTop2Cell30.setBorderColor(BaseColor.WHITE); - tableTop2Cell30.setPaddingBottom(3); - tableTop2Cell30.setPaddingTop(1); - tableTop2Cell30.setPaddingLeft(5); - tableTop2Cell30.setColspan(5); - tableTop2.addCell(tableTop2Cell30); - - PdfPCell tableTop2Cell31 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProduceEnd(), valueFont)); - tableTop2Cell31.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell31.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell31.setBorder(Rectangle.NO_BORDER); - tableTop2Cell31.setPaddingBottom(3); - tableTop2Cell31.setPaddingTop(1); - tableTop2Cell31.setPaddingLeft(5); - tableTop2Cell31.setColspan(5); - tableTop2.addCell(tableTop2Cell31); - - PdfPCell tableTop2Cell32 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell32.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell32.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell32.setPaddingBottom(3); - tableTop2Cell32.setPaddingTop(1); - tableTop2Cell32.setPaddingLeft(5); - tableTop2Cell32.setBorderColor(BaseColor.WHITE); - tableTop2Cell32.setColspan(5); - tableTop2.addCell(tableTop2Cell32); - - PdfPCell tableTop2Cell34 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell34.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell34.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell34.setBorder(Rectangle.NO_BORDER); - tableTop2Cell34.setPaddingBottom(3); - tableTop2Cell34.setPaddingTop(1); - tableTop2Cell34.setPaddingLeft(5); - tableTop2Cell34.setColspan(5); - tableTop2.addCell(tableTop2Cell34); - - - //持续时间 - PdfPCell tableTop2Cell40 = new PdfPCell(new Paragraph(lz("持续时间") + ":", whiteFont)); - tableTop2Cell40.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell40.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell40.setBackgroundColor(backgroundColor); - tableTop2Cell40.setBorderColor(BaseColor.WHITE); - tableTop2Cell40.setPaddingBottom(3); - tableTop2Cell40.setPaddingTop(1); - tableTop2Cell40.setPaddingLeft(5); - tableTop2Cell40.setColspan(5); - tableTop2.addCell(tableTop2Cell40); - - PdfPCell tableTop2Cell41 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getDurationStr(), valueFont)); - tableTop2Cell41.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell41.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell41.setBorder(Rectangle.NO_BORDER); - tableTop2Cell41.setPaddingBottom(3); - tableTop2Cell41.setPaddingTop(1); - tableTop2Cell41.setPaddingLeft(5); - tableTop2Cell41.setColspan(5); - tableTop2.addCell(tableTop2Cell41); - - PdfPCell tableTop2Cell42 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell42.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell42.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell42.setPaddingBottom(3); - tableTop2Cell42.setPaddingTop(1); - tableTop2Cell42.setPaddingLeft(5); - tableTop2Cell42.setBorderColor(BaseColor.WHITE); - tableTop2Cell42.setColspan(5); - tableTop2.addCell(tableTop2Cell42); - - PdfPCell tableTop2Cell44 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell44.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell44.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell44.setBorder(Rectangle.NO_BORDER); - tableTop2Cell44.setPaddingBottom(3); - tableTop2Cell44.setPaddingTop(1); - tableTop2Cell44.setPaddingLeft(5); - tableTop2Cell44.setColspan(5); - tableTop2.addCell(tableTop2Cell44); - - - //生产状态 - PdfPCell tableTop2Cell50 = new PdfPCell(new Paragraph(lz("生产状态") + ":", whiteFont)); - tableTop2Cell50.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell50.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell50.setBackgroundColor(backgroundColor); - tableTop2Cell50.setBorderColor(BaseColor.WHITE); - tableTop2Cell50.setPaddingBottom(3); - tableTop2Cell50.setPaddingTop(1); - tableTop2Cell50.setPaddingLeft(5); - tableTop2Cell50.setColspan(5); - tableTop2.addCell(tableTop2Cell50); - - PdfPCell tableTop2Cell51 = new PdfPCell(new Paragraph(MesExtEnumUtil.PRODUCE_SN_STATUS.valueOfDescription(mesTraceabilityReportModel.getProdStatus()), valueFont)); - tableTop2Cell51.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell51.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell51.setBorder(Rectangle.NO_BORDER); - tableTop2Cell51.setPaddingBottom(3); - tableTop2Cell51.setPaddingTop(1); - tableTop2Cell51.setPaddingLeft(5); - tableTop2Cell51.setColspan(5); - tableTop2.addCell(tableTop2Cell51); - - PdfPCell tableTop2Cell52 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell52.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell52.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell52.setPaddingBottom(3); - tableTop2Cell52.setPaddingTop(1); - tableTop2Cell52.setPaddingLeft(5); - tableTop2Cell52.setBorderColor(BaseColor.WHITE); - tableTop2Cell52.setColspan(5); - tableTop2.addCell(tableTop2Cell52); - - PdfPCell tableTop2Cell53 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell53.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell53.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell53.setBorder(Rectangle.NO_BORDER); - tableTop2Cell53.setPaddingBottom(3); - tableTop2Cell53.setPaddingTop(1); - tableTop2Cell53.setPaddingLeft(5); - tableTop2Cell53.setColspan(5); - tableTop2.addCell(tableTop2Cell53); - - - //托盘条码 - PdfPCell tableTop2Cell60 = new PdfPCell(new Paragraph(lz("托盘条码") + ":", whiteFont)); - tableTop2Cell60.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell60.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell60.setBackgroundColor(backgroundColor); - tableTop2Cell60.setBorderColor(BaseColor.WHITE); - tableTop2Cell60.setPaddingBottom(3); - tableTop2Cell60.setPaddingTop(1); - tableTop2Cell60.setPaddingLeft(5); - tableTop2Cell60.setColspan(5); - tableTop2.addCell(tableTop2Cell60); - - PdfPCell tableTop2Cell61 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell61.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell61.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell61.setBorder(Rectangle.NO_BORDER); - tableTop2Cell61.setPaddingBottom(3); - tableTop2Cell61.setPaddingTop(1); - tableTop2Cell61.setPaddingLeft(5); - tableTop2Cell61.setColspan(5); - tableTop2.addCell(tableTop2Cell61); - - PdfPCell tableTop2Cell62 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell62.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell62.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell62.setPaddingBottom(3); - tableTop2Cell62.setPaddingTop(1); - tableTop2Cell62.setPaddingLeft(5); - tableTop2Cell62.setBorderColor(BaseColor.WHITE); - tableTop2Cell62.setColspan(5); - tableTop2.addCell(tableTop2Cell62); - - PdfPCell tableTop2Cell63 = new PdfPCell(new Paragraph("", valueFont)); - tableTop2Cell63.setHorizontalAlignment(Element.ALIGN_LEFT); - tableTop2Cell63.setVerticalAlignment(Element.ALIGN_MIDDLE); - tableTop2Cell63.setBorder(Rectangle.NO_BORDER); - tableTop2Cell63.setPaddingBottom(3); - tableTop2Cell63.setPaddingTop(1); - tableTop2Cell63.setPaddingLeft(5); - tableTop2Cell63.setColspan(5); - tableTop2.addCell(tableTop2Cell63); - - document.add(tableTop2); - - for (MesTraceabilityReportDataModel dataModel : mesTraceabilityReportModel.getMesTraceabilityReportDataModelList()) { - //设备工艺表格 - PdfPTable equtable = new PdfPTable(6); - equtable.setSpacingBefore(10); - equtable.setWidths(new float[]{8f, 8f, 8f, 8f, 8f, 8f}); - equtable.setWidthPercentage(100); - - //表头 - PdfPCell equCell01 = new PdfPCell(new Paragraph(lz("设备/工艺"), whiteFont)); - equCell01.setBackgroundColor(backgroundColor); - equCell01.setHorizontalAlignment(Element.ALIGN_CENTER); - equCell01.setHorizontalAlignment(Element.ALIGN_MIDDLE); - equCell01.setPaddingBottom(3); - equCell01.setPaddingTop(1); - equCell01.setColspan(1); - equtable.addCell(equCell01); - - PdfPCell equCell02 = new PdfPCell(new Paragraph(lz("工艺开始时间"), whiteFont)); - equCell02.setBackgroundColor(backgroundColor); - equCell02.setHorizontalAlignment(Element.ALIGN_CENTER); - equCell02.setHorizontalAlignment(Element.ALIGN_MIDDLE); - equCell02.setPaddingBottom(3); - equCell02.setPaddingTop(1); - equCell02.setColspan(1); - equtable.addCell(equCell02); - - PdfPCell equCell03 = new PdfPCell(new Paragraph(lz("工艺结束时间"), whiteFont)); - equCell03.setBackgroundColor(backgroundColor); - equCell03.setHorizontalAlignment(Element.ALIGN_CENTER); - equCell03.setHorizontalAlignment(Element.ALIGN_MIDDLE); - equCell03.setPaddingBottom(3); - equCell03.setPaddingTop(1); - equCell03.setColspan(1); - equtable.addCell(equCell03); - - PdfPCell equCell04 = new PdfPCell(new Paragraph(lz("托盘条码"), whiteFont)); - equCell04.setBackgroundColor(backgroundColor); - equCell04.setHorizontalAlignment(Element.ALIGN_CENTER); - equCell04.setHorizontalAlignment(Element.ALIGN_MIDDLE); - equCell04.setPaddingBottom(3); - equCell04.setPaddingTop(1); - equCell04.setColspan(1); - equtable.addCell(equCell04); - - PdfPCell equCell05 = new PdfPCell(new Paragraph(lz("持续时间"), whiteFont)); - equCell05.setBackgroundColor(backgroundColor); - equCell05.setHorizontalAlignment(Element.ALIGN_CENTER); - equCell05.setVerticalAlignment(Element.ALIGN_MIDDLE); - equCell05.setPaddingBottom(3); - equCell05.setPaddingTop(1); - equCell05.setColspan(1); - equtable.addCell(equCell05); - - PdfPCell equCell06 = new PdfPCell(new Paragraph(lz("结果"), whiteFont)); - equCell06.setBackgroundColor(backgroundColor); - equCell06.setHorizontalAlignment(Element.ALIGN_CENTER); - equCell06.setVerticalAlignment(Element.ALIGN_MIDDLE); - equCell06.setPaddingBottom(3); - equCell06.setPaddingTop(1); - equCell06.setColspan(1); - equtable.addCell(equCell06); - - // 构建每一列 - PdfPCell equCell00 = new PdfPCell(new Paragraph(dataModel.getEquipmentCode(), valueFont)); - 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)); - 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)); - 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)); - 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)); - 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)); - 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)); - equCell61.setHorizontalAlignment(Element.ALIGN_CENTER); - equCell61.setVerticalAlignment(Element.ALIGN_MIDDLE); - equCell61.setPaddingBottom(3); - equCell61.setPaddingTop(1); - equtable.addCell(equCell61); - int index = 0; - // 构建每一列 - PdfPCell equcontentCell00 = new PdfPCell(new Paragraph("", valueFont)); - 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)); + 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 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)); + //蓝色背景色 + BaseColor backgroundColor = new BaseColor(84, 132, 216); + //创建临时文件 + 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(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 totalCell0 = new PdfPCell(new Paragraph(lz("工厂") + ":", whiteFont)); + totalCell0.setHorizontalAlignment(Element.ALIGN_LEFT); + totalCell0.setVerticalAlignment(Element.ALIGN_MIDDLE); + totalCell0.setPaddingBottom(3); + totalCell0.setPaddingTop(1); + totalCell0.setPaddingLeft(5); + totalCell0.setColspan(5); + totalCell0.setBackgroundColor(backgroundColor); + totalCell0.setBorderColor(BaseColor.WHITE); + table0.addCell(totalCell0); + + PdfPCell totalCell01 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getOrganizeCode(), topValueFont)); + totalCell01.setHorizontalAlignment(Element.ALIGN_LEFT); + totalCell01.setVerticalAlignment(Element.ALIGN_MIDDLE); + totalCell01.setPaddingBottom(3); + totalCell01.setPaddingTop(1); + totalCell01.setPaddingLeft(5); + totalCell01.setBorder(Rectangle.NO_BORDER); + totalCell01.setColspan(5); + table0.addCell(totalCell01); + + PdfPCell totalCell02 = new PdfPCell(new Paragraph(lz("条码") + ":", whiteFont)); + totalCell02.setHorizontalAlignment(Element.ALIGN_LEFT); + totalCell02.setVerticalAlignment(Element.ALIGN_MIDDLE); + totalCell02.setPaddingBottom(3); + totalCell02.setPaddingTop(1); + totalCell02.setPaddingLeft(5); + totalCell02.setBackgroundColor(backgroundColor); + totalCell02.setBorderColor(BaseColor.WHITE); + totalCell02.setColspan(5); + table0.addCell(totalCell02); + + PdfPCell totalCell03 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProductSn(), topValueFont)); + totalCell03.setHorizontalAlignment(Element.ALIGN_LEFT); + totalCell03.setVerticalAlignment(Element.ALIGN_MIDDLE); + totalCell03.setBorder(Rectangle.NO_BORDER); + totalCell03.setPaddingBottom(3); + totalCell03.setPaddingTop(1); + totalCell03.setPaddingLeft(5); + totalCell03.setColspan(5); + table0.addCell(totalCell03); + + PdfPCell totalCell04 = new PdfPCell(new Paragraph(lz("产线") + ":", whiteFont)); + totalCell04.setHorizontalAlignment(Element.ALIGN_LEFT); + totalCell04.setVerticalAlignment(Element.ALIGN_MIDDLE); + totalCell04.setPaddingBottom(3); + totalCell04.setPaddingTop(1); + totalCell04.setPaddingLeft(5); + totalCell04.setBackgroundColor(backgroundColor); + totalCell04.setBorderColor(BaseColor.WHITE); + totalCell04.setColspan(5); + table0.addCell(totalCell04); + + PdfPCell totalCell05 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getWorkCenterCode(), topValueFont)); + totalCell05.setHorizontalAlignment(Element.ALIGN_LEFT); + totalCell05.setVerticalAlignment(Element.ALIGN_MIDDLE); + totalCell05.setBorder(Rectangle.NO_BORDER); + totalCell05.setPaddingBottom(3); + totalCell05.setPaddingTop(3); + totalCell05.setPaddingLeft(5); + totalCell05.setColspan(5); + table0.addCell(totalCell05); + + PdfPCell totalCell06 = new PdfPCell(new Paragraph(lz("零件号") + ":", whiteFont)); + totalCell06.setHorizontalAlignment(Element.ALIGN_LEFT); + totalCell06.setVerticalAlignment(Element.ALIGN_MIDDLE); + totalCell06.setPaddingBottom(3); + totalCell06.setPaddingTop(3); + totalCell06.setPaddingLeft(5); + totalCell06.setBackgroundColor(backgroundColor); + totalCell06.setBorderColor(BaseColor.WHITE); + totalCell06.setColspan(5); + table0.addCell(totalCell06); + + PdfPCell totalCell07 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getPartNo(), topValueFont)); + totalCell07.setHorizontalAlignment(Element.ALIGN_LEFT); + totalCell07.setVerticalAlignment(Element.ALIGN_MIDDLE); + totalCell07.setBorder(Rectangle.NO_BORDER); + totalCell07.setPaddingBottom(3); + totalCell07.setPaddingTop(3); + totalCell07.setPaddingLeft(5); + totalCell07.setColspan(5); + table0.addCell(totalCell07); + + 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(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); + + //加工类型 + PdfPCell tableTop2Cell00 = new PdfPCell(new Paragraph(lz("加工类型") + ":", whiteFont)); + tableTop2Cell00.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell00.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell00.setPaddingBottom(3); + tableTop2Cell00.setPaddingTop(1); + tableTop2Cell00.setPaddingLeft(5); + tableTop2Cell00.setBackgroundColor(backgroundColor); + tableTop2Cell00.setBorderColor(BaseColor.WHITE); + tableTop2Cell00.setColspan(5); + tableTop2.addCell(tableTop2Cell00); + + 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); + tableTop2Cell01.setPaddingBottom(3); + tableTop2Cell01.setPaddingTop(1); + tableTop2Cell01.setPaddingLeft(5); + tableTop2Cell01.setColspan(5); + tableTop2.addCell(tableTop2Cell01); + + PdfPCell tableTop2Cell02 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell02.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell02.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell02.setPaddingBottom(3); + tableTop2Cell02.setPaddingTop(1); + tableTop2Cell02.setPaddingLeft(5); + tableTop2Cell02.setBorderColor(BaseColor.WHITE); + tableTop2Cell02.setColspan(5); + tableTop2.addCell(tableTop2Cell02); + + PdfPCell tableTop2Cell03 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell03.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell03.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell03.setBorder(Rectangle.NO_BORDER); + tableTop2Cell03.setPaddingBottom(3); + tableTop2Cell03.setPaddingTop(1); + tableTop2Cell03.setPaddingLeft(5); + tableTop2Cell03.setColspan(5); + tableTop2.addCell(tableTop2Cell03); + + //零件状态 + PdfPCell tableTop2Cell10 = new PdfPCell(new Paragraph(lz("零件状态") + ":", whiteFont)); + tableTop2Cell10.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell10.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell10.setBackgroundColor(backgroundColor); + tableTop2Cell10.setBorderColor(BaseColor.WHITE); + tableTop2Cell10.setPaddingBottom(3); + tableTop2Cell10.setPaddingTop(1); + tableTop2Cell10.setPaddingLeft(5); + tableTop2Cell10.setColspan(5); + tableTop2.addCell(tableTop2Cell10); + + 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); + tableTop2Cell11.setPaddingBottom(3); + tableTop2Cell11.setPaddingTop(1); + tableTop2Cell11.setPaddingLeft(5); + tableTop2Cell11.setColspan(5); + tableTop2.addCell(tableTop2Cell11); + + PdfPCell tableTop2Cell12 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell12.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell12.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell12.setPaddingBottom(3); + tableTop2Cell12.setPaddingTop(3); + tableTop2Cell12.setPaddingLeft(5); + tableTop2Cell12.setBorderColor(BaseColor.WHITE); + tableTop2Cell12.setColspan(5); + tableTop2.addCell(tableTop2Cell12); + + PdfPCell tableTop2Cell14 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell14.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell14.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell14.setBorder(Rectangle.NO_BORDER); + tableTop2Cell14.setPaddingBottom(3); + tableTop2Cell14.setPaddingTop(3); + tableTop2Cell14.setPaddingLeft(5); + tableTop2Cell14.setColspan(5); + tableTop2.addCell(tableTop2Cell14); + + //加工开始时间 + PdfPCell tableTop2Cell20 = new PdfPCell(new Paragraph(lz("加工开始时间") + ":", whiteFont)); + tableTop2Cell20.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell20.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell20.setBackgroundColor(backgroundColor); + tableTop2Cell20.setBorderColor(BaseColor.WHITE); + tableTop2Cell20.setPaddingBottom(3); + tableTop2Cell20.setPaddingTop(1); + tableTop2Cell20.setPaddingLeft(5); + tableTop2Cell20.setColspan(5); + tableTop2.addCell(tableTop2Cell20); + + PdfPCell tableTop2Cell21 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProduceBegin(), topValueFont)); + tableTop2Cell21.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell21.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell21.setBorder(Rectangle.NO_BORDER); + tableTop2Cell21.setPaddingBottom(3); + tableTop2Cell21.setPaddingTop(1); + tableTop2Cell21.setPaddingLeft(5); + tableTop2Cell21.setColspan(5); + tableTop2.addCell(tableTop2Cell21); + + PdfPCell tableTop2Cell22 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell22.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell22.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell22.setPaddingBottom(3); + tableTop2Cell22.setPaddingTop(1); + tableTop2Cell22.setPaddingLeft(5); + tableTop2Cell22.setBorderColor(BaseColor.WHITE); + tableTop2Cell22.setColspan(5); + tableTop2.addCell(tableTop2Cell22); + + PdfPCell tableTop2Cell24 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell24.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell24.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell24.setBorder(Rectangle.NO_BORDER); + tableTop2Cell24.setPaddingBottom(3); + tableTop2Cell24.setPaddingTop(1); + tableTop2Cell24.setPaddingLeft(5); + tableTop2Cell24.setColspan(5); + tableTop2.addCell(tableTop2Cell24); + + //加工结束时间 + PdfPCell tableTop2Cell30 = new PdfPCell(new Paragraph(lz("加工结束时间") + ":", whiteFont)); + tableTop2Cell30.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell30.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell30.setBackgroundColor(backgroundColor); + tableTop2Cell30.setBorderColor(BaseColor.WHITE); + tableTop2Cell30.setPaddingBottom(3); + tableTop2Cell30.setPaddingTop(1); + tableTop2Cell30.setPaddingLeft(5); + tableTop2Cell30.setColspan(5); + tableTop2.addCell(tableTop2Cell30); + + PdfPCell tableTop2Cell31 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getProduceEnd(), topValueFont)); + tableTop2Cell31.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell31.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell31.setBorder(Rectangle.NO_BORDER); + tableTop2Cell31.setPaddingBottom(3); + tableTop2Cell31.setPaddingTop(1); + tableTop2Cell31.setPaddingLeft(5); + tableTop2Cell31.setColspan(5); + tableTop2.addCell(tableTop2Cell31); + + PdfPCell tableTop2Cell32 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell32.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell32.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell32.setPaddingBottom(3); + tableTop2Cell32.setPaddingTop(1); + tableTop2Cell32.setPaddingLeft(5); + tableTop2Cell32.setBorderColor(BaseColor.WHITE); + tableTop2Cell32.setColspan(5); + tableTop2.addCell(tableTop2Cell32); + + PdfPCell tableTop2Cell34 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell34.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell34.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell34.setBorder(Rectangle.NO_BORDER); + tableTop2Cell34.setPaddingBottom(3); + tableTop2Cell34.setPaddingTop(1); + tableTop2Cell34.setPaddingLeft(5); + tableTop2Cell34.setColspan(5); + tableTop2.addCell(tableTop2Cell34); + + + //持续时间 + PdfPCell tableTop2Cell40 = new PdfPCell(new Paragraph(lz("持续时间") + ":", whiteFont)); + tableTop2Cell40.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell40.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell40.setBackgroundColor(backgroundColor); + tableTop2Cell40.setBorderColor(BaseColor.WHITE); + tableTop2Cell40.setPaddingBottom(3); + tableTop2Cell40.setPaddingTop(1); + tableTop2Cell40.setPaddingLeft(5); + tableTop2Cell40.setColspan(5); + tableTop2.addCell(tableTop2Cell40); + + PdfPCell tableTop2Cell41 = new PdfPCell(new Paragraph(mesTraceabilityReportModel.getDurationStr(), topValueFont)); + tableTop2Cell41.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell41.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell41.setBorder(Rectangle.NO_BORDER); + tableTop2Cell41.setPaddingBottom(3); + tableTop2Cell41.setPaddingTop(1); + tableTop2Cell41.setPaddingLeft(5); + tableTop2Cell41.setColspan(5); + tableTop2.addCell(tableTop2Cell41); + + PdfPCell tableTop2Cell42 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell42.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell42.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell42.setPaddingBottom(3); + tableTop2Cell42.setPaddingTop(1); + tableTop2Cell42.setPaddingLeft(5); + tableTop2Cell42.setBorderColor(BaseColor.WHITE); + tableTop2Cell42.setColspan(5); + tableTop2.addCell(tableTop2Cell42); + + PdfPCell tableTop2Cell44 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell44.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell44.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell44.setBorder(Rectangle.NO_BORDER); + tableTop2Cell44.setPaddingBottom(3); + tableTop2Cell44.setPaddingTop(1); + tableTop2Cell44.setPaddingLeft(5); + tableTop2Cell44.setColspan(5); + tableTop2.addCell(tableTop2Cell44); + + + //生产状态 + PdfPCell tableTop2Cell50 = new PdfPCell(new Paragraph(lz("生产状态") + ":", whiteFont)); + tableTop2Cell50.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell50.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell50.setBackgroundColor(backgroundColor); + tableTop2Cell50.setBorderColor(BaseColor.WHITE); + tableTop2Cell50.setPaddingBottom(3); + tableTop2Cell50.setPaddingTop(1); + tableTop2Cell50.setPaddingLeft(5); + tableTop2Cell50.setColspan(5); + tableTop2.addCell(tableTop2Cell50); + + 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); + tableTop2Cell51.setPaddingBottom(3); + tableTop2Cell51.setPaddingTop(1); + tableTop2Cell51.setPaddingLeft(5); + tableTop2Cell51.setColspan(5); + tableTop2.addCell(tableTop2Cell51); + + PdfPCell tableTop2Cell52 = new PdfPCell(new Paragraph("", whiteFont)); + tableTop2Cell52.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell52.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell52.setPaddingBottom(3); + tableTop2Cell52.setPaddingTop(1); + tableTop2Cell52.setPaddingLeft(5); + tableTop2Cell52.setBorderColor(BaseColor.WHITE); + tableTop2Cell52.setColspan(5); + tableTop2.addCell(tableTop2Cell52); + + PdfPCell tableTop2Cell53 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell53.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell53.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell53.setBorder(Rectangle.NO_BORDER); + tableTop2Cell53.setPaddingBottom(3); + tableTop2Cell53.setPaddingTop(1); + tableTop2Cell53.setPaddingLeft(5); + tableTop2Cell53.setColspan(5); + tableTop2.addCell(tableTop2Cell53); + + //托盘条码 + PdfPCell tableTop2Cell60 = new PdfPCell(new Paragraph(lz("托盘条码") + ":", whiteFont)); + tableTop2Cell60.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell60.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell60.setBackgroundColor(backgroundColor); + tableTop2Cell60.setBorderColor(BaseColor.WHITE); + tableTop2Cell60.setPaddingBottom(3); + tableTop2Cell60.setPaddingTop(1); + tableTop2Cell60.setPaddingLeft(5); + tableTop2Cell60.setColspan(5); + tableTop2.addCell(tableTop2Cell60); + + PdfPCell tableTop2Cell61 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell61.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell61.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell61.setBorder(Rectangle.NO_BORDER); + tableTop2Cell61.setPaddingBottom(3); + tableTop2Cell61.setPaddingTop(1); + tableTop2Cell61.setPaddingLeft(5); + tableTop2Cell61.setColspan(5); + tableTop2.addCell(tableTop2Cell61); + + PdfPCell tableTop2Cell62 = new PdfPCell(new Paragraph("", whiteFont)); + tableTop2Cell62.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell62.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell62.setPaddingBottom(3); + tableTop2Cell62.setPaddingTop(1); + tableTop2Cell62.setPaddingLeft(5); + tableTop2Cell62.setBorderColor(BaseColor.WHITE); + tableTop2Cell62.setColspan(5); + tableTop2.addCell(tableTop2Cell62); + + PdfPCell tableTop2Cell63 = new PdfPCell(new Paragraph("", topValueFont)); + tableTop2Cell63.setHorizontalAlignment(Element.ALIGN_LEFT); + tableTop2Cell63.setVerticalAlignment(Element.ALIGN_MIDDLE); + tableTop2Cell63.setBorder(Rectangle.NO_BORDER); + tableTop2Cell63.setPaddingBottom(3); + tableTop2Cell63.setPaddingTop(1); + tableTop2Cell63.setPaddingLeft(5); + tableTop2Cell63.setColspan(5); + tableTop2.addCell(tableTop2Cell63); + + document.add(tableTop2); + + for (MesTraceabilityReportDataModel dataModel : mesTraceabilityReportModel.getMesTraceabilityReportDataModelList()) { + //设备工艺表格 + PdfPTable equtable = new PdfPTable(6); + equtable.setSpacingBefore(10); + equtable.setWidths(new float[]{8f, 8f, 8f, 8f, 8f, 8f}); + equtable.setWidthPercentage(100); + + //表头 + PdfPCell equCell01 = new PdfPCell(new Paragraph(lz("设备/工艺"), whiteFont)); + equCell01.setBackgroundColor(backgroundColor); + equCell01.setHorizontalAlignment(Element.ALIGN_CENTER); + equCell01.setVerticalAlignment(Element.ALIGN_MIDDLE); + equCell01.setPaddingBottom(3); + equCell01.setPaddingTop(1); + equCell01.setColspan(1); + equtable.addCell(equCell01); + + PdfPCell equCell02 = new PdfPCell(new Paragraph(lz("工艺开始时间"), whiteFont)); + equCell02.setBackgroundColor(backgroundColor); + equCell02.setHorizontalAlignment(Element.ALIGN_CENTER); + equCell02.setVerticalAlignment(Element.ALIGN_MIDDLE); + equCell02.setPaddingBottom(3); + equCell02.setPaddingTop(1); + equCell02.setColspan(1); + equtable.addCell(equCell02); + + PdfPCell equCell03 = new PdfPCell(new Paragraph(lz("工艺结束时间"), whiteFont)); + equCell03.setBackgroundColor(backgroundColor); + equCell03.setHorizontalAlignment(Element.ALIGN_CENTER); + equCell03.setVerticalAlignment(Element.ALIGN_MIDDLE); + equCell03.setPaddingBottom(3); + equCell03.setPaddingTop(1); + equCell03.setColspan(1); + equtable.addCell(equCell03); + + PdfPCell equCell04 = new PdfPCell(new Paragraph(lz("托盘条码"), whiteFont)); + equCell04.setBackgroundColor(backgroundColor); + equCell04.setHorizontalAlignment(Element.ALIGN_CENTER); + equCell04.setVerticalAlignment(Element.ALIGN_MIDDLE); + equCell04.setPaddingBottom(3); + equCell04.setPaddingTop(1); + equCell04.setColspan(1); + equtable.addCell(equCell04); + + PdfPCell equCell05 = new PdfPCell(new Paragraph(lz("持续时间"), whiteFont)); + equCell05.setBackgroundColor(backgroundColor); + equCell05.setHorizontalAlignment(Element.ALIGN_CENTER); + equCell05.setVerticalAlignment(Element.ALIGN_MIDDLE); + equCell05.setPaddingBottom(3); + equCell05.setPaddingTop(1); + equCell05.setColspan(1); + equtable.addCell(equCell05); + + PdfPCell equCell06 = new PdfPCell(new Paragraph(lz("结果"), whiteFont)); + equCell06.setBackgroundColor(backgroundColor); + equCell06.setHorizontalAlignment(Element.ALIGN_CENTER); + equCell06.setVerticalAlignment(Element.ALIGN_MIDDLE); + equCell06.setPaddingBottom(3); + equCell06.setPaddingTop(1); + equCell06.setColspan(1); + equtable.addCell(equCell06); + + // 构建每一列 + 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(), 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(), 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(), 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(), 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(), 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", 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("", tableValueFont)); + equcontentCell00.setHorizontalAlignment(Element.ALIGN_LEFT); + equcontentCell00.setBorder(Rectangle.NO_BORDER); + equcontentCell00.setColspan(1); + equtable.addCell(equcontentCell00); + + PdfPCell equcontentCell11 = new PdfPCell(new Paragraph(log.getMessage(), tableValueFont)); + equcontentCell11.setHorizontalAlignment(Element.ALIGN_CENTER); + equcontentCell11.setVerticalAlignment(Element.ALIGN_MIDDLE); + equcontentCell11.setPaddingBottom(3); + equcontentCell11.setPaddingTop(1); + + if (index % 2 == 0) { + equcontentCell11.setBackgroundColor(new BaseColor(253, 239, 192));//黄色 + } else { + equcontentCell11.setBackgroundColor(BaseColor.WHITE);//白色 + } + + equcontentCell11.setColspan(4); + equtable.addCell(equcontentCell11); + + PdfPCell equcontentCell21 = new PdfPCell(new Paragraph(log.getScanInfo(), tableValueFont)); + equcontentCell21.setHorizontalAlignment(Element.ALIGN_CENTER); + equcontentCell21.setVerticalAlignment(Element.ALIGN_MIDDLE); + equcontentCell21.setPaddingBottom(3); + equcontentCell21.setPaddingTop(1); + + if (index % 2 == 0) { + equcontentCell21.setBackgroundColor(new BaseColor(253, 239, 192));//黄色 + } else { + equcontentCell21.setBackgroundColor(BaseColor.WHITE);//白色 + } + equcontentCell21.setColspan(2); + equtable.addCell(equcontentCell21); + index++; + } + } else { + // 构建每一列 + 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); equcontentCell11.setPaddingTop(1); - - if (index % 2 == 0) { - equcontentCell11.setBackgroundColor(new BaseColor(253, 239, 192));//黄色 - } else { - equcontentCell11.setBackgroundColor(BaseColor.WHITE);//白色 - } - - equcontentCell11.setColspan(4); + equcontentCell11.setBackgroundColor(new BaseColor(253, 239, 192));//黄色 + equcontentCell11.setColspan(8); equtable.addCell(equcontentCell11); - - PdfPCell equcontentCell21 = new PdfPCell(new Paragraph(log.getScanInfo(), valueFont)); - equcontentCell21.setHorizontalAlignment(Element.ALIGN_CENTER); - equcontentCell21.setVerticalAlignment(Element.ALIGN_MIDDLE); - equcontentCell21.setPaddingBottom(3); - equcontentCell21.setPaddingTop(1); - - if (index % 2 == 0) { - equcontentCell21.setBackgroundColor(new BaseColor(253, 239, 192));//黄色 - } else { - equcontentCell21.setBackgroundColor(BaseColor.WHITE);//白色 - } - equcontentCell21.setColspan(2); - equtable.addCell(equcontentCell21); - index++; } - }else { - PdfPCell equcontentCell11 = new PdfPCell(new Paragraph(" ", valueFont)); - equcontentCell11.setHorizontalAlignment(Element.ALIGN_CENTER); - equcontentCell11.setVerticalAlignment(Element.ALIGN_MIDDLE); - equcontentCell11.setPaddingBottom(3); - equcontentCell11.setPaddingTop(1); - equcontentCell11.setBackgroundColor(new BaseColor(253, 239, 192));//黄色 - equcontentCell11.setColspan(8); - equtable.addCell(equcontentCell11); - } - document.add(equtable); + document.add(equtable); + } + // 关闭文档 + document.close(); + //添加分页 + destFile = new File(PageNumPdfPageEvent.addPageNum(file.getPath(), file.getPath().replace("追溯报表orgPdf", "追溯报表"))); + //文件上传 + url = HuaWeiOBSUtil.putObjectByMultipartFile(MesCommonConstant.OBS_BUCKET_NAME, destFile.getName(), convert(destFile)).getObjectUrl(); + } catch (DocumentException | IOException e) { + MesException.throwMesBusiException("生成PDF文件失败"); + } finally { + //删除文件 + Files.deleteIfExists(destFile.toPath()); + Files.deleteIfExists(file.toPath()); } - // 关闭文档 - document.close(); - //文件上传 - PutObjectResult result = HuaWeiOBSUtil.putObjectByMultipartFile(MesCommonConstant.OBS_BUCKET_NAME, file.getName(), convert(file)); - //删除文件 - file.deleteOnExit(); - return result.getObjectUrl(); + return url; } public static MultipartFile convert(File file) throws IOException { diff --git a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/PageNumPdfPageEvent.java b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/PageNumPdfPageEvent.java new file mode 100644 index 0000000..006e296 --- /dev/null +++ b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/PageNumPdfPageEvent.java @@ -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; + + } + +}