|
|
|
@ -1,7 +1,22 @@
|
|
|
|
|
package com.bookstore.bookmall.product.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.bookstore.bookmall.product.entity.*;
|
|
|
|
|
import com.bookstore.bookmall.product.feign.CouponFeignService;
|
|
|
|
|
import com.bookstore.bookmall.product.service.*;
|
|
|
|
|
import com.bookstore.bookmall.product.vo.*;
|
|
|
|
|
import com.bookstore.common.to.SpuBoundsTo;
|
|
|
|
|
import com.fasterxml.jackson.databind.annotation.JsonAppend;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
@ -9,13 +24,29 @@ import com.bookstore.common.utils.PageUtils;
|
|
|
|
|
import com.bookstore.common.utils.Query;
|
|
|
|
|
|
|
|
|
|
import com.bookstore.bookmall.product.dao.SpuInfoDao;
|
|
|
|
|
import com.bookstore.bookmall.product.entity.SpuInfoEntity;
|
|
|
|
|
import com.bookstore.bookmall.product.service.SpuInfoService;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service("spuInfoService")
|
|
|
|
|
public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
SpuInfoDescService DescService;
|
|
|
|
|
@Autowired
|
|
|
|
|
SpuImagesService imagesService;
|
|
|
|
|
@Autowired
|
|
|
|
|
AttrService attrService;
|
|
|
|
|
@Autowired
|
|
|
|
|
ProductAttrValueService valueService;
|
|
|
|
|
@Autowired
|
|
|
|
|
SkuInfoService skuInfoService;
|
|
|
|
|
@Autowired
|
|
|
|
|
SkuImagesService skuImagesService;
|
|
|
|
|
@Autowired
|
|
|
|
|
SkuSaleAttrValueService skuSaleAttrValueService;
|
|
|
|
|
@Autowired
|
|
|
|
|
CouponFeignService couponFeignService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageUtils queryPage(Map<String, Object> params) {
|
|
|
|
|
IPage<SpuInfoEntity> page = this.page(
|
|
|
|
@ -26,4 +57,118 @@ public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> i
|
|
|
|
|
return new PageUtils(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//商品保存
|
|
|
|
|
//基本信息在pms_spu_info
|
|
|
|
|
//描述信息在pms_spu_info_desc
|
|
|
|
|
//sku: spu销售属性笛卡尔积得出了sku
|
|
|
|
|
@Transactional
|
|
|
|
|
@Override
|
|
|
|
|
public void saveSpuInfo(SpuSaveVo vo) {
|
|
|
|
|
//1、保存基本信息 pms_spu_info
|
|
|
|
|
SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
|
|
|
|
|
BeanUtils.copyProperties(vo, spuInfoEntity);
|
|
|
|
|
spuInfoEntity.setCreateTime(new Date());
|
|
|
|
|
spuInfoEntity.setUpdateTime(new Date());
|
|
|
|
|
this.saveBaseSpuInfo(spuInfoEntity);
|
|
|
|
|
|
|
|
|
|
//2、保存spu的描述图片 pms_spu_images
|
|
|
|
|
List<String> decript = vo.getDecript();
|
|
|
|
|
SpuInfoDescEntity DescEntity = new SpuInfoDescEntity();
|
|
|
|
|
DescEntity.setSpuId(spuInfoEntity.getId());
|
|
|
|
|
DescEntity.setDecript(String.join(",",decript));
|
|
|
|
|
DescService.saveSpuInfoDesc(DescEntity);
|
|
|
|
|
|
|
|
|
|
//3、保存spu的图片集 pms_spu_images
|
|
|
|
|
List<String> images = vo.getImages();
|
|
|
|
|
imagesService.saveImages(spuInfoEntity.getId(), images);
|
|
|
|
|
|
|
|
|
|
//4、保存spu的基本属性(规格参数) //pms_product_attr_value
|
|
|
|
|
List<BaseAttrs> baseAttrs = vo.getBaseAttrs();
|
|
|
|
|
List<ProductAttrValueEntity> collect = baseAttrs.stream().map(attr -> {
|
|
|
|
|
ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();
|
|
|
|
|
valueEntity.setAttrId(attr.getAttrId());
|
|
|
|
|
AttrEntity byId = attrService.getById(attr.getAttrId());
|
|
|
|
|
valueEntity.setAttrName(byId.getAttrName());
|
|
|
|
|
valueEntity.setAttrValue(attr.getAttrValues());
|
|
|
|
|
valueEntity.setQuickShow(attr.getShowDesc());
|
|
|
|
|
valueEntity.setSpuId(spuInfoEntity.getId());
|
|
|
|
|
|
|
|
|
|
return valueEntity;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
valueService.saveProductAttr(collect);
|
|
|
|
|
|
|
|
|
|
//保存spu的积分信息;mall-sms-> sms_spu_bounds
|
|
|
|
|
Bounds bounds = vo.getBounds();
|
|
|
|
|
SpuBoundsTo spuBoundsTo = new SpuBoundsTo();
|
|
|
|
|
BeanUtils.copyProperties(bounds, spuBoundsTo);
|
|
|
|
|
spuBoundsTo.setSpuId(spuInfoEntity.getId());
|
|
|
|
|
couponFeignService.saveSpuBounds(spuBoundsTo);
|
|
|
|
|
|
|
|
|
|
//5、保存当前spu对应的所有sku信息
|
|
|
|
|
List<Skus> skus = vo.getSkus();
|
|
|
|
|
if (skus!=null && skus.size()>0) {
|
|
|
|
|
skus.forEach(item->{
|
|
|
|
|
String defaultImg = "";
|
|
|
|
|
for (Images image : item.getImages()) {
|
|
|
|
|
if (image.getDefaultImg() == 1) {
|
|
|
|
|
defaultImg = image.getImgUrl();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// private String skuName;
|
|
|
|
|
// private BigDecimal price;
|
|
|
|
|
// private String skuTitle;
|
|
|
|
|
// private String skuSubtitle;
|
|
|
|
|
//5.1 sku的基本属性(pms_sku_info):id, 名字,标题,副标题,价格,默认图片,分类id
|
|
|
|
|
SkuInfoEntity skuInfoEntity = new SkuInfoEntity();
|
|
|
|
|
BeanUtils.copyProperties(item, skuInfoEntity);
|
|
|
|
|
skuInfoEntity.setBrandId(spuInfoEntity.getBrandId());
|
|
|
|
|
skuInfoEntity.setCatalogId(spuInfoEntity.getCatalogId());
|
|
|
|
|
skuInfoEntity.setSaleCount(0L);
|
|
|
|
|
skuInfoEntity.setSpuId(spuInfoEntity.getId());
|
|
|
|
|
skuInfoEntity.setSkuDefaultImg(defaultImg);
|
|
|
|
|
skuInfoService.saveSkuInfo(skuInfoEntity);
|
|
|
|
|
|
|
|
|
|
//5.2 sku的图片信息: pms_sku_images
|
|
|
|
|
Long skuId = skuInfoEntity.getSkuId();
|
|
|
|
|
List<SkuImagesEntity> skuImagesEntities = item.getImages().stream().map(image -> {
|
|
|
|
|
SkuImagesEntity skuImagesEntity = new SkuImagesEntity();
|
|
|
|
|
|
|
|
|
|
skuImagesEntity.setSkuId(skuId);
|
|
|
|
|
skuImagesEntity.setImgUrl(image.getImgUrl());
|
|
|
|
|
skuImagesEntity.setDefaultImg(image.getDefaultImg());
|
|
|
|
|
|
|
|
|
|
return skuImagesEntity;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
skuImagesService.saveBatch(skuImagesEntities);
|
|
|
|
|
|
|
|
|
|
//5.3 sku的销售属性信息 pms_sku_sale_attr_value
|
|
|
|
|
List<Attr> attr = item.getAttr();
|
|
|
|
|
List<SkuSaleAttrValueEntity> skuSaleAttrValueEntities = attr.stream().map(a -> {
|
|
|
|
|
SkuSaleAttrValueEntity skuSaleAttrValueEntity = new SkuSaleAttrValueEntity();
|
|
|
|
|
BeanUtils.copyProperties(skuSaleAttrValueEntity, a);
|
|
|
|
|
skuSaleAttrValueEntity.setSkuId(skuId);
|
|
|
|
|
return skuSaleAttrValueEntity;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities);
|
|
|
|
|
|
|
|
|
|
//5.4 sku的优惠满减信息
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void saveBaseSpuInfo(SpuInfoEntity spuInfoEntity) {
|
|
|
|
|
this.baseMapper.insert(spuInfoEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|