Commit be370ba2cf190b1a441b13ff13074eba1a79bc11
1 parent
613eef37
spu 修改调整,组合分类和规格属性,方便前端修改的回显展示
Showing
3 changed files
with
82 additions
and
3 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/ProductPropertyViewRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.product.controller.admin.property.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.ToString; | ||
| 7 | + | ||
| 8 | +import java.util.Set; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * @Description: ProductPropertyViewRespVO | ||
| 12 | + * @Author: franky | ||
| 13 | + * @CreateDate: 2022/7/5 21:29 | ||
| 14 | + * @Version: 1.0.0 | ||
| 15 | + */ | ||
| 16 | +@ApiModel("管理后台 - 规格名称详情展示 Request VO") | ||
| 17 | +@Data | ||
| 18 | +@ToString(callSuper = true) | ||
| 19 | +public class ProductPropertyViewRespVO { | ||
| 20 | + | ||
| 21 | + @ApiModelProperty(value = "规格名称id", example = "1") | ||
| 22 | + public Long propertyId; | ||
| 23 | + | ||
| 24 | + @ApiModelProperty(value = "规格名称", example = "内存") | ||
| 25 | + public String name; | ||
| 26 | + | ||
| 27 | + @ApiModelProperty(value = "规格属性值集合", example = "[{\"v1\":11,\"v2\":\"64G\"},{\"v1\":10,\"v2\":\"32G\"}]") | ||
| 28 | + public Set<Tuple2> propertyValues; | ||
| 29 | + | ||
| 30 | + @Data | ||
| 31 | + @ApiModel(value = "规格属性值元组") | ||
| 32 | + public static class Tuple2 { | ||
| 33 | + private final long v1; | ||
| 34 | + private final String v2; | ||
| 35 | + public Tuple2(Long v1, String v2) { | ||
| 36 | + this.v1 = v1; | ||
| 37 | + this.v2 = v2; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + | ||
| 43 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; | 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyViewRespVO; | ||
| 3 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; | 4 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; |
| 4 | import io.swagger.annotations.ApiModel; | 5 | import io.swagger.annotations.ApiModel; |
| 5 | import io.swagger.annotations.ApiModelProperty; | 6 | import io.swagger.annotations.ApiModelProperty; |
| @@ -19,7 +20,7 @@ public class SpuRespVO extends ProductSpuBaseVO { | @@ -19,7 +20,7 @@ public class SpuRespVO extends ProductSpuBaseVO { | ||
| 19 | 20 | ||
| 20 | // TODO @franky:注解要完整 | 21 | // TODO @franky:注解要完整 |
| 21 | 22 | ||
| 22 | - @ApiModelProperty(value = "主键", required = true) | 23 | + @ApiModelProperty(value = "主键", required = true, example = "1") |
| 23 | private Long id; | 24 | private Long id; |
| 24 | 25 | ||
| 25 | @ApiModelProperty(value = "创建时间") | 26 | @ApiModelProperty(value = "创建时间") |
| @@ -28,9 +29,13 @@ public class SpuRespVO extends ProductSpuBaseVO { | @@ -28,9 +29,13 @@ public class SpuRespVO extends ProductSpuBaseVO { | ||
| 28 | /** | 29 | /** |
| 29 | * SKU 数组 | 30 | * SKU 数组 |
| 30 | */ | 31 | */ |
| 31 | - List<ProductSkuRespVO> skus; | 32 | + @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}]") |
| 33 | + private List<ProductSkuRespVO> skus; | ||
| 32 | 34 | ||
| 33 | @ApiModelProperty(value = "分类id数组,一直递归到一级父节点", example = "[1,2,4]") | 35 | @ApiModelProperty(value = "分类id数组,一直递归到一级父节点", example = "[1,2,4]") |
| 34 | - LinkedList<Long> categoryIds; | 36 | + private LinkedList<Long> categoryIds; |
| 37 | + | ||
| 38 | + @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\"}]}]") | ||
| 39 | + private List<ProductPropertyViewRespVO> productPropertyViews; | ||
| 35 | 40 | ||
| 36 | } | 41 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.spu; | 1 | package cn.iocoder.yudao.module.product.service.spu; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyRespVO; | ||
| 5 | +import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyViewRespVO; | ||
| 6 | +import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueRespVO; | ||
| 7 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; | ||
| 4 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; | 8 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; |
| 5 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; | 9 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; |
| 6 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; | 10 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; |
| @@ -11,6 +15,7 @@ import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | @@ -11,6 +15,7 @@ import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | ||
| 11 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | 15 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 12 | import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; | 16 | import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; |
| 13 | import cn.iocoder.yudao.module.product.service.category.CategoryService; | 17 | import cn.iocoder.yudao.module.product.service.category.CategoryService; |
| 18 | +import cn.iocoder.yudao.module.product.service.property.ProductPropertyService; | ||
| 14 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; | 19 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 15 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 16 | import org.springframework.transaction.annotation.Transactional; | 21 | import org.springframework.transaction.annotation.Transactional; |
| @@ -41,6 +46,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -41,6 +46,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 41 | @Resource | 46 | @Resource |
| 42 | private ProductSkuService productSkuService; | 47 | private ProductSkuService productSkuService; |
| 43 | 48 | ||
| 49 | + @Resource | ||
| 50 | + private ProductPropertyService productPropertyService; | ||
| 51 | + | ||
| 44 | @Override | 52 | @Override |
| 45 | @Transactional | 53 | @Transactional |
| 46 | public Long createSpu(ProductSpuCreateReqVO createReqVO) { | 54 | public Long createSpu(ProductSpuCreateReqVO createReqVO) { |
| @@ -104,6 +112,29 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -104,6 +112,29 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 104 | if (null != spuVO) { | 112 | if (null != spuVO) { |
| 105 | List<ProductSkuRespVO> skuReqs = ProductSkuConvert.INSTANCE.convertList(productSkuService.getSkusBySpuId(id)); | 113 | List<ProductSkuRespVO> skuReqs = ProductSkuConvert.INSTANCE.convertList(productSkuService.getSkusBySpuId(id)); |
| 106 | spuVO.setSkus(skuReqs); | 114 | spuVO.setSkus(skuReqs); |
| 115 | + List<ProductSkuRespVO.Property> properties = new ArrayList<>(); | ||
| 116 | + // 组合 sku 规格属性 | ||
| 117 | + for (ProductSkuRespVO productSkuRespVO : skuReqs) { | ||
| 118 | + properties.addAll(productSkuRespVO.getProperties()); | ||
| 119 | + } | ||
| 120 | + Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId)); | ||
| 121 | + List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet())); | ||
| 122 | + // 装载组装过后的属性 | ||
| 123 | + List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>(); | ||
| 124 | + propertyAndValueList.forEach(p -> { | ||
| 125 | + ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO(); | ||
| 126 | + productPropertyViewRespVO.setPropertyId(p.getId()); | ||
| 127 | + productPropertyViewRespVO.setName(p.getName()); | ||
| 128 | + Set<ProductPropertyViewRespVO.Tuple2> propertyValues = new HashSet<>(); | ||
| 129 | + Map<Long, ProductPropertyValueRespVO> propertyValueMaps = p.getPropertyValueList().stream().collect(Collectors.toMap(ProductPropertyValueRespVO::getId, pv -> pv)); | ||
| 130 | + propertyMaps.get(p.getId()).forEach(pv -> { | ||
| 131 | + ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName()); | ||
| 132 | + propertyValues.add(tuple2); | ||
| 133 | + }); | ||
| 134 | + productPropertyViewRespVO.setPropertyValues(propertyValues); | ||
| 135 | + productPropertyViews.add(productPropertyViewRespVO); | ||
| 136 | + }); | ||
| 137 | + spuVO.setProductPropertyViews(productPropertyViews); | ||
| 107 | // 组合分类 | 138 | // 组合分类 |
| 108 | if (null != spuVO.getCategoryId()) { | 139 | if (null != spuVO.getCategoryId()) { |
| 109 | LinkedList<Long> categoryArray = new LinkedList<>(); | 140 | LinkedList<Long> categoryArray = new LinkedList<>(); |