mamingxu 1 месяц назад
Родитель
Сommit
ab8dd22bf1

+ 55 - 3
easier-report-biz/src/main/java/com/yaoyicloud/template/AbstractReportExporter.java

@@ -7,6 +7,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
@@ -132,9 +133,14 @@ public abstract class AbstractReportExporter  implements ReportDataProcessor {
         String reportTempWordFile = basicPath + "/" + label + ".docx";
         // 定义策略
         ConfigureBuilder builder = Configure.builder();
-        this.bindConfigure(builder, data);
+        this.bindConfigure(builder);
         // 渲染数据
-        this.renderTemplate(reportTempWordFile, templatePath, builder, data);
+        Map<String, Object> processedData = data.entrySet().stream()
+                .collect(Collectors.toMap(
+                        Map.Entry::getKey,
+                        entry -> entry.getValue() != null ? entry.getValue() : "-"
+                ));
+        this.renderTemplate(reportTempWordFile, templatePath, builder, processedData);
         String imagePath = this.imagePath();
         // word转pdf
         String html = OfficeUtil1.convert(reportTempWordFile, reportImagePath);
@@ -181,7 +187,7 @@ public abstract class AbstractReportExporter  implements ReportDataProcessor {
      * @param builder POI configureBuilder
      * @return {@link String} 模板地址
      */
-    protected abstract void bindConfigure(ConfigureBuilder builder, Map<String, Object> data);
+    protected abstract void bindConfigure(ConfigureBuilder builder);
 
 
     protected  abstract  String imagePath();
@@ -225,6 +231,52 @@ public abstract class AbstractReportExporter  implements ReportDataProcessor {
         };
         return policy;
     }
+    protected RenderPolicy indicatorsRenderPolicy() {
+        return new LoopRowTableRenderPolicy() {
+            @Override
+            public void render(ElementTemplate eleTemplate, Object data, XWPFTemplate template) {
+                // 处理数据中的null值
+                Object processedData = processData(data);
+                // 调用父类渲染处理后的数据
+                super.render(eleTemplate, processedData, template);
+            }
+
+            private Object processData(Object data) {
+                if (data == null) {
+                    return null;
+                }
+
+                if (data instanceof List) {
+                    // 处理List类型数据
+                    return ((List<?>) data).stream()
+                            .map(this::processItem)
+                            .collect(Collectors.toList());
+                }
+
+                return data;
+            }
+
+            private Object processItem(Object item) {
+                if (item == null) {
+                    return "-";
+                }
+
+                // 如果元素是Map,处理Map中的null值
+                if (item instanceof Map) {
+                    Map<?, ?> map = (Map<?, ?>) item;
+                    return map.entrySet().stream()
+                            .collect(Collectors.toMap(
+                                    Map.Entry::getKey,
+                                    e -> e.getValue() == null ? "-" : e.getValue()
+                            ));
+                }
+
+                return item;
+            }
+        };
+    }
+
+
     protected RenderPolicy getScoreRenderPolicy() {
         RenderPolicy policy = new LoopRowTableRenderPolicy() {
             @SuppressWarnings("checkstyle:NestedForDepth")

+ 7 - 17
easier-report-biz/src/main/java/com/yaoyicloud/template/AcademicAssociationReport.java

@@ -12,7 +12,6 @@ import com.deepoove.poi.config.Configure;
 import com.deepoove.poi.config.ConfigureBuilder;
 
 import com.deepoove.poi.data.Texts;
-import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
 import com.deepoove.poi.policy.RenderPolicy;
 import com.yaoyicloud.config.FilerepoProperties;
 import com.yaoyicloud.constant.enums.ReportType;
@@ -41,23 +40,14 @@ public class AcademicAssociationReport extends AbstractReportExporter {
     }
 
     @Override
-    protected void bindConfigure(ConfigureBuilder builder, Map<String, Object> data) {
-        LoopRowTableRenderPolicy hackLoopTableRenderPolicy = new LoopRowTableRenderPolicy();
-        Object checkItemScores = data.get("checkItemScores");
-        if (checkItemScores != null) {
+    protected void bindConfigure(ConfigureBuilder builder) {
+        RenderPolicy indicatorsRenderPolicy = this.indicatorsRenderPolicy();
             RenderPolicy scoreRenderPolicy = this.getScoreRenderPolicy();
-            builder.bind("checkItemScores", scoreRenderPolicy).bind("basicInfoChecks", hackLoopTableRenderPolicy)
-                    .bind("businessAbnormals", hackLoopTableRenderPolicy).bind("dishonestPersons", hackLoopTableRenderPolicy)
-                    .bind("penaltyRecords", hackLoopTableRenderPolicy).bind("taxPenalties", hackLoopTableRenderPolicy)
-                    .bind("severeViolations", hackLoopTableRenderPolicy).bind("questionnaireItems", hackLoopTableRenderPolicy)
-                    .bind("indicators", hackLoopTableRenderPolicy).bind("superiorAuthority", hackLoopTableRenderPolicy);
-        }
-        builder.bind("basicInfoChecks", hackLoopTableRenderPolicy)
-                .bind("businessAbnormals", hackLoopTableRenderPolicy).bind("dishonestPersons", hackLoopTableRenderPolicy)
-                .bind("penaltyRecords", hackLoopTableRenderPolicy).bind("taxPenalties", hackLoopTableRenderPolicy)
-                .bind("severeViolations", hackLoopTableRenderPolicy).bind("questionnaireItems", hackLoopTableRenderPolicy)
-                .bind("indicators", hackLoopTableRenderPolicy).bind("superiorAuthority", hackLoopTableRenderPolicy);
-
+        builder.bind("checkItemScores", scoreRenderPolicy).bind("basicInfoChecks", indicatorsRenderPolicy)
+                    .bind("businessAbnormals", indicatorsRenderPolicy).bind("dishonestPersons", indicatorsRenderPolicy)
+                    .bind("penaltyRecords", indicatorsRenderPolicy).bind("taxPenalties", indicatorsRenderPolicy)
+                    .bind("severeViolations", indicatorsRenderPolicy).bind("questionnaireItems", indicatorsRenderPolicy)
+                    .bind("indicators", indicatorsRenderPolicy).bind("superiorAuthority", indicatorsRenderPolicy);
     }
 
     @Override

+ 8 - 20
easier-report-biz/src/main/java/com/yaoyicloud/template/FoundationReport.java

@@ -8,16 +8,13 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.springframework.stereotype.Component;
-
 import com.deepoove.poi.XWPFTemplate;
 import com.deepoove.poi.config.Configure;
 import com.deepoove.poi.config.ConfigureBuilder;
 import com.deepoove.poi.data.Texts;
-import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
 import com.deepoove.poi.policy.RenderPolicy;
 import com.yaoyicloud.config.FilerepoProperties;
 import com.yaoyicloud.constant.enums.ReportType;
-
 import cn.hutool.core.util.StrUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -42,23 +39,14 @@ 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) {
-            RenderPolicy scoreRenderPolicy = this.getScoreRenderPolicy();
-            builder.bind("checkItemScores", scoreRenderPolicy).bind("basicInfoChecks", hackLoopTableRenderPolicy)
-                    .bind("businessAbnormals", hackLoopTableRenderPolicy).bind("dishonestPersons", hackLoopTableRenderPolicy)
-                    .bind("penaltyRecords", hackLoopTableRenderPolicy).bind("taxPenalties", hackLoopTableRenderPolicy)
-                    .bind("severeViolations", hackLoopTableRenderPolicy).bind("questionnaireItems", hackLoopTableRenderPolicy)
-                    .bind("indicators", hackLoopTableRenderPolicy).bind("superiorAuthority", hackLoopTableRenderPolicy);
-        }
-        builder.bind("basicInfoChecks", hackLoopTableRenderPolicy)
-                .bind("businessAbnormals", hackLoopTableRenderPolicy).bind("dishonestPersons", hackLoopTableRenderPolicy)
-                .bind("penaltyRecords", hackLoopTableRenderPolicy).bind("taxPenalties", hackLoopTableRenderPolicy)
-                .bind("severeViolations", hackLoopTableRenderPolicy).bind("questionnaireItems", hackLoopTableRenderPolicy)
-                .bind("indicators", hackLoopTableRenderPolicy).bind("superiorAuthority", hackLoopTableRenderPolicy);
+    protected void bindConfigure(ConfigureBuilder builder) {
+        RenderPolicy indicatorsRenderPolicy = this.indicatorsRenderPolicy();
+        RenderPolicy scoreRenderPolicy = this.getScoreRenderPolicy();
+        builder.bind("checkItemScores", scoreRenderPolicy).bind("basicInfoChecks", indicatorsRenderPolicy)
+            .bind("businessAbnormals", indicatorsRenderPolicy).bind("dishonestPersons", indicatorsRenderPolicy)
+            .bind("penaltyRecords", indicatorsRenderPolicy).bind("taxPenalties", indicatorsRenderPolicy)
+            .bind("severeViolations", indicatorsRenderPolicy).bind("questionnaireItems", indicatorsRenderPolicy)
+            .bind("indicators", indicatorsRenderPolicy).bind("superiorAuthority", indicatorsRenderPolicy);
     }
 
     @Override

+ 9 - 17
easier-report-biz/src/main/java/com/yaoyicloud/template/PlatformCompanyReport.java

@@ -9,7 +9,6 @@ import java.util.Map;
 
 import cn.hutool.core.util.StrUtil;
 import com.deepoove.poi.data.Texts;
-import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
 import com.yaoyicloud.config.FilerepoProperties;
 import com.yaoyicloud.constant.enums.ReportType;
 import org.springframework.stereotype.Component;
@@ -42,22 +41,15 @@ public class PlatformCompanyReport extends AbstractReportExporter {
     }
 
     @Override
-    protected void bindConfigure(ConfigureBuilder builder, Map<String, Object> data) {
-        LoopRowTableRenderPolicy hackLoopTableRenderPolicy = new LoopRowTableRenderPolicy();
-        Object checkItemScores = data.get("checkItemScores");
-        if (checkItemScores != null) {
-            RenderPolicy scoreRenderPolicy = this.getScoreRenderPolicy();
-            builder.bind("checkItemScores", scoreRenderPolicy).bind("basicInfoChecks", hackLoopTableRenderPolicy)
-                    .bind("businessAbnormals", hackLoopTableRenderPolicy).bind("dishonestPersons", hackLoopTableRenderPolicy)
-                    .bind("penaltyRecords", hackLoopTableRenderPolicy).bind("taxPenalties", hackLoopTableRenderPolicy)
-                    .bind("severeViolations", hackLoopTableRenderPolicy).bind("questionnaireItems", hackLoopTableRenderPolicy)
-                    .bind("indicators", hackLoopTableRenderPolicy);
-        }
-        builder.bind("basicInfoChecks", hackLoopTableRenderPolicy)
-                .bind("businessAbnormals", hackLoopTableRenderPolicy).bind("dishonestPersons", hackLoopTableRenderPolicy)
-                .bind("penaltyRecords", hackLoopTableRenderPolicy).bind("taxPenalties", hackLoopTableRenderPolicy)
-                .bind("severeViolations", hackLoopTableRenderPolicy).bind("questionnaireItems", hackLoopTableRenderPolicy)
-                .bind("indicators", hackLoopTableRenderPolicy);
+    protected void bindConfigure(ConfigureBuilder builder) {
+
+        RenderPolicy scoreRenderPolicy = this.getScoreRenderPolicy();
+        RenderPolicy indicatorsRenderPolicy = this.indicatorsRenderPolicy();
+        builder.bind("checkItemScores", scoreRenderPolicy).bind("basicInfoChecks", indicatorsRenderPolicy)
+            .bind("businessAbnormals", indicatorsRenderPolicy).bind("dishonestPersons", indicatorsRenderPolicy)
+            .bind("penaltyRecords", indicatorsRenderPolicy).bind("taxPenalties", indicatorsRenderPolicy)
+            .bind("severeViolations", indicatorsRenderPolicy).bind("questionnaireItems", indicatorsRenderPolicy)
+            .bind("indicators", indicatorsRenderPolicy);
     }
 
     @Override

+ 15 - 16
easier-report-biz/src/main/java/com/yaoyicloud/tools/OfficeUtil1.java

@@ -304,36 +304,28 @@ public class OfficeUtil1 {
         // 8. 一级标题前分页样式
         Elements paragraphs = doc.select("p.X1.X2");
         for (Element p : paragraphs) {
-            p.attr("style", "page-break-before:always;");
+            p.attr("style", p.attr("style") + "page-break-before:always;");
+
         }
 
         //二级标题上边距调整
         Elements secondaryHeadingStyle = doc.select("p.X1.X3");
-        for (Element element : secondaryHeadingStyle) {
-            String text = element.text().trim();
-
-            // 检查标题文本是否匹配
-            if (text.equals("4.2 财务指标(一)") || text.equals("4.1 重要财务数据") || text.equals("2.2 业务主管单位情况")) {
-                // 获取下一个同级元素
-                Element nextSibling = element.nextElementSibling();
+        for (Element secondaryelement : secondaryHeadingStyle) {
 
-                // 如果存在下一个元素,则删除它
-                if (nextSibling != null) {
-                    nextSibling.remove();
-                }
-            }
-            String secondarycurrentStyle = element.attr("style");
+            String secondarycurrentStyle = secondaryelement.attr("style");
             if (secondarycurrentStyle.contains("margin-top:")) {
                 secondarycurrentStyle = secondarycurrentStyle.replaceAll("margin-top:0.0pt", "margin-top: 13pt");
             } else {
                 secondarycurrentStyle += " margin-top: 13pt;";
             }
-            element.attr("style",  secondarycurrentStyle + "line-height: 1.5; margin-bottom: 4pt; margin-left: 0.5em");
+            secondaryelement.attr("style",  secondarycurrentStyle + "line-height: 1.5; margin-bottom: 2pt; margin-left: 0.5em");
         }
+
        //三级标题样式
         Elements otherElements = doc.select("p.X1.X4");
         for (Element element : otherElements) {
-            element.attr("style",  element + "line-height: 1.5;margin-top: 3pt; margin-bottom: 2pt  !important; margin-left: 0.5em");
+            String style3 = element.attr("style");
+            element.attr("style",  style3 + "margin-top: 0pt !important; margin-bottom: 0pt  !important; margin-left: 0.5em");
         }
         //六级标题样式
         Elements select1 = doc.select("p.X1.X6");
@@ -538,6 +530,13 @@ public class OfficeUtil1 {
                     true,
                     null
             );
+            fontResolver.addFont(
+                    mediumFont,
+                    "Arial",
+                    BaseFont.IDENTITY_H,
+                    true,
+                    null
+            );
             html = html.replace("C:\\", "file:///C:/")
                     .replace("\\", "/");
             // 设置HTML(确保CSS中使用相同的font-family)