🐛 代码生成器未能读取到环境变量.
This commit is contained in:
@@ -23,6 +23,8 @@
|
|||||||
package org.dromara.visor.framework.mybatis.core.generator;
|
package org.dromara.visor.framework.mybatis.core.generator;
|
||||||
|
|
||||||
import cn.orionsec.kit.lang.constant.Const;
|
import cn.orionsec.kit.lang.constant.Const;
|
||||||
|
import cn.orionsec.kit.lang.utils.Strings;
|
||||||
|
import cn.orionsec.kit.lang.utils.Systems;
|
||||||
import cn.orionsec.kit.lang.utils.ansi.AnsiAppender;
|
import cn.orionsec.kit.lang.utils.ansi.AnsiAppender;
|
||||||
import cn.orionsec.kit.lang.utils.ansi.style.AnsiFont;
|
import cn.orionsec.kit.lang.utils.ansi.style.AnsiFont;
|
||||||
import cn.orionsec.kit.lang.utils.ansi.style.color.AnsiForeground;
|
import cn.orionsec.kit.lang.utils.ansi.style.color.AnsiForeground;
|
||||||
@@ -32,6 +34,8 @@ import org.dromara.visor.framework.mybatis.core.generator.template.Table;
|
|||||||
import org.dromara.visor.framework.mybatis.core.generator.template.Template;
|
import org.dromara.visor.framework.mybatis.core.generator.template.Template;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成器
|
* 代码生成器
|
||||||
@@ -42,6 +46,8 @@ import java.io.File;
|
|||||||
*/
|
*/
|
||||||
public class CodeGenerators {
|
public class CodeGenerators {
|
||||||
|
|
||||||
|
private static final Pattern ENV_VAR_PATTERN = Pattern.compile("\\$\\{([^:]+):([^}]+)\\}");
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// 输出路径
|
// 输出路径
|
||||||
String outputDir = "D:/MP/";
|
String outputDir = "D:/MP/";
|
||||||
@@ -76,11 +82,6 @@ public class CodeGenerators {
|
|||||||
.disableUnitTest()
|
.disableUnitTest()
|
||||||
.enableProviderApi()
|
.enableProviderApi()
|
||||||
.vue("system", "message")
|
.vue("system", "message")
|
||||||
.dict("messageClassify", "classify", "messageClassify")
|
|
||||||
.comment("消息分类")
|
|
||||||
.fields("NOTICE", "TODO")
|
|
||||||
.labels("通知", "待办")
|
|
||||||
.valueUseFields()
|
|
||||||
.dict("messageType", "type", "messageType")
|
.dict("messageType", "type", "messageType")
|
||||||
.comment("消息类型")
|
.comment("消息类型")
|
||||||
.fields("EXEC_FAILED", "UPLOAD_FAILED")
|
.fields("EXEC_FAILED", "UPLOAD_FAILED")
|
||||||
@@ -94,9 +95,9 @@ public class CodeGenerators {
|
|||||||
// jdbc 配置 - 使用配置文件
|
// jdbc 配置 - 使用配置文件
|
||||||
File yamlFile = new File("orion-visor-launch/src/main/resources/application-dev.yaml");
|
File yamlFile = new File("orion-visor-launch/src/main/resources/application-dev.yaml");
|
||||||
YmlExt yaml = YmlExt.load(yamlFile);
|
YmlExt yaml = YmlExt.load(yamlFile);
|
||||||
String url = yaml.getValue("spring.datasource.druid.url");
|
String url = resolveConfigValue(yaml.getValue("spring.datasource.druid.url"));
|
||||||
String username = yaml.getValue("spring.datasource.druid.username");
|
String username = resolveConfigValue(yaml.getValue("spring.datasource.druid.username"));
|
||||||
String password = yaml.getValue("spring.datasource.druid.password");
|
String password = resolveConfigValue(yaml.getValue("spring.datasource.druid.password"));
|
||||||
|
|
||||||
// 执行
|
// 执行
|
||||||
runGenerator(outputDir, author,
|
runGenerator(outputDir, author,
|
||||||
@@ -147,4 +148,31 @@ public class CodeGenerators {
|
|||||||
System.out.print(line);
|
System.out.print(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析实际的配置
|
||||||
|
*
|
||||||
|
* @param value value
|
||||||
|
* @return value
|
||||||
|
*/
|
||||||
|
private static String resolveConfigValue(String value) {
|
||||||
|
if (Strings.isBlank(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
Matcher matcher = ENV_VAR_PATTERN.matcher(value);
|
||||||
|
StringBuffer resultString = new StringBuffer();
|
||||||
|
while (matcher.find()) {
|
||||||
|
// 环境变量名
|
||||||
|
String envVar = matcher.group(1);
|
||||||
|
// 默认值
|
||||||
|
String defaultValue = matcher.group(2);
|
||||||
|
// 获取环境变量的值
|
||||||
|
String envValue = Systems.getEnv(envVar, defaultValue);
|
||||||
|
// 替换占位符
|
||||||
|
matcher.appendReplacement(resultString, Matcher.quoteReplacement(envValue));
|
||||||
|
}
|
||||||
|
// 处理结尾的剩余部分
|
||||||
|
matcher.appendTail(resultString);
|
||||||
|
return resultString.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ SELECT @TYPE_KEY_ID:= id FROM dict_key WHERE key_name = 'operatorLogType' AND de
|
|||||||
INSERT INTO dict_value
|
INSERT INTO dict_value
|
||||||
(`key_id`, `key_name`, `value`, `label`, `extra`, `sort`, `create_time`, `update_time`, `creator`, `updater`, `deleted`)
|
(`key_id`, `key_name`, `value`, `label`, `extra`, `sort`, `create_time`, `update_time`, `creator`, `updater`, `deleted`)
|
||||||
VALUES
|
VALUES
|
||||||
(@MODULE_KEY_ID, 'operatorLogModule', '${package.ModuleName}:${typeHyphen}', '$!{table.comment}', '{}', @MODULE_KEY_MAX_SORT + 10, now(), now(), '1', '1', 0),
|
(@MODULE_KEY_ID, 'operatorLogModule', '${package.ModuleName}:${typeHyphen}', '$!{table.comment}', '{}', @MODULE_KEY_MAX_SORT + 10, now(), now(), 'admin', 'admin', 0),
|
||||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:create', '创建$!{table.comment}', '{}', 10, now(), now(), '1', '1', 0),
|
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:create', '创建$!{table.comment}', '{}', 10, now(), now(), 'admin', 'admin', 0),
|
||||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:update', '更新$!{table.comment}', '{}', 20, now(), now(), '1', '1', 0),
|
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:update', '更新$!{table.comment}', '{}', 20, now(), now(), 'admin', 'admin', 0),
|
||||||
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:delete', '删除$!{table.comment}', '{}', 30, now(), now(), '1', '1', 0);
|
(@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:delete', '删除$!{table.comment}', '{}', 30, now(), now(), 'admin', 'admin', 0);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#if($dictMap.entrySet().size() > 0)
|
#if($dictMap.entrySet().size() > 0)
|
||||||
@@ -23,7 +23,7 @@ VALUES
|
|||||||
INSERT INTO dict_key
|
INSERT INTO dict_key
|
||||||
(`key_name`, `value_type`, `extra_schema`, `description`, `create_time`, `update_time`, `creator`, `updater`, `deleted`)
|
(`key_name`, `value_type`, `extra_schema`, `description`, `create_time`, `update_time`, `creator`, `updater`, `deleted`)
|
||||||
VALUES
|
VALUES
|
||||||
('$enumEntity.value.keyName', 'STRING', '$enumEntity.value.extraSchema', '$enumEntity.value.comment', now(), now(), '1', '1', 0);
|
('$enumEntity.value.keyName', 'STRING', '$enumEntity.value.extraSchema', '$enumEntity.value.comment', now(), now(), 'admin', 'admin', 0);
|
||||||
|
|
||||||
-- 设置临时配置项id
|
-- 设置临时配置项id
|
||||||
SELECT @TMP_KEY_ID:=LAST_INSERT_ID();
|
SELECT @TMP_KEY_ID:=LAST_INSERT_ID();
|
||||||
@@ -35,7 +35,7 @@ VALUES
|
|||||||
#set($count = $enumEntity.value.fields.size() - 1)
|
#set($count = $enumEntity.value.fields.size() - 1)
|
||||||
#foreach($index in [0..$count])
|
#foreach($index in [0..$count])
|
||||||
#set($sort = $index * 10 + 10)
|
#set($sort = $index * 10 + 10)
|
||||||
(@TMP_KEY_ID, '$enumEntity.value.keyName', '$enumEntity.value.values.get($index)', '$enumEntity.value.labels.get($index)', #if($enumEntity.value.extraJson.size() > $index)'$enumEntity.value.extraJson.get($index)'#else'{}'#end, $sort, now(), now(), '1', '1', 0)#if($foreach.hasNext),#else;#end
|
(@TMP_KEY_ID, '$enumEntity.value.keyName', '$enumEntity.value.values.get($index)', '$enumEntity.value.labels.get($index)', #if($enumEntity.value.extraJson.size() > $index)'$enumEntity.value.extraJson.get($index)'#else'{}'#end, $sort, now(), now(), 'admin', 'admin', 0)#if($foreach.hasNext),#else;#end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#end
|
#end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
INSERT INTO system_menu
|
INSERT INTO system_menu
|
||||||
(parent_id, name, type, sort, visible, status, cache, component, creator, updater, deleted)
|
(parent_id, name, type, sort, visible, status, cache, component, creator, updater, deleted)
|
||||||
VALUES
|
VALUES
|
||||||
(0, '${table.comment}管理', 1, 10, 1, 1, 1, '${vue.moduleEntityFirstLower}Module', '1', '1', 0);
|
(0, '${table.comment}管理', 1, 10, 1, 1, 1, '${vue.moduleEntityFirstLower}Module', 'admin', 'admin', 0);
|
||||||
|
|
||||||
-- 设置临时父菜单id
|
-- 设置临时父菜单id
|
||||||
SELECT @TMP_PARENT_ID:=LAST_INSERT_ID();
|
SELECT @TMP_PARENT_ID:=LAST_INSERT_ID();
|
||||||
@@ -13,7 +13,7 @@ SELECT @TMP_PARENT_ID:=LAST_INSERT_ID();
|
|||||||
INSERT INTO system_menu
|
INSERT INTO system_menu
|
||||||
(parent_id, name, type, sort, visible, status, cache, component, creator, updater, deleted)
|
(parent_id, name, type, sort, visible, status, cache, component, creator, updater, deleted)
|
||||||
VALUES
|
VALUES
|
||||||
(@TMP_PARENT_ID, '$table.comment', 2, 10, 1, 1, 1, '$vue.featureEntityFirstLower', '1', '1', 0);
|
(@TMP_PARENT_ID, '$table.comment', 2, 10, 1, 1, 1, '$vue.featureEntityFirstLower', 'admin', 'admin', 0);
|
||||||
|
|
||||||
-- 设置临时子菜单id
|
-- 设置临时子菜单id
|
||||||
SELECT @TMP_SUB_ID:=LAST_INSERT_ID();
|
SELECT @TMP_SUB_ID:=LAST_INSERT_ID();
|
||||||
@@ -22,7 +22,7 @@ SELECT @TMP_SUB_ID:=LAST_INSERT_ID();
|
|||||||
INSERT INTO system_menu
|
INSERT INTO system_menu
|
||||||
(parent_id, name, permission, type, sort, creator, updater, deleted)
|
(parent_id, name, permission, type, sort, creator, updater, deleted)
|
||||||
VALUES
|
VALUES
|
||||||
(@TMP_SUB_ID, '查询$table.comment', '${package.ModuleName}:${typeHyphen}:query', 3, 10, '1', '1', 0),
|
(@TMP_SUB_ID, '查询$table.comment', '${package.ModuleName}:${typeHyphen}:query', 3, 10, 'admin', 'admin', 0),
|
||||||
(@TMP_SUB_ID, '创建$table.comment', '${package.ModuleName}:${typeHyphen}:create', 3, 20, '1', '1', 0),
|
(@TMP_SUB_ID, '创建$table.comment', '${package.ModuleName}:${typeHyphen}:create', 3, 20, 'admin', 'admin', 0),
|
||||||
(@TMP_SUB_ID, '修改$table.comment', '${package.ModuleName}:${typeHyphen}:update', 3, 30, '1', '1', 0),
|
(@TMP_SUB_ID, '修改$table.comment', '${package.ModuleName}:${typeHyphen}:update', 3, 30, 'admin', 'admin', 0),
|
||||||
(@TMP_SUB_ID, '删除$table.comment', '${package.ModuleName}:${typeHyphen}:delete', 3, 40, '1', '1', 0);
|
(@TMP_SUB_ID, '删除$table.comment', '${package.ModuleName}:${typeHyphen}:delete', 3, 40, 'admin', 'admin', 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user