1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package com.yaoyicloud.render;
- import java.io.IOException;
- import java.nio.file.Paths;
- 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, 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, templateFileContent, builder,
- Paths.get(cwd, UUID.randomUUID().toString() + ".docx").toString());
- return this.docxResultPath;
- }
- }
|