商品自有属性
parent
adfce2bc5c
commit
4e8922da81
|
@ -1,6 +1,7 @@
|
||||||
package com.muyu.product.domain.model;
|
package com.muyu.product.domain.model;
|
||||||
|
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
|
import com.muyu.product.domain.AttributeInfo;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
@ -33,4 +34,12 @@ public class TemplateAttributeModel extends BaseEntity {
|
||||||
* 编码
|
* 编码
|
||||||
*/
|
*/
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
|
public static TemplateAttributeModel attributeInfoBuild(AttributeInfo attributeInfo){
|
||||||
|
return TemplateAttributeModel.builder()
|
||||||
|
.id(attributeInfo.getId())
|
||||||
|
.name(attributeInfo.getName())
|
||||||
|
.code(attributeInfo.getCode())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,9 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
|
||||||
@Autowired
|
@Autowired
|
||||||
private BrandInfoService brandInfoService;
|
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());
|
CategoryCommonElementResp templateAttribute = this.categoryInfoService.getTemplateAttributeByCateGoryId(projectInfo.getType());
|
||||||
List<TemplateAttributeModel> templateAttributeList = templateAttribute.getTemplateAttributeList();
|
List<TemplateAttributeGroupModel> templateAttributeGroupList = templateAttribute.getTemplateAttributeGroupList();
|
||||||
// TODO 添加上,商品的自有属性
|
List<TemplateAttributeModel> templateAttributeList = new ArrayList<>(){{
|
||||||
List<TemplateAttributeModel> projectAttributeList = null;
|
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()
|
return ProjectDetailResp.builder()
|
||||||
.projectInfo(projectInfo)
|
.projectInfo(projectInfo)
|
||||||
.brandInfo(brandInfo)
|
.brandInfo(brandInfo)
|
||||||
|
@ -184,7 +226,7 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
|
||||||
.productAttributeInfoList(productAttributeInfoList)
|
.productAttributeInfoList(productAttributeInfoList)
|
||||||
.ruleAttrModelList(ruleAttrModelList)
|
.ruleAttrModelList(ruleAttrModelList)
|
||||||
.attributeInfoList(templateAttributeList)
|
.attributeInfoList(templateAttributeList)
|
||||||
.attributeGroupList(templateAttribute.getTemplateAttributeGroupList())
|
.attributeGroupList(templateAttributeGroupList)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue