فهرست منبع

An example of template part render

dengjia 1 ماه پیش
والد
کامیت
7372d2f7f8

+ 90 - 0
easier-report-biz/src/main/java/com/yaoyicloud/render/AbstractRender.java

@@ -0,0 +1,90 @@
+package com.yaoyicloud.render;
+
+import java.io.IOException;
+
+
+
+/**
+ * 抽象渲染器
+ *
+ */
+public abstract class AbstractRender {
+
+    /*
+    * 导出文件位置
+    */
+    protected final String cwd;
+
+    /*
+     * Docx结果文件路径
+     */
+    protected String docxResultPath;
+
+    /*
+     * html结果文件路径
+     */
+    protected String htmlResultPath;
+
+    /*
+     * pdf结果文件路径
+     */
+    protected String pdfResultPath;
+
+    public AbstractRender(String cwd) {
+        this.cwd = cwd;
+    }
+
+    /**
+     * Docx 渲染
+     * @param info 数据
+     * @param templateFileContent 模板内容
+     * @return 本地文件目录
+     * @throws IOException
+     */
+    public final String renderDocx(String json /* 可能会改成对象 */, Byte[] templateFileContent, String outputPath) throws IOException {
+        // 用POI 渲染模板
+        // 保存到 cwd 目录,文件名使用 ServiceProviderInfo + uuid
+        // 注: 目前的实现假设:一个session对应一个cwd目录
+
+        this.docxResultPath = cwd + "/1.docx";
+        return this.docxResultPath;
+    }
+
+    /**
+     *  docx转换为pdf
+     * @return 本地文件目录
+     * @throws IOException
+     */
+    public final String fromDocxToPdf() throws IOException {
+        // 转换 docxResultPath 为 html
+        // 加工html
+        // 把 html 文件转成 pdf
+        fromDocxToHtml();
+        this.pdfResultPath = fromHtmlToPdf();
+        return this.pdfResultPath;
+    }
+
+    /**
+     *  docx转换为Html
+     * @return 本地文件目录
+     * @throws IOException
+     */
+    public final String fromDocxToHtml() throws IOException {
+        // 转换 docxResultPath 为 html
+        // 加工html
+        this.htmlResultPath = cwd + "/1.html";
+        return this.htmlResultPath;
+    }
+
+    /**
+     *  html转换为pdf
+     * @return 本地文件目录
+     * @throws IOException
+     */
+    public final String fromHtmlToPdf() throws IOException {
+        // 转换 htmlResultPath 为 pdf
+        this.pdfResultPath = cwd + "/1.pdf";
+        return this.pdfResultPath;
+    }
+
+}

+ 14 - 0
easier-report-biz/src/main/java/com/yaoyicloud/render/ServiceProviderInfo.java

@@ -0,0 +1,14 @@
+package com.yaoyicloud.render;
+
+import lombok.Data;
+
+/**
+ * 服务商信息类
+ */
+@Data
+public class ServiceProviderInfo {
+    private String name;          // ${服务商信息:服务商名称}
+    private String type;          // "基金会"
+    private String reportDate;    // ${服务商信息:报告日期}
+    private String tenantName;    // ${服务商信息:租户名称}
+}

+ 35 - 0
easier-report-biz/src/main/java/com/yaoyicloud/render/ServiceProviderInfoRender.java

@@ -0,0 +1,35 @@
+package com.yaoyicloud.render;
+
+import java.io.IOException;
+
+
+
+/**
+ * ServiceProviderInfo渲染器
+ *
+ */
+public final class ServiceProviderInfoRender extends AbstractRender {
+
+    public ServiceProviderInfoRender(String cwd) {
+        super(cwd);
+    }
+
+    /**
+     * Docx 渲染
+     * @param info 数据
+     * @param templateFileContent 模板内容
+     * @return 本地文件目录
+     * @throws IOException
+     */
+    public final String renderDocx(ServiceProviderInfo info, Byte[] templateFileContent) throws IOException {
+        // json序列化 info
+        // 注: 报告模板的模板变量按照json序列化的结果命名
+        // 用POI 渲染模板
+        // 保存到 cwd 目录,文件名使用 ServiceProviderInfo + uuid
+        // 注: 目前的实现假设:一个session对应一个cwd目录
+
+        this.docxResultPath = this.renderDocx(info.toString() /* Fake */, templateFileContent, cwd + "/1.docx");
+        return this.docxResultPath;
+    }
+    
+}