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