Commit ff5276998cb956fc0878bf39a194040378ce7363

Authored by YunaiV
1 parent 5d58037d

【移除】数据库文档,简化项目的复杂度

yudao-dependencies/pom.xml
@@ -476,22 +476,6 @@ @@ -476,22 +476,6 @@
476 </dependency> 476 </dependency>
477 477
478 <dependency> 478 <dependency>
479 - <groupId>cn.smallbun.screw</groupId>  
480 - <artifactId>screw-core</artifactId> <!-- 实现数据库文档 -->  
481 - <version>${screw.version}</version>  
482 - <exclusions>  
483 - <exclusion>  
484 - <groupId>org.freemarker</groupId>  
485 - <artifactId>freemarker</artifactId> <!-- 移除 Freemarker 依赖,采用 Velocity 作为模板引擎 -->  
486 - </exclusion>  
487 - <exclusion>  
488 - <groupId>com.alibaba</groupId>  
489 - <artifactId>fastjson</artifactId> <!-- 最新版screw-core1.0.5依赖fastjson1.2.73存在漏洞,移除。 -->  
490 - </exclusion>  
491 - </exclusions>  
492 - </dependency>  
493 -  
494 - <dependency>  
495 <groupId>com.google.guava</groupId> 479 <groupId>com.google.guava</groupId>
496 <artifactId>guava</artifactId> 480 <artifactId>guava</artifactId>
497 <version>${guava.version}</version> 481 <version>${guava.version}</version>
yudao-module-infra/yudao-module-infra-biz/pom.xml
@@ -95,11 +95,6 @@ @@ -95,11 +95,6 @@
95 <artifactId>velocity-engine-core</artifactId> <!-- 实现代码生成 --> 95 <artifactId>velocity-engine-core</artifactId> <!-- 实现代码生成 -->
96 </dependency> 96 </dependency>
97 97
98 - <dependency>  
99 - <groupId>cn.smallbun.screw</groupId>  
100 - <artifactId>screw-core</artifactId> <!-- 实现数据库文档 -->  
101 - </dependency>  
102 -  
103 <!-- 监控相关 --> 98 <!-- 监控相关 -->
104 <dependency> 99 <dependency>
105 <groupId>cn.iocoder.boot</groupId> 100 <groupId>cn.iocoder.boot</groupId>
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DatabaseDocController.java deleted
1 -package cn.iocoder.yudao.module.infra.controller.admin.db;  
2 -  
3 -import cn.hutool.core.io.FileUtil;  
4 -import cn.hutool.core.util.IdUtil;  
5 -import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;  
6 -import cn.smallbun.screw.core.Configuration;  
7 -import cn.smallbun.screw.core.engine.EngineConfig;  
8 -import cn.smallbun.screw.core.engine.EngineFileType;  
9 -import cn.smallbun.screw.core.engine.EngineTemplateType;  
10 -import cn.smallbun.screw.core.execute.DocumentationExecute;  
11 -import cn.smallbun.screw.core.process.ProcessConfig;  
12 -import com.baomidou.dynamic.datasource.creator.DataSourceProperty;  
13 -import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;  
14 -import com.zaxxer.hikari.HikariConfig;  
15 -import com.zaxxer.hikari.HikariDataSource;  
16 -import io.swagger.v3.oas.annotations.tags.Tag;  
17 -import io.swagger.v3.oas.annotations.Parameter;  
18 -import io.swagger.v3.oas.annotations.Operation;  
19 -import org.springframework.web.bind.annotation.GetMapping;  
20 -import org.springframework.web.bind.annotation.RequestMapping;  
21 -import org.springframework.web.bind.annotation.RequestParam;  
22 -import org.springframework.web.bind.annotation.RestController;  
23 -  
24 -import jakarta.annotation.Resource;  
25 -import jakarta.servlet.http.HttpServletResponse;  
26 -import java.io.File;  
27 -import java.io.IOException;  
28 -import java.util.Arrays;  
29 -  
30 -@Tag(name = "管理后台 - 数据库文档")  
31 -@RestController  
32 -@RequestMapping("/infra/db-doc")  
33 -public class DatabaseDocController {  
34 -  
35 - @Resource  
36 - private DynamicDataSourceProperties dynamicDataSourceProperties;  
37 -  
38 - private static final String FILE_OUTPUT_DIR = System.getProperty("java.io.tmpdir") + File.separator  
39 - + "db-doc";  
40 - private static final String DOC_FILE_NAME = "数据库文档";  
41 - private static final String DOC_VERSION = "1.0.0";  
42 - private static final String DOC_DESCRIPTION = "文档描述";  
43 -  
44 - @GetMapping("/export-html")  
45 - @Operation(summary = "导出 html 格式的数据文档")  
46 - @Parameter(name = "deleteFile", description = "是否删除在服务器本地生成的数据库文档", example = "true")  
47 - public void exportHtml(@RequestParam(defaultValue = "true") Boolean deleteFile,  
48 - HttpServletResponse response) throws IOException {  
49 - doExportFile(EngineFileType.HTML, deleteFile, response);  
50 - }  
51 -  
52 - @GetMapping("/export-word")  
53 - @Operation(summary = "导出 word 格式的数据文档")  
54 - @Parameter(name = "deleteFile", description = "是否删除在服务器本地生成的数据库文档", example = "true")  
55 - public void exportWord(@RequestParam(defaultValue = "true") Boolean deleteFile,  
56 - HttpServletResponse response) throws IOException {  
57 - doExportFile(EngineFileType.WORD, deleteFile, response);  
58 - }  
59 -  
60 - @GetMapping("/export-markdown")  
61 - @Operation(summary = "导出 markdown 格式的数据文档")  
62 - @Parameter(name = "deleteFile", description = "是否删除在服务器本地生成的数据库文档", example = "true")  
63 - public void exportMarkdown(@RequestParam(defaultValue = "true") Boolean deleteFile,  
64 - HttpServletResponse response) throws IOException {  
65 - doExportFile(EngineFileType.MD, deleteFile, response);  
66 - }  
67 -  
68 - private void doExportFile(EngineFileType fileOutputType, Boolean deleteFile,  
69 - HttpServletResponse response) throws IOException {  
70 - String docFileName = DOC_FILE_NAME + "_" + IdUtil.fastSimpleUUID();  
71 - String filePath = doExportFile(fileOutputType, docFileName);  
72 - String downloadFileName = DOC_FILE_NAME + fileOutputType.getFileSuffix(); //下载后的文件名  
73 - try {  
74 - // 读取,返回  
75 - ServletUtils.writeAttachment(response, downloadFileName, FileUtil.readBytes(filePath));  
76 - } finally {  
77 - handleDeleteFile(deleteFile, filePath);  
78 - }  
79 - }  
80 -  
81 - /**  
82 - * 输出文件,返回文件路径  
83 - *  
84 - * @param fileOutputType 文件类型  
85 - * @param fileName 文件名, 无需 ".docx" 等文件后缀  
86 - * @return 生成的文件所在路径  
87 - */  
88 - private String doExportFile(EngineFileType fileOutputType, String fileName) {  
89 - try (HikariDataSource dataSource = buildDataSource()) {  
90 - // 创建 screw 的配置  
91 - Configuration config = Configuration.builder()  
92 - .version(DOC_VERSION) // 版本  
93 - .description(DOC_DESCRIPTION) // 描述  
94 - .dataSource(dataSource) // 数据源  
95 - .engineConfig(buildEngineConfig(fileOutputType, fileName)) // 引擎配置  
96 - .produceConfig(buildProcessConfig()) // 处理配置  
97 - .build();  
98 -  
99 - // 执行 screw,生成数据库文档  
100 - new DocumentationExecute(config).execute();  
101 -  
102 - return FILE_OUTPUT_DIR + File.separator + fileName + fileOutputType.getFileSuffix();  
103 - }  
104 - }  
105 -  
106 - private void handleDeleteFile(Boolean deleteFile, String filePath) {  
107 - if (!deleteFile) {  
108 - return;  
109 - }  
110 - FileUtil.del(filePath);  
111 - }  
112 -  
113 - /**  
114 - * 创建数据源  
115 - */  
116 - // TODO 芋艿:screw 暂时不支持 druid,尴尬  
117 - private HikariDataSource buildDataSource() {  
118 - // 获得 DataSource 数据源,目前只支持首个  
119 - String primary = dynamicDataSourceProperties.getPrimary();  
120 - DataSourceProperty dataSourceProperty = dynamicDataSourceProperties.getDatasource().get(primary);  
121 - // 创建 HikariConfig 配置类  
122 - HikariConfig hikariConfig = new HikariConfig();  
123 - hikariConfig.setJdbcUrl(dataSourceProperty.getUrl());  
124 - hikariConfig.setUsername(dataSourceProperty.getUsername());  
125 - hikariConfig.setPassword(dataSourceProperty.getPassword());  
126 - hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息  
127 - // 创建数据源  
128 - return new HikariDataSource(hikariConfig);  
129 - }  
130 -  
131 - /**  
132 - * 创建 screw 的引擎配置  
133 - */  
134 - private static EngineConfig buildEngineConfig(EngineFileType fileOutputType, String docFileName) {  
135 - return EngineConfig.builder()  
136 - .fileOutputDir(FILE_OUTPUT_DIR) // 生成文件路径  
137 - .openOutputDir(false) // 打开目录  
138 - .fileType(fileOutputType) // 文件类型  
139 - .produceType(EngineTemplateType.velocity) // 文件类型  
140 - .fileName(docFileName) // 自定义文件名称  
141 - .build();  
142 - }  
143 -  
144 - /**  
145 - * 创建 screw 的处理配置,一般可忽略  
146 - * 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置  
147 - */  
148 - private static ProcessConfig buildProcessConfig() {  
149 - return ProcessConfig.builder()  
150 - .ignoreTablePrefix(Arrays.asList("QRTZ_", "ACT_", "FLW_")) // 忽略表前缀  
151 - .build();  
152 - }  
153 -  
154 -}