商品自有属性

dev
DongZeLiang 2024-03-26 14:15:14 +08:00
parent adfce2bc5c
commit 4e8922da81
2 changed files with 56 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package com.muyu.product.domain.model;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.product.domain.AttributeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -33,4 +34,12 @@ public class TemplateAttributeModel extends BaseEntity {
*
*/
private String code;
public static TemplateAttributeModel attributeInfoBuild(AttributeInfo attributeInfo){
return TemplateAttributeModel.builder()
.id(attributeInfo.getId())
.name(attributeInfo.getName())
.code(attributeInfo.getCode())
.build();
}
}

View File

@ -45,6 +45,9 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
@Autowired
private BrandInfoService brandInfoService;
@Autowired
private AttributeInfoService attributeInfoService;
/**
*
*
@ -171,11 +174,50 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
CategoryCommonElementResp templateAttribute = this.categoryInfoService.getTemplateAttributeByCateGoryId(projectInfo.getType());
List<TemplateAttributeModel> templateAttributeList = templateAttribute.getTemplateAttributeList();
// TODO 添加上,商品的自有属性
List<TemplateAttributeModel> projectAttributeList = null;
List<TemplateAttributeGroupModel> templateAttributeGroupList = templateAttribute.getTemplateAttributeGroupList();
List<TemplateAttributeModel> templateAttributeList = new ArrayList<>(){{
addAll(templateAttribute.getTemplateAttributeList());
}};
// 属性组和商品属性的ID
List<Long> notInAttributeIdList = new ArrayList<>();
List<Long> attributeGroupIdList = templateAttributeGroupList.stream()
.flatMap(templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
.map(TemplateAttributeModel::getId)
.toList();
List<Long> attributeIdList = templateAttributeList.stream()
.map(TemplateAttributeModel::getId)
.toList();
if (!attributeGroupIdList.isEmpty()){
notInAttributeIdList.addAll( attributeGroupIdList );
}
if (!attributeIdList.isEmpty()){
notInAttributeIdList.addAll( attributeIdList );
}
// 添加上,商品的自有属性
List<AsProductAttributeInfo> productAttributeList = this.asProductAttributeInfoService.list(
new LambdaQueryWrapper<>() {{
eq(AsProductAttributeInfo::getProductId, projectInfo.getId());
notIn(AsProductAttributeInfo::getAttributeId, notInAttributeIdList);
}}
);
List<TemplateAttributeModel> projectAttributeList = new ArrayList<>();
if (!productAttributeList.isEmpty()){
List<Long> attrIdList = productAttributeList.stream()
.map(AsProductAttributeInfo::getAttributeId)
.toList();
projectAttributeList = attributeInfoService.list(
new LambdaQueryWrapper<>() {{
in(AttributeInfo::getId, attrIdList);
}}
).stream()
.map(TemplateAttributeModel::attributeInfoBuild)
.toList();
}
// 把自有属性添加到商品属性的集合当中,进行合并
templateAttributeList.addAll(projectAttributeList);
if (!projectAttributeList.isEmpty()){
templateAttributeList.addAll(projectAttributeList);
}
return ProjectDetailResp.builder()
.projectInfo(projectInfo)
.brandInfo(brandInfo)
@ -184,7 +226,7 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
.productAttributeInfoList(productAttributeInfoList)
.ruleAttrModelList(ruleAttrModelList)
.attributeInfoList(templateAttributeList)
.attributeGroupList(templateAttribute.getTemplateAttributeGroupList())
.attributeGroupList(templateAttributeGroupList)
.build();
}
}