公共元素优化
parent
74b67dae1c
commit
dc1e669dc5
|
@ -21,6 +21,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 品类信息Service业务层处理
|
||||
|
@ -277,6 +279,15 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
.build();
|
||||
}
|
||||
|
||||
private void getParentIdListByCateGoryId(List<Long> parentIdList, Long cateGoryId){
|
||||
if (cateGoryId.equals(0L)){
|
||||
return;
|
||||
}
|
||||
CategoryInfo categoryInfo = this.getById(cateGoryId);
|
||||
parentIdList.add(categoryInfo.getId());
|
||||
getParentIdListByCateGoryId(parentIdList, categoryInfo.getParentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过品类ID获取品类共有属性
|
||||
*
|
||||
|
@ -286,31 +297,67 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
*/
|
||||
@Override
|
||||
public CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId) {
|
||||
List<Long> cateGoryIdList = new ArrayList<>();
|
||||
getParentIdListByCateGoryId(cateGoryIdList, cateGoryId);
|
||||
// 取出和品类相关联的属性组关系 - 中间表
|
||||
LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(){{
|
||||
eq(AsCategoryAttributeGroup::getCategoryId, cateGoryId);
|
||||
in(AsCategoryAttributeGroup::getCategoryId, cateGoryIdList);
|
||||
}};
|
||||
List<AsCategoryAttributeGroup> categoryAttributeGroupList = asCategoryAttributeGroupService.list(asCategoryAttributeGroupLambdaQueryWrapper);
|
||||
List<TemplateAttributeGroupModel> attributeGroupModelList = categoryAttributeGroupList.stream()
|
||||
.map(asCategoryAttributeGroup -> TemplateAttributeGroupModel.attributeGroupBuild(
|
||||
attributeGroupService.getById(asCategoryAttributeGroup.getAttributeGroupId()),
|
||||
attributeGroupId -> attributeInfoService.listByIds(
|
||||
asAttributeGroupService.list(
|
||||
new LambdaQueryWrapper<>(){{
|
||||
attributeGroupId -> {
|
||||
LambdaQueryWrapper<AsAttributeGroup> asAttributeGroupQueryWrapper = new LambdaQueryWrapper<>() {{
|
||||
eq(AsAttributeGroup::getGroupId, asCategoryAttributeGroup.getAttributeGroupId());
|
||||
}}
|
||||
).stream().map(AsAttributeGroup::getAttributeId).toList()
|
||||
).stream()
|
||||
}};
|
||||
List<Long> attributeIdList = asAttributeGroupService.list(asAttributeGroupQueryWrapper).stream()
|
||||
.map(AsAttributeGroup::getAttributeId)
|
||||
.toList();
|
||||
if (attributeIdList.isEmpty()){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return attributeInfoService.listByIds(attributeIdList).stream()
|
||||
.map(AttributeInfo::buildTemplateModel)
|
||||
.toList()
|
||||
.toList();
|
||||
}
|
||||
))
|
||||
.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()
|
||||
);
|
||||
}
|
||||
if (!attributeGroupModelList.isEmpty()){
|
||||
attributeIdList.addAll(
|
||||
attributeGroupModelList.stream()
|
||||
.flatMap((Function<TemplateAttributeGroupModel, Stream<TemplateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
|
||||
.map(TemplateAttributeModel::getId)
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<AttributeInfo> attributeInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
attributeInfoLambdaQueryWrapper.notIn(!attributeIdList.isEmpty(), AttributeInfo::getId, attributeIdList);
|
||||
attributeModelList = attributeInfoService.list(attributeInfoLambdaQueryWrapper).stream().map(AttributeInfo::buildTemplateModel).toList();
|
||||
|
||||
return CategoryCommonElementResp.builder()
|
||||
.templateAttributeGroupList(attributeGroupModelList)
|
||||
|
|
Loading…
Reference in New Issue