解决bug 重复属性的问题

dev
DongZeLiang 2024-03-06 17:27:11 +08:00
parent dc1e669dc5
commit 61b0b14749
1 changed files with 29 additions and 24 deletions

View File

@ -20,7 +20,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream;
@ -324,30 +326,11 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
))
.filter(TemplateAttributeGroupModel::isEffective)
.toList();
List<TemplateAttributeModel> templateAttributeModelList = new ArrayList<>();
LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeQueryWrapper = new LambdaQueryWrapper<>();
categoryAttributeQueryWrapper.in(AsCategoryAttribute::getCategoryId, cateGoryIdList);
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(categoryAttributeQueryWrapper);
if (asCategoryAttributeList != null && !asCategoryAttributeList.isEmpty()){
templateAttributeModelList = attributeInfoService.listByIds(
asCategoryAttributeList.stream()
.map(AsCategoryAttribute::getAttributeId)
.toList()
).stream()
.map(AttributeInfo::buildTemplateModel)
.toList();
}
List<TemplateAttributeModel> attributeModelList = new ArrayList<>();
List<Long> attributeIdList = new ArrayList<>();
if (!templateAttributeModelList.isEmpty()){
attributeIdList.addAll(
templateAttributeModelList.stream().map(TemplateAttributeModel::getId).toList()
);
}
// 查重集合
Set<Long> attributeIdSet = new HashSet<>();
// 获取组内所有的属性Id
if (!attributeGroupModelList.isEmpty()){
attributeIdList.addAll(
attributeIdSet.addAll(
attributeGroupModelList.stream()
.flatMap((Function<TemplateAttributeGroupModel, Stream<TemplateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
.map(TemplateAttributeModel::getId)
@ -355,8 +338,30 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
);
}
List<TemplateAttributeModel> templateAttributeModelList = new ArrayList<>();
LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeQueryWrapper = new LambdaQueryWrapper<>();
categoryAttributeQueryWrapper.in(AsCategoryAttribute::getCategoryId, cateGoryIdList);
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(categoryAttributeQueryWrapper);
if (asCategoryAttributeList != null && !asCategoryAttributeList.isEmpty()){
List<Long> templateAttributeIdList = asCategoryAttributeList.stream()
.map(AsCategoryAttribute::getAttributeId)
.filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId))
.toList();
templateAttributeModelList = attributeInfoService.listByIds(templateAttributeIdList).stream()
.map(AttributeInfo::buildTemplateModel)
.toList();
}
List<TemplateAttributeModel> attributeModelList = new ArrayList<>();
if (!templateAttributeModelList.isEmpty()){
attributeIdSet.addAll(
templateAttributeModelList.stream().map(TemplateAttributeModel::getId).toList()
);
}
LambdaQueryWrapper<AttributeInfo> attributeInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
attributeInfoLambdaQueryWrapper.notIn(!attributeIdList.isEmpty(), AttributeInfo::getId, attributeIdList);
attributeInfoLambdaQueryWrapper.notIn(!attributeIdSet.isEmpty(), AttributeInfo::getId, attributeIdSet);
attributeModelList = attributeInfoService.list(attributeInfoLambdaQueryWrapper).stream().map(AttributeInfo::buildTemplateModel).toList();
return CategoryCommonElementResp.builder()