添加 sql 模板文件.

This commit is contained in:
lijiahang
2023-08-16 10:20:51 +08:00
parent bc163d786a
commit 482b928532
3 changed files with 80 additions and 4 deletions

View File

@@ -328,6 +328,8 @@ public class CodeGenerator {
new String[]{"/templates/orion-vue-views-types-form.rules.ts.vm", "form.rules.ts", "vue/views/${module}/${feature}/types"},
// vue table.vue 文件
new String[]{"/templates/orion-vue-views-types-table.columns.ts.vm", "table.columns.ts", "vue/views/${module}/${feature}/types"},
// sql menu.sql 文件
new String[]{"/templates/orion-sql-menu.sql.vm", "${feature}-menu.sql", "sql"},
};
// 构建文件

View File

@@ -209,7 +209,7 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
// 生成后端文件
List<CustomFile> serverFiles = customFiles.stream()
.filter(s -> !this.isVueFile(s.getTemplatePath()))
.filter(s -> this.isServerFile(s.getTemplatePath()))
.collect(Collectors.toList());
this.generatorServerFile(serverFiles, tableInfo, objectMap);
// 生成前端文件
@@ -264,7 +264,6 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
beanMap.put("featureAllUpper", table.getFeature().toUpperCase());
// 枚举
beanMap.put("enums", this.getEnumMap(table));
System.out.println( this.getEnumMap(table));
objectMap.put("vue", beanMap);
@@ -279,6 +278,46 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
});
}
/**
* 生成 sql 文件
*
* @param customFiles customFiles
* @param tableInfo tableInfo
* @param objectMap objectMap
*/
private void generatorSqlFile(@NotNull List<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
String outPath = getConfigBuilder().getGlobalConfig().getOutputDir();
GenTable table = tables.get(tableInfo.getName());
BeanMap beanMap = BeanMap.create(table, "enums");
// 模块名称首字母大写
beanMap.put("moduleFirstUpper", Strings.firstUpper(table.getModule()));
// 功能名称首字母大写
beanMap.put("featureFirstUpper", Strings.firstUpper(table.getFeature()));
// 功能名称全大写
beanMap.put("featureAllUpper", table.getFeature().toUpperCase());
objectMap.put("vue", beanMap);
// 生成文件
customFiles.forEach(file -> {
// 文件路径
String filePath = outPath
+ "/" + Strings.format(file.getPackageName(), beanMap)
+ "/" + Strings.format(file.getFileName(), beanMap);
// 输出文件
this.outputFile(Files1.newFile(filePath), objectMap, file.getTemplatePath(), file.isFileOverride());
});
}
/**
* 是否为后端文件
*
* @param templatePath templatePath
* @return 是否为后端文件
*/
private boolean isServerFile(String templatePath) {
return templatePath.startsWith("orion-server");
}
/**
* 是否为 vue 文件
*
@@ -286,8 +325,18 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
* @return 是否为 vue 文件
*/
private boolean isVueFile(String templatePath) {
return templatePath.endsWith(".ts.vm") ||
templatePath.endsWith(".vue.vm");
return templatePath.contains("orion-vue-") ||
templatePath.contains("orion-sql-menu.sql");
}
/**
* 是否为 sql 文件
*
* @param templatePath templatePath
* @return 是否为 sql 文件
*/
private boolean isSqlFile(String templatePath) {
return templatePath.contains("orion-sql-");
}
/**

View File

@@ -0,0 +1,25 @@
-- 执行完成后 需要在菜单页面刷新缓存
-- 设置临时子菜单id
SELECT @TMP_PARENT_ID:=LAST_INSERT_ID();
-- 父菜单
INSERT INTO system_menu (parent_id, name, type, sort, visible, status, cache)
VALUES (0, '${vue.comment}管理', 1, 10, 1, 1, 1);
-- 子菜单
INSERT INTO system_menu (parent_id, name, type, sort, visible, status, cache, component)
VALUES (@TMP_PARENT_ID, '$vue.comment', 2, 10, 1, 1, 1, '$vue.module$vue.featureFirstUpper');
-- 设置临时子菜单id
SELECT @TMP_SUB_ID:=LAST_INSERT_ID();
-- 功能
INSERT INTO system_menu (parent_id, name, permission, type, sort)
VALUES (@TMP_SUB_ID, '创建$vue.comment', '${package.ModuleName}:${typeHyphen}:create', 3, 10);
INSERT INTO system_menu (parent_id, name, permission, type, sort)
VALUES (@TMP_SUB_ID, '修改$vue.comment', '${package.ModuleName}:${typeHyphen}:update', 3, 20);
INSERT INTO system_menu (parent_id, name, permission, type, sort)
VALUES (@TMP_SUB_ID, '查询$vue.comment', '${package.ModuleName}:${typeHyphen}:query', 3, 30);
INSERT INTO system_menu (parent_id, name, permission, type, sort)
VALUES (@TMP_SUB_ID, '删除$vue.comment', '${package.ModuleName}:${typeHyphen}:delete', 3, 40);