!249 修复代码生成-同步功能删除存在的字段问题。

Merge pull request !249 from xrcoder/master
This commit is contained in:
芋道源码 2022-08-19 12:02:28 +00:00 committed by Gitee
commit 96b3cb23e2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -154,12 +154,12 @@ public class CodegenServiceImpl implements CodegenService {
// 构建 CodegenColumnDO 数组只同步新增的字段
List<CodegenColumnDO> codegenColumns = codegenColumnMapper.selectListByTableId(tableId);
Set<String> codegenColumnNames = CollectionUtils.convertSet(codegenColumns, CodegenColumnDO::getColumnName);
// 移除已经存在的字段
tableFields.removeIf(column -> codegenColumnNames.contains(column.getColumnName()));
// 计算需要删除的字段
Set<String> tableFieldNames = CollectionUtils.convertSet(tableFields, TableField::getName);
Set<Long> deleteColumnIds = codegenColumns.stream().filter(column -> !tableFieldNames.contains(column.getColumnName()))
.map(CodegenColumnDO::getId).collect(Collectors.toSet());
// 移除已经存在的字段
tableFields.removeIf(column -> codegenColumnNames.contains(column.getColumnName()));
if (CollUtil.isEmpty(tableFields) && CollUtil.isEmpty(deleteColumnIds)) {
throw exception(CODEGEN_SYNC_NONE_CHANGE);
}