From f18a187b16208b2e8cf654f4de8b96d1a59e25e9 Mon Sep 17 00:00:00 2001 From: yinwenshi <2606091457@qq.com> Date: Sun, 3 Mar 2024 13:45:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BB=A3=E7=A0=81=E6=9F=A5=E8=AF=A2=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=8D=E5=85=A8=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codegen/database/DbTypeConverterManager.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ballcat-codegen-backend/src/main/java/com/hccake/ballcat/codegen/database/DbTypeConverterManager.java b/ballcat-codegen-backend/src/main/java/com/hccake/ballcat/codegen/database/DbTypeConverterManager.java index 307fcf9..5def07a 100644 --- a/ballcat-codegen-backend/src/main/java/com/hccake/ballcat/codegen/database/DbTypeConverterManager.java +++ b/ballcat-codegen-backend/src/main/java/com/hccake/ballcat/codegen/database/DbTypeConverterManager.java @@ -1,5 +1,6 @@ package com.hccake.ballcat.codegen.database; +import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.annotation.DbType; import com.hccake.ballcat.codegen.converter.DbColumnTypeConverter; import com.hccake.ballcat.codegen.model.entity.DbColumnType; @@ -11,6 +12,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; import java.util.List; +import java.util.stream.Collectors; /** * @author hccake @@ -30,6 +32,18 @@ public class DbTypeConverterManager { List fieldTypeList = fieldTypeService.selectDbTypeList(dbType, templateGroupKey); if (ObjectUtils.isEmpty(fieldTypeList)) { fieldTypeList = fieldTypeService.selectDbTypeList(dbType); + } else { + //不包含当前字段类型的集合,其他默认的字段类型 + List otherFieldTypeList = fieldTypeService.selectDbTypeList(dbType); + + List columnKeyList = fieldTypeList.stream().map(FieldType::getColumnKey).collect(Collectors.toList()); + + List fieldTypes = otherFieldTypeList.stream().filter(fieldType -> { + return !columnKeyList.contains(fieldType.getColumnKey()); + }).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(fieldTypes)) { + fieldTypeList.addAll(fieldTypes); + } } return fieldTypeList; } -- Gitee From bcb292a25a0e17b186b9aa9b9b5331ca9f42915e Mon Sep 17 00:00:00 2001 From: yinwenshi <2606091457@qq.com> Date: Tue, 5 Mar 2024 10:29:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BB=A3=E7=A0=81=E6=9F=A5=E8=AF=A2=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=8D=E5=85=A8=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../database/DbTypeConverterManager.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/ballcat-codegen-backend/src/main/java/com/hccake/ballcat/codegen/database/DbTypeConverterManager.java b/ballcat-codegen-backend/src/main/java/com/hccake/ballcat/codegen/database/DbTypeConverterManager.java index 5def07a..29126ec 100644 --- a/ballcat-codegen-backend/src/main/java/com/hccake/ballcat/codegen/database/DbTypeConverterManager.java +++ b/ballcat-codegen-backend/src/main/java/com/hccake/ballcat/codegen/database/DbTypeConverterManager.java @@ -2,6 +2,7 @@ package com.hccake.ballcat.codegen.database; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.annotation.DbType; +import com.hccake.ballcat.codegen.constant.TemplateEntryConstants; import com.hccake.ballcat.codegen.converter.DbColumnTypeConverter; import com.hccake.ballcat.codegen.model.entity.DbColumnType; import com.hccake.ballcat.codegen.model.entity.FieldType; @@ -11,7 +12,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -30,22 +35,21 @@ public class DbTypeConverterManager { */ public List getDbTypeList(DbType dbType, String templateGroupKey) { List fieldTypeList = fieldTypeService.selectDbTypeList(dbType, templateGroupKey); - if (ObjectUtils.isEmpty(fieldTypeList)) { - fieldTypeList = fieldTypeService.selectDbTypeList(dbType); - } else { - //不包含当前字段类型的集合,其他默认的字段类型 - List otherFieldTypeList = fieldTypeService.selectDbTypeList(dbType); - - List columnKeyList = fieldTypeList.stream().map(FieldType::getColumnKey).collect(Collectors.toList()); - - List fieldTypes = otherFieldTypeList.stream().filter(fieldType -> { - return !columnKeyList.contains(fieldType.getColumnKey()); - }).collect(Collectors.toList()); - if (CollUtil.isNotEmpty(fieldTypes)) { - fieldTypeList.addAll(fieldTypes); + Map fieldTypeMap = new HashMap<>(fieldTypeList.size()); + for (FieldType fieldType : fieldTypeList) { + String columnKey = fieldType.getColumnKey(); + FieldType fieldTypeMapValue = fieldTypeMap.get(columnKey); + if (Objects.isNull(fieldTypeMapValue)) { + fieldTypeMap.put(columnKey, fieldType); + } + else { + String groupKey = fieldTypeMapValue.getGroupKey(); + if (!Objects.equals(TemplateEntryConstants.TREE_ROOT_ID, groupKey)) { + fieldTypeMap.put(columnKey, fieldType); + } } } - return fieldTypeList; + return new ArrayList<>(fieldTypeMap.values()); } /** -- Gitee