商品公共属性优化
parent
842fa2d667
commit
3289202aab
|
@ -2,6 +2,7 @@ package com.muyu.product.domain.model;
|
|||
|
||||
import com.fasterxml.jackson.databind.ser.Serializers;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import com.muyu.product.domain.AttributeGroup;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
@ -23,7 +24,7 @@ import java.util.function.Function;
|
|||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TemplateAttributeGroupModel extends Serializers.Base {
|
||||
public class TemplateAttributeGroupModel extends BaseEntity {
|
||||
private String groupName;
|
||||
|
||||
private List<TemplateAttributeModel> attributeList;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.product.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
@ -268,28 +269,13 @@ 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,cateGroupIdList);
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
HashSet<Long> attributeIdSet = new HashSet<>();
|
||||
|
||||
|
||||
if (!attributeGroupModelList.isEmpty()){
|
||||
attributeIdList.addAll(
|
||||
attributeIdSet.addAll(
|
||||
attributeGroupModelList.stream()
|
||||
.flatMap((Function<TemplateAttributeGroupModel, Stream<TemplateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
|
||||
.map(TemplateAttributeModel::getId)
|
||||
|
@ -297,8 +283,32 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
);
|
||||
}
|
||||
|
||||
List<TemplateAttributeModel> templateAttributeModelList = new ArrayList<>();
|
||||
LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
categoryAttributeLambdaQueryWrapper.in(AsCategoryAttribute::getCategoryId,cateGroupIdList);
|
||||
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(categoryAttributeLambdaQueryWrapper);
|
||||
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()
|
||||
.templateAttributeGroupList(attributeGroupModelList)
|
||||
|
|
Loading…
Reference in New Issue