|
|
@ -2,13 +2,12 @@ package space.caoshd.otone.builder;
|
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import space.caoshd.otone.entity.ClassInfo;
|
|
|
|
|
|
|
|
import space.caoshd.otone.entity.ContextInfo;
|
|
|
|
import space.caoshd.otone.entity.OutputInfo;
|
|
|
|
import space.caoshd.otone.entity.OutputInfo;
|
|
|
|
import space.caoshd.otone.entity.TableInfo;
|
|
|
|
import space.caoshd.otone.entity.TableInfo;
|
|
|
|
import space.caoshd.otone.tool.PropTools;
|
|
|
|
import space.caoshd.otone.tool.PropTools;
|
|
|
|
import space.caoshd.otone.util.CfgUtils;
|
|
|
|
import space.caoshd.otone.util.*;
|
|
|
|
import space.caoshd.otone.util.FileUtils;
|
|
|
|
|
|
|
|
import space.caoshd.otone.util.PathConsts;
|
|
|
|
|
|
|
|
import space.caoshd.otone.util.VelocityUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
@ -89,34 +88,32 @@ public class SourceBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void build(TableInfo tableInfo, OutputInfo outputInfo) {
|
|
|
|
private void build(TableInfo tableInfo, OutputInfo outputInfo) {
|
|
|
|
// 获取表信息 配置信息
|
|
|
|
|
|
|
|
String beanName = tableInfo.getClassName();
|
|
|
|
|
|
|
|
String nameSuffix = outputInfo.getNameSuffix();
|
|
|
|
|
|
|
|
String namePrefix = outputInfo.getNamePrefix();
|
|
|
|
|
|
|
|
String packagePath = outputInfo.getPackagePath();
|
|
|
|
|
|
|
|
String packageName = outputInfo.getPackageName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加附加信息
|
|
|
|
|
|
|
|
tableInfo.setExtra(extra);
|
|
|
|
|
|
|
|
tableInfo.setClassNameSuffix(nameSuffix);
|
|
|
|
|
|
|
|
tableInfo.setClassNamePrefix(namePrefix);
|
|
|
|
|
|
|
|
tableInfo.setPackageName(packageName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建数据文件夹
|
|
|
|
// 创建数据文件夹
|
|
|
|
FileUtils.mkdir(packagePath);
|
|
|
|
FileUtils.mkdir(outputInfo.getPackagePath());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建上下文环境信息
|
|
|
|
|
|
|
|
ContextInfo contextInfo = new ContextInfo();
|
|
|
|
|
|
|
|
// 设置表信息
|
|
|
|
|
|
|
|
contextInfo.setTableInfo(tableInfo);
|
|
|
|
|
|
|
|
// 设置类信息
|
|
|
|
|
|
|
|
ClassInfo classInfo = buildClassInfo(tableInfo, outputInfo);
|
|
|
|
|
|
|
|
contextInfo.setConfigInfo(classInfo);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取输出文件路径
|
|
|
|
// 获取输出文件路径
|
|
|
|
String outputPath = CfgUtils.getJavaFilePath(packagePath, beanName, nameSuffix, namePrefix);
|
|
|
|
enhanceOutputInfo(outputInfo, classInfo);
|
|
|
|
|
|
|
|
String outputPath = outputInfo.getOutputPath();
|
|
|
|
|
|
|
|
|
|
|
|
// 获取模板文件路径
|
|
|
|
// 获取模板文件路径
|
|
|
|
String templatePath = outputInfo.getTemplatePath();
|
|
|
|
String templatePath = outputInfo.getTemplatePath();
|
|
|
|
// 判断输出文件是否已存在
|
|
|
|
// 判断输出文件是否已存在
|
|
|
|
if (!FileUtils.exists(outputPath)) {
|
|
|
|
if (!FileUtils.exists(outputPath)) {
|
|
|
|
// 输出文件不存在 直接生成
|
|
|
|
// 输出文件不存在 直接生成
|
|
|
|
VelocityUtils.render(CfgUtils.VALUE_TABLE, tableInfo, templatePath, outputPath);
|
|
|
|
VelocityUtils.render(templatePath, outputPath, contextInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 输出文件存在 判断是否可以覆盖
|
|
|
|
// 输出文件存在 判断是否可以覆盖
|
|
|
|
if (CONFIG.getBoolean(CfgUtils.OUTPUT_COVER_IF_EXIST)) {
|
|
|
|
if (CONFIG.getBoolean(CfgUtils.OUTPUT_COVER_IF_EXIST)) {
|
|
|
|
// 配置可以执行覆盖 覆盖生成
|
|
|
|
// 配置可以执行覆盖 覆盖生成
|
|
|
|
VelocityUtils.render(CfgUtils.VALUE_TABLE, tableInfo, templatePath, outputPath);
|
|
|
|
VelocityUtils.render(templatePath, outputPath, contextInfo);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 配置不可以执行覆盖 提示错误消息
|
|
|
|
// 配置不可以执行覆盖 提示错误消息
|
|
|
|
LOGGER.warn("output file already exists: {}, " + "please remove it or enable auto " + "cover exist file,"
|
|
|
|
LOGGER.warn("output file already exists: {}, " + "please remove it or enable auto " + "cover exist file,"
|
|
|
@ -126,6 +123,20 @@ public class SourceBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void enhanceOutputInfo(OutputInfo outputInfo, ClassInfo classInfo) {
|
|
|
|
|
|
|
|
new InfoOutBuilder()
|
|
|
|
|
|
|
|
.init(outputInfo)
|
|
|
|
|
|
|
|
.setClassName(classInfo.getClassName())
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static ClassInfo buildClassInfo(TableInfo tableInfo, OutputInfo outputInfo) {
|
|
|
|
|
|
|
|
return new InfoClsBuilder()
|
|
|
|
|
|
|
|
.setTableName(tableInfo.getTableName())
|
|
|
|
|
|
|
|
.setPackageName(outputInfo.getPackageName())
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void build(TableInfo tableInfo, List<OutputInfo> outputInfoList) {
|
|
|
|
private void build(TableInfo tableInfo, List<OutputInfo> outputInfoList) {
|
|
|
|
// 循环输出信息
|
|
|
|
// 循环输出信息
|
|
|
|
for (OutputInfo outputInfo : outputInfoList) {
|
|
|
|
for (OutputInfo outputInfo : outputInfoList) {
|
|
|
@ -137,50 +148,50 @@ public class SourceBuilder {
|
|
|
|
private List<OutputInfo> defaultOutputInfoList() {
|
|
|
|
private List<OutputInfo> defaultOutputInfoList() {
|
|
|
|
return Arrays.asList(
|
|
|
|
return Arrays.asList(
|
|
|
|
// PO
|
|
|
|
// PO
|
|
|
|
new OutputBuilder().setNameSuffix(CfgUtils.getPoNameSuffix())
|
|
|
|
new InfoOutBuilder().setNameSuffix(CfgUtils.getPoNameSuffix())
|
|
|
|
.setTemplatePath(CfgUtils.getPoTemplatePath())
|
|
|
|
.setTemplatePath(CfgUtils.getPoTemplatePath())
|
|
|
|
.setPackagePath(CfgUtils.getPoPackagePath())
|
|
|
|
.setPackagePath(CfgUtils.getPoPackagePath())
|
|
|
|
.setPackageName(CfgUtils.getPoPackageName())
|
|
|
|
.setPackageName(CfgUtils.getPoPackageName())
|
|
|
|
.build(),
|
|
|
|
.build(),
|
|
|
|
// MAPPER
|
|
|
|
// MAPPER
|
|
|
|
new OutputBuilder().setNameSuffix(CfgUtils.getMapperNameSuffix())
|
|
|
|
new InfoOutBuilder().setNameSuffix(CfgUtils.getMapperNameSuffix())
|
|
|
|
.setTemplatePath(CfgUtils.getMapperTemplatePath())
|
|
|
|
.setTemplatePath(CfgUtils.getMapperTemplatePath())
|
|
|
|
.setPackagePath(CfgUtils.getMapperPackagePath())
|
|
|
|
.setPackagePath(CfgUtils.getMapperPackagePath())
|
|
|
|
.setPackageName(CfgUtils.getMapperPackageName())
|
|
|
|
.setPackageName(CfgUtils.getMapperPackageName())
|
|
|
|
.build(),
|
|
|
|
.build(),
|
|
|
|
// SERVICE
|
|
|
|
// SERVICE
|
|
|
|
new OutputBuilder().setNameSuffix(CfgUtils.getServiceNameSuffix())
|
|
|
|
new InfoOutBuilder().setNameSuffix(CfgUtils.getServiceNameSuffix())
|
|
|
|
.setTemplatePath(CfgUtils.getServiceTemplatePath())
|
|
|
|
.setTemplatePath(CfgUtils.getServiceTemplatePath())
|
|
|
|
.setPackagePath(CfgUtils.getServicePackagePath())
|
|
|
|
.setPackagePath(CfgUtils.getServicePackagePath())
|
|
|
|
.setPackageName(CfgUtils.getServicePackageName())
|
|
|
|
.setPackageName(CfgUtils.getServicePackageName())
|
|
|
|
.build(),
|
|
|
|
.build(),
|
|
|
|
// SERVICE INTERFACE
|
|
|
|
// SERVICE INTERFACE
|
|
|
|
new OutputBuilder().setNameSuffix(CfgUtils.getServiceNameSuffix())
|
|
|
|
new InfoOutBuilder().setNameSuffix(CfgUtils.getServiceNameSuffix())
|
|
|
|
.setNamePrefix(CfgUtils.getServiceInterfacePrefix())
|
|
|
|
.setNamePrefix(CfgUtils.getServiceInterfacePrefix())
|
|
|
|
.setTemplatePath(CfgUtils.getServiceInterfaceTemplatePath())
|
|
|
|
.setTemplatePath(CfgUtils.getServiceInterfaceTemplatePath())
|
|
|
|
.setPackagePath(CfgUtils.getServiceInterfacePackagePath())
|
|
|
|
.setPackagePath(CfgUtils.getServiceInterfacePackagePath())
|
|
|
|
.setPackageName(CfgUtils.getServiceInterfacePackageName())
|
|
|
|
.setPackageName(CfgUtils.getServiceInterfacePackageName())
|
|
|
|
.build(),
|
|
|
|
.build(),
|
|
|
|
// CONTROLLER
|
|
|
|
// CONTROLLER
|
|
|
|
new OutputBuilder().setNameSuffix(CfgUtils.getControllerNameSuffix())
|
|
|
|
new InfoOutBuilder().setNameSuffix(CfgUtils.getControllerNameSuffix())
|
|
|
|
.setTemplatePath(CfgUtils.getControllerTemplatePath())
|
|
|
|
.setTemplatePath(CfgUtils.getControllerTemplatePath())
|
|
|
|
.setPackagePath(CfgUtils.getControllerPackagePath())
|
|
|
|
.setPackagePath(CfgUtils.getControllerPackagePath())
|
|
|
|
.setPackageName(CfgUtils.getControllerPackageName())
|
|
|
|
.setPackageName(CfgUtils.getControllerPackageName())
|
|
|
|
.build(),
|
|
|
|
.build(),
|
|
|
|
// VIEW
|
|
|
|
// VIEW
|
|
|
|
new OutputBuilder().setNameSuffix(CfgUtils.getViewNameSuffix())
|
|
|
|
new InfoOutBuilder().setNameSuffix(CfgUtils.getViewNameSuffix())
|
|
|
|
.setTemplatePath(CfgUtils.getViewTemplatePath())
|
|
|
|
.setTemplatePath(CfgUtils.getViewTemplatePath())
|
|
|
|
.setPackagePath(CfgUtils.getViewPackagePath())
|
|
|
|
.setPackagePath(CfgUtils.getViewPackagePath())
|
|
|
|
.setPackageName(CfgUtils.getViewPackageName())
|
|
|
|
.setPackageName(CfgUtils.getViewPackageName())
|
|
|
|
.build(),
|
|
|
|
.build(),
|
|
|
|
// FORM
|
|
|
|
// FORM
|
|
|
|
new OutputBuilder().setNameSuffix(CfgUtils.getFormNameSuffix())
|
|
|
|
new InfoOutBuilder().setNameSuffix(CfgUtils.getFormNameSuffix())
|
|
|
|
.setTemplatePath(CfgUtils.getFormTemplatePath())
|
|
|
|
.setTemplatePath(CfgUtils.getFormTemplatePath())
|
|
|
|
.setPackagePath(CfgUtils.getFormPackagePath())
|
|
|
|
.setPackagePath(CfgUtils.getFormPackagePath())
|
|
|
|
.setPackageName(CfgUtils.getFormPackageName())
|
|
|
|
.setPackageName(CfgUtils.getFormPackageName())
|
|
|
|
.build(),
|
|
|
|
.build(),
|
|
|
|
// QUERY
|
|
|
|
// QUERY
|
|
|
|
new OutputBuilder().setNameSuffix(CfgUtils.getQueryNameSuffix())
|
|
|
|
new InfoOutBuilder().setNameSuffix(CfgUtils.getQueryNameSuffix())
|
|
|
|
.setTemplatePath(CfgUtils.getQueryTemplatePath())
|
|
|
|
.setTemplatePath(CfgUtils.getQueryTemplatePath())
|
|
|
|
.setPackagePath(CfgUtils.getQueryPackagePath())
|
|
|
|
.setPackagePath(CfgUtils.getQueryPackagePath())
|
|
|
|
.setPackageName(CfgUtils.getQueryPackageName())
|
|
|
|
.setPackageName(CfgUtils.getQueryPackageName())
|
|
|
|