修复代码生成导入的异常

pull/2/head
YunaiV 2022-03-19 16:11:25 +08:00
parent bf7c6db58c
commit 62f7d34952
2 changed files with 7 additions and 4 deletions

View File

@ -82,7 +82,7 @@ public class CodegenServiceImpl implements CodegenService {
table.setAuthor(userApi.getUser(userId).getNickname()); table.setAuthor(userApi.getUser(userId).getNickname());
codegenTableMapper.insert(table); codegenTableMapper.insert(table);
// 构建 CodegenColumnDO 数组,插入到 DB 中 // 构建 CodegenColumnDO 数组,插入到 DB 中
List<CodegenColumnDO> columns = codegenBuilder.buildColumns(schemaColumns); List<CodegenColumnDO> columns = codegenBuilder.buildColumns(table.getId(), schemaColumns);
codegenColumnMapper.insertBatch(columns); codegenColumnMapper.insertBatch(columns);
return table.getId(); return table.getId();
} }
@ -196,7 +196,7 @@ public class CodegenServiceImpl implements CodegenService {
} }
// 插入新增的字段 // 插入新增的字段
List<CodegenColumnDO> columns = codegenBuilder.buildColumns(schemaColumns); List<CodegenColumnDO> columns = codegenBuilder.buildColumns(tableId, schemaColumns);
codegenColumnMapper.insertBatch(columns); codegenColumnMapper.insertBatch(columns);
// 删除不存在的字段 // 删除不存在的字段
if (CollUtil.isNotEmpty(deleteColumnIds)) { if (CollUtil.isNotEmpty(deleteColumnIds)) {

View File

@ -133,9 +133,12 @@ public class CodegenBuilder {
table.setTemplateType(CodegenTemplateTypeEnum.CRUD.getType()); table.setTemplateType(CodegenTemplateTypeEnum.CRUD.getType());
} }
public List<CodegenColumnDO> buildColumns(List<SchemaColumnDO> schemaColumns) { public List<CodegenColumnDO> buildColumns(Long tableId, List<SchemaColumnDO> schemaColumns) {
List<CodegenColumnDO> columns = CodegenConvert.INSTANCE.convertList(schemaColumns); List<CodegenColumnDO> columns = CodegenConvert.INSTANCE.convertList(schemaColumns);
columns.forEach(this::initColumnDefault); for (CodegenColumnDO column : columns) {
column.setTableId(tableId);
initColumnDefault(column);
}
return columns; return columns;
} }