diff --git a/zdxt-modules/zdxt-generator/src/main/java/org/dromara/generator/service/GenTableServiceImpl.java b/zdxt-modules/zdxt-generator/src/main/java/org/dromara/generator/service/GenTableServiceImpl.java index 455f8d9e..e3bba12c 100644 --- a/zdxt-modules/zdxt-generator/src/main/java/org/dromara/generator/service/GenTableServiceImpl.java +++ b/zdxt-modules/zdxt-generator/src/main/java/org/dromara/generator/service/GenTableServiceImpl.java @@ -14,6 +14,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.anyline.metadata.Column; import org.anyline.metadata.Table; +import org.anyline.metadata.View; import org.anyline.proxy.ServiceProxy; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; @@ -123,7 +124,16 @@ public class GenTableServiceImpl implements IGenTableService { String tableComment = genTable.getTableComment(); LinkedHashMap> tablesMap = ServiceProxy.metadata().tables(); - if (CollUtil.isEmpty(tablesMap)) { + LinkedHashMap viewsMap = ServiceProxy.metadata().views(); + // 合并表与视图,统一展示 + LinkedHashMap> allMap = new LinkedHashMap<>(); + if (CollUtil.isNotEmpty(tablesMap)) { + allMap.putAll(tablesMap); + } + if (CollUtil.isNotEmpty(viewsMap)) { + allMap.putAll(viewsMap); + } + if (CollUtil.isEmpty(allMap)) { return TableDataInfo.build(); } List tableNames = baseMapper.selectTableNameList(genTable.getDataName()); @@ -134,7 +144,7 @@ public class GenTableServiceImpl implements IGenTableService { tableArrays = new String[0]; } // 过滤并转换表格数据 - List tables = tablesMap.values().stream() + List tables = allMap.values().stream() .filter(x -> !StringUtils.startWithAnyIgnoreCase(x.getName(), TABLE_IGNORE)) .filter(x -> { if (CollUtil.isEmpty(tableNames)) { @@ -181,12 +191,21 @@ public class GenTableServiceImpl implements IGenTableService { public List selectDbTableListByNames(String[] tableNames, String dataName) { Set tableNameSet = new HashSet<>(List.of(tableNames)); LinkedHashMap> tablesMap = ServiceProxy.metadata().tables(); + LinkedHashMap viewsMap = ServiceProxy.metadata().views(); + // 合并表与视图,统一处理 + LinkedHashMap> allMap = new LinkedHashMap<>(); + if (CollUtil.isNotEmpty(tablesMap)) { + allMap.putAll(tablesMap); + } + if (CollUtil.isNotEmpty(viewsMap)) { + allMap.putAll(viewsMap); + } - if (CollUtil.isEmpty(tablesMap)) { + if (CollUtil.isEmpty(allMap)) { return new ArrayList<>(); } - List> tableList = tablesMap.values().stream() + List> tableList = allMap.values().stream() .filter(x -> !StringUtils.startWithAnyIgnoreCase(x.getName(), TABLE_IGNORE)) .filter(x -> tableNameSet.contains(x.getName())).toList(); @@ -289,6 +308,10 @@ public class GenTableServiceImpl implements IGenTableService { @Override public List selectDbTableColumnsByName(String tableName, String dataName) { Table table = ServiceProxy.metadata().table(tableName); + // 表查询为空时,回退尝试视图查询 + if (ObjectUtil.isNull(table)) { + table = ServiceProxy.metadata().view(tableName); + } if (ObjectUtil.isNull(table)) { return new ArrayList<>(); }