1.抽取VO
1.1.Bounds
package com.atguigu.gulimall.product.vo;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class Bounds {
private BigDecimal buyBounds;
private BigDecimal growBounds;
}
1.2.BaseAttrs
package com.atguigu.gulimall.product.vo;
import lombok.Data;
@Data
public class BaseAttrs {
private Long attrId;
private String attrValues;
private int showDesc;
}
1.3.Attr
package com.atguigu.gulimall.product.vo;
import lombok.Data;
@Data
public class Attr {
private Long attrId;
private String attrName;
private String attrValue;
}
1.4.Images
package com.atguigu.gulimall.product.vo;
import lombok.Data;
@Data
public class Images {
private String imgUrl;
private int defaultImg;
}
1.5.MemberPrice
package com.atguigu.gulimall.product.vo;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class MemberPrice {
private Long id;
private String name;
private BigDecimal price;
}
1.6.Skus
package com.atguigu.gulimall.product.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class Skus {
private List<Attr> attr;
private String skuName;
private BigDecimal price;
private String skuTitle;
private String skuSubtitle;
private List<Images> images;
private List<String> descar;
private int fullCount;
private BigDecimal discount;
private int countStatus;
private BigDecimal fullPrice;
private BigDecimal reducePrice;
private int priceStatus;
private List<MemberPrice> memberPrice;
}
1.7.SpuSaveVo
package com.atguigu.gulimall.product.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class SpuSaveVo {
private String spuName;
private String spuDescription;
private Long catalogId;
private Long brandId;
private BigDecimal weight;
private int publishStatus;
private List<String> decript;
private List<String> images;
private Bounds bounds;
private List<BaseAttrs> baseAttrs;
private List<Skus> skus;
}
2.修改SpuInfoController的save方法
@RequestMapping("/save")
public R save(@RequestBody SpuSaveVo spuSaveVo){
spuInfoService.saveSpuInfo(spuSaveVo);
return R.ok();
}
3.SpuInfoService中添加saveSpuInfo方法
void saveSpuInfo(SpuSaveVo spuSaveVo);
4.SpuInfoServiceImpl中saveSpuInfo方法实现分析
@Transactional
@Override
public void saveSpuInfo(SpuSaveVo spuSaveVo) {
}
5.保存spu基本信息
5.1.SpuInfoService中添加saveBaseSpuInfo方法
void saveBaseSpuInfo(SpuInfoEntity infoEntity);
5.2.SpuInfoServiceImpl中添加saveBaseSpuInfo方法实现
@Override
public void saveBaseSpuInfo(SpuInfoEntity infoEntity) {
this.baseMapper.insert(infoEntity);
}
6.保存Spu的描述图片
6.1.SpuInfoDescService中添加saveSpuInfoDesc方法
void saveSpuInfoDesc(SpuInfoDescEntity descEntity);
6.2.SpuInfoDescServiceImpl中saveSpuInfoDesc方法实现
@Override
public void saveSpuInfoDesc(SpuInfoDescEntity descEntity) {
this.baseMapper.insert(descEntity);
}
7.保存spu的图片集
7.1.SpuImagesService中添加saveImages方法
void saveImages(Long id, List<String> images);
7.2.SpuImagesServiceImpl中添加saveImages方法实现
@Override
public void saveImages(Long id, List<String> images) {
if(images == null || images.size() == 0){
}else{
List<SpuImagesEntity> spuImagesEntityList = images.stream().map(img -> {
SpuImagesEntity spuImagesEntity = new SpuImagesEntity();
spuImagesEntity.setSpuId(id);
spuImagesEntity.setImgUrl(img);
return spuImagesEntity;
}).collect(Collectors.toList());
this.saveBatch(spuImagesEntityList);
}
}
8.保存spu的规格参数
8.1.ProductAttrValueService中添加saveProductAttr方法
void saveProductAttr(List<ProductAttrValueEntity> collect);
8.2.ProductAttrValueServiceImpl中添加saveProductAttr方法实现
@Override
public void saveProductAttr(List<ProductAttrValueEntity> collect) {
this.saveBatch(collect);
}
9.保存sku的基本信息
9.1.SkuInfoService添加saveSkuInfo方法
void saveSkuInfo(SkuInfoEntity skuInfoEntity);
9.2.SkuInfoServiceImpl添加saveSkuInfo方法实现
@Override
public void saveSkuInfo(SkuInfoEntity skuInfoEntity) {
this.baseMapper.insert(skuInfoEntity);
}