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