|
|
|
@ -299,74 +299,75 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId) {
|
|
|
|
|
ArrayList<Long> cateGoryIdList = new ArrayList<>();
|
|
|
|
|
getParentIdListByCateGoryId(cateGoryIdList,cateGoryId);
|
|
|
|
|
LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>() {{
|
|
|
|
|
List<Long> cateGoryIdList = new ArrayList<>();
|
|
|
|
|
getParentIdListByCateGoryId(cateGoryIdList, cateGoryId);
|
|
|
|
|
// 取出和品类相关联的属性组关系 - 中间表
|
|
|
|
|
LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(){{
|
|
|
|
|
in(AsCategoryAttributeGroup::getCategoryId, cateGoryIdList);
|
|
|
|
|
}};
|
|
|
|
|
List<AsCategoryAttributeGroup> categoryAttributeGroupList = asCategoryAttributeGroupService.list(asCategoryAttributeGroupLambdaQueryWrapper);
|
|
|
|
|
List<TemplateAttributeGroupModel> attributeGroupModelList = categoryAttributeGroupList.stream()
|
|
|
|
|
List<TemplateAttributeGroupModel> attributeGroupModelList = categoryAttributeGroupList.stream()
|
|
|
|
|
.map(asCategoryAttributeGroup -> TemplateAttributeGroupModel.attributeGroupBuild(
|
|
|
|
|
attributeGroupService.getById(asCategoryAttributeGroup.getAttributeGroupId()),
|
|
|
|
|
attributeGroupId -> {
|
|
|
|
|
LambdaQueryWrapper<AsAttributeGroup> asAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>() {{
|
|
|
|
|
LambdaQueryWrapper<AsAttributeGroup> asAttributeGroupQueryWrapper = new LambdaQueryWrapper<>() {{
|
|
|
|
|
eq(AsAttributeGroup::getGroupId, asCategoryAttributeGroup.getAttributeGroupId());
|
|
|
|
|
}};
|
|
|
|
|
List<Long> attributeList = asAttributeGroupService.list(asAttributeGroupLambdaQueryWrapper).stream()
|
|
|
|
|
List<Long> attributeIdList = asAttributeGroupService.list(asAttributeGroupQueryWrapper).stream()
|
|
|
|
|
.map(AsAttributeGroup::getAttributeId)
|
|
|
|
|
.toList();
|
|
|
|
|
if (attributeList.isEmpty()) {
|
|
|
|
|
if (attributeIdList.isEmpty()){
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
return attributeInfoService.listByIds(attributeList).stream()
|
|
|
|
|
return attributeInfoService.listByIds(attributeIdList).stream()
|
|
|
|
|
.map(AttributeInfo::buildTemplateModel)
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
))
|
|
|
|
|
.filter(TemplateAttributeGroupModel::isEffective)
|
|
|
|
|
.toList();
|
|
|
|
|
// 查重集合
|
|
|
|
|
Set<Long> attributeIdSet = new HashSet<>();
|
|
|
|
|
// 获取组内所有的属性Id
|
|
|
|
|
if (!attributeGroupModelList.isEmpty()){
|
|
|
|
|
attributeIdSet.addAll(
|
|
|
|
|
attributeGroupModelList.stream()
|
|
|
|
|
.flatMap((Function<? super TemplateAttributeGroupModel,Stream<TemplateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
|
|
|
|
|
.flatMap((Function<TemplateAttributeGroupModel, Stream<TemplateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
|
|
|
|
|
.map(TemplateAttributeModel::getId)
|
|
|
|
|
.toList()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
List<TemplateAttributeModel> templateAttributeModelList =new ArrayList<>();
|
|
|
|
|
LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
|
|
categoryAttributeLambdaQueryWrapper.in(AsCategoryAttribute::getCategoryId,cateGoryIdList);
|
|
|
|
|
List<AsCategoryAttribute> asCategoryAttributeList=asCategoryAttributeService.list(categoryAttributeLambdaQueryWrapper);
|
|
|
|
|
List<Long> templateAttributeIdList = asCategoryAttributeList.stream()
|
|
|
|
|
.map(AsCategoryAttribute::getAttributeId)
|
|
|
|
|
.filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId))
|
|
|
|
|
.toList();
|
|
|
|
|
if (asCategoryAttributeList!=null && ! asCategoryAttributeList.isEmpty())
|
|
|
|
|
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<>();
|
|
|
|
|
|
|
|
|
|
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(!attributeIdSet.isEmpty(),AttributeInfo::getId,attributeIdSet);
|
|
|
|
|
attributeModelList=attributeInfoService.list(attributeInfoLambdaQueryWrapper).stream().map(AttributeInfo::buildTemplateModel).toList();
|
|
|
|
|
LambdaQueryWrapper<AttributeInfo> attributeInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
attributeInfoLambdaQueryWrapper.notIn(!attributeIdSet.isEmpty(), AttributeInfo::getId, attributeIdSet);
|
|
|
|
|
attributeModelList = attributeInfoService.list(attributeInfoLambdaQueryWrapper).stream().map(AttributeInfo::buildTemplateModel).toList();
|
|
|
|
|
|
|
|
|
|
return CategoryCommonElementResp.builder()
|
|
|
|
|
.templateAttributeGroupList(attributeGroupModelList)
|
|
|
|
|
.templateAttributeList(templateAttributeModelList)
|
|
|
|
|
.attributeList(attributeModelList)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|