From 093501a40061a14ffb6bc891e0d2a93547f18312 Mon Sep 17 00:00:00 2001 From: lijiahang Date: Thu, 6 Mar 2025 10:17:48 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=99=A8=E6=9C=AA=E8=83=BD=E8=AF=BB=E5=8F=96=E5=88=B0=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/generator/CodeGenerators.java | 44 +++++++++++++++---- .../resources/templates/orion-sql-dict.sql.vm | 12 ++--- .../resources/templates/orion-sql-menu.sql.vm | 12 ++--- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/java/org/dromara/visor/framework/mybatis/core/generator/CodeGenerators.java b/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/java/org/dromara/visor/framework/mybatis/core/generator/CodeGenerators.java index bdabf5b9..1cd3bd16 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/java/org/dromara/visor/framework/mybatis/core/generator/CodeGenerators.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/java/org/dromara/visor/framework/mybatis/core/generator/CodeGenerators.java @@ -23,6 +23,8 @@ package org.dromara.visor.framework.mybatis.core.generator; 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.style.AnsiFont; 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 java.io.File; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * 代码生成器 @@ -42,6 +46,8 @@ import java.io.File; */ public class CodeGenerators { + private static final Pattern ENV_VAR_PATTERN = Pattern.compile("\\$\\{([^:]+):([^}]+)\\}"); + public static void main(String[] args) { // 输出路径 String outputDir = "D:/MP/"; @@ -76,11 +82,6 @@ public class CodeGenerators { .disableUnitTest() .enableProviderApi() .vue("system", "message") - .dict("messageClassify", "classify", "messageClassify") - .comment("消息分类") - .fields("NOTICE", "TODO") - .labels("通知", "待办") - .valueUseFields() .dict("messageType", "type", "messageType") .comment("消息类型") .fields("EXEC_FAILED", "UPLOAD_FAILED") @@ -94,9 +95,9 @@ public class CodeGenerators { // jdbc 配置 - 使用配置文件 File yamlFile = new File("orion-visor-launch/src/main/resources/application-dev.yaml"); YmlExt yaml = YmlExt.load(yamlFile); - String url = yaml.getValue("spring.datasource.druid.url"); - String username = yaml.getValue("spring.datasource.druid.username"); - String password = yaml.getValue("spring.datasource.druid.password"); + String url = resolveConfigValue(yaml.getValue("spring.datasource.druid.url")); + String username = resolveConfigValue(yaml.getValue("spring.datasource.druid.username")); + String password = resolveConfigValue(yaml.getValue("spring.datasource.druid.password")); // 执行 runGenerator(outputDir, author, @@ -147,4 +148,31 @@ public class CodeGenerators { 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(); + } + } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-dict.sql.vm b/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-dict.sql.vm index a6779d46..2c1bb0ec 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-dict.sql.vm +++ b/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-dict.sql.vm @@ -11,10 +11,10 @@ SELECT @TYPE_KEY_ID:= id FROM dict_key WHERE key_name = 'operatorLogType' AND de INSERT INTO dict_value (`key_id`, `key_name`, `value`, `label`, `extra`, `sort`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES - (@MODULE_KEY_ID, 'operatorLogModule', '${package.ModuleName}:${typeHyphen}', '$!{table.comment}', '{}', @MODULE_KEY_MAX_SORT + 10, now(), now(), '1', '1', 0), - (@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:create', '创建$!{table.comment}', '{}', 10, now(), now(), '1', '1', 0), - (@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:update', '更新$!{table.comment}', '{}', 20, now(), now(), '1', '1', 0), - (@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:delete', '删除$!{table.comment}', '{}', 30, 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(), 'admin', 'admin', 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(), 'admin', 'admin', 0); #end #if($dictMap.entrySet().size() > 0) @@ -23,7 +23,7 @@ VALUES INSERT INTO dict_key (`key_name`, `value_type`, `extra_schema`, `description`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) 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 SELECT @TMP_KEY_ID:=LAST_INSERT_ID(); @@ -35,7 +35,7 @@ VALUES #set($count = $enumEntity.value.fields.size() - 1) #foreach($index in [0..$count]) #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 diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-menu.sql.vm b/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-menu.sql.vm index 44cf25a1..db7938fa 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-menu.sql.vm +++ b/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-menu.sql.vm @@ -4,7 +4,7 @@ INSERT INTO system_menu (parent_id, name, type, sort, visible, status, cache, component, creator, updater, deleted) 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 SELECT @TMP_PARENT_ID:=LAST_INSERT_ID(); @@ -13,7 +13,7 @@ SELECT @TMP_PARENT_ID:=LAST_INSERT_ID(); INSERT INTO system_menu (parent_id, name, type, sort, visible, status, cache, component, creator, updater, deleted) 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 SELECT @TMP_SUB_ID:=LAST_INSERT_ID(); @@ -22,7 +22,7 @@ SELECT @TMP_SUB_ID:=LAST_INSERT_ID(); INSERT INTO system_menu (parent_id, name, permission, type, sort, creator, updater, deleted) VALUES - (@TMP_SUB_ID, '查询$table.comment', '${package.ModuleName}:${typeHyphen}:query', 3, 10, '1', '1', 0), - (@TMP_SUB_ID, '创建$table.comment', '${package.ModuleName}:${typeHyphen}:create', 3, 20, '1', '1', 0), - (@TMP_SUB_ID, '修改$table.comment', '${package.ModuleName}:${typeHyphen}:update', 3, 30, '1', '1', 0), - (@TMP_SUB_ID, '删除$table.comment', '${package.ModuleName}:${typeHyphen}:delete', 3, 40, '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, 'admin', 'admin', 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, 'admin', 'admin', 0);