From ff5276998cb956fc0878bf39a194040378ce7363 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 22 Apr 2024 19:14:10 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=A7=BB=E9=99=A4=E3=80=91=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=96=87=E6=A1=A3=EF=BC=8C=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=9A=84=E5=A4=8D=E6=9D=82=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 16 -- .../yudao-module-infra-biz/pom.xml | 5 - .../admin/db/DatabaseDocController.java | 154 ------------------ 3 files changed, 175 deletions(-) delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DatabaseDocController.java diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index 2ee3a3037..e25014d41 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -475,22 +475,6 @@ ${fastjson.version} - - cn.smallbun.screw - screw-core - ${screw.version} - - - org.freemarker - freemarker - - - com.alibaba - fastjson - - - - com.google.guava guava diff --git a/yudao-module-infra/yudao-module-infra-biz/pom.xml b/yudao-module-infra/yudao-module-infra-biz/pom.xml index 44f3aef67..f2840cfc7 100644 --- a/yudao-module-infra/yudao-module-infra-biz/pom.xml +++ b/yudao-module-infra/yudao-module-infra-biz/pom.xml @@ -95,11 +95,6 @@ velocity-engine-core - - cn.smallbun.screw - screw-core - - cn.iocoder.boot diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DatabaseDocController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DatabaseDocController.java deleted file mode 100644 index ea66645b4..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DatabaseDocController.java +++ /dev/null @@ -1,154 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.db; - -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.IdUtil; -import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; -import cn.smallbun.screw.core.Configuration; -import cn.smallbun.screw.core.engine.EngineConfig; -import cn.smallbun.screw.core.engine.EngineFileType; -import cn.smallbun.screw.core.engine.EngineTemplateType; -import cn.smallbun.screw.core.execute.DocumentationExecute; -import cn.smallbun.screw.core.process.ProcessConfig; -import com.baomidou.dynamic.datasource.creator.DataSourceProperty; -import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties; -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Operation; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; - -@Tag(name = "管理后台 - 数据库文档") -@RestController -@RequestMapping("/infra/db-doc") -public class DatabaseDocController { - - @Resource - private DynamicDataSourceProperties dynamicDataSourceProperties; - - private static final String FILE_OUTPUT_DIR = System.getProperty("java.io.tmpdir") + File.separator - + "db-doc"; - private static final String DOC_FILE_NAME = "数据库文档"; - private static final String DOC_VERSION = "1.0.0"; - private static final String DOC_DESCRIPTION = "文档描述"; - - @GetMapping("/export-html") - @Operation(summary = "导出 html 格式的数据文档") - @Parameter(name = "deleteFile", description = "是否删除在服务器本地生成的数据库文档", example = "true") - public void exportHtml(@RequestParam(defaultValue = "true") Boolean deleteFile, - HttpServletResponse response) throws IOException { - doExportFile(EngineFileType.HTML, deleteFile, response); - } - - @GetMapping("/export-word") - @Operation(summary = "导出 word 格式的数据文档") - @Parameter(name = "deleteFile", description = "是否删除在服务器本地生成的数据库文档", example = "true") - public void exportWord(@RequestParam(defaultValue = "true") Boolean deleteFile, - HttpServletResponse response) throws IOException { - doExportFile(EngineFileType.WORD, deleteFile, response); - } - - @GetMapping("/export-markdown") - @Operation(summary = "导出 markdown 格式的数据文档") - @Parameter(name = "deleteFile", description = "是否删除在服务器本地生成的数据库文档", example = "true") - public void exportMarkdown(@RequestParam(defaultValue = "true") Boolean deleteFile, - HttpServletResponse response) throws IOException { - doExportFile(EngineFileType.MD, deleteFile, response); - } - - private void doExportFile(EngineFileType fileOutputType, Boolean deleteFile, - HttpServletResponse response) throws IOException { - String docFileName = DOC_FILE_NAME + "_" + IdUtil.fastSimpleUUID(); - String filePath = doExportFile(fileOutputType, docFileName); - String downloadFileName = DOC_FILE_NAME + fileOutputType.getFileSuffix(); //下载后的文件名 - try { - // 读取,返回 - ServletUtils.writeAttachment(response, downloadFileName, FileUtil.readBytes(filePath)); - } finally { - handleDeleteFile(deleteFile, filePath); - } - } - - /** - * 输出文件,返回文件路径 - * - * @param fileOutputType 文件类型 - * @param fileName 文件名, 无需 ".docx" 等文件后缀 - * @return 生成的文件所在路径 - */ - private String doExportFile(EngineFileType fileOutputType, String fileName) { - try (HikariDataSource dataSource = buildDataSource()) { - // 创建 screw 的配置 - Configuration config = Configuration.builder() - .version(DOC_VERSION) // 版本 - .description(DOC_DESCRIPTION) // 描述 - .dataSource(dataSource) // 数据源 - .engineConfig(buildEngineConfig(fileOutputType, fileName)) // 引擎配置 - .produceConfig(buildProcessConfig()) // 处理配置 - .build(); - - // 执行 screw,生成数据库文档 - new DocumentationExecute(config).execute(); - - return FILE_OUTPUT_DIR + File.separator + fileName + fileOutputType.getFileSuffix(); - } - } - - private void handleDeleteFile(Boolean deleteFile, String filePath) { - if (!deleteFile) { - return; - } - FileUtil.del(filePath); - } - - /** - * 创建数据源 - */ - // TODO 芋艿:screw 暂时不支持 druid,尴尬 - private HikariDataSource buildDataSource() { - // 获得 DataSource 数据源,目前只支持首个 - String primary = dynamicDataSourceProperties.getPrimary(); - DataSourceProperty dataSourceProperty = dynamicDataSourceProperties.getDatasource().get(primary); - // 创建 HikariConfig 配置类 - HikariConfig hikariConfig = new HikariConfig(); - hikariConfig.setJdbcUrl(dataSourceProperty.getUrl()); - hikariConfig.setUsername(dataSourceProperty.getUsername()); - hikariConfig.setPassword(dataSourceProperty.getPassword()); - hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息 - // 创建数据源 - return new HikariDataSource(hikariConfig); - } - - /** - * 创建 screw 的引擎配置 - */ - private static EngineConfig buildEngineConfig(EngineFileType fileOutputType, String docFileName) { - return EngineConfig.builder() - .fileOutputDir(FILE_OUTPUT_DIR) // 生成文件路径 - .openOutputDir(false) // 打开目录 - .fileType(fileOutputType) // 文件类型 - .produceType(EngineTemplateType.velocity) // 文件类型 - .fileName(docFileName) // 自定义文件名称 - .build(); - } - - /** - * 创建 screw 的处理配置,一般可忽略 - * 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置 - */ - private static ProcessConfig buildProcessConfig() { - return ProcessConfig.builder() - .ignoreTablePrefix(Arrays.asList("QRTZ_", "ACT_", "FLW_")) // 忽略表前缀 - .build(); - } - -}