|
@@ -7,6 +7,7 @@ import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -132,9 +133,14 @@ public abstract class AbstractReportExporter implements ReportDataProcessor {
|
|
String reportTempWordFile = basicPath + "/" + label + ".docx";
|
|
String reportTempWordFile = basicPath + "/" + label + ".docx";
|
|
// 定义策略
|
|
// 定义策略
|
|
ConfigureBuilder builder = Configure.builder();
|
|
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();
|
|
String imagePath = this.imagePath();
|
|
// word转pdf
|
|
// word转pdf
|
|
String html = OfficeUtil1.convert(reportTempWordFile, reportImagePath);
|
|
String html = OfficeUtil1.convert(reportTempWordFile, reportImagePath);
|
|
@@ -181,7 +187,7 @@ public abstract class AbstractReportExporter implements ReportDataProcessor {
|
|
* @param builder POI configureBuilder
|
|
* @param builder POI configureBuilder
|
|
* @return {@link String} 模板地址
|
|
* @return {@link String} 模板地址
|
|
*/
|
|
*/
|
|
- protected abstract void bindConfigure(ConfigureBuilder builder, Map<String, Object> data);
|
|
|
|
|
|
+ protected abstract void bindConfigure(ConfigureBuilder builder);
|
|
|
|
|
|
|
|
|
|
protected abstract String imagePath();
|
|
protected abstract String imagePath();
|
|
@@ -225,6 +231,52 @@ public abstract class AbstractReportExporter implements ReportDataProcessor {
|
|
};
|
|
};
|
|
return policy;
|
|
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() {
|
|
protected RenderPolicy getScoreRenderPolicy() {
|
|
RenderPolicy policy = new LoopRowTableRenderPolicy() {
|
|
RenderPolicy policy = new LoopRowTableRenderPolicy() {
|
|
@SuppressWarnings("checkstyle:NestedForDepth")
|
|
@SuppressWarnings("checkstyle:NestedForDepth")
|