BasicInfoRender.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.yaoyicloud.render;
  2. import java.io.IOException;
  3. import java.nio.file.Paths;
  4. import java.util.UUID;
  5. import com.deepoove.poi.config.Configure;
  6. import com.deepoove.poi.config.ConfigureBuilder;
  7. import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
  8. import com.google.protobuf.util.JsonFormat;
  9. import com.yaoyicloud.message.FxyProtos.BasicInfo;
  10. /**
  11. * BasicInfo渲染器
  12. *
  13. */
  14. public final class BasicInfoRender extends AbstractRender {
  15. public BasicInfoRender(String cwd) {
  16. super(cwd);
  17. }
  18. /**
  19. * Docx 渲染
  20. *
  21. * @param info 数据
  22. * @param templateFileContent 模板内容
  23. * @return 本地文件目录
  24. * @throws IOException
  25. */
  26. public String renderDocx(BasicInfo info, byte[] templateFileContent) throws IOException {
  27. // 不需要定制展示逻辑的时候,使用protobuf的转json方法
  28. String jsonStr = JsonFormat.printer().print(info);
  29. // 注: 报告模板的模板变量按照json序列化的结果命名
  30. // 注: 目前的实现假设:一个session对应一个cwd目录
  31. ConfigureBuilder builder = Configure.builder();
  32. builder.bind("basicInfoChecks", new LoopRowTableRenderPolicy());
  33. this.docxResultPath = this.renderDocx(jsonStr, templateFileContent, builder,
  34. Paths.get(cwd, UUID.randomUUID().toString() + ".docx").toString());
  35. return this.docxResultPath;
  36. }
  37. }