mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-04-15 15:03:16 +08:00
update 适配 根据导入数据源指定代码生成模板
This commit is contained in:
@@ -54,6 +54,26 @@ public class DataBaseHelper {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定数据源对应的数据库类型
|
||||
*
|
||||
* @param dsName 数据源名称
|
||||
* @return 指定数据库对应的 DataBaseType 枚举,找不到时默认返回 MY_SQL
|
||||
* @throws ServiceException 当获取数据库连接或元数据出现异常时抛出业务异常
|
||||
*/
|
||||
public static DataBaseType getDataBaseType(String dsName) {
|
||||
DataSource dataSource = DS.getDataSource(dsName);
|
||||
return DB_TYPE_CACHE.computeIfAbsent(dsName, k -> {
|
||||
try (Connection conn = dataSource.getConnection()) {
|
||||
DatabaseMetaData metaData = conn.getMetaData();
|
||||
String databaseProductName = metaData.getDatabaseProductName();
|
||||
return DataBaseType.find(databaseProductName);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("获取数据库类型失败", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据当前数据库类型,生成兼容的 FIND_IN_SET 语句片段
|
||||
* <p>
|
||||
|
||||
@@ -369,7 +369,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
|
||||
Dict context = TemplateEngineUtils.buildContext(table);
|
||||
// 获取模板列表
|
||||
List<PathNamedTemplate> templates = TemplateEngineUtils.getTemplateList(table.getTplCategory());
|
||||
List<PathNamedTemplate> templates = TemplateEngineUtils.getTemplateList(table.getTplCategory(), table.getDataName());
|
||||
for (PathNamedTemplate template : templates) {
|
||||
String pathName = template.getPathName();
|
||||
// 渲染模板
|
||||
@@ -492,7 +492,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
table.setMenuIds(menuIds);
|
||||
setPkColumn(table);
|
||||
Dict context = TemplateEngineUtils.buildContext(table);
|
||||
List<PathNamedTemplate> templates = TemplateEngineUtils.getTemplateList(table.getTplCategory());
|
||||
List<PathNamedTemplate> templates = TemplateEngineUtils.getTemplateList(table.getTplCategory(), table.getDataName());
|
||||
return new RenderContext(table, context, templates);
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ public class TemplateEngineUtils {
|
||||
*
|
||||
* @return 模板列表
|
||||
*/
|
||||
public static List<PathNamedTemplate> getTemplateList(String tplCategory) {
|
||||
public static List<PathNamedTemplate> getTemplateList(String tplCategory, String dsName) {
|
||||
List<PathNamedTemplate> templates = new ArrayList<>();
|
||||
// 后端源码模板
|
||||
templates.add(TEMPLATE_MAPPER.get(GenConstants.JAVA_DOMAIN_TEMPLATE_PATH));
|
||||
@@ -172,7 +172,7 @@ public class TemplateEngineUtils {
|
||||
templates.add(TEMPLATE_MAPPER.get(GenConstants.TS_API_TEMPLATE_PATH));
|
||||
templates.add(TEMPLATE_MAPPER.get(TS_TYPES_TEMPLATE_PATH));
|
||||
// 数据库模板
|
||||
DataBaseType dataBaseType = DataBaseHelper.getDataBaseType();
|
||||
DataBaseType dataBaseType = DataBaseHelper.getDataBaseType(dsName);
|
||||
if (dataBaseType.isOracle()) {
|
||||
templates.add(TEMPLATE_MAPPER.get(GenConstants.SQL_ORACLE_TEMPLATE_PATH));
|
||||
} else if (dataBaseType.isPostgreSql()) {
|
||||
|
||||
Reference in New Issue
Block a user