修复代码生成导入的异常

This commit is contained in:
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());
codegenTableMapper.insert(table);
// 构建 CodegenColumnDO 数组插入到 DB
List<CodegenColumnDO> columns = codegenBuilder.buildColumns(schemaColumns);
List<CodegenColumnDO> columns = codegenBuilder.buildColumns(table.getId(), schemaColumns);
codegenColumnMapper.insertBatch(columns);
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);
// 删除不存在的字段
if (CollUtil.isNotEmpty(deleteColumnIds)) {

View File

@ -133,9 +133,12 @@ public class CodegenBuilder {
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);
columns.forEach(this::initColumnDefault);
for (CodegenColumnDO column : columns) {
column.setTableId(tableId);
initColumnDefault(column);
}
return columns;
}