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

This commit is contained in:
疯狂的狮子Li
2026-03-13 17:46:23 +08:00
parent 068e2de831
commit 916282ba68
28 changed files with 585 additions and 553 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;
}
/**
* 设置主键列信息
*

View File

@@ -3,39 +3,6 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.generator.mapper.GenTableMapper">
<!-- 多结构嵌套自动映射需带上每个实体的主键id 否则映射会失败 -->
<resultMap type="org.dromara.generator.domain.GenTable" id="GenTableResult">
<id property="tableId" column="table_id" />
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" />
</resultMap>
<resultMap type="org.dromara.generator.domain.GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id"/>
</resultMap>
<sql id="genSelect">
SELECT t.table_id, t.data_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
</sql>
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
<include refid="genSelect"/>
where t.table_id = #{tableId} order by c.sort
</select>
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
<include refid="genSelect"/>
where t.table_name = #{tableName} order by c.sort
</select>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
<include refid="genSelect"/>
order by c.sort
</select>
<select id="selectTableNameList" resultType="java.lang.String">
select table_name from gen_table where data_name = #{dataName,jdbcType=VARCHAR}
</select>