package com.example.screw.screwdemo;
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.example.screw.screwdemo.generator.GeneratorProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import javax.sql.DataSource;
import java.util.List;
@SpringBootTest
class ScrewTests {
@Autowired
ApplicationContext applicationContext;
@Autowired
GeneratorProperties generatorProperties;
@Test
void generatorDoc() {
DataSource dataSource = applicationContext.getBean(DataSource.class);
// 生成文档配置
EngineConfig engineConfig = EngineConfig.builder()
// 生成文档路径
.fileOutputDir(generatorProperties.getFileOutputDir())
// 是否打开目录
.openOutputDir(generatorProperties.getOpenOutputDir())
// 文档类型
.fileType(this.getEngineFileType(generatorProperties.getFileType()))
//文档名称
.fileName(generatorProperties.getFileName() + generatorProperties.getVersion())
// 生成模板实现
.produceType(this.getEngineTemplateType(generatorProperties.getProduceType())).build();
Configuration config = Configuration.builder()
.version(generatorProperties.getVersion())
.description(generatorProperties.getDescription())
.dataSource(dataSource)
.engineConfig(engineConfig)
.produceConfig(getProcessConfig())
.build();
new DocumentationExecute(config).execute();
}
/**
* 配置想要生成的表+ 配置想要忽略的表
*
* @return 生成表配置
*/
private ProcessConfig getProcessConfig() {
List<String> tableName = generatorProperties.getTableName();
List<String> prefix = generatorProperties.getPrefix();
List<String> suffix = generatorProperties.getSuffix();
// 两种生成策略,一种是根据指定的表、表前缀、表后缀去生成;二种是忽略指定的表、表前缀、表后缀去生成。1采用忽略策略,2采用指定策略
Integer strategy = generatorProperties.getStrategy();
switch (strategy) {
case 2:
return ProcessConfig.builder()
//根据名称指定表生成
.designatedTableName(tableName)
//根据表前缀生成
.designatedTablePrefix(prefix)
//根据表后缀生成
.designatedTableSuffix(suffix).build();
default:
return ProcessConfig.builder()
//忽略表名
.ignoreTableName(tableName)
//忽略表前缀
.ignoreTablePrefix(prefix)
//忽略表后缀
.ignoreTableSuffix(suffix).build();
}
}
/**
* @param fileType
* @return
*/
private EngineFileType getEngineFileType(String fileType) {
String fileTypeLowerCase = fileType.toLowerCase();
switch (fileTypeLowerCase) {
case "html":
return EngineFileType.HTML;
case "word":
return EngineFileType.WORD;
default:
return EngineFileType.MD;
}
}
/**
* 采用哪种模板生成
*
* @param produceType
* @return
*/
private EngineTemplateType getEngineTemplateType(String produceType) {
String produceTypeLowerCase = produceType.toLowerCase();
switch (produceTypeLowerCase) {
case "velocity":
return EngineTemplateType.velocity;
default:
return EngineTemplateType.freemarker;
}
}
}
最近下载更多
zolscy LV24
2024年11月26日
2206371875 LV7
2024年3月1日
shuangfu LV25
2023年10月25日
opq221 LV5
2023年3月10日
二进制2 LV3
2023年1月6日
crosa_Don LV18
2022年10月7日
dengjunjun LV15
2022年9月30日
yjh120470 LV3
2022年9月29日
zw5097 LV23
2022年9月29日
qintian1023 LV2
2022年9月28日

最近浏览