|
@@ -1,54 +1,105 @@
|
|
|
-//package com.yaoyicloud.render;
|
|
|
-//
|
|
|
-//import java.io.IOException;
|
|
|
-//import java.nio.file.Paths;
|
|
|
-//import java.util.Map;
|
|
|
-//import java.util.UUID;
|
|
|
-//
|
|
|
-//import com.deepoove.poi.config.Configure;
|
|
|
-//import com.deepoove.poi.config.ConfigureBuilder;
|
|
|
-//import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
|
-//import com.google.protobuf.util.JsonFormat;
|
|
|
-//import com.yaoyicloud.message.FxyProtos.BasicInfo;
|
|
|
-//
|
|
|
-///**
|
|
|
-// * BasicInfo渲染器
|
|
|
-// *
|
|
|
-// */
|
|
|
-//public final class BasicInfoRender extends AbstractRender {
|
|
|
-//
|
|
|
-// public BasicInfoRender(String cwd) {
|
|
|
-// super(cwd);
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * Docx 渲染
|
|
|
-// *
|
|
|
-// * @param info 数据
|
|
|
-// * @param templateFileContent 模板内容
|
|
|
-// * @return 本地文件目录
|
|
|
-// * @throws IOException
|
|
|
-// */
|
|
|
-// public String renderDocx(BasicInfo info, Map<String, Object> addtionalMap, byte[] templateFileContent) throws IOException {
|
|
|
-// // 不需要定制展示逻辑的时候,使用protobuf的转json方法
|
|
|
-// String jsonStr = JsonFormat.printer().print(info);
|
|
|
-//
|
|
|
-// // 注: 报告模板的模板变量按照json序列化的结果命名
|
|
|
-// // 注: 目前的实现假设:一个session对应一个cwd目录
|
|
|
-// ConfigureBuilder builder = Configure.builder();
|
|
|
-// builder.bind("basicInfoChecks", new LoopRowTableRenderPolicy());
|
|
|
-//// this.docxResultPath = this.renderDocx(jsonStr, addtionalMap, templateFileContent, builder,
|
|
|
-//// Paths.get(cwd, UUID.randomUUID().toString() + ".docx").toString());
|
|
|
-// return this.docxResultPath;
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// protected String getBasicPath() throws IOException {
|
|
|
-// return "";
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// protected String getReportImagePath() {
|
|
|
-// return "";
|
|
|
-// }
|
|
|
-//}
|
|
|
+package com.yaoyicloud.render;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+import com.deepoove.poi.config.Configure;
|
|
|
+import com.deepoove.poi.config.ConfigureBuilder;
|
|
|
+import com.deepoove.poi.policy.RenderPolicy;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.google.protobuf.util.JsonFormat;
|
|
|
+import com.yaoyicloud.config.FilerepoProperties;
|
|
|
+
|
|
|
+import com.yaoyicloud.message.FxyProtos;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+/**
|
|
|
+ * BasicInfo渲染器
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public final class BasicInfoRender extends AbstractRender {
|
|
|
+ private final FilerepoProperties filerepoProperties;
|
|
|
+ public BasicInfoRender(String cwd, FilerepoProperties filerepoProperties) {
|
|
|
+ super(cwd);
|
|
|
+ this.filerepoProperties = filerepoProperties;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getBasicPath() throws IOException {
|
|
|
+ return filerepoProperties.getBasePath();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getReportImagePath() {
|
|
|
+ return filerepoProperties.getReportImagePath();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Docx 渲染
|
|
|
+ *
|
|
|
+ * @param info 数据
|
|
|
+ * @param templateFileContent 模板内容
|
|
|
+ * @return 本地文件目录
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public String renderDocx(String info, Map<String, Object> addtionalMap, byte[] templateFileContent, String relationId) throws IOException {
|
|
|
+ log.info("开始渲染基础信息报告模块,relationId: {}", relationId);
|
|
|
+
|
|
|
+ // 配置POI-TL渲染器
|
|
|
+ ConfigureBuilder builder = Configure.builder();
|
|
|
+ RenderPolicy indicatorsRenderPolicy = this.indicatorsRenderPolicy();
|
|
|
+ builder.bind("basicInfoChecks", indicatorsRenderPolicy);
|
|
|
+ FxyProtos.BasicInfo.Builder basicInfoBuilder = FxyProtos.BasicInfo.newBuilder();
|
|
|
+ JsonFormat.parser().merge(info, basicInfoBuilder);
|
|
|
+
|
|
|
+ FxyProtos.BasicInfo defaultInstance = FxyProtos.BasicInfo.getDefaultInstance();
|
|
|
+ FxyProtos.BasicInfo mergedProto = defaultInstance.toBuilder()
|
|
|
+ .mergeFrom(basicInfoBuilder.build())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ String completeJson = JsonFormat.printer()
|
|
|
+ .includingDefaultValueFields()
|
|
|
+ .print(mergedProto);
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Map<String, Object> data = objectMapper.readValue(completeJson, new TypeReference<Map<String, Object>>() {});
|
|
|
+ data.replaceAll((k, v) -> v.equals("") ? "-" : v);
|
|
|
+
|
|
|
+ if (addtionalMap != null) {
|
|
|
+ data.putAll(addtionalMap);
|
|
|
+ }
|
|
|
+ fillBasicDefaultValues(data);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 渲染文档
|
|
|
+ String resultPath = this.renderDocx(data, templateFileContent, builder, relationId);
|
|
|
+ log.info("渲染基础信息报告模块成功,文件路径: {}", resultPath);
|
|
|
+ return resultPath;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("渲染基础信息报告模块失败,relationId: {}", relationId, e);
|
|
|
+ throw new IOException("文档渲染失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充默认值,确保所有必要字段都存在
|
|
|
+ */
|
|
|
+ private void fillBasicDefaultValues(Map<String, Object> data) {
|
|
|
+ Map<String, Object> basicInfoSummary = (Map<String, Object>) data.get("basicInfoSummary");
|
|
|
+ basicInfoSummary.replaceAll((k, v) -> v.equals("") ? "-" : v);
|
|
|
+ Map<String, Object> platformExt = (Map<String, Object>) data.get("platformExt");
|
|
|
+ platformExt.replaceAll((k, v) -> v.equals("") ? "-" : v);
|
|
|
+ Object certReceived = data.get("certReceived");
|
|
|
+ if (certReceived.equals("-")) {
|
|
|
+ data.put("certReceived", "否");
|
|
|
+ }
|
|
|
+ Object bankLicense = data.get("bankLicense");
|
|
|
+ if (bankLicense.equals("-")) {
|
|
|
+ data.put("bankLicense", "否");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|