diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/ProductPropertyViewRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/ProductPropertyViewRespVO.java new file mode 100644 index 000000000..0499138a9 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/ProductPropertyViewRespVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.product.controller.admin.property.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import java.util.Set; + +/** + * @Description: ProductPropertyViewRespVO + * @Author: franky + * @CreateDate: 2022/7/5 21:29 + * @Version: 1.0.0 + */ +@ApiModel("管理后台 - 规格名称详情展示 Request VO") +@Data +@ToString(callSuper = true) +public class ProductPropertyViewRespVO { + + @ApiModelProperty(value = "规格名称id", example = "1") + public Long propertyId; + + @ApiModelProperty(value = "规格名称", example = "内存") + public String name; + + @ApiModelProperty(value = "规格属性值集合", example = "[{\"v1\":11,\"v2\":\"64G\"},{\"v1\":10,\"v2\":\"32G\"}]") + public Set propertyValues; + + @Data + @ApiModel(value = "规格属性值元组") + public static class Tuple2 { + private final long v1; + private final String v2; + public Tuple2(Long v1, String v2) { + this.v1 = v1; + this.v2 = v2; + } + + } + + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java index 90387f90a..0121aec47 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.product.controller.admin.spu.vo; +import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyViewRespVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -19,7 +20,7 @@ public class SpuRespVO extends ProductSpuBaseVO { // TODO @franky:注解要完整 - @ApiModelProperty(value = "主键", required = true) + @ApiModelProperty(value = "主键", required = true, example = "1") private Long id; @ApiModelProperty(value = "创建时间") @@ -28,9 +29,13 @@ public class SpuRespVO extends ProductSpuBaseVO { /** * SKU 数组 */ - List skus; + @ApiModelProperty(value = "sku 数组", example = "[{\"spuId\":4,\"properties\":[{\"propertyId\":3,\"valueId\":15},{\"propertyId\":2,\"valueId\":10}],\"price\":12,\"originalPrice\":32,\"costPrice\":22,\"barCode\":\"765670123123\",\"picUrl\":\"http://test.yudao.iocoder.cn/72938088f1ca8438837c3b51394aea43.jpg\",\"status\":0,\"id\":7,\"createTime\":1656683270000},{\"spuId\":4,\"properties\":[{\"propertyId\":3,\"valueId\":15},{\"propertyId\":2,\"valueId\":11}],\"price\":13,\"originalPrice\":33,\"costPrice\":23,\"barCode\":\"888788770999\",\"picUrl\":\"http://test.yudao.iocoder.cn/6b902c700e5d32e862b6fd9af2e1c0e4.jpg\",\"status\":0,\"id\":8,\"createTime\":1656683270000},{\"spuId\":4,\"properties\":[{\"propertyId\":3,\"valueId\":16},{\"propertyId\":2,\"valueId\":10}],\"price\":14,\"originalPrice\":34,\"costPrice\":24,\"barCode\":\"9999981212\",\"picUrl\":\"http://test.yudao.iocoder.cn/eddf3c79b1917160d94d05244e1f47da.jpg\",\"status\":0,\"id\":9,\"createTime\":1656683270000},{\"spuId\":4,\"properties\":[{\"propertyId\":3,\"valueId\":16},{\"propertyId\":2,\"valueId\":11}],\"price\":15,\"originalPrice\":35,\"costPrice\":25,\"barCode\":\"4444121212\",\"picUrl\":\"http://test.yudao.iocoder.cn/88ac3eb068ea9cfac4726879b2776ccf.jpg\",\"status\":0,\"id\":10,\"createTime\":1656683270000}]") + private List skus; @ApiModelProperty(value = "分类id数组,一直递归到一级父节点", example = "[1,2,4]") - LinkedList categoryIds; + private LinkedList categoryIds; + + @ApiModelProperty(value = "规格属性修改和详情展示组合", example = "[{\"propertyId\":2,\"name\":\"内存\",\"propertyValues\":[{\"v1\":11,\"v2\":\"64G\"},{\"v1\":10,\"v2\":\"32G\"}]},{\"propertyId\":3,\"name\":\"尺寸\",\"propertyValues\":[{\"v1\":16,\"v2\":\"6.1\"},{\"v1\":15,\"v2\":\"5.7\"}]}]") + private List productPropertyViews; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index 4420b0af8..eb48bed25 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -1,6 +1,10 @@ package cn.iocoder.yudao.module.product.service.spu; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyRespVO; +import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyViewRespVO; +import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueRespVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; @@ -11,6 +15,7 @@ import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; import cn.iocoder.yudao.module.product.service.category.CategoryService; +import cn.iocoder.yudao.module.product.service.property.ProductPropertyService; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -41,6 +46,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { @Resource private ProductSkuService productSkuService; + @Resource + private ProductPropertyService productPropertyService; + @Override @Transactional public Long createSpu(ProductSpuCreateReqVO createReqVO) { @@ -104,6 +112,29 @@ public class ProductSpuServiceImpl implements ProductSpuService { if (null != spuVO) { List skuReqs = ProductSkuConvert.INSTANCE.convertList(productSkuService.getSkusBySpuId(id)); spuVO.setSkus(skuReqs); + List properties = new ArrayList<>(); + // 组合 sku 规格属性 + for (ProductSkuRespVO productSkuRespVO : skuReqs) { + properties.addAll(productSkuRespVO.getProperties()); + } + Map> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId)); + List propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet())); + // 装载组装过后的属性 + List productPropertyViews = new ArrayList<>(); + propertyAndValueList.forEach(p -> { + ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO(); + productPropertyViewRespVO.setPropertyId(p.getId()); + productPropertyViewRespVO.setName(p.getName()); + Set propertyValues = new HashSet<>(); + Map propertyValueMaps = p.getPropertyValueList().stream().collect(Collectors.toMap(ProductPropertyValueRespVO::getId, pv -> pv)); + propertyMaps.get(p.getId()).forEach(pv -> { + ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName()); + propertyValues.add(tuple2); + }); + productPropertyViewRespVO.setPropertyValues(propertyValues); + productPropertyViews.add(productPropertyViewRespVO); + }); + spuVO.setProductPropertyViews(productPropertyViews); // 组合分类 if (null != spuVO.getCategoryId()) { LinkedList categoryArray = new LinkedList<>();