|
|
|
@ -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<>();
|
|
|
|
|