|
|
|
@ -7,6 +7,11 @@ import com.xujie.sys.common.utils.DateUtils; |
|
|
|
import com.xujie.sys.common.utils.ExcelTemplate; |
|
|
|
import com.xujie.sys.common.utils.MailUtil; |
|
|
|
import com.xujie.sys.common.utils.PageUtils; |
|
|
|
import com.aspose.cells.Workbook; |
|
|
|
import com.aspose.cells.SaveFormat; |
|
|
|
import com.aspose.cells.PageSetup; |
|
|
|
import com.aspose.cells.PageOrientationType; |
|
|
|
import com.aspose.cells.PaperSizeType; |
|
|
|
import com.xujie.sys.modules.attrbute.entity.PropertyModelHeader; |
|
|
|
import com.xujie.sys.modules.ecss.data.*; |
|
|
|
import com.xujie.sys.modules.ecss.entity.*; |
|
|
|
@ -41,6 +46,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.math.BigDecimal; |
|
|
|
@ -1834,6 +1841,135 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导出PDF格式的单证信息(不包含出口货物委托书) |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void downloadAllPdf(HttpServletResponse response, EcssDeclarationHeaderData data) { |
|
|
|
EcssCoDelNotifyHeaderData notifyHeader = coDelMapper.getEcssCoDelNotifyHeader(data.getSite(), data.getDelNo()); |
|
|
|
// RFID和RF和硬标天线使用的模版不一样 |
|
|
|
// RFID和RF如果勾选了合同,导出需要带公章(declaration-all-seal-template.xlsx) |
|
|
|
String xlsx; |
|
|
|
if (notifyHeader.getBuNo().equals("03-RFID") || notifyHeader.getBuNo().equals("01-Label")) { |
|
|
|
xlsx = "templates/declaration-all-template-pdf.xlsx"; |
|
|
|
if (data.getContractFlag()!=null && data.getContractFlag()) { |
|
|
|
xlsx = "templates/declaration-all-seal-template-pdf.xlsx"; |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 硬标天线需要po(declaration-all2-template.xlsx),且多一个合同sheet |
|
|
|
xlsx = "templates/declaration-all2-template.xlsx"; |
|
|
|
} |
|
|
|
|
|
|
|
XSSFWorkbook excelWorkbook = null; |
|
|
|
try { |
|
|
|
ExcelTemplate template = ExcelTemplate.load(new ClassPathResource(xlsx).getInputStream()); |
|
|
|
|
|
|
|
// 第一个sheet - 发票(PDF导出时跳过出口货物委托书) |
|
|
|
extractedInvoice(data, template, notifyHeader); |
|
|
|
excelWorkbook = template.render(0); |
|
|
|
|
|
|
|
// 第二个sheet - 箱单 |
|
|
|
template.clearAll(); |
|
|
|
exportPackingList(data, template, notifyHeader, 0); |
|
|
|
template.render(1); |
|
|
|
|
|
|
|
// 第三个sheet - 报关单 |
|
|
|
template.clearAll(); |
|
|
|
extractedDeclaration(data, template); |
|
|
|
template.render(2); |
|
|
|
|
|
|
|
// 第四个sheet - 申报要素 |
|
|
|
template.clearAll(); |
|
|
|
extractedElements(data, template); |
|
|
|
template.render(3); |
|
|
|
|
|
|
|
// 第五个sheet - 合同 (仅特定BU需要) |
|
|
|
if (notifyHeader.getBuNo().equals("04-MHM") || notifyHeader.getBuNo().equals("02-Hardtag")) { |
|
|
|
template.clearAll(); |
|
|
|
extractedContract(data, template); |
|
|
|
template.render(4); |
|
|
|
} |
|
|
|
|
|
|
|
// 将Excel转换为PDF |
|
|
|
byte[] pdfBytes = convertExcelToPdf(excelWorkbook); |
|
|
|
|
|
|
|
response.setContentType("application/pdf"); |
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=\"单证信息.pdf\""); |
|
|
|
response.getOutputStream().write(pdfBytes); |
|
|
|
response.flushBuffer(); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("报关导出PDF异常:{}", e.getMessage()); |
|
|
|
e.printStackTrace(); |
|
|
|
throw new RuntimeException("报关导出PDF异常:"+e.getMessage()); |
|
|
|
} finally { |
|
|
|
if (excelWorkbook != null) { |
|
|
|
try { |
|
|
|
excelWorkbook.close(); // 显式关闭资源 |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("关闭资源异常{}", e.getMessage()); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 将Excel工作簿转换为PDF字节数组 |
|
|
|
*/ |
|
|
|
private byte[] convertExcelToPdf(XSSFWorkbook excelWorkbook) throws Exception { |
|
|
|
// 创建临时文件保存Excel |
|
|
|
java.io.File tempExcelFile = java.io.File.createTempFile("temp_excel", ".xlsx"); |
|
|
|
java.io.File tempPdfFile = java.io.File.createTempFile("temp_pdf", ".pdf"); |
|
|
|
|
|
|
|
try (java.io.FileOutputStream fos = new java.io.FileOutputStream(tempExcelFile)) { |
|
|
|
excelWorkbook.write(fos); |
|
|
|
} |
|
|
|
|
|
|
|
// 使用Aspose.Cells转换Excel为PDF |
|
|
|
Workbook asposeWorkbook = new Workbook(tempExcelFile.getAbsolutePath()); |
|
|
|
|
|
|
|
// 设置PDF页面属性 |
|
|
|
for (int i = 0; i < asposeWorkbook.getWorksheets().getCount(); i++) { |
|
|
|
com.aspose.cells.Worksheet worksheet = asposeWorkbook.getWorksheets().get(i); |
|
|
|
PageSetup pageSetup = worksheet.getPageSetup(); |
|
|
|
|
|
|
|
// 设置页面方向(纵向) |
|
|
|
pageSetup.setOrientation(PageOrientationType.PORTRAIT); |
|
|
|
// 设置纸张大小(A4) |
|
|
|
pageSetup.setPaperSize(PaperSizeType.PAPER_A_4); |
|
|
|
// 设置缩放比例 |
|
|
|
pageSetup.setZoom(80); |
|
|
|
// 设置边距 |
|
|
|
pageSetup.setLeftMargin(0.5); |
|
|
|
pageSetup.setRightMargin(0.5); |
|
|
|
pageSetup.setTopMargin(0.5); |
|
|
|
pageSetup.setBottomMargin(0.5); |
|
|
|
} |
|
|
|
|
|
|
|
// 保存为PDF |
|
|
|
asposeWorkbook.save(tempPdfFile.getAbsolutePath(), SaveFormat.PDF); |
|
|
|
|
|
|
|
// 读取PDF文件为字节数组 |
|
|
|
byte[] pdfBytes; |
|
|
|
try (FileInputStream fis = new FileInputStream(tempPdfFile); |
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream()) { |
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|
int len; |
|
|
|
while ((len = fis.read(buffer)) != -1) { |
|
|
|
bos.write(buffer, 0, len); |
|
|
|
} |
|
|
|
pdfBytes = bos.toByteArray(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 清理临时文件 |
|
|
|
tempExcelFile.delete(); |
|
|
|
tempPdfFile.delete(); |
|
|
|
|
|
|
|
return pdfBytes; |
|
|
|
} |
|
|
|
|
|
|
|
private void extractedDeclaration(EcssDeclarationHeaderData data, ExcelTemplate template) { |
|
|
|
template.setMoveSeal(true); |
|
|
|
template.setDelRight(true); |
|
|
|
|