Bläddra i källkod

build 基金会数据不显示问题

mamingxu 1 månad sedan
förälder
incheckning
75771765d2

+ 26 - 0
easier-report-biz/src/main/java/com/yaoyicloud/template/AbstractReportExporter.java

@@ -17,6 +17,7 @@ import com.deepoove.poi.data.PictureType;
 import com.deepoove.poi.data.Pictures;
 import com.deepoove.poi.data.Texts;
 import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
+import com.deepoove.poi.template.run.RunTemplate;
 import com.yaoyicloud.constant.enums.ReportType;
 import com.yaoyicloud.tools.OfficeUtil1;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
@@ -199,6 +200,31 @@ public abstract class AbstractReportExporter  implements ReportDataProcessor {
 
     protected abstract String getBasicPath() throws IOException;
 
+
+    protected RenderPolicy customHackLoopTableRenderPolicy() {
+        RenderPolicy policy = new LoopRowTableRenderPolicy() {
+            @Override
+            public void render(ElementTemplate eleTemplate, Object data, XWPFTemplate template) {
+                super.render(eleTemplate, data, template);
+                // 2. 获取当前表格
+                RunTemplate runTemplate = (RunTemplate) eleTemplate;
+                XWPFTable table = (XWPFTable) runTemplate.getRun().getParent();
+
+                // 3. 遍历表格行,检查字段是否为空,并替换为 "-"
+                List<XWPFTableRow> rows = table.getRows();
+                for (XWPFTableRow row : rows) {
+                    List<XWPFTableCell> cells = row.getTableCells();
+                    for (XWPFTableCell cell : cells) {
+                        String text = cell.getText();
+                        if (text == null || text.trim().isEmpty()) {
+                            cell.setText("-"); // 替换空值为 "-"
+                        }
+                    }
+                }
+            }
+        };
+        return policy;
+    }
     protected RenderPolicy getScoreRenderPolicy() {
         RenderPolicy policy = new LoopRowTableRenderPolicy() {
             @SuppressWarnings("checkstyle:NestedForDepth")

+ 2 - 1
easier-report-biz/src/main/java/com/yaoyicloud/template/FoundationReport.java

@@ -50,6 +50,7 @@ public class FoundationReport extends AbstractReportExporter {
 
     @Override
     protected void bindConfigure(ConfigureBuilder builder, Map<String, Object> data) {
+        RenderPolicy policy = this.customHackLoopTableRenderPolicy();
         LoopRowTableRenderPolicy hackLoopTableRenderPolicy = new LoopRowTableRenderPolicy();
         Object checkItemScores = data.get("checkItemScores");
         if (checkItemScores != null) {
@@ -227,7 +228,7 @@ public class FoundationReport extends AbstractReportExporter {
             }
             NumberingFormat numberingFormat = new NumberingFormat(1, "");
             NumberingRenderData numberedImages = new NumberingRenderData(numberingFormat, interestConflictparagraphImages);
-            processedData.put("files", numberedImages);
+            processedData.put("interestConflict", numberedImages);
         }
         // Process other specific links
         processLink(processedData, "financialStatementsForLastThreeYears");

+ 61 - 1
easier-report-biz/src/main/java/com/yaoyicloud/tools/OfficeUtil1.java

@@ -186,6 +186,44 @@ public class OfficeUtil1 {
         }
         doc.head().appendElement("style").text(baseCss);
 
+//        int groupId = 0;
+//        for (Element row : doc.select("tr:has(td[rowspan], th[rowspan])")) {
+//            int rowspan = Integer.parseInt(row.select("[rowspan]").first().attr("rowspan"));
+//            row.attr("data-group-id", String.valueOf(groupId++));
+//
+//            // 标记被rowspan覆盖的行
+//            Element nextRow = row.nextElementSibling();
+//            for (int i = 1; i < rowspan && nextRow != null; i++) {
+//                nextRow.attr("data-group-child", "true");
+//                nextRow = nextRow.nextElementSibling();
+//            }
+//        }
+//
+//        doc.head().appendElement("style")
+//                .text("tr[data-group-id], tr[data-group-child] { "
+//                        + "page-break-inside: avoid !important; "
+//                        + "}");
+
+//        //合并单元格的处理
+//        Elements rowsWithRowspan = doc.select("tr:has(td[rowspan], th[rowspan])");
+//
+//        // 遍历所有包含合并单元格的行
+//        for (Element row : rowsWithRowspan) {
+//            // 找到合并单元格的跨行数
+//            int rowspan = Integer.parseInt(row.select("td[rowspan], th[rowspan]").first().attr("rowspan"));
+//
+//            // 创建新的 tbody 包裹当前行及后续受影响的行
+//            Element tbody = new Element("tbody").attr("style", "page-break-inside: avoid;  width: 100%;");
+//            for (int i = 0; i < rowspan; i++) {
+//                Element nextRow = row.nextElementSibling();
+//                row.before(tbody);
+//                tbody.appendChild(row);
+//                if (nextRow != null) {
+//                    row = nextRow; // 处理后续行
+//                }
+//            }
+//        }
+
         Elements tds = doc.select("td");
         for (Element td : tds) {
             Elements ps = td.select("p");
@@ -311,6 +349,10 @@ public class OfficeUtil1 {
         for (Element element : select9) {
             element.attr("style", element.attr("style") + "word-break: break-all; overflow-wrap: anywhere; max-width: 100%;");
         }
+        Elements select8 = doc.select("p.X1.X8");
+        for (Element element : select8) {
+            element.attr("style", element.attr("style") + "word-break: break-all; overflow-wrap: anywhere; max-width: 100%;");
+        }
         //1.3合并的单元格 不分页
         Elements select11 = doc.select("td.X10.X11");
         for (Element element : select11) {
@@ -531,10 +573,11 @@ public class OfficeUtil1 {
                                   String backgroundImagePath, boolean onlyCollectPageNumbers)
             throws Exception {
         PdfReader reader = new PdfReader(inputPdfPath);
+
         PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputPdfPath));
         int startPage = 1;
         if (onlyCollectPageNumbers) {
-pageNumberMap.clear();
+        pageNumberMap.clear();
             Pattern startPattern = Pattern.compile("^1\\.\\s+报告概述$");
 
             // 查找起始页
@@ -649,4 +692,21 @@ pageNumberMap.clear();
         reader.close();
     }
 
+//    private static boolean isTableNearBottom(PdfWriter writer, PdfPTable table, float bottom) {
+//        try {
+//            // 获取当前页面的剩余高度
+//            float remainingHeight = writer.getVerticalPosition(true) - bottom;
+//
+//            // 估算当前行高度
+//            float estimatedRowHeight = 30f;
+//            float estimatedTableHeight = table.getRows().size() * estimatedRowHeight;
+//
+//            // 如果剩余空间不足以容纳整个表格,则换页
+//            return remainingHeight < estimatedTableHeight;
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            return false;
+//        }
+//    }
+
 }