mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +08:00
代码生成:支持设置主子表的信息
This commit is contained in:
parent
a75bb825d7
commit
06649624e5
@ -238,7 +238,7 @@ public class CollectionUtils {
|
|||||||
if (CollUtil.isEmpty(from)) {
|
if (CollUtil.isEmpty(from)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
assert from.size() > 0; // 断言,避免告警
|
assert !from.isEmpty(); // 断言,避免告警
|
||||||
T t = from.stream().max(Comparator.comparing(valueFunc)).get();
|
T t = from.stream().max(Comparator.comparing(valueFunc)).get();
|
||||||
return valueFunc.apply(t);
|
return valueFunc.apply(t);
|
||||||
}
|
}
|
||||||
|
@ -93,10 +93,15 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> {
|
|||||||
return selectList(new LambdaQueryWrapper<T>().in(field, values));
|
return selectList(new LambdaQueryWrapper<T>().in(field, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default List<T> selectList(SFunction<T, ?> leField, SFunction<T, ?> geField, Object value) {
|
default List<T> selectList(SFunction<T, ?> leField, SFunction<T, ?> geField, Object value) {
|
||||||
return selectList(new LambdaQueryWrapper<T>().le(leField, value).ge(geField, value));
|
return selectList(new LambdaQueryWrapper<T>().le(leField, value).ge(geField, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<T> selectList(SFunction<T, ?> field1, Object value1, SFunction<T, ?> field2, Object value2) {
|
||||||
|
return selectList(new LambdaQueryWrapper<T>().eq(field1, value1).eq(field2, value2));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量插入,适合大量数据插入
|
* 批量插入,适合大量数据插入
|
||||||
*
|
*
|
||||||
|
@ -44,6 +44,8 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode CODEGEN_TABLE_INFO_COLUMN_COMMENT_IS_NULL = new ErrorCode(1_003_001_009, "数据库的表字段({})注释未填写");
|
ErrorCode CODEGEN_TABLE_INFO_COLUMN_COMMENT_IS_NULL = new ErrorCode(1_003_001_009, "数据库的表字段({})注释未填写");
|
||||||
ErrorCode CODEGEN_MASTER_TABLE_NOT_EXISTS = new ErrorCode(1_003_001_010, "主表(id={})定义不存在,请检查");
|
ErrorCode CODEGEN_MASTER_TABLE_NOT_EXISTS = new ErrorCode(1_003_001_010, "主表(id={})定义不存在,请检查");
|
||||||
ErrorCode CODEGEN_SUB_COLUMN_NOT_EXISTS = new ErrorCode(1_003_001_011, "子表的字段(id={})不存在,请检查");
|
ErrorCode CODEGEN_SUB_COLUMN_NOT_EXISTS = new ErrorCode(1_003_001_011, "子表的字段(id={})不存在,请检查");
|
||||||
|
ErrorCode CODEGEN_MASTER_GENERATION_FAIL_NO_SUB_TABLE = new ErrorCode(1_003_001_012, "主表生成代码失败,原因:它没有子表");
|
||||||
|
ErrorCode CODEGEN_MASTER_GENERATION_FAIL_NO_SUB_COLUMN = new ErrorCode(1_003_001_013, "主表生成代码失败,原因:它的子表({})没有字段");
|
||||||
|
|
||||||
// ========== 文件配置 1-001-006-000 ==========
|
// ========== 文件配置 1-001-006-000 ==========
|
||||||
ErrorCode FILE_CONFIG_NOT_EXISTS = new ErrorCode(1_001_006_000, "文件配置不存在");
|
ErrorCode FILE_CONFIG_NOT_EXISTS = new ErrorCode(1_001_006_000, "文件配置不存在");
|
||||||
|
@ -29,4 +29,9 @@ public interface CodegenTableMapper extends BaseMapperX<CodegenTableDO> {
|
|||||||
return selectList(CodegenTableDO::getDataSourceConfigId, dataSourceConfigId);
|
return selectList(CodegenTableDO::getDataSourceConfigId, dataSourceConfigId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<CodegenTableDO> selectListByTemplateTypeAndMasterTableId(Integer templateType, Long masterTableId) {
|
||||||
|
return selectList(CodegenTableDO::getTemplateType, templateType,
|
||||||
|
CodegenTableDO::getMasterTableId, masterTableId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -252,13 +252,25 @@ public class CodegenServiceImpl implements CodegenService {
|
|||||||
List<CodegenTableDO> subTables = null;
|
List<CodegenTableDO> subTables = null;
|
||||||
List<List<CodegenColumnDO>> subColumnsList = null;
|
List<List<CodegenColumnDO>> subColumnsList = null;
|
||||||
if (CodegenTemplateTypeEnum.isMaster(table.getTemplateType())) {
|
if (CodegenTemplateTypeEnum.isMaster(table.getTemplateType())) {
|
||||||
subTables = codegenTableMapper.selectListByMasterTableId(tableId);
|
// 校验子表存在
|
||||||
subTable = codegenTableMapper.selectById(table.getMasterTableId());
|
subTables = codegenTableMapper.selectListByTemplateTypeAndMasterTableId(
|
||||||
subColumns = codegenColumnMapper.selectListByTableId(table.getMasterTableId());
|
CodegenTemplateTypeEnum.SUB.getType(), tableId);
|
||||||
|
if (CollUtil.isEmpty(subTables)) {
|
||||||
|
throw exception(CODEGEN_MASTER_GENERATION_FAIL_NO_SUB_TABLE);
|
||||||
|
}
|
||||||
|
// 校验子表的关联字段存在
|
||||||
|
subColumnsList = new ArrayList<>();
|
||||||
|
for (CodegenTableDO subTable : subTables) {
|
||||||
|
List<CodegenColumnDO> subColumns = codegenColumnMapper.selectListByTableId(subTable.getId());
|
||||||
|
if (CollUtil.findOne(subColumns, column -> column.getId().equals(subTable.getSubJoinColumnId())) == null) {
|
||||||
|
throw exception(CODEGEN_SUB_COLUMN_NOT_EXISTS, subTable.getId());
|
||||||
|
}
|
||||||
|
subColumnsList.add(subColumns);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 执行生成
|
// 执行生成
|
||||||
return codegenEngine.execute(table, columns, subTable, subColumns);
|
return codegenEngine.execute(table, columns, subTables, subColumnsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user