[重大更新] 集成 mybatis-plus-join 重构项目代码(实验性功能不稳定)

This commit is contained in:
疯狂的狮子Li
2026-03-19 12:42:06 +08:00
parent e8fc7fb0df
commit 24743c779f
23 changed files with 439 additions and 392 deletions

View File

@@ -15,29 +15,6 @@ import java.util.List;
@InterceptorIgnore(dataPermission = "true", tenantLine = "true")
public interface GenTableMapper extends BaseMapperPlus<GenTable, GenTable> {
/**
* 查询所有表信息
*
* @return 表信息集合
*/
List<GenTable> selectGenTableAll();
/**
* 查询表ID业务信息
*
* @param id 业务ID
* @return 业务信息
*/
GenTable selectGenTableById(Long id);
/**
* 查询表名称业务信息
*
* @param tableName 表名称
* @return 业务信息
*/
GenTable selectGenTableByName(String tableName);
/**
* 查询指定数据源下的所有表名列表
*

View File

@@ -84,7 +84,7 @@ public class GenTableServiceImpl implements IGenTableService {
*/
@Override
public GenTable selectGenTableById(Long id) {
GenTable genTable = baseMapper.selectGenTableById(id);
GenTable genTable = getGenTable(id);
setTableFromOptions(genTable);
return genTable;
}
@@ -211,7 +211,8 @@ public class GenTableServiceImpl implements IGenTableService {
*/
@Override
public List<GenTable> selectGenTableAll() {
return baseMapper.selectGenTableAll();
return fillTableColumns(baseMapper.selectList(new LambdaQueryWrapper<GenTable>()
.orderByAsc(GenTable::getTableId)));
}
/**
@@ -318,7 +319,7 @@ public class GenTableServiceImpl implements IGenTableService {
public Map<String, String> previewCode(Long tableId) {
Map<String, String> dataMap = new LinkedHashMap<>();
// 查询表信息
GenTable table = baseMapper.selectGenTableById(tableId);
GenTable table = getGenTable(tableId);
List<Long> menuIds = new ArrayList<>();
for (int i = 0; i < 6; i++) {
menuIds.add(IdGeneratorUtil.nextLongId());
@@ -365,7 +366,7 @@ public class GenTableServiceImpl implements IGenTableService {
@Override
public void generatorCode(Long tableId) {
// 查询表信息
GenTable table = baseMapper.selectGenTableById(tableId);
GenTable table = getGenTable(tableId);
// 设置主键列信息
setPkColumn(table);
@@ -399,7 +400,7 @@ public class GenTableServiceImpl implements IGenTableService {
@DSTransactional
@Override
public void synchDb(Long tableId) {
GenTable table = baseMapper.selectGenTableById(tableId);
GenTable table = getGenTable(tableId);
List<GenTableColumn> tableColumns = table.getColumns();
Map<String, GenTableColumn> tableColumnMap = StreamUtils.toIdentityMap(tableColumns, GenTableColumn::getColumnName);
@@ -464,7 +465,7 @@ public class GenTableServiceImpl implements IGenTableService {
*/
private void generatorCode(Long tableId, ZipOutputStream zip) {
// 查询表信息
GenTable table = baseMapper.selectGenTableById(tableId);
GenTable table = getGenTable(tableId);
List<Long> menuIds = new ArrayList<>();
for (int i = 0; i < 6; i++) {
menuIds.add(IdGeneratorUtil.nextLongId());
@@ -517,6 +518,29 @@ public class GenTableServiceImpl implements IGenTableService {
}
}
private GenTable getGenTable(Long tableId) {
GenTable table = baseMapper.selectById(tableId);
if (ObjectUtil.isNull(table)) {
throw new ServiceException("业务表不存在");
}
fillTableColumns(Collections.singletonList(table));
return table;
}
private List<GenTable> fillTableColumns(List<GenTable> tables) {
if (CollUtil.isEmpty(tables)) {
return tables;
}
List<Long> tableIds = StreamUtils.toList(tables, GenTable::getTableId);
List<GenTableColumn> columns = genTableColumnMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
.in(GenTableColumn::getTableId, tableIds)
.orderByAsc(GenTableColumn::getTableId)
.orderByAsc(GenTableColumn::getSort));
Map<Long, List<GenTableColumn>> columnMap = StreamUtils.groupByKey(columns, GenTableColumn::getTableId);
tables.forEach(table -> table.setColumns(columnMap.getOrDefault(table.getTableId(), new ArrayList<>())));
return tables;
}
/**
* 设置主键列信息
*