diff --git a/yudao-admin-server/pom.xml b/yudao-admin-server/pom.xml index 120d3e926f..f19a1b1720 100644 --- a/yudao-admin-server/pom.xml +++ b/yudao-admin-server/pom.xml @@ -99,6 +99,17 @@ spring-boot-admin-starter-server + + + cn.iocoder.boot + yudao-spring-boot-biz-export + + + + org.jsoup + jsoup + + cn.iocoder.boot diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/notice/SysNoticeController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/notice/SysNoticeController.java index f004c953e6..09d13b5cb6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/notice/SysNoticeController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/notice/SysNoticeController.java @@ -1,22 +1,28 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.notice; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticeCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticePageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticeRespVO; import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticeUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.system.convert.notice.SysNoticeConvert; import cn.iocoder.yudao.adminserver.modules.system.service.notice.SysNoticeService; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; +import org.springframework.http.MediaType; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -69,4 +75,26 @@ public class SysNoticeController { return success(SysNoticeConvert.INSTANCE.convert(noticeService.getNotice(id))); } + @GetMapping(value = "/exportPdf", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE ) + @ApiOperation(value = "导出通知公告pdf") + public void exportPdf(@RequestParam("id") Long id, HttpServletResponse response) throws IOException { + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + String fileName = URLEncoder.encode("通知公告.pdf", StandardCharsets.UTF_8.name()); + response.setHeader("Content-Disposition", String.format("attachment;filename=%s",fileName)); + ServletOutputStream outputStream = response.getOutputStream(); + noticeService.exportPdf(id, outputStream); + } + + + @GetMapping(value = "/exportWord", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) + @ApiOperation("导出通知公告word") + public void exportWord(@RequestParam("id") Long id, HttpServletResponse response) throws IOException { + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + String fileName = URLEncoder.encode("通知公告.docx", StandardCharsets.UTF_8.name()); + response.setHeader("Content-Disposition", String.format("attachment;filename=%s",fileName)); + ServletOutputStream outputStream = response.getOutputStream(); + noticeService.exportWord(id, outputStream); + } + + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/notice/SysNoticeService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/notice/SysNoticeService.java index ee4ecddb7b..cab1e600ff 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/notice/SysNoticeService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/notice/SysNoticeService.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.system.service.notice; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticeCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticePageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticeUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.notice.SysNoticeDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import java.io.OutputStream; /** * 通知公告 Service 接口 @@ -49,4 +51,19 @@ public interface SysNoticeService { */ SysNoticeDO getNotice(Long id); + + /** + * 导出 通知公告 pdf + * @param id + * @param outputStream + */ + void exportPdf(Long id, OutputStream outputStream); + + + /** + * 导出 通知公告 word + * @param id + * @param outputStream + */ + void exportWord(Long id, OutputStream outputStream); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/notice/impl/SysNoticeServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/notice/impl/SysNoticeServiceImpl.java index 2cb770b06c..30af67f365 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/notice/impl/SysNoticeServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/notice/impl/SysNoticeServiceImpl.java @@ -1,18 +1,24 @@ package cn.iocoder.yudao.adminserver.modules.system.service.notice.impl; -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticeCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticePageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticeUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.system.convert.notice.SysNoticeConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.notice.SysNoticeMapper; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.notice.SysNoticeDO; +import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.notice.SysNoticeMapper; import cn.iocoder.yudao.adminserver.modules.system.service.notice.SysNoticeService; +import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.export.service.TemplateExportPdfService; +import cn.iocoder.yudao.framework.export.service.TemplateExportWordService; import com.google.common.annotations.VisibleForTesting; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Entities; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.io.OutputStream; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.NOTICE_NOT_FOUND; @@ -27,6 +33,12 @@ public class SysNoticeServiceImpl implements SysNoticeService { @Resource private SysNoticeMapper noticeMapper; + @Resource + private TemplateExportPdfService exportPdfService; + + @Resource + private TemplateExportWordService exportWordService; + @Override public Long createNotice(SysNoticeCreateReqVO reqVO) { SysNoticeDO notice = SysNoticeConvert.INSTANCE.convert(reqVO); @@ -61,6 +73,33 @@ public class SysNoticeServiceImpl implements SysNoticeService { return noticeMapper.selectById(id); } + + @Override + public void exportPdf(Long id, OutputStream outputStream) { + // 校验是否存在 + checkNoticeExists(id); + final SysNoticeDO sysNoticeDO = noticeMapper.selectById(id); + final String content = sysNoticeDO.getContent(); + Document doc = Jsoup.parse(content); + doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).escapeMode(Entities.EscapeMode.xhtml); + //html 转化 xhtml + sysNoticeDO.setContent(doc.getElementsByTag("body").html()); + exportPdfService.exportPdf(outputStream, sysNoticeDO, "notice.ftl"); + } + + @Override + public void exportWord(Long id, OutputStream outputStream) { + // 校验是否存在 + checkNoticeExists(id); + final SysNoticeDO sysNoticeDO = noticeMapper.selectById(id); + final String content = sysNoticeDO.getContent(); + Document doc = Jsoup.parse(content); + doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).escapeMode(Entities.EscapeMode.xhtml); + //html 转化 xhtml + sysNoticeDO.setContent(doc.getElementsByTag("body").html()); + exportWordService.exportWord(outputStream, sysNoticeDO,"notice.ftl"); + } + @VisibleForTesting public void checkNoticeExists(Long id) { if (id == null) { diff --git a/yudao-admin-server/src/main/resources/templates/msyh.ttf b/yudao-admin-server/src/main/resources/templates/msyh.ttf new file mode 100644 index 0000000000..ea3c090069 Binary files /dev/null and b/yudao-admin-server/src/main/resources/templates/msyh.ttf differ diff --git a/yudao-admin-server/src/main/resources/templates/notice.ftl b/yudao-admin-server/src/main/resources/templates/notice.ftl new file mode 100644 index 0000000000..c28e359ee9 --- /dev/null +++ b/yudao-admin-server/src/main/resources/templates/notice.ftl @@ -0,0 +1,19 @@ + + + Notice + + + +<#-- Greet the user with his/her name --> +
${title}
+

${content}

+ + \ No newline at end of file diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index 723ea0c6a6..0f8f9027a5 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -52,6 +52,11 @@ 4.5.25 2.1.0 1.2.7 + + + 1.0.8 + 1.13.1 + 8.2.1 @@ -92,7 +97,11 @@ yudao-spring-boot-starter-biz-sms ${revision}
- + + cn.iocoder.boot + yudao-spring-boot-biz-export + ${revision} + @@ -421,6 +430,40 @@ ${aliyun-java-sdk-dysmsapi.version} + + + + org.springframework.boot + spring-boot-starter-freemarker + ${spring.boot.version} + + + + com.openhtmltopdf + openhtmltopdf-pdfbox + ${openhtmltopdf.version} + + + org.jsoup + jsoup + ${jsoup.version} + + + org.docx4j + docx4j-ImportXHTML + ${doc4j.import.xhtml.version} + + + openhtmltopdf-pdfbox + com.openhtmltopdf + + + openhtmltopdf-core + com.openhtmltopdf + + + + diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 635dc7cf62..ce6bcfaf0e 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -28,6 +28,7 @@ yudao-spring-boot-starter-biz-operatelog yudao-spring-boot-starter-biz-dict yudao-spring-boot-starter-biz-sms + yudao-spring-boot-biz-export yudao-framework diff --git a/yudao-framework/yudao-spring-boot-biz-export/pom.xml b/yudao-framework/yudao-spring-boot-biz-export/pom.xml new file mode 100644 index 0000000000..1470950f70 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-biz-export/pom.xml @@ -0,0 +1,32 @@ + + + + yudao-framework + cn.iocoder.boot + 1.0.0 + + 4.0.0 + + yudao-spring-boot-biz-export + + + cn.iocoder.boot + yudao-common + + + org.springframework.boot + spring-boot-starter-freemarker + + + com.openhtmltopdf + openhtmltopdf-pdfbox + + + org.docx4j + docx4j-ImportXHTML + + + + \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/TemplateExportPdfService.java b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/TemplateExportPdfService.java new file mode 100644 index 0000000000..9a59666f89 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/TemplateExportPdfService.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.framework.export.service; + +import java.io.OutputStream; + +public interface TemplateExportPdfService { + + void exportPdf(OutputStream outputStream, Object dataModel, String tplName); + + +} diff --git a/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/TemplateExportWordService.java b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/TemplateExportWordService.java new file mode 100644 index 0000000000..6389971daa --- /dev/null +++ b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/TemplateExportWordService.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.framework.export.service; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; + +import java.io.OutputStream; + +public interface TemplateExportWordService { + + void exportWord(OutputStream outputStream, Object dataModel, String tplName); +} diff --git a/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/XhtmlExportPdfService.java b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/XhtmlExportPdfService.java new file mode 100644 index 0000000000..9163a6417a --- /dev/null +++ b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/XhtmlExportPdfService.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.framework.export.service; + +import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.export.service.exception.ExportException; +import com.openhtmltopdf.pdfboxout.PdfRendererBuilder; +import freemarker.template.TemplateException; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.io.OutputStream; + +@Slf4j +public abstract class XhtmlExportPdfService implements TemplateExportPdfService { + + private String baseDocumentUri; + + + public XhtmlExportPdfService(){ + + } + + public XhtmlExportPdfService(String baseDocumentUri) { + this.baseDocumentUri = baseDocumentUri; + } + + @Override + public void exportPdf(OutputStream outputStream, Object dataModel, String tplName){ + try { + PdfRendererBuilder builder = new PdfRendererBuilder(); + String html = getXHtmlContent(dataModel, tplName); + builder.withHtmlContent(html, baseDocumentUri); + builder.toStream(outputStream); + builder.run(); + }catch (IOException | TemplateException ex){ + log.error(" 导出 pdf 报错", ex); + throw new ExportException("export pdf error", ex); + } + } + + public void setBaseDocumentUri(String baseDocumentUri) { + this.baseDocumentUri = baseDocumentUri; + } + + protected abstract String getXHtmlContent(Object dataModel, String tplName) throws IOException, TemplateException; +} diff --git a/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/XhtmlExportWordService.java b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/XhtmlExportWordService.java new file mode 100644 index 0000000000..d326634028 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/XhtmlExportWordService.java @@ -0,0 +1,50 @@ +package cn.iocoder.yudao.framework.export.service; + +import cn.iocoder.yudao.framework.export.service.exception.ExportException; +import freemarker.template.TemplateException; +import lombok.extern.slf4j.Slf4j; +import org.docx4j.convert.in.xhtml.XHTMLImporterImpl; +import org.docx4j.openpackaging.exceptions.Docx4JException; +import org.docx4j.openpackaging.packages.WordprocessingMLPackage; + +import java.io.IOException; +import java.io.OutputStream; + +@Slf4j +public abstract class XhtmlExportWordService implements TemplateExportWordService { + + private String baseDocumentUri; + + + public XhtmlExportWordService() { + + } + + public XhtmlExportWordService(String baseDocumentUri) { + this.baseDocumentUri = baseDocumentUri; + } + + @Override + public void exportWord(OutputStream outputStream, Object dataModel, String tplName) { + try { + WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); + String content = getXHtmlContent(dataModel, tplName); + + XHTMLImporterImpl xHTMLImporter = new XHTMLImporterImpl(wordMLPackage); + wordMLPackage.getMainDocumentPart().getContent().addAll(xHTMLImporter.convert(content,baseDocumentUri)); + wordMLPackage.save(outputStream); + + } catch (Docx4JException | IOException | TemplateException ex) { + log.error(" 导出 word 报错", ex); + throw new ExportException("export word error", ex); + } + + } + + public void setBaseDocumentUri(String baseDocumentUri) { + this.baseDocumentUri = baseDocumentUri; + } + + + protected abstract String getXHtmlContent(Object dataModel, String tplName) throws IOException, TemplateException; +} diff --git a/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/config/YudaoExportAutoConfiguration.java b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/config/YudaoExportAutoConfiguration.java new file mode 100644 index 0000000000..a5877f3179 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/config/YudaoExportAutoConfiguration.java @@ -0,0 +1,63 @@ +package cn.iocoder.yudao.framework.export.service.config; + +import cn.iocoder.yudao.framework.export.service.TemplateExportPdfService; +import cn.iocoder.yudao.framework.export.service.TemplateExportWordService; +import cn.iocoder.yudao.framework.export.service.XhtmlExportPdfService; +import cn.iocoder.yudao.framework.export.service.XhtmlExportWordService; +import cn.iocoder.yudao.framework.export.service.freemarker.FreemarkerXhtmlExportPdfService; +import cn.iocoder.yudao.framework.export.service.freemarker.FreemarkerXhtmlExportWordService; +import com.openhtmltopdf.pdfboxout.PdfRendererBuilder; +import org.docx4j.convert.in.xhtml.XHTMLImporterImpl; +import org.docx4j.openpackaging.packages.WordprocessingMLPackage; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; +import org.springframework.boot.autoconfigure.freemarker.FreeMarkerProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import java.io.IOException; + +@Configuration( + proxyBeanMethods = false +) +@ConditionalOnClass({freemarker.template.Configuration.class, XhtmlExportPdfService.class, XhtmlExportWordService.class}) +@AutoConfigureAfter({ FreeMarkerAutoConfiguration.class}) +public class YudaoExportAutoConfiguration { + + private final ApplicationContext applicationContext; + + private final FreeMarkerProperties properties; + + public YudaoExportAutoConfiguration(ApplicationContext applicationContext, FreeMarkerProperties properties) { + this.applicationContext = applicationContext; + this.properties = properties; + } + + @Bean + @ConditionalOnClass({PdfRendererBuilder.class}) + @ConditionalOnMissingBean({TemplateExportPdfService.class}) + @ConditionalOnBean(freemarker.template.Configuration.class) + TemplateExportPdfService exportPdfService(freemarker.template.Configuration configuration) throws IOException { + final String[] templateLoaderPath = properties.getTemplateLoaderPath(); + //get the first template loader path + String path = templateLoaderPath[0]; + String baseDocumentUri = applicationContext.getResource(path).getURI().toString(); + return new FreemarkerXhtmlExportPdfService(configuration,baseDocumentUri); + } + + + @Bean + @ConditionalOnClass({WordprocessingMLPackage.class, XHTMLImporterImpl.class}) + @ConditionalOnMissingBean({TemplateExportWordService.class}) + @ConditionalOnBean(freemarker.template.Configuration.class) + TemplateExportWordService exportWordService(freemarker.template.Configuration configuration) throws IOException { + final String[] templateLoaderPath = properties.getTemplateLoaderPath(); + //get the first template loader path + String path = templateLoaderPath[0]; + String baseDocumentUri = applicationContext.getResource(path).getURI().toString(); + return new FreemarkerXhtmlExportWordService(configuration,baseDocumentUri); + } +} diff --git a/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/exception/ExportException.java b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/exception/ExportException.java new file mode 100644 index 0000000000..2d6eb6fcaa --- /dev/null +++ b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/exception/ExportException.java @@ -0,0 +1,13 @@ +package cn.iocoder.yudao.framework.export.service.exception; + + +public class ExportException extends RuntimeException { + + public ExportException(String msg) { + super(msg); + } + + public ExportException(String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/freemarker/FreemarkerXhtmlExportPdfService.java b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/freemarker/FreemarkerXhtmlExportPdfService.java new file mode 100644 index 0000000000..9cf7a66d53 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/freemarker/FreemarkerXhtmlExportPdfService.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.framework.export.service.freemarker; + +import cn.iocoder.yudao.framework.export.service.XhtmlExportPdfService; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; + +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; + + +public class FreemarkerXhtmlExportPdfService extends XhtmlExportPdfService { + + private final Configuration configuration; + + + public FreemarkerXhtmlExportPdfService(Configuration configuration) { + this.configuration = configuration; + } + + + public FreemarkerXhtmlExportPdfService(Configuration configuration, + String baseDocumentUri) { + super(baseDocumentUri); + this.configuration = configuration; + } + + + @Override + protected String getXHtmlContent(Object dataModel, String tplName) throws IOException, TemplateException { + + Template template = configuration.getTemplate(tplName, StandardCharsets.UTF_8.name()); + + StringWriter stringWriter = new StringWriter(256); + + template.process(dataModel, stringWriter); + + return stringWriter.toString(); + } +} diff --git a/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/freemarker/FreemarkerXhtmlExportWordService.java b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/freemarker/FreemarkerXhtmlExportWordService.java new file mode 100644 index 0000000000..5a35c96eec --- /dev/null +++ b/yudao-framework/yudao-spring-boot-biz-export/src/main/java/cn/iocoder/yudao/framework/export/service/freemarker/FreemarkerXhtmlExportWordService.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.framework.export.service.freemarker; + +import cn.iocoder.yudao.framework.export.service.XhtmlExportWordService; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; + +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; + +public class FreemarkerXhtmlExportWordService extends XhtmlExportWordService { + + private final Configuration configuration; + + + public FreemarkerXhtmlExportWordService(Configuration configuration, String baseDocumentUri) { + super(baseDocumentUri); + this.configuration = configuration; + } + + public FreemarkerXhtmlExportWordService(Configuration configuration) { + this.configuration = configuration; + } + + + + @Override + protected String getXHtmlContent(Object dataModel, String tplName) throws IOException, TemplateException { + + Template template = configuration.getTemplate(tplName, StandardCharsets.UTF_8.name()); + + StringWriter stringWriter = new StringWriter(256); + + template.process(dataModel, stringWriter); + + return stringWriter.toString(); + } +} diff --git a/yudao-framework/yudao-spring-boot-biz-export/src/main/resources/META-INF/spring.factories b/yudao-framework/yudao-spring-boot-biz-export/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..0bf9aca616 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-biz-export/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + cn.iocoder.yudao.framework.export.service.config.YudaoExportAutoConfiguration