mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
spu 修改调整,组合分类和规格属性,方便前端修改的回显展示
This commit is contained in:
parent
613eef3758
commit
be370ba2cf
@ -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<Tuple2> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
|
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 cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
@ -19,7 +20,7 @@ public class SpuRespVO extends ProductSpuBaseVO {
|
|||||||
|
|
||||||
// TODO @franky:注解要完整
|
// TODO @franky:注解要完整
|
||||||
|
|
||||||
@ApiModelProperty(value = "主键", required = true)
|
@ApiModelProperty(value = "主键", required = true, example = "1")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@ApiModelProperty(value = "创建时间")
|
@ApiModelProperty(value = "创建时间")
|
||||||
@ -28,9 +29,13 @@ public class SpuRespVO extends ProductSpuBaseVO {
|
|||||||
/**
|
/**
|
||||||
* SKU 数组
|
* SKU 数组
|
||||||
*/
|
*/
|
||||||
List<ProductSkuRespVO> 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<ProductSkuRespVO> skus;
|
||||||
|
|
||||||
@ApiModelProperty(value = "分类id数组,一直递归到一级父节点", example = "[1,2,4]")
|
@ApiModelProperty(value = "分类id数组,一直递归到一级父节点", example = "[1,2,4]")
|
||||||
LinkedList<Long> categoryIds;
|
private LinkedList<Long> 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<ProductPropertyViewRespVO> productPropertyViews;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package cn.iocoder.yudao.module.product.service.spu;
|
package cn.iocoder.yudao.module.product.service.spu;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
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.ProductSkuCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
|
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
|
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.dataobject.spu.ProductSpuDO;
|
||||||
import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
|
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.category.CategoryService;
|
||||||
|
import cn.iocoder.yudao.module.product.service.property.ProductPropertyService;
|
||||||
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -41,6 +46,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ProductSkuService productSkuService;
|
private ProductSkuService productSkuService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ProductPropertyService productPropertyService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Long createSpu(ProductSpuCreateReqVO createReqVO) {
|
public Long createSpu(ProductSpuCreateReqVO createReqVO) {
|
||||||
@ -104,6 +112,29 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||||||
if (null != spuVO) {
|
if (null != spuVO) {
|
||||||
List<ProductSkuRespVO> skuReqs = ProductSkuConvert.INSTANCE.convertList(productSkuService.getSkusBySpuId(id));
|
List<ProductSkuRespVO> skuReqs = ProductSkuConvert.INSTANCE.convertList(productSkuService.getSkusBySpuId(id));
|
||||||
spuVO.setSkus(skuReqs);
|
spuVO.setSkus(skuReqs);
|
||||||
|
List<ProductSkuRespVO.Property> properties = new ArrayList<>();
|
||||||
|
// 组合 sku 规格属性
|
||||||
|
for (ProductSkuRespVO productSkuRespVO : skuReqs) {
|
||||||
|
properties.addAll(productSkuRespVO.getProperties());
|
||||||
|
}
|
||||||
|
Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId));
|
||||||
|
List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet()));
|
||||||
|
// 装载组装过后的属性
|
||||||
|
List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>();
|
||||||
|
propertyAndValueList.forEach(p -> {
|
||||||
|
ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO();
|
||||||
|
productPropertyViewRespVO.setPropertyId(p.getId());
|
||||||
|
productPropertyViewRespVO.setName(p.getName());
|
||||||
|
Set<ProductPropertyViewRespVO.Tuple2> propertyValues = new HashSet<>();
|
||||||
|
Map<Long, ProductPropertyValueRespVO> 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()) {
|
if (null != spuVO.getCategoryId()) {
|
||||||
LinkedList<Long> categoryArray = new LinkedList<>();
|
LinkedList<Long> categoryArray = new LinkedList<>();
|
||||||
|
Loading…
Reference in New Issue
Block a user