From b5cef50c53bbd69d29543d96bc51511ec90987d1 Mon Sep 17 00:00:00 2001
From: jiangxiaoming <7548901@qq.com>
Date: Sun, 1 Sep 2024 15:50:08 +0800
Subject: [PATCH] =?UTF-8?q?pdf=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?=
 =?UTF-8?q?=E7=BB=93=E6=9D=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../query/dto/out/InvoiceDetailOut.java       |   1 +
 .../command/EntryCommandServiceImpl.java      |  11 +-
 .../mapper/xml/IncomeMapper.xml               |   1 +
 .../controller/EntryBillControllerImpl.java   |  15 +-
 .../seasky/ledgerincome/utils/FileUtil.java   | 337 +++++++++++-------
 5 files changed, 214 insertions(+), 151 deletions(-)

diff --git a/ServiceSite/facade/src/main/java/com/seasky/ledgerincome/application/query/dto/out/InvoiceDetailOut.java b/ServiceSite/facade/src/main/java/com/seasky/ledgerincome/application/query/dto/out/InvoiceDetailOut.java
index 0def17a4..ac65121c 100644
--- a/ServiceSite/facade/src/main/java/com/seasky/ledgerincome/application/query/dto/out/InvoiceDetailOut.java
+++ b/ServiceSite/facade/src/main/java/com/seasky/ledgerincome/application/query/dto/out/InvoiceDetailOut.java
@@ -9,6 +9,7 @@ import java.math.BigDecimal;
 @NoArgsConstructor
 @Data
 public class InvoiceDetailOut {
+    private Integer rowIndex;
     public String itemCode;
     public String itemName;
     public String standards;
diff --git a/ServiceSite/src/main/java/com/seasky/ledgerincome/application/command/EntryCommandServiceImpl.java b/ServiceSite/src/main/java/com/seasky/ledgerincome/application/command/EntryCommandServiceImpl.java
index 59fcc821..d7898c8f 100644
--- a/ServiceSite/src/main/java/com/seasky/ledgerincome/application/command/EntryCommandServiceImpl.java
+++ b/ServiceSite/src/main/java/com/seasky/ledgerincome/application/command/EntryCommandServiceImpl.java
@@ -386,17 +386,14 @@ public class EntryCommandServiceImpl extends BaseControllerImpl implements Entry
 
     @Override
     public void downloadVoucherPDF(Long incomeId) throws IOException, DocumentException {
-        VoucherOut voucherOut=incomeQueryService.selectVoucher(incomeId);
-        if(voucherOut == null){
-            throw new RuntimeException("鏈煡璇㈠埌鍥炲崟鍑瘉");
+        IncomeAggregate incomeAggregate = incomeRepository.findById(incomeId);
+        if(incomeAggregate == null){
+            throw new RuntimeException("鏈煡璇㈠埌鍥炲崟");
         }
         ClassLoader classLoader = getClass().getClassLoader();
         URL resourceURL = classLoader.getResource("arialuni.ttf");
         String filePath = resourceURL.getPath();
         String userName  = getLoginInfoOut().getUserName();
-        IncomeAggregate incomeAggregate = incomeRepository.findById(incomeId);
-        String billNo = incomeAggregate.getReceiptBillVo().getBillNo();
-        voucherOut.setBillNo(billNo);
-        //FileUtil.downloadVoucherPDF(response,filePath,voucherOut,userName);
+        FileUtil.downloadVoucherPDF(filePath,"灏忔爣棰�",userName,incomeAggregate);
     }
 }
diff --git a/ServiceSite/src/main/java/com/seasky/ledgerincome/infrastructure/mapper/xml/IncomeMapper.xml b/ServiceSite/src/main/java/com/seasky/ledgerincome/infrastructure/mapper/xml/IncomeMapper.xml
index f2d7ab63..87d38eeb 100644
--- a/ServiceSite/src/main/java/com/seasky/ledgerincome/infrastructure/mapper/xml/IncomeMapper.xml
+++ b/ServiceSite/src/main/java/com/seasky/ledgerincome/infrastructure/mapper/xml/IncomeMapper.xml
@@ -428,6 +428,7 @@ select *from t_income
         <result column="invoice_date" property="invoiceDate"></result>
         <result column="invoice_type" property="invoiceType"></result>
         <collection property="detailOutList" ofType="com.seasky.ledgerincome.application.query.dto.out.InvoiceDetailOut">
+            <result column="row_index" property="rowIndex"></result>
             <result column="item_code" property="itemCode"></result>
             <result column="item_name" property="itemName"></result>
             <result column="standards" property="standards"></result>
diff --git a/ServiceSite/src/main/java/com/seasky/ledgerincome/interfaces/controller/EntryBillControllerImpl.java b/ServiceSite/src/main/java/com/seasky/ledgerincome/interfaces/controller/EntryBillControllerImpl.java
index 7f33f6b5..99978677 100644
--- a/ServiceSite/src/main/java/com/seasky/ledgerincome/interfaces/controller/EntryBillControllerImpl.java
+++ b/ServiceSite/src/main/java/com/seasky/ledgerincome/interfaces/controller/EntryBillControllerImpl.java
@@ -23,52 +23,51 @@ public class EntryBillControllerImpl implements EntryBillController {
 
     @Autowired
     EntryCommandService entryCommandService;
-    @LogOperation("鍏ヨ处-鏀舵鏆傚瓨")
+    @LogOperation("鍏ヨ处鐢宠-鏀舵鏆傚瓨")
     @Override
     public Result<Object> storageTemp(Long incomeId) {
         entryCommandService.storageTemp(incomeId);
         return Response.success();    }
 
-    @LogOperation("鍏ヨ处-鏆傚瓨杞敹鍏�")
+    @LogOperation("鍏ヨ处鐢宠-鏆傚瓨杞敹鍏�")
     @Override
     public Result<Object> entryTemp(EntryTempCmd cmd) {
         entryCommandService.entryTemp(cmd);
         return Response.success();
     }
 
-    @LogOperation("鍏ヨ处-鏆傚瓨杞敹鍏ワ紙寮€绁級")
+    @LogOperation("鍏ヨ处鐢宠-鏆傚瓨杞敹鍏ワ紙寮€绁級")
     @Override
     public Result<Object> entryTempWithInvoice(SuppInvoiceCmd cmd) {
         entryCommandService.entryTempWithInvoice(cmd);
         return Response.success();
     }
 
-    @LogOperation("鍏ヨ处-鏆傚瓨杞敹鍏ワ紙棰勫紑绁級")
+    @LogOperation("鍏ヨ处鐢宠-鏆傚瓨杞敹鍏ワ紙棰勫紑绁級")
     @Override
     public Result<Object> entryTempLinkInvoice(EntryTempCmd cmd) {
         entryCommandService.entryTempLinkInvoice(cmd);
         return Response.success();
     }
 
-    @LogOperation("鍏ヨ处-纭鏀跺叆")
+    @LogOperation("鍏ヨ处鐢宠-纭鏀跺叆")
     @Override
     public Result<Object> entryIncome(EntryTempCmd cmd) {
         entryCommandService.entryIncome(cmd);
         return Response.success();
     }
-    @LogOperation("鍏ヨ处-纭鏀跺叆锛堝紑绁級")
+    @LogOperation("鍏ヨ处鐢宠-纭鏀跺叆锛堝紑绁級")
     @Override
     public Result<Object> entryIncomeWithInvoice(SuppInvoiceCmd cmd) {
         entryCommandService.entryIncomeWithInvoice(cmd);
         return Response.success();
     }
-    @LogOperation("鍏ヨ处-纭鏀跺叆锛堥寮€绁級")
+    @LogOperation("鍏ヨ处鐢宠-纭鏀跺叆锛堥寮€绁級")
     @Override
     public Result<Object> entryIncomeLinkInvoice(EntryTempCmd cmd) {
         entryCommandService.entryIncomeLinkInvoice(cmd);
         return Response.success();
     }
-    @LogOperation("鍏ヨ处-鎺ㄩ€佸嚟璇�")
     @Override
     public Result<Object> downloadVoucherPDF(Long incomeId) throws Exception {
         entryCommandService.downloadVoucherPDF(incomeId);
diff --git a/ServiceSite/src/main/java/com/seasky/ledgerincome/utils/FileUtil.java b/ServiceSite/src/main/java/com/seasky/ledgerincome/utils/FileUtil.java
index d1f9cea0..c01e76f8 100644
--- a/ServiceSite/src/main/java/com/seasky/ledgerincome/utils/FileUtil.java
+++ b/ServiceSite/src/main/java/com/seasky/ledgerincome/utils/FileUtil.java
@@ -1,10 +1,8 @@
 package com.seasky.ledgerincome.utils;
 
 import com.itextpdf.text.*;
-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.itextpdf.text.pdf.*;
+import com.itextpdf.text.pdf.draw.LineSeparator;
 import com.seasky.core.common.SpringContainer;
 import com.seasky.core.ddd.middleground.application.query.api.InstanceQueryService;
 import com.seasky.ledgerincome.application.command.api.FileCommandService;
@@ -123,176 +121,243 @@ public class FileUtil  {
         }
     }
 
-    public static void downloadVoucherPDF(String ttfFilePath, String userName, IncomeAggregate incomeAggregate) throws IOException, DocumentException {
+    public static void downloadVoucherPDF(String ttfFilePath, String smallTile,String userName, IncomeAggregate incomeAggregate) throws IOException, DocumentException {
         String fileName = "鏀舵鍥炲崟鍏ヨ处鐢宠.pdf";
         File tempFile = new File(System.getProperty("java.io.tmpdir") + "/" + fileName);
         if (!tempFile.exists()) {
             tempFile.createNewFile();
         }
-        Rectangle pageSize = new Rectangle(PageSize.A4.getWidth(), 100); // 椤甸潰楂樺害璁剧疆涓�600
+        Rectangle pageSize = new Rectangle(PageSize.A4.getWidth()+200, 800); // 椤甸潰楂樺害璁剧疆涓�600
         Document document = new Document(pageSize, 50, 50, 50, 50);
         BaseFont baseFont = BaseFont.createFont(ttfFilePath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
 
         try {
-            PdfWriter.getInstance(document, new FileOutputStream(tempFile));
+            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(tempFile));
             document.open();
-            Font headerFont = new Font(baseFont, 12, Font.BOLD);
-            Font bodyFont = new Font(baseFont, 8, Font.NORMAL);
+            Font headerFont = new Font(baseFont, 10, Font.BOLD);
+            Font bodyFont = new Font(baseFont, 10, Font.NORMAL);
 
-            // 鏍囬灞呬腑
+            // 鍒涘缓涓€涓寘鍚�3鍒楃殑琛ㄦ牸
+            PdfPTable table = new PdfPTable(3);
+            table.setWidthPercentage(100);
+            table.setWidths(new float[]{20, 60, 20}); // 20% 绌哄垪, 60% 鏍囬, 20% 鏉″舰鐮�
+            // 绗竴鍒�: 绌虹櫧
+            PdfPCell emptyCell = new PdfPCell();
+            emptyCell.setBorder(Rectangle.NO_BORDER);
+            table.addCell(emptyCell);
+
+            // 绗簩鍒�: 鏍囬
+            PdfPCell titleCell = new PdfPCell();
+            titleCell.setBorder(Rectangle.NO_BORDER);
             Paragraph title = new Paragraph("鏀舵鍥炲崟鍏ヨ处鐢宠", headerFont);
             title.setAlignment(Element.ALIGN_CENTER);
-            document.add(title);
+            titleCell.addElement(title);
+            table.addCell(titleCell);
+
+            // 绗笁鍒�: 鏉″舰鐮佸強缂栧彿
+            PdfPCell barcodeCell = new PdfPCell();
+            barcodeCell.setBorder(Rectangle.NO_BORDER);
+            barcodeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
+
+            // 鍒涘缓鏉″舰鐮�
+            String billNo = incomeAggregate.getReceiptBillVo().getBillNo();
+            PdfContentByte cb = writer.getDirectContent();
+            Barcode128 barcode = new Barcode128();
+            barcode.setCode(billNo); // 鏉″舰鐮佸唴瀹�
+            barcode.setCodeType(Barcode128.CODE128);
+            Image barcodeImage = barcode.createImageWithBarcode(cb, null, null);
+            barcodeImage.scalePercent(100);
+            barcodeCell.addElement(barcodeImage);
+            table.addCell(barcodeCell);
+            document.add(table);
+
+            Paragraph dateParagraph = new Paragraph(smallTile, bodyFont);
+            dateParagraph.setAlignment(Element.ALIGN_CENTER);
+            document.add(dateParagraph);
+            dateParagraph = new Paragraph("鏀舵绫诲瀷锛�"+incomeAggregate.getReceiptBillVo().getIncomeTypeName() , headerFont);
+            dateParagraph.setAlignment(Element.ALIGN_LEFT);
+            document.add(dateParagraph);
+            dateParagraph = new Paragraph("鍥炲崟淇℃伅", headerFont);
+            dateParagraph.setAlignment(Element.ALIGN_LEFT);
+            dateParagraph.setSpacingAfter(2f);
+            document.add(dateParagraph);
+            // 鍦ㄦí绾夸箣鍓嶆彃鍏ヤ竴涓┖娈佃惤锛屽噺灏戞í绾跨殑涓婃柟闂磋窛
+            Paragraph reduceSpace = new Paragraph();
+            reduceSpace.setSpacingBefore(-10f); // 璁剧疆涓鸿礋鍊硷紝鍑忓皯闂磋窛
+            document.add(reduceSpace);
+            // 鍒涘缓骞堕厤缃í绾�
+            LineSeparator line = new LineSeparator();
+            line.setLineColor(BaseColor.BLACK);  // 璁剧疆绾挎潯棰滆壊
+            line.setLineWidth(1);  // 璁剧疆绾挎潯瀹藉害
+            // 灏嗘í绾挎坊鍔犲埌鏂囨。
+            document.add(new Chunk(line));
 
-           /* Date voucherDate = voucherOut.getVoucherDate();
-            String voucherCode = voucherOut.getVoucherCode();
-            if(voucherDate!=null){
-                // 娣诲姞鏃ユ湡锛屽眳涓榻�
-                Paragraph dateParagraph = new Paragraph(new SimpleDateFormat("yyyy骞碝M鏈坉d鏃�").format(voucherDate), bodyFont);
-                dateParagraph.setAlignment(Element.ALIGN_CENTER);
-                document.add(dateParagraph);
-            }else{
-                // 娣诲姞鏃ユ湡锛屽眳涓榻�
-                Paragraph dateParagraph = new Paragraph("", bodyFont);
-                dateParagraph.setAlignment(Element.ALIGN_CENTER);
-                document.add(dateParagraph);
-            }*/
             //1 鍥炲崟
             ReceiptBillVo receiptBillVo = incomeAggregate.getReceiptBillVo();
-            String[] headers = {"鍥炲崟鍗曞彿", "鏀舵鏃ユ湡","鏀舵璐︽埛", "鏀舵璐︽埛鍚嶇О", "浠樻璐︽埛", "浠樻璐︽埛鍚嶇О", "閲戦","鎽樿","闄勮█","杩涘害","棰勫垎閰嶆敹娆剧被鍨�","鏀舵绫诲瀷","鍒嗛厤浜�","涓氬姟琛ュ厖浜哄憳","琛ュ厖鐘舵€�","鏄惁璁ら"};
-            PdfPTable table = new PdfPTable(headers.length);
+            String[] headers = {"鍥炲崟鍗曞彿", "鏀舵绫诲瀷","鏀舵鏃ユ湡","鏀舵璐︽埛", "鏀舵璐︽埛鍚嶇О", "浠樻璐︽埛", "浠樻璐︽埛鍚嶇О", "閲戦","鎽樿","闄勮█"};
+            table = new PdfPTable(3);
+            table.setWidthPercentage(100);
+
             if(receiptBillVo!=null){
-                // 琛ㄦ牸澶�
-                table.setWidthPercentage(100);
-                //table.setWidths(new float[]{2, 2, 2, 4, 1, 1});
-                for (String header : headers) {
-                    PdfPCell cell = new PdfPCell(new Phrase(header, headerFont));
-                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
-                    table.addCell(cell);
-                }
-            }
-            String[][] data  = new String[1][headers.length];
-            Date incomeDate = incomeAggregate.getIncomeDate();
-            String date = incomeDate==null ? "":new SimpleDateFormat("yyyy骞碝M鏈坉d鏃�").format(incomeDate);
-            for (int i = 0; i < 1; i++) {
-                data[i][0] = receiptBillVo.getBillNo()==null ? "" : receiptBillVo.getBillNo();
-                data[i][1] = date;
-                data[i][2] = incomeAggregate.getInComeAccount().getAccount()==null ? "" : incomeAggregate.getInComeAccount().getAccount();
-                data[i][3] = incomeAggregate.getInComeAccount().getAccountName()==null ? "" : incomeAggregate.getInComeAccount().getAccountName();
-                data[i][4] = incomeAggregate.getPaymentAccount().getAccountName()==null ? "" : incomeAggregate.getPaymentAccount().getAccountName();
-                data[i][5] = incomeAggregate.getPaymentAccount().getAccountName()==null ? "" : incomeAggregate.getPaymentAccount().getAccountName();
-                data[i][6] = incomeAggregate.getPaymentAccount().getAccountName()==null ? "" : incomeAggregate.getPaymentAccount().getAccountName();
-                data[i][7] = incomeAggregate.getIncomeAmount()==null ? "" : incomeAggregate.getIncomeAmount().toString();
-                data[i][8] = incomeAggregate.getIncomeSummary()==null ? "" : incomeAggregate.getIncomeSummary();
-                data[i][9] = incomeAggregate.getIncomePostscript()==null ? "" : incomeAggregate.getIncomePostscript();
-                data[i][10] = receiptBillVo.getIncomeSpeed()==null ? "" : receiptBillVo.getIncomeSpeed();
-                data[i][11] = receiptBillVo.getPreIncomeType()==null ? "" : receiptBillVo.getPreIncomeType();
-                data[i][12] = receiptBillVo.getIncomeTypeName()==null ? "" : receiptBillVo.getIncomeTypeName();
-                data[i][13] = receiptBillVo.getAllocationName()==null ? "" : receiptBillVo.getAllocationName();
-                data[i][14] = receiptBillVo.getSupplementName()==null ? "" : receiptBillVo.getSupplementName();
-                data[i][15] = receiptBillVo.getSupplementState();
-                data[i][16] = incomeAggregate.getNeedInQuire()==null ? "" : incomeAggregate.getNeedInQuire()?"鏄�":"鍚�";
-            }
-            for (String[] row : data) {
-                for (String cellData : row) {
-                    PdfPCell cell = new PdfPCell(new Phrase(cellData, bodyFont));
-                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
-                    table.addCell(cell);
-                }
-            }
-            document.add(table);
+                String[][] data  = new String[3][3];
+                Date incomeDate = incomeAggregate.getIncomeDate();
+                String date = incomeDate==null ? "":new SimpleDateFormat("yyyy骞碝M鏈坉d鏃�").format(incomeDate);
+                data[0][0] = receiptBillVo.getBillNo()==null ? "鍥炲崟鍗曞彿锛�" : "鍥炲崟鍗曞彿:"+receiptBillVo.getBillNo();
+                data[0][2] = "鏀舵鏃ユ湡锛�"+date;
+                data[0][1] = incomeAggregate.getInComeAccount().getAccount()==null ? "鏀舵璐︽埛:" :"鏀舵璐︽埛:"+ incomeAggregate.getInComeAccount().getAccount();
 
-            //椤圭洰
-            headers = new String[]{"鏀舵绫诲瀷", "椤圭洰绫诲瀷", "椤圭洰娓呭崟","鍏ヨ处閲戦","琛ュ厖浜哄憳"};
-            table = new PdfPTable(headers.length);
-            table.setWidthPercentage(100);
-            table.setSpacingBefore(10f); // 璁剧疆闂磋窛
-            //1. 鏌ヨ椤圭洰
-            IncomeQueryService incomeQueryService = SpringContainer.getBeanOfType(IncomeQueryService.class);
-            List<ProjectOut> projectOuts = incomeQueryService.getIncomeProject(incomeAggregate.getIncomeId());
-            if(projectOuts!=null && !projectOuts.isEmpty()){
-                data  = new String[projectOuts.size()][headers.length];
-                for (int i = 0; i < projectOuts.size(); i++) {
-                    ProjectOut project = projectOuts.get(i);
-                    data[i][0] = project.getIncomeTypeName()==null?"":project.getIncomeTypeName();
-                    data[i][1] = project.getProjectType()==null?"":project.getProjectType();
-                    data[i][2] = project.getProjectList()==null?"":project.getProjectList();
-                    data[i][3] = incomeAggregate.getIncomeAmount()==null?"":incomeAggregate.getIncomeAmount().toString();
-                    data[i][4] = project.getSupplementPerson()==null?"":project.getSupplementPerson();
+                data[1][0] = incomeAggregate.getInComeAccount().getAccountName()==null ? "鏀舵璐︽埛鍚嶇О锛�" : "鏀舵璐︽埛鍚嶇О:"+incomeAggregate.getInComeAccount().getAccountName();
+                data[1][1] = incomeAggregate.getPaymentAccount().getAccount()==null ? "浠樻璐︽埛锛�" : "浠樻璐︽埛:"+incomeAggregate.getPaymentAccount().getAccount();
+                data[1][2] = incomeAggregate.getPaymentAccount().getAccountName()==null ? "浠樻璐︽埛鍚嶇О:" : "浠樻璐︽埛鍚嶇О:"+incomeAggregate.getPaymentAccount().getAccountName();
+
+                data[2][0] = incomeAggregate.getIncomePostscript()==null ? "闄勮█锛�" : "闄勮█锛�"+incomeAggregate.getIncomePostscript();
+                data[2][1] = incomeAggregate.getIncomeSummary()==null ? "鎽樿锛�" :"鎽樿:"+ incomeAggregate.getIncomeSummary();
+                data[2][2] = "";
+                for (String[] row : data) {
+                    for (String cellData : row) {
+                        PdfPCell cell = new PdfPCell(new Phrase(cellData, bodyFont));
+                        cell.setBorder(Rectangle.NO_BORDER);  // 璁剧疆鏃犺竟妗�
+                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+                        table.addCell(cell);
+                    }
                 }
+                document.add(table);
+                table.setSpacingAfter(40f); // 璁剧疆闂磋窛
+
             }
-            for (String[] row : data) {
-                for (String cellData : row) {
-                    PdfPCell cell = new PdfPCell(new Phrase(cellData, bodyFont));
-                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
-                    table.addCell(cell);
+
+            dateParagraph = new Paragraph("椤圭洰淇℃伅", headerFont);
+            dateParagraph.setAlignment(Element.ALIGN_LEFT);
+            dateParagraph.setSpacingAfter(2f); // 璁剧疆娈佃惤涓嬫柟鐨勯棿璺濅负 2f
+            document.add(dateParagraph);
+            // 鍦ㄦí绾夸箣鍓嶆彃鍏ヤ竴涓┖娈佃惤锛屽噺灏戞í绾跨殑涓婃柟闂磋窛
+            reduceSpace = new Paragraph();
+            reduceSpace.setSpacingBefore(-10f); // 璁剧疆涓鸿礋鍊硷紝鍑忓皯闂磋窛
+            document.add(reduceSpace);
+            // 鍒涘缓骞堕厤缃í绾�
+            line = new LineSeparator();
+            line.setLineColor(BaseColor.BLACK);  // 璁剧疆绾挎潯棰滆壊
+            line.setLineWidth(1);  //
+
+            // 灏嗘í绾挎坊鍔犲埌鏂囨。
+            document.add(new Chunk(line));
+
+                //椤圭洰
+              //headers = new String[]{"鏀舵绫诲瀷", "鍏ヨ处閲戦","琛ュ厖浜哄憳"};
+                table = new PdfPTable(3);
+                table.setWidthPercentage(100);
+               String[][] data  = new String[1][3];
+                data[0][0] = incomeAggregate.getIncomeProject()==null?"椤圭洰:":"椤圭洰:"+incomeAggregate.getIncomeProject();
+                data[0][1] = incomeAggregate.getIncomeAmount()==null?"": "鍏ヨ处閲戦:"+incomeAggregate.getIncomeAmount().toString();
+                data[0][2] = incomeAggregate.getReceiptBillVo().getSupplementName() ==null?"琛ュ厖浜哄憳:":"琛ュ厖浜哄憳:"+incomeAggregate.getReceiptBillVo().getSupplementName();
+                for (String[] row : data) {
+                    for (String cellData : row) {
+                        PdfPCell cell = new PdfPCell(new Phrase(cellData, bodyFont));
+                        cell.setBorder(Rectangle.NO_BORDER);  // 璁剧疆鏃犺竟妗�
+                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+                        table.addCell(cell);
+                    }
                 }
-            }
-            document.add(table);
+                document.add(table);
+
+
             //绁ㄦ嵁
-          List<InvoiceOut> listInvoices = incomeQueryService.getInvoiceList(incomeAggregate.getIncomeId());
+            IncomeQueryService incomeQueryService = SpringContainer.getBeanOfType(IncomeQueryService.class);
+            List<InvoiceOut> listInvoices = incomeQueryService.getInvoiceList(incomeAggregate.getIncomeId());
           if(listInvoices!=null && !listInvoices.isEmpty()){
-              headers = new String[]{"绁ㄦ嵁绫诲瀷","璐拱鏂瑰悕绉�","璐拱鏂圭紪鍙�", "閿€鍞柟鍚嶇О","閿€鍞柟缂栧彿", "鍙戠エ鍐呭","寮€绁ㄧ被鍨�","鍙戠エ鍙风爜","鍙戠エ浠g爜","寮€绁ㄦ棩鏈�",
+              dateParagraph = new Paragraph("绁ㄦ嵁淇℃伅", headerFont);
+              dateParagraph.setAlignment(Element.ALIGN_LEFT);
+              dateParagraph.setSpacingAfter(2f); // 璁剧疆娈佃惤涓嬫柟鐨勯棿璺濅负 2f
+              document.add(dateParagraph);
+              // 鍦ㄦí绾夸箣鍓嶆彃鍏ヤ竴涓┖娈佃惤锛屽噺灏戞í绾跨殑涓婃柟闂磋窛
+              reduceSpace = new Paragraph();
+              reduceSpace.setSpacingBefore(-10f); // 璁剧疆涓鸿礋鍊硷紝鍑忓皯闂磋窛
+              document.add(reduceSpace);
+              // 鍒涘缓骞堕厤缃í绾�
+              line = new LineSeparator();
+              line.setLineColor(BaseColor.BLACK);  // 璁剧疆绾挎潯棰滆壊
+              line.setLineWidth(1);  // 璁剧疆绾挎潯瀹藉害
+              // 灏嗘í绾挎坊鍔犲埌鏂囨。
+              document.add(new Chunk(line));
+              headers = new String[]{"绁ㄦ嵁绫诲瀷","璐拱鏂瑰悕绉�","璐拱鏂圭紪鍙�", "閿€鍞柟鍚嶇О","閿€鍞柟缂栧彿", "鍙戠エ鍐呭",
+                      "寮€绁ㄧ被鍨�","鍙戠エ鍙风爜","鍙戠エ浠g爜","寮€绁ㄦ棩鏈�",
                       "椤圭洰浠g爜", "椤圭洰鍚嶇О", "瑙勬牸鍨嬪彿", "鍗曚綅" ,"鏁伴噺","鍗曚环","閲戦","绋庣巼","绋庨"};
-              table = new PdfPTable(headers.length);
+              table = new PdfPTable(3);
               table.setWidthPercentage(100);
-              table.setSpacingBefore(10f); // 璁剧疆闂磋窛
-              // 璁$畻data鏁扮粍鐨勫ぇ灏忥紝鍥犱负涓€涓狪nvoiceOut鍙兘鍖呭惈澶氫釜InvoiceDetailOut
-              int totalRows = 0;
-              for (InvoiceOut invoice : listInvoices) {
-                  totalRows += invoice.getDetailOutList().size(); // 璁$畻鎵€鏈夌殑琛屾暟
-              }
+              data  = new String[4][3];
+              InvoiceOut voiceOut = listInvoices.get(0);
+              data[0][0] = voiceOut.getBillType()==null?"绁ㄦ嵁绫诲瀷:":"绁ㄦ嵁绫诲瀷:"+voiceOut.getBillType();
+              data[0][1] = voiceOut.getBuyerName()==null?"璐拱鏂瑰悕绉�:": "璐拱鏂瑰悕绉�:"+voiceOut.getBuyerName();
+              data[0][2] = voiceOut.getBuyerCode() ==null?"璐拱鏂圭紪鍙�:":"璐拱鏂圭紪鍙�:"+voiceOut.getBuyerCode();
 
-              // 鍒涘缓data鏁扮粍
-              data = new String[totalRows][headers.length];
-              int rowIndex = 0; // 鐢ㄤ簬璺熻釜data鏁扮粍鐨勫綋鍓嶈绱㈠紩
-              for (InvoiceOut invoiceOut : listInvoices) {
-                  // 鑾峰彇绁ㄦ嵁鏄庣粏鍒楄〃
-                  List<InvoiceDetailOut> detailOutList = invoiceOut.getDetailOutList();
-                  if (detailOutList != null) {
-                      for (InvoiceDetailOut detailOut : detailOutList) {
-                          // 濉厖data鏁扮粍
-                          data[rowIndex][0] = invoiceOut.getBillType()==null?"":invoiceOut.getBillType();
-                          data[rowIndex][1] = invoiceOut.getBuyerName()==null?"":invoiceOut.getBuyerName();
-                          data[rowIndex][2] = invoiceOut.getBuyerCode()==null?"":invoiceOut.getBuyerCode();
-                          data[rowIndex][3] = invoiceOut.getSellerName()==null?"":invoiceOut.getSellerName();
-                          data[rowIndex][4] = invoiceOut.getSellerCode()==null?"":invoiceOut.getSellerCode();
-                          data[rowIndex][5] = invoiceOut.getRemark()==null?"":invoiceOut.getRemark();
-                          data[rowIndex][6] = invoiceOut.getInvoiceType()==null?"":invoiceOut.getInvoiceType();
-                          data[rowIndex][7] = invoiceOut.getInvoiceNo()==null?"":invoiceOut.getInvoiceNo();
-                          data[rowIndex][8] = invoiceOut.getInvoiceCode()==null?"":invoiceOut.getInvoiceCode();
-                          String date2 = invoiceOut.getInvoiceDate() == null ? "" : new SimpleDateFormat("yyyy骞碝M鏈坉d鏃�").format(invoiceOut.getInvoiceDate());
-                          data[rowIndex][9] = date2;
+              data[1][0] = voiceOut.getSellerName()==null?"閿€鍞柟鍚嶇О:":"閿€鍞柟鍚嶇О:"+voiceOut.getSellerName();
+              data[1][1] = voiceOut.getSellerCode()==null?"閿€鍞柟缂栧彿:": "閿€鍞柟缂栧彿:"+voiceOut.getSellerCode();
+              data[1][2] = voiceOut.getRemark() ==null?"鍙戠エ鍐呭:":"鍙戠エ鍐呭:"+voiceOut.getRemark();
+
+              data[2][0] = voiceOut.getInvoiceType()==null?"寮€绁ㄧ被鍨�:":"寮€绁ㄧ被鍨�:"+voiceOut.getInvoiceType();
+              data[2][1] = voiceOut.getInvoiceNo()==null?"鍙戠エ鍙风爜:": "鍙戠エ鍙风爜:"+voiceOut.getInvoiceNo();
+              data[2][2] = voiceOut.getInvoiceCode() ==null?"鍙戠エ浠g爜:":"鍙戠エ浠g爜:"+voiceOut.getInvoiceCode();
 
-                          // 濉厖鏄庣粏鏁版嵁
-                          data[rowIndex][10] = detailOut.getItemCode() ==null?"":detailOut.getItemCode();
-                          data[rowIndex][11] = detailOut.getItemName() == null ? "" : detailOut.getItemName();
-                          data[rowIndex][12] = detailOut.getStandards() == null ? "" : detailOut.getStandards();
-                          data[rowIndex][13] = detailOut.getUnit() == null ? "" : detailOut.getUnit();
-                          data[rowIndex][14] = detailOut.getQuantity() == null ? "" : detailOut.getQuantity().toString();
-                          data[rowIndex][15] = detailOut.getPrice() == null ? "" : detailOut.getPrice().toString();
-                          data[rowIndex][16] = detailOut.getAmount() == null ? "" : detailOut.getAmount().toString();
-                          data[rowIndex][17] = detailOut.getRate() == null ? "" : detailOut.getRate().toString();
-                          data[rowIndex][18] = detailOut.getTax() == null ? "" : detailOut.getTax().toString();
+              String date2 = voiceOut.getInvoiceDate() == null ? "" : new SimpleDateFormat("yyyy骞碝M鏈坉d鏃�").format(voiceOut.getInvoiceDate());
+              data[3][0] = "寮€绁ㄦ棩鏈�:"+date2;
+              data[3][1] = "";
+              data[3][2] = "";
 
-                          rowIndex++; // 澧炲姞琛岀储寮�
-                      }
+              for (String[] row : data) {
+                  for (String cellData : row) {
+                      PdfPCell cell = new PdfPCell(new Phrase(cellData, bodyFont));
+                      cell.setBorder(Rectangle.NO_BORDER);  // 璁剧疆鏃犺竟妗�
+                      cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+                      table.addCell(cell);
                   }
               }
-              //
+              document.add(table);
+              //涓嬮潰鏄槑缁�
+              headers = new String[]{ "搴忓彿","椤圭洰浠g爜", "椤圭洰鍚嶇О", "瑙勬牸鍨嬪彿", "鍗曚綅" ,"鏁伴噺","鍗曚环","閲戦","绋庣巼","绋庨"};
+              table = new PdfPTable(headers.length);
+              table.setWidthPercentage(100);
+              for (String header : headers) {
+                  PdfPCell cell = new PdfPCell(new Phrase(header, headerFont));
+                  cell.setBorder(Rectangle.NO_BORDER);  // 璁剧疆鏃犺竟妗�
+                  cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+                  table.addCell(cell);
+              }
+              // 閬嶅巻InvoiceOut鍒楄〃锛屽皢姣忎釜InvoiceOut鐨勬槑缁嗘坊鍔犲埌data鏁扮粍涓�
+              List<InvoiceDetailOut> detailOutList = voiceOut.getDetailOutList();
+              data = new String[detailOutList.size()][headers.length];
+              int rowIndex = 0; // 鐢ㄤ簬璺熻釜data鏁扮粍鐨勫綋鍓嶈绱㈠紩
+              for (InvoiceDetailOut detailOut : detailOutList) {
+                  data[rowIndex][0] = detailOut.getRowIndex() == null ? "" : detailOut.getRowIndex()+"";
+                  data[rowIndex][1] = detailOut.getItemName() == null ? "" : detailOut.getItemName();
+                  data[rowIndex][2] = detailOut.getItemName() == null ? "" : detailOut.getItemCode();
+                  data[rowIndex][3] = detailOut.getStandards() == null ? "" : detailOut.getStandards();
+                  data[rowIndex][4] = detailOut.getUnit() == null ? "" : detailOut.getUnit();
+                  data[rowIndex][5] = detailOut.getQuantity() == null ? "" : detailOut.getQuantity().toString();
+                  data[rowIndex][6] = detailOut.getPrice() == null ? "" : detailOut.getPrice().toString();
+                  data[rowIndex][7] = detailOut.getAmount() == null ? "" : detailOut.getAmount().toString();
+                  data[rowIndex][8] = detailOut.getRate() == null ? "" : detailOut.getRate().toString();
+                  data[rowIndex][9] = detailOut.getTax() == null ? "" : detailOut.getTax().toString();
+                  rowIndex++;
+              }
               for (String[] row : data) {
                   for (String cellData : row) {
                       PdfPCell cell = new PdfPCell(new Phrase(cellData, bodyFont));
-                      cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+                      cell.setBorder(Rectangle.NO_BORDER);  // 璁剧疆鏃犺竟妗�
+                      cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                       table.addCell(cell);
                   }
               }
               document.add(table);
-              table.setSpacingBefore(10f); // 璁剧疆闂磋窛
-              Paragraph dateParagraph = new Paragraph("鐢宠浜猴細"+userName+"   " +
+              dateParagraph = new Paragraph("鐢宠浜猴細"+userName, bodyFont);
+              dateParagraph.setAlignment(Element.ALIGN_LEFT);
+              dateParagraph.setSpacingBefore(50f);
+              document.add(dateParagraph);
+
+              dateParagraph = new Paragraph(
                       "鐢宠鏃堕棿锛�"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), bodyFont);
               dateParagraph.setAlignment(Element.ALIGN_LEFT);
               document.add(dateParagraph);
+
           }
         } catch (DocumentException e) {
             e.printStackTrace();
@@ -314,9 +379,9 @@ public class FileUtil  {
         String billNo = incomeAggregate.getReceiptBillVo().getBillNo();
         fileCommandService.SaveFileInfo(incomeId,null,billNo,incomeId.toString(),
                 FileTypeEmun.鍏ヨ处鐢宠鍗�.getCode(),convertFileToBytes(tempFile),type,tempFile.getName(), userName);
-       /* if (!tempFile.delete()) {
+        if (!tempFile.delete()) {
             throw new RuntimeException("鍒犻櫎鏂囦欢鍑洪敊");
-        }*/
+        }
     }
     private static byte[] convertFileToBytes(File file) throws IOException {
         try (FileInputStream fis = new FileInputStream(file)) {
-- 
GitLab