package com.smart.trucking.service;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.smart.trucking.base.Page;
import com.smart.trucking.constant.FeeDirectionEnum;
import com.smart.trucking.constant.FeeInfoStatusEnum;
import com.smart.trucking.dao.AttachmentMapper;
import com.smart.trucking.entity.Attachment;
import com.smart.trucking.entity.MainOrders;
import com.smart.trucking.entity.vo.FeeInfoMainVo;
import com.smart.trucking.entity.vo.MainOrderDetailVo;
import com.smart.trucking.entity.vo.MainOrderFeeInfoVo;
import com.smart.trucking.entity.vo.PassingPlaceVo;
import com.smart.trucking.entity.vo.SubOrdersDetailVo;
import com.smart.trucking.param.AttachmentQueryParam;
import com.smart.trucking.param.MainOrdersQueryParam;
import com.smart.trucking.util.DateFormatUtil;
@Service
public class MainOrderPdfService {
@Autowired
private MainOrdersService mainOrdersService;
@Autowired
private AttachmentMapper attachmentMapper;
// 导出文件的路径
@Value("${spring.multipart.location}")
private String multipartLocation;
private final static String fileServer = "https://www.hswl.tech/file_server";
private final static String suffix = "?code=admin&key=1589282477226&result=ac756645a1224a0c1a7503e9e9fb350a8480c08c&system=safety_exam";
private final Font titlefont = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 10f,
Font.BOLD, BaseColor.BLACK);
private final Font contentfont = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 10f,
Font.NORMAL, BaseColor.BLACK);
private final Font chapterfont = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 20f,
Font.BOLD, BaseColor.BLACK);
private final Font sectionfont = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 15f,
Font.BOLD, BaseColor.BLACK);
private final Font textfont = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 13f,
Font.BOLD, BaseColor.BLACK);
private final Font mobiletextfont = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 13f,
Font.BOLD, BaseColor.BLACK);
public void createPdf() throws DocumentException, IOException {
MainOrdersQueryParam mainOrdersQueryParam = new MainOrdersQueryParam();
mainOrdersQueryParam.setId(264);
mainOrdersQueryParam.setOrgType(3);
MainOrderDetailVo mainOrderDetailVo = mainOrdersService.getById(mainOrdersQueryParam);
// 必须要设置字体
// 页面大小,默认A4
Rectangle pageSize = new Rectangle(PageSize.A4);
// Step 1—Create a Document.
Document doc = new Document(pageSize, 30, 30, 50, 50);
// Step 2—Get a PdfWriter instance.
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(multipartLocation + "createSamplePDF.pdf"));
// Step 3—Open the Document.
doc.open();
createProperties(doc, writer);
// Step 4—Add content.
doc.add(getTitle(mainOrderDetailVo));
doc.add(getSplit());
doc.add(getChapter("一、运单附件"));
// PdfContentByte imgC = writer.getDirectContent();
//
// AttachmentQueryParam attachmentQueryParam = new AttachmentQueryParam();
// attachmentQueryParam.setMaterialId(153);
// attachmentQueryParam.setAlias(MainOrders.class.getSimpleName());
// attachmentQueryParam.setPs(Integer.MAX_VALUE);
// List<Attachment> attachmentList =
// attachmentMapper.listQuery(attachmentQueryParam);
//
// float absolute = 0 ;
// if(attachmentList.size() > 0) {
// Attachment attachment2 = attachmentList.get(0);
// Image img = Image.getInstance(fileServer + attachment2.getFilePath()+suffix);
// img.setAbsolutePosition(absolute+=30f, 600f);
// img.scaleToFit(100f, 100f);
// // imgC.addImage(img);
// attachmentList.remove(attachment2);
// if(attachmentList.size() > 0) {
// for(Attachment attachment: attachmentList) {
// Image img2 = Image.getInstance(fileServer + attachment.getFilePath()+suffix);
// img2.setAbsolutePosition(absolute+=100f, 600f);
// img2.scaleToFit(100f, 100f);
// imgC.addImage(img2);
// }
// }
// }
// 此处的路径取附件的路径
Image img = Image.getInstance("D:/pdf/1.jpg");
img.setAbsolutePosition(30f, 600f);
img.scaleToFit(100f, 100f);
PdfContentByte imgC = writer.getDirectContent();
imgC.addImage(img);
Image img2 = Image.getInstance("D:/pdf/1.jpg");
img2.setAbsolutePosition(130f, 600f);
img2.scaleToFit(100f, 100f);
imgC.addImage(img2);
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getChapter("二、运单信息"));
doc.add(getLine());
// doc.add(getSection("(一)货主信息"));
// doc.add(getLine());
//
// doc.add(getText(" 货主名称:" +
// this.processingValue(mainOrderDetailVo.getOwnerName())));
// doc.add(getText(" 货主联系人/联系方式:" +
// this.processingValue(mainOrderDetailVo.getOwnerContacts()) + "/"
// + this.processingValue(mainOrderDetailVo.getOwnerContactsTel())));
// doc.add(getText(" 货主运费:"
// + this.processingValue(String.valueOf(mainOrderDetailVo.getOwnerFee()))));
// doc.add(getText(" 货主结算方式:" +
// this.processingValue(mainOrderDetailVo.getOwnerSettlementMethod())));
// doc.add(getText(" 承运内容/数量:" +
// this.processingValue(mainOrderDetailVo.getCargoId().toString()) + "/" +
// this.processingValue(mainOrderDetailVo.getCargoQuality())));
// doc.add(getText(" 货主备注:" +
// this.processingValue(mainOrderDetailVo.getOwnerMemo())));
// doc.add(getLine());
doc.add(getSection("(一)航运信息"));
doc.add(getLine());
doc.add(getText(" 航名/航次:" + this.processingValue(mainOrderDetailVo.getVesselVoyage())));
doc.add(getText(" 截港时间:" + this.isEmptyTime(mainOrderDetailVo.getPortEndTime())));
doc.add(getText(" 开船时间:" + this.isEmptyTime(mainOrderDetailVo.getSailingTime())));
doc.add(getText(" 目的港:" + this.processingValue(mainOrderDetailVo.getDestinationPort())));
doc.add(getText(" 截单时间:" + this.isEmptyTime(mainOrderDetailVo.getOrderEndTime())));
doc.add(getLine());
doc.add(getSection("(二)背箱信息"));
doc.add(getLine());
doc.add(getText(" 提单号:" + this.processingValue(mainOrderDetailVo.getLadingNo())));
doc.add(getText(" 场站:" + this.processingValue(mainOrderDetailVo.getSiteInfoStationSiteName())));
doc.add(getText(" 场站联系人/联系电话:" + this.processingValue(mainOrderDetailVo.getSiteInfoStationContacts()) + "/"
+ this.processingValue(mainOrderDetailVo.getSiteInfoStationContactsTel())));
// doc.add(getText(" 场站联系电话:" +
// this.processingValue(mainOrderDetailVo.getSiteInfoStationContactsTel())));
doc.add(getText(" 可背箱时间:" + this.isEmptyTime(mainOrderDetailVo.getGetContainerTime())));
doc.add(getText(" 出发地:" + this.processingValue(mainOrderDetailVo.getSiteInfoDepartureSiteName())));
doc.add(getText(" 出发地地址:" + this.processingValue(mainOrderDetailVo.getSiteInfoDepartureAddress())));
doc.add(getLine());
doc.add(getSection("(三)运单信息-回箱信息"));
doc.add(getLine());
doc.add(getText(" 回箱地:" + this.processingValue(mainOrderDetailVo.getSiteInfoContainerSiteName())));
doc.add(getText(" 回箱地址:" + this.processingValue(mainOrderDetailVo.getSiteInfoContainerAddress())));
doc.add(getLine());
doc.add(getChapter("三、装货地信息"));
doc.add(getLine());
doc.add(createPositionTable(mainOrderDetailVo));
doc.add(getLine());
doc.add(getChapter("四、承运车队"));
doc.add(getLine());
doc.add(getText(" 承运车队:" + this.processingValue(mainOrderDetailVo.getCarrierName())));
doc.add(getText(" 车队联系人/联系方式:" + this.processingValue(mainOrderDetailVo.getCarrierContacts()) + "/"
+ this.processingValue(mainOrderDetailVo.getCarrierContactsTel())));
// doc.add(getText(" 车队联系方式:" +
// this.processingValue(mainOrderDetailVo.getCarrierContactsTel())));
// doc.add(getText(" 车队结算方式:" +
// this.processingValue(mainOrderDetailVo.getCarrierSettlementMethod())));
doc.add(getText(" 车队运费/结算方式:"
+ String.valueOf(mainOrderDetailVo.getCarrierFee() != null ? mainOrderDetailVo.getCarrierFee() : 0.0)
+ "/" + this.processingValue(mainOrderDetailVo.getCarrierSettlementMethod())));
doc.add(getText(" 车队备注:" + this.processingValue(mainOrderDetailVo.getCarrierMemo())));
doc.add(getText(" 车队传真附件:"));
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
Image img3 = Image.getInstance("D:/pdf/1.jpg");
img3.setAbsolutePosition(30f, 600f);
img3.scaleToFit(100f, 100f);
imgC.addImage(img3);
Image img4 = Image.getInstance("D:/pdf/1.jpg");
img4.setAbsolutePosition(130f, 600f);
img4.scaleToFit(100f, 100f);
imgC.addImage(img4);
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getChapter("五、派车信息"));
doc.add(getLine());
doc.add(createDispatchTable(mainOrderDetailVo));
doc.add(getLine());
doc.add(getChapter("六、费用信息"));
doc.add(getLine());
doc.add(createFeeTable(mainOrderDetailVo));
doc.add(getLine());
// doc.add(new Paragraph("你好 World", font));
// Step 5—Close the Document.
doc.close();
}
public void createPdfOwner() throws DocumentException, MalformedURLException, IOException {
MainOrdersQueryParam mainOrdersQueryParam = new MainOrdersQueryParam();
mainOrdersQueryParam.setId(264);
mainOrdersQueryParam.setOrgType(3);
MainOrderDetailVo mainOrderDetailVo = mainOrdersService.getById(mainOrdersQueryParam);
// 必须要设置字体
// 页面大小,默认A4
Rectangle pageSize = new Rectangle(PageSize.A4);
// Step 1—Create a Document.
Document doc = new Document(pageSize, 30, 30, 50, 50);
// Step 2—Get a PdfWriter instance.
PdfWriter writer = PdfWriter.getInstance(doc,
new FileOutputStream(multipartLocation + "createPdfOwnerPDF.pdf"));
// Step 3—Open the Document.
doc.open();
createProperties(doc, writer);
// Step 4—Add content.
doc.add(getTitle(mainOrderDetailVo));
doc.add(getSplit());
doc.add(getChapter("一、运单附件"));
// PdfContentByte imgC = writer.getDirectContent();
//
// AttachmentQueryParam attachmentQueryParam = new AttachmentQueryParam();
// attachmentQueryParam.setMaterialId(153);
// attachmentQueryParam.setAlias(MainOrders.class.getSimpleName());
// attachmentQueryParam.setPs(Integer.MAX_VALUE);
// List<Attachment> attachmentList =
// attachmentMapper.listQuery(attachmentQueryParam);
//
// float absolute = 0 ;
// if(attachmentList.size() > 0) {
// Attachment attachment2 = attachmentList.get(0);
// Image img = Image.getInstance(fileServer + attachment2.getFilePath()+suffix);
// img.setAbsolutePosition(absolute+=30f, 600f);
// img.scaleToFit(100f, 100f);
// // imgC.addImage(img);
// attachmentList.remove(attachment2);
// if(attachmentList.size() > 0) {
// for(Attachment attachment: attachmentList) {
// Image img2 = Image.getInstance(fileServer + attachment.getFilePath()+suffix);
// img2.setAbsolutePosition(absolute+=100f, 600f);
// img2.scaleToFit(100f, 100f);
// imgC.addImage(img2);
// }
// }
// }
// 此处的路径取附件的路径
Image img = Image.getInstance("D:/pdf/1.jpg");
img.setAbsolutePosition(30f, 600f);
img.scaleToFit(100f, 100f);
PdfContentByte imgC = writer.getDirectContent();
imgC.addImage(img);
Image img2 = Image.getInstance("D:/pdf/1.jpg");
img2.setAbsolutePosition(130f, 600f);
img2.scaleToFit(100f, 100f);
imgC.addImage(img2);
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getChapter("二、运单信息"));
doc.add(getLine());
doc.add(getSection("(一)货主信息"));
doc.add(getLine());
doc.add(getText(" 货主名称:" + this.processingValue(mainOrderDetailVo.getOwnerName())));
doc.add(getText(" 货主联系人/联系方式:" + this.processingValue(mainOrderDetailVo.getOwnerContacts()) + "/"
+ this.processingValue(mainOrderDetailVo.getOwnerContactsTel())));
doc.add(getText(" 货主运费/结算方式:" + this.processingValue(String.valueOf(mainOrderDetailVo.getOwnerFee())) + "/"
+ this.processingValue(mainOrderDetailVo.getOwnerSettlementMethod())));
// doc.add(getText(" 货主结算方式:" +
// this.processingValue(mainOrderDetailVo.getOwnerSettlementMethod())));
doc.add(getText(" 承运内容/数量:" + this.processingValue(mainOrderDetailVo.getCargoId().toString()) + "/"
+ this.processingValue(mainOrderDetailVo.getCargoQuality())));
doc.add(getText(" 货主备注:" + this.processingValue(mainOrderDetailVo.getOwnerMemo())));
doc.add(getLine());
doc.add(getSection("(二)航运信息"));
doc.add(getLine());
doc.add(getText(" 航名/航次:" + this.processingValue(mainOrderDetailVo.getVesselVoyage())));
doc.add(getText(" 截港时间:" + this.isEmptyTime(mainOrderDetailVo.getPortEndTime())));
doc.add(getText(" 开船时间:" + this.isEmptyTime(mainOrderDetailVo.getSailingTime())));
doc.add(getText(" 目的港:" + this.processingValue(mainOrderDetailVo.getDestinationPort())));
doc.add(getText(" 截单时间:" + this.isEmptyTime(mainOrderDetailVo.getOrderEndTime())));
doc.add(getLine());
doc.add(getSection("(三)背箱信息"));
doc.add(getLine());
doc.add(getText(" 提单号:" + this.processingValue(mainOrderDetailVo.getLadingNo())));
doc.add(getText(" 场站:" + this.processingValue(mainOrderDetailVo.getSiteInfoStationSiteName())));
doc.add(getText(" 场站联系人/联系电话:" + this.processingValue(mainOrderDetailVo.getSiteInfoStationContacts()) + "/"
+ this.processingValue(mainOrderDetailVo.getSiteInfoStationContactsTel())));
// doc.add(getText(" 场站联系电话:" +
// this.processingValue(mainOrderDetailVo.getSiteInfoStationContactsTel())));
doc.add(getText(" 可背箱时间:" + this.isEmptyTime(mainOrderDetailVo.getGetContainerTime())));
doc.add(getText(" 出发地:" + this.processingValue(mainOrderDetailVo.getSiteInfoDepartureSiteName())));
doc.add(getText(" 出发地地址:" + this.processingValue(mainOrderDetailVo.getSiteInfoDepartureAddress())));
doc.add(getLine());
doc.add(getSection("(四)运单-回箱信息"));
doc.add(getLine());
doc.add(getText(" 回箱地:" + this.processingValue(mainOrderDetailVo.getSiteInfoContainerSiteName())));
doc.add(getText(" 回箱地址:" + this.processingValue(mainOrderDetailVo.getSiteInfoContainerAddress())));
doc.add(getLine());
doc.add(getChapter("三、装货地信息"));
doc.add(getLine());
doc.add(createPositionTable(mainOrderDetailVo));
doc.add(getLine());
// doc.add(getChapter("四、承运车队"));
// doc.add(getLine());
//
// doc.add(getText(" 承运车队:" +
// this.processingValue(mainOrderDetailVo.getCarrierName())));
// doc.add(getText(" 车队联系人:" +
// this.processingValue(mainOrderDetailVo.getCarrierContacts())));
// doc.add(getText(" 车队联系方式:" +
// this.processingValue(mainOrderDetailVo.getCarrierContactsTel())));
// doc.add(getText(" 车队结算方式:" +
// this.processingValue(mainOrderDetailVo.getCarrierSettlementMethod())));
// doc.add(getText(" 车队备注:" +
// this.processingValue(mainOrderDetailVo.getCarrierMemo())));
// doc.add(getText(" 车队运费:"
// + String.valueOf(mainOrderDetailVo.getCarrierFee() != null ?
// mainOrderDetailVo.getCarrierFee() : 0.0)));
// doc.add(getText(" 车队传真附件:"));
// doc.add(getLine());
doc.add(getChapter("四、派车信息"));
doc.add(getLine());
doc.add(createDispatchTable(mainOrderDetailVo));
doc.add(getLine());
doc.add(getChapter("五、费用信息"));
doc.add(getLine());
doc.add(createFeeTable(mainOrderDetailVo));
doc.add(getLine());
// doc.add(new Paragraph("你好 World", font));
// Step 5—Close the Document.
doc.close();
}
public void createPdfCustomerOwner() throws MalformedURLException, IOException, DocumentException {
MainOrdersQueryParam mainOrdersQueryParam = new MainOrdersQueryParam();
mainOrdersQueryParam.setId(264);
mainOrdersQueryParam.setOrgType(3);
MainOrderDetailVo mainOrderDetailVo = mainOrdersService.getById(mainOrdersQueryParam);
// 必须要设置字体
// 页面大小,默认A4
Rectangle pageSize = new Rectangle(PageSize.A4);
// Step 1—Create a Document.
Document doc = new Document(pageSize, 30, 30, 50, 50);
// Step 2—Get a PdfWriter instance.
PdfWriter writer = PdfWriter.getInstance(doc,
new FileOutputStream(multipartLocation + "createPdfCustomerOwnerPDF.pdf"));
// Step 3—Open the Document.
doc.open();
createProperties(doc, writer);
// Step 4—Add content.
doc.add(getTitle(mainOrderDetailVo));
doc.add(getSplit());
doc.add(getChapter("一、运单附件"));
// PdfContentByte imgC = writer.getDirectContent();
//
// AttachmentQueryParam attachmentQueryParam = new AttachmentQueryParam();
// attachmentQueryParam.setMaterialId(153);
// attachmentQueryParam.setAlias(MainOrders.class.getSimpleName());
// attachmentQueryParam.setPs(Integer.MAX_VALUE);
// List<Attachment> attachmentList =
// attachmentMapper.listQuery(attachmentQueryParam);
//
// float absolute = 0 ;
// if(attachmentList.size() > 0) {
// Attachment attachment2 = attachmentList.get(0);
// Image img = Image.getInstance(fileServer + attachment2.getFilePath()+suffix);
// img.setAbsolutePosition(absolute+=30f, 600f);
// img.scaleToFit(100f, 100f);
// // imgC.addImage(img);
// attachmentList.remove(attachment2);
// if(attachmentList.size() > 0) {
// for(Attachment attachment: attachmentList) {
// Image img2 = Image.getInstance(fileServer + attachment.getFilePath()+suffix);
// img2.setAbsolutePosition(absolute+=100f, 600f);
// img2.scaleToFit(100f, 100f);
// imgC.addImage(img2);
// }
// }
// }
// 此处的路径取附件的路径
Image img = Image.getInstance("D:/pdf/1.jpg");
img.setAbsolutePosition(30f, 600f);
img.scaleToFit(100f, 100f);
PdfContentByte imgC = writer.getDirectContent();
imgC.addImage(img);
Image img2 = Image.getInstance("D:/pdf/1.jpg");
img2.setAbsolutePosition(130f, 600f);
img2.scaleToFit(100f, 100f);
imgC.addImage(img2);
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getLine());
doc.add(getChapter("二、运单信息"));
doc.add(getLine());
doc.add(getSection("(一)货主信息"));
doc.add(getLine());
doc.add(getText(" 货主名称:" + this.processingValue(mainOrderDetailVo.getOwnerName())));
doc.add(getText(" 货主联系人/联系方式:" + this.processingValue(mainOrderDetailVo.getOwnerContacts()) + "/"
+ this.processingValue(mainOrderDetailVo.getOwnerContactsTel())));
doc.add(getText(" 货主运费/结算方式:" + this.processingValue(String.valueOf(mainOrderDetailVo.getOwnerFee())) + "/"
+ this.processingValue(mainOrderDetailVo.getOwnerSettlementMethod())));
// doc.add(getText(" 货主结算方式:" +
// this.processingValue(mainOrderDetailVo.getOwnerSettlementMethod())));
doc.add(getText(" 承运内容/数量:" + this.processingValue(mainOrderDetailVo.getCargoId().toString()) + "/"
+ this.processingValue(mainOrderDetailVo.getCargoQuality())));
doc.add(getText(" 货主备注:" + this.processingValue(mainOrderDetailVo.getOwnerMemo())));
doc.add(getLine());
doc.add(getSection("(二)航运信息"));
doc.add(getLine());
doc.add(getText(" 航名/航次:" + this.processingValue(mainOrderDetailVo.getVesselVoyage())));
doc.add(getText(" 截港时间:" + this.isEmptyTime(mainOrderDetailVo.getPortEndTime())));
doc.add(getText(" 开船时间:" + this.isEmptyTime(mainOrderDetailVo.getSailingTime())));
doc.add(getText(" 目的港:" + this.processingValue(mainOrderDetailVo.getDestinationPort())));
doc.add(getText(" 截单时间:" + this.isEmptyTime(mainOrderDetailVo.getOrderEndTime())));
doc.add(getLine());
doc.add(getSection("(三)背箱信息"));
doc.add(getLine());
doc.add(getText(" 提单号:" + this.processingValue(mainOrderDetailVo.getLadingNo())));
doc.add(getText(" 场站:" + this.processingValue(mainOrderDetailVo.getSiteInfoStationSiteName())));
doc.add(getText(" 场站联系人/联系电话:" + this.processingValue(mainOrderDetailVo.getSiteInfoStationContacts()) + "/"
+ this.processingValue(mainOrderDetailVo.getSiteInfoStationContactsTel())));
// doc.add(getText(" 场站联系电话:" +
// this.processingValue(mainOrderDetailVo.getSiteInfoStationContactsTel())));
doc.add(getText(" 可背箱时间:" + this.isEmptyTime(mainOrderDetailVo.getGetContainerTime())));
doc.add(getText(" 出发地:" + this.processingValue(mainOrderDetailVo.getSiteInfoDepartureSiteName())));
doc.add(getText(" 出发地地址:" + this.processingValue(mainOrderDetailVo.getSiteInfoDepartureAddress())));
doc.add(getLine());
doc.add(getSection("(四)运单信息-回箱信息"));
doc.add(getLine());
doc.add(getText(" 回箱地:" + this.processingValue(mainOrderDetailVo.getSiteInfoContainerSiteName())));
doc.add(getText(" 回箱地址:" + this.processingValue(mainOrderDetailVo.getSiteInfoContainerAddress())));
doc.add(getLine());
doc.add(getChapter("三、装货地信息"));
doc.add(getLine());
doc.add(createPositionTable(mainOrderDetailVo));
doc.add(getLine());
doc.add(getChapter("四、承运车队"));
doc.add(getLine());
doc.add(getText(" 承运车队:" + this.processingValue(mainOrderDetailVo.getCarrierName())));
doc.add(getText(" 车队联系人/联系方式:" + this.processingValue(mainOrderDetailVo.getCarrierContacts()) + "/"
+ this.processingValue(mainOrderDetailVo.getCarrierContactsTel())));
// doc.add(getText(" 车队联系方式:" +
// this.processingValue(mainOrderDetailVo.getCarrierContactsTel())));
// doc.add(getText(" 车队结算方式:" +
// this.processingValue(mainOrderDetailVo.getCarrierSettlementMethod())));
doc.add(getText(" 车队备注:" + this.processingValue(mainOrderDetailVo.getCarrierMemo())));
doc.add(getText(" 车队运费/结算方式:"
+ String.valueOf(mainOrderDetailVo.getCarrierFee() != null ? mainOrderDetailVo.getCarrierFee() : 0.0)
+ "/" + this.processingValue(mainOrderDetailVo.getCarrierSettlementMethod())));
doc.add(getText(" 车队传真附件:"));
doc.add(getLine());
doc.add(getChapter("五、派车信息"));
doc.add(getLine());
doc.add(createDispatchTable(mainOrderDetailVo));
doc.add(getLine());
doc.add(getChapter("六、费用信息"));
doc.add(getLine());
doc.add(createFeeTable(mainOrderDetailVo));
doc.add(getLine());
// doc.add(new Paragraph("你好 World", font));
// Step 5—Close the Document.
doc.close();
}
public void pdfMobileOwner() throws DocumentException, MalformedURLException, IOException {
MainOrdersQueryParam mainOrdersQueryParam = new MainOrdersQueryParam();
mainOrdersQueryParam.setOwnerId(1);
mainOrdersQueryParam.setPs(Integer.MAX_VALUE);
Page<FeeInfoMainVo> pageQueryFeeInfo = mainOrdersService.pageQueryFeeInfo(mainOrdersQueryParam);
List<FeeInfoMainVo> FeeInfoMainVoList = pageQueryFeeInfo.getContents();
// 必须要设置字体
// 页面大小,默认A4
Rectangle pageSize = new Rectangle(PageSize.A4);
// Step 1—Create a Document.
Document doc = new Document(pageSize, 30, 30, 50, 50);
// Step 2—Get a PdfWriter instance.
PdfWriter writer = PdfWriter.getInstance(doc,
new FileOutputStream(multipartLocation + "pdfMobileOwnerPDF.pdf"));
// Step 3—Open the Document.
doc.open();
createProperties(doc, writer);
// Step 4—Add content.
// doc.add(getTitle(mainOrderDetailVo));
// doc.add(getSplit());orderTime
if (FeeInfoMainVoList.size() > 0) {
for (FeeInfoMainVo feeInfoMainVo : FeeInfoMainVoList) {
doc.add(getChapter("运单单号:" + this.processingValue(feeInfoMainVo.getOrderNo()) + this.notSmallWrap()
+ "应付/未付总费用: " + "¥"
+ String.valueOf(
feeInfoMainVo.getMainFeeNumber() != null ? feeInfoMainVo.getMainFeeNumber() : 0.0)
+ "/" + String.valueOf(
feeInfoMainVo.getMainoffNumber() != null ? feeInfoMainVo.getMainoffNumber() : 0.0)));
doc.add(getLine());
doc.add(getMobileText(" 下单时间:" + this.isEmptyTime(feeInfoMainVo.getOrderTime()) + this.notWrap()
+ "负责人:" + this.processingValue(feeInfoMainVo.getAgentcontacts())));
doc.add(getMobileText(" 完成时间:" + this.isEmptyTime(feeInfoMainVo.getServiceFinishTime())
+ this.notWrap() + " 箱型/箱量:" + this.processingValue(feeInfoMainVo.getBox())));
doc.add(getMobileText(" 账期:" + this.processingValue(feeInfoMainVo.getOwnerSettlementMethod())));
doc.add(getLine());
doc.add(getMobileText(" 费用调整 "));
doc.add(getLine());
doc.add(createCostAdjustmentTable(feeInfoMainVo));
doc.add(getLine());
}
}
doc.close();
}
public void pdfMobileCarrier() throws DocumentException, MalformedURLException, IOException {
MainOrdersQueryParam mainOrdersQueryParam = new MainOrdersQueryParam();
mainOrdersQueryParam.setOwnerId(1);
mainOrdersQueryParam.setPs(Integer.MAX_VALUE);
Page<FeeInfoMainVo> pageQueryFeeInfo = mainOrdersService.pageQueryFeeInfo(mainOrdersQueryParam);
List<FeeInfoMainVo> FeeInfoMainVoList = pageQueryFeeInfo.getContents();
// 必须要设置字体
// 页面大小,默认A4
Rectangle pageSize = new Rectangle(PageSize.A4);
// Step 1—Create a Document.
Document doc = new Document(pageSize, 30, 30, 50, 50);
// Step 2—Get a PdfWriter instance.
PdfWriter writer = PdfWriter.getInstance(doc,
new FileOutputStream(multipartLocation + "pdfMobileCarrierPDF.pdf"));
// Step 3—Open the Document.
doc.open();
createProperties(doc, writer);
// Step 4—Add content.
if (FeeInfoMainVoList.size() > 0) {
for (FeeInfoMainVo feeInfoMainVo : FeeInfoMainVoList) {
doc.add(getChapter("运单单号:" + this.processingValue(feeInfoMainVo.getOrderNo()) + this.notSmallWrap()
+ "应付/未付总费用:" + "¥"
+ String.valueOf(
feeInfoMainVo.getMainFeeNumber() != null ? feeInfoMainVo.getMainFeeNumber() : 0.0)
+ "/" + String.valueOf(
feeInfoMainVo.getMainoffNumber() != null ? feeInfoMainVo.getMainoffNumber() : 0.0)));
doc.add(getLine());
doc.add(getMobileText(" 派单时间:" + this.isEmptyTime(feeInfoMainVo.getOrderTime()) + this.notWrap()
+ "负责人:" + this.processingValue(feeInfoMainVo.getAgentcontacts())));
doc.add(getMobileText(" 完成时间:" + this.isEmptyTime(feeInfoMainVo.getServiceFinishTime())
+ this.notWrap() + " 箱型/箱量:" + this.processingValue(feeInfoMainVo.getBox())));
doc.add(getMobileText(" 账期:" + this.processingValue(feeInfoMainVo.getOwnerSettlementMethod())));
doc.add(getLine());
doc.add(getMobileText(" 费用调整 "));
doc.add(getLine());
doc.add(createCostAdjustmentCarrierTable(feeInfoMainVo));
doc.add(getLine());
}
}
// doc.add(new Paragraph("你好 World", font));
// Step 5—Close the Document.
doc.close();
}
/**
* 顶部的title
*/
private Paragraph getTitle(MainOrderDetailVo mainOrderDetailVo) {
Chunk chunkSpace = new Chunk(String.join("", Collections.nCopies(40, " ")));
Paragraph paragraph = new Paragraph();
Chunk chunkTitle = new Chunk("订单号:", titlefont);
Chunk chunkContent = new Chunk(this.processingValue(mainOrderDetailVo.getOrderNo()), contentfont);
paragraph.add(chunkTitle);
paragraph.add(chunkContent);
paragraph.add(chunkSpace);
// chunkTitle = new Chunk("派单人:", titlefont);
// chunkContent = new
// Chunk(this.processingValue(mainOrderDetailVo.getAgentContacts())
// , contentfont);
// paragraph.add(chunkTitle);
// paragraph.add(chunkContent);
// paragraph.add(chunkSpace);
chunkTitle = new Chunk("派单人/联系方式:", titlefont);
chunkContent = new Chunk(this.processingValue(mainOrderDetailVo.getAgentContacts()) + "/"
+ this.processingValue(mainOrderDetailVo.getAgentContactsTel()), contentfont);
paragraph.add(chunkTitle);
paragraph.add(chunkContent);
paragraph.setAlignment(Element.ALIGN_CENTER);
return paragraph;
}
/**
* 横线
*/
private Paragraph getSplit() {
Paragraph paragraph = new Paragraph();
Chunk chunkSplit = new Chunk(String.join("", Collections.nCopies(120, "-")));
paragraph.add(chunkSplit);
paragraph.setAlignment(Element.ALIGN_CENTER);
return paragraph;
}
/**
* 大章节
*/
private Paragraph getChapter(String value) {
return new Paragraph(value, chapterfont);
}
/**
* 换行
*/
private Paragraph getLine() {
return new Paragraph(" ", chapterfont);
}
/**
* 小章节
*/
private Paragraph getSection(String value) {
return new Paragraph(value, sectionfont);
}
/**
* 正文
*/
private Paragraph getText(String value) {
return new Paragraph(value, textfont);
}
/**
* 小程序正文
*/
private Paragraph getMobileText(String value) {
return new Paragraph(value, mobiletextfont);
}
private void createProperties(Document doc, PdfWriter writer) throws DocumentException, FileNotFoundException {
// PDF版本(默认1.4)
writer.setPdfVersion(PdfWriter.PDF_VERSION_1_2);
// 文档属性
doc.addTitle("Title@sample");
doc.addAuthor("Author@rensanning");
doc.addSubject("Subject@iText sample");
doc.addKeywords("Keywords@iText");
doc.addCreator("Creator@iText");
}
/**
* 创建表 加入的字段必须都是对齐的,定义了每行cell的数量就必须对应填充够,会自动填充到下一行中
*/
private PdfPTable createPositionTable(MainOrderDetailVo mainOrderDetailVo) {
PdfPTable table = new PdfPTable(4);
table.addCell(new PdfPCell(new Phrase("地点名称", titlefont)));
table.addCell(new PdfPCell(new Phrase("地址", titlefont)));
table.addCell(new PdfPCell(new Phrase("联系电话", titlefont)));
table.addCell(new PdfPCell(new Phrase("要求到达时间", titlefont)));
if (mainOrderDetailVo.getPassingPlaceList().size() > 0) {
for (PassingPlaceVo passingPlaceVo : mainOrderDetailVo.getPassingPlaceList()) {
if (passingPlaceVo.getSiteInfoSiteName() != null) {
table.addCell(new PdfPCell(new Phrase(passingPlaceVo.getSiteInfoSiteName(), titlefont)));
} else {
table.addCell(" ");
}
if (passingPlaceVo.getSiteInfoAddress() != null) {
table.addCell(new PdfPCell(new Phrase(passingPlaceVo.getSiteInfoAddress(), titlefont)));
} else {
table.addCell(" ");
}
if (passingPlaceVo.getSiteInfoContactsTel() != null) {
table.addCell(new PdfPCell(new Phrase(passingPlaceVo.getSiteInfoContactsTel(), titlefont)));
} else {
table.addCell(" ");
}
String emptyTime4 = this.isEmptyTime(passingPlaceVo.getAskTime());
if (passingPlaceVo.getAskTime() == null) {
table.addCell(" ");
} else {
table.addCell(new PdfPCell(new Phrase(emptyTime4, titlefont)));
}
}
} else {
// 第一行填充完毕,开始第二行
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
}
// 第一行填充完毕,开始第二行
// table.addCell(" ");
// table.addCell(" ");
// table.addCell(" ");
// table.addCell(" ");
return table;
}
private PdfPTable createDispatchTable(MainOrderDetailVo mainOrderDetailVo) {
PdfPTable table = new PdfPTable(6);
table.addCell(new PdfPCell(new Phrase("海关监管", titlefont)));
table.addCell(new PdfPCell(new Phrase("箱型", titlefont)));
table.addCell(new PdfPCell(new Phrase("箱号", titlefont)));
table.addCell(new PdfPCell(new Phrase("铅封号", titlefont)));
table.addCell(new PdfPCell(new Phrase("车牌号", titlefont)));
table.addCell(new PdfPCell(new Phrase("驾驶员", titlefont)));
if (mainOrderDetailVo.getListSubOrdersDetailVo().size() > 0) {
for (SubOrdersDetailVo subOrdersDetailVo : mainOrderDetailVo.getListSubOrdersDetailVo()) {
if (subOrdersDetailVo.getSubOrdersState() != null) {
table.addCell(new PdfPCell(new Phrase(
subOrdersDetailVo.getSubOrdersState().toString().equals("0") ? "不监管" : "监管", titlefont)));
} else {
table.addCell(" ");
}
if (subOrdersDetailVo.getContainerName() != null) {
table.addCell(new PdfPCell(new Phrase(subOrdersDetailVo.getContainerName(), titlefont)));
} else {
table.addCell(" ");
}
if (subOrdersDetailVo.getContainerType() != null) {
table.addCell(new PdfPCell(new Phrase(subOrdersDetailVo.getContainerType(), titlefont)));
} else {
table.addCell(" ");
}
if (subOrdersDetailVo.getSealNo() != null) {
table.addCell(new PdfPCell(new Phrase(subOrdersDetailVo.getSealNo(), titlefont)));
} else {
table.addCell(" ");
}
if (subOrdersDetailVo.getPlateNo() != null) {
table.addCell(new PdfPCell(new Phrase(subOrdersDetailVo.getPlateNo(), titlefont)));
} else {
table.addCell(" ");
}
if (subOrdersDetailVo.getDriverName() != null) {
table.addCell(new PdfPCell(new Phrase(subOrdersDetailVo.getDriverName(), titlefont)));
} else {
table.addCell(" ");
}
}
} else {
// 第一行填充完毕,开始第二行
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
}
return table;
}
private PdfPTable createFeeTable(MainOrderDetailVo mainOrderDetailVo) {
PdfPTable table = new PdfPTable(9);
table.addCell(new PdfPCell(new Phrase("状态", titlefont)));
table.addCell(new PdfPCell(new Phrase("费用对象", titlefont)));
table.addCell(new PdfPCell(new Phrase("费用名称", titlefont)));
table.addCell(new PdfPCell(new Phrase("费用方向", titlefont)));
table.addCell(new PdfPCell(new Phrase("金额", titlefont)));
table.addCell(new PdfPCell(new Phrase("审核人/时间", titlefont)));
table.addCell(new PdfPCell(new Phrase("提报人/时间", titlefont)));
table.addCell(new PdfPCell(new Phrase("销账人/时间", titlefont)));
table.addCell(new PdfPCell(new Phrase("销账金额", titlefont)));
if (mainOrderDetailVo.getListMainFee().size() > 0) {
for (MainOrderFeeInfoVo mainOrderFeeInfoVo : mainOrderDetailVo.getListMainFee()) {
if (mainOrderFeeInfoVo.getServiceState() != null) {
table.addCell(new PdfPCell(
new Phrase(this.serviceState(mainOrderFeeInfoVo.getServiceState()), titlefont)));
} else {
table.addCell(" ");
}
if (mainOrderFeeInfoVo.getAccountName() != null) {
table.addCell(new PdfPCell(new Phrase(mainOrderFeeInfoVo.getAccountName(), titlefont)));
} else {
table.addCell(" ");
}
if (mainOrderFeeInfoVo.getFeeName() != null) {
table.addCell(new PdfPCell(new Phrase(mainOrderFeeInfoVo.getFeeName(), titlefont)));
} else {
table.addCell(" ");
}
if (mainOrderFeeInfoVo.getFeeDirection() != null) {
table.addCell(new PdfPCell(new Phrase(mainOrderFeeInfoVo.getFeeDirection().toString(), titlefont)));
} else {
table.addCell(" ");
}
if (mainOrderFeeInfoVo.getFeeNumber() != null) {
table.addCell(new PdfPCell(new Phrase(mainOrderFeeInfoVo.getFeeNumber().toString(), titlefont)));
} else {
table.addCell(" ");
}
System.err.println(mainOrderFeeInfoVo.getApprovalTime() == null);
// DateFormatUtil.dataFormat(mainOrderFeeInfoVo.getApprovalTime(),DateFormatUtil.DATA_FORMAT_ONE);
String emptyTime = this.isEmptyTime(mainOrderFeeInfoVo.getApprovalTime());
table.addCell(new PdfPCell(new Phrase(
mainOrderFeeInfoVo.getApprovalUserName() != null ? mainOrderFeeInfoVo.getApprovalUserName()
: " " + "/" + emptyTime,
titlefont)));
String emptyTime2 = this.isEmptyTime(mainOrderFeeInfoVo.getCreateTime());
table.addCell(new PdfPCell(new Phrase(
mainOrderFeeInfoVo.getCreateUserId() != null ? mainOrderFeeInfoVo.getCreateUserId().toString()
: " " + "/" + emptyTime2,
titlefont)));
String emptyTime3 = this.isEmptyTime(mainOrderFeeInfoVo.getCreateTime());
table.addCell(new PdfPCell(
new Phrase(mainOrderFeeInfoVo.getOffsetName() != null ? mainOrderFeeInfoVo.getOffsetName()
: " " + "/" + emptyTime3, titlefont)));
if (mainOrderFeeInfoVo.getOffsetFeeNumber() != null) {
table.addCell(
new PdfPCell(new Phrase(mainOrderFeeInfoVo.getOffsetFeeNumber().toString(), titlefont)));
} else {
table.addCell(" ");
}
}
} else {
// 第一行填充完毕,开始第二行
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
}
return table;
}
/**
* 创建表 加入的字段必须都是对齐的,定义了每行cell的数量就必须对应填充够,会自动填充到下一行中
*/
private PdfPTable createCostAdjustmentTable(FeeInfoMainVo feeInfoMainVo) {
PdfPTable table = new PdfPTable(3);
table.addCell(new PdfPCell(new Phrase("费用名称", titlefont)));
table.addCell(new PdfPCell(new Phrase("费用金额", titlefont)));
table.addCell(new PdfPCell(new Phrase("费用方向", titlefont)));
// 判断 费用对象是否为空 不为空让它走下边的列表循环
if (feeInfoMainVo.getListMainFee().size() > 0) {
for (MainOrderFeeInfoVo mainOrderFeeInfoVo : feeInfoMainVo.getListMainFee()) {
if (mainOrderFeeInfoVo.getFeeName() != null) {
table.addCell(new PdfPCell(new Phrase(mainOrderFeeInfoVo.getFeeName(), titlefont)));
} else {
table.addCell(" ");
}
if (mainOrderFeeInfoVo.getFeeNumber() != null) {
table.addCell(new PdfPCell(new Phrase(mainOrderFeeInfoVo.getFeeNumber().toString(), titlefont)));
} else {
table.addCell(" ");
}
if (mainOrderFeeInfoVo.getFeeDirection() != null) {
table.addCell(new PdfPCell(
new Phrase(this.feeDirection(mainOrderFeeInfoVo.getFeeDirection()), titlefont)));
} else {
table.addCell(" ");
}
}
} else {
// 第一行填充完毕,开始第二行
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
}
// 第一行填充完毕,开始第二行
// table.addCell(" ");
// table.addCell(" ");
// table.addCell(" ");
// table.addCell(" ");
return table;
}
/**
* 创建表 加入的字段必须都是对齐的,定义了每行cell的数量就必须对应填充够,会自动填充到下一行中
*/
private PdfPTable createCostAdjustmentCarrierTable(FeeInfoMainVo feeInfoMainVo) {
PdfPTable table = new PdfPTable(3);
table.addCell(new PdfPCell(new Phrase("费用名称", titlefont)));
table.addCell(new PdfPCell(new Phrase("费用金额", titlefont)));
table.addCell(new PdfPCell(new Phrase("费用方向", titlefont)));
// 判断 费用对象是否为空 不为空让它走下边的列表循环
if (feeInfoMainVo.getListMainFee().size() > 0) {
for (MainOrderFeeInfoVo mainOrderFeeInfoVo : feeInfoMainVo.getListMainFee()) {
if (mainOrderFeeInfoVo.getFeeName() != null) {
table.addCell(new PdfPCell(new Phrase(mainOrderFeeInfoVo.getFeeName(), titlefont)));
} else {
table.addCell(" ");
}
if (mainOrderFeeInfoVo.getFeeNumber() != null) {
table.addCell(new PdfPCell(new Phrase(mainOrderFeeInfoVo.getFeeNumber().toString(), titlefont)));
} else {
table.addCell(" ");
}
if (mainOrderFeeInfoVo.getFeeDirection() != null) {
table.addCell(new PdfPCell(
new Phrase(this.feeDirection(mainOrderFeeInfoVo.getFeeDirection()), titlefont)));
} else {
table.addCell(" ");
}
}
} else {
// 第一行填充完毕,开始第二行
table.addCell(" ");
table.addCell(" ");
table.addCell(" ");
}
// 第一行填充完毕,开始第二行
// table.addCell(" ");·
// table.addCell(" ");
// table.addCell(" ");
// table.addCell(" ");
return table;
}
/**
* 对费用方向状态的处理
*/
private String feeDirection(Integer feeDirection) {
switch (feeDirection) {
case 1:
return FeeDirectionEnum.RECEIVALBLE.getDesc();
case 2:
return FeeDirectionEnum.COPEWITH.getDesc();
case 3:
return FeeDirectionEnum.BOOKKEEPING.getDesc();
default:
break;
}
return null;
}
/**
* 对时间的处理
*
* @param Time
* @return
*/
private String isEmptyTime(Date Time) {
if (Time == null) {
return " ";
} else {
String dataFormat = DateFormatUtil.dataFormat(Time, DateFormatUtil.DATA_FORMAT_ONE);
return dataFormat;
}
}
/**
* 对费用信息状态的处理
*/
private String serviceState(Integer serviceState) {
switch (serviceState) {
case 0:
return FeeInfoStatusEnum.UNAPPROVAL.getContent();
case 1:
return FeeInfoStatusEnum.ONGOING.getContent();
case 2:
return FeeInfoStatusEnum.ADOPT.getContent();
case 3:
return FeeInfoStatusEnum.NON_THROUGHT.getContent();
case 4:
return FeeInfoStatusEnum.PART.getContent();
case 5:
return FeeInfoStatusEnum.ALL.getContent();
default:
break;
}
return null;
}
/**
* 对值为null 的处理
*/
private String processingValue(String value) {
if (value == null) {
return " ";
} else {
return value;
}
}
/**
* 对小程序空格 不换行处理
*/
private String notWrap() {
return " ";
}
/**
* 对小程序大标题空格 不换行处理
*/
private String notSmallWrap() {
return " ";
}
/**
* double对值为null 的处理
*/
private String processingValue(Double value) {
if (value == null) {
return " ";
} else {
return String.valueOf(value);
}
}
}