diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java index 31db3d572..cdf5d3dc7 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java @@ -82,7 +82,7 @@ public class CodegenServiceImpl implements CodegenService { table.setAuthor(userApi.getUser(userId).getNickname()); codegenTableMapper.insert(table); // 构建 CodegenColumnDO 数组,插入到 DB 中 - List columns = codegenBuilder.buildColumns(schemaColumns); + List columns = codegenBuilder.buildColumns(table.getId(), schemaColumns); codegenColumnMapper.insertBatch(columns); return table.getId(); } @@ -196,7 +196,7 @@ public class CodegenServiceImpl implements CodegenService { } // 插入新增的字段 - List columns = codegenBuilder.buildColumns(schemaColumns); + List columns = codegenBuilder.buildColumns(tableId, schemaColumns); codegenColumnMapper.insertBatch(columns); // 删除不存在的字段 if (CollUtil.isNotEmpty(deleteColumnIds)) { diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java index 4c7ba479f..2a4281e50 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java @@ -133,9 +133,12 @@ public class CodegenBuilder { table.setTemplateType(CodegenTemplateTypeEnum.CRUD.getType()); } - public List buildColumns(List schemaColumns) { + public List buildColumns(Long tableId, List schemaColumns) { List columns = CodegenConvert.INSTANCE.convertList(schemaColumns); - columns.forEach(this::initColumnDefault); + for (CodegenColumnDO column : columns) { + column.setTableId(tableId); + initColumnDefault(column); + } return columns; }