商品服务-新增商品实现(1)

34 篇文章 0 订阅
32 篇文章 0 订阅

1.抽取VO

1.1.Bounds

/**
  * Copyright 2019 bejson.com 
  */
package com.atguigu.gulimall.product.vo;

import lombok.Data;

import java.math.BigDecimal;

/**
 * Auto-generated: 2019-11-26 10:50:34
 *
 * @author bejson.com (i@bejson.com)
 * @website http://www.bejson.com/java2pojo/
 */
@Data
public class Bounds {
    private BigDecimal buyBounds;
    private BigDecimal growBounds;
}

1.2.BaseAttrs

/**
 * Copyright 2019 bejson.com
 */
package com.atguigu.gulimall.product.vo;

import lombok.Data;

/**
 * Auto-generated: 2019-11-26 10:50:34
 *
 * @author bejson.com (i@bejson.com)
 * @website http://www.bejson.com/java2pojo/
 */
@Data
public class BaseAttrs {
    private Long attrId;
    private String attrValues;
    private int showDesc;
}

1.3.Attr

/**
  * Copyright 2019 bejson.com 
  */
package com.atguigu.gulimall.product.vo;

import lombok.Data;

/**
 * Auto-generated: 2019-11-26 10:50:34
 *
 * @author bejson.com (i@bejson.com)
 * @website http://www.bejson.com/java2pojo/
 */
@Data
public class Attr {
    private Long attrId;
    private String attrName;
    private String attrValue;
}

1.4.Images

/**
  * Copyright 2019 bejson.com 
  */
package com.atguigu.gulimall.product.vo;

import lombok.Data;

/**
 * Auto-generated: 2019-11-26 10:50:34
 *
 * @author bejson.com (i@bejson.com)
 * @website http://www.bejson.com/java2pojo/
 */
@Data
public class Images {
    private String imgUrl;
    private int defaultImg;
}

1.5.MemberPrice

/**
  * Copyright 2019 bejson.com 
  */
package com.atguigu.gulimall.product.vo;

import lombok.Data;

import java.math.BigDecimal;

/**
 * Auto-generated: 2019-11-26 10:50:34
 * @author bejson.com (i@bejson.com)
 * @website http://www.bejson.com/java2pojo/
 */
@Data
public class MemberPrice {
    private Long id;
    private String name;
    private BigDecimal price;
}

1.6.Skus

/**
  * Copyright 2019 bejson.com 
  */
package com.atguigu.gulimall.product.vo;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * Auto-generated: 2019-11-26 10:50:34
 *
 * @author bejson.com (i@bejson.com)
 * @website http://www.bejson.com/java2pojo/
 */
@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

/**
 * Copyright 2019 bejson.com
 */
package com.atguigu.gulimall.product.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * Auto-generated: 2019-11-26 10:50:34
 * @author bejson.com (i@bejson.com)
 * @website http://www.bejson.com/java2pojo/
 */
@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方法

 /**
     * 新增商品
     * /product/spuinfo/save
     * @param spuSaveVo
     * @return
     */
    @RequestMapping("/save")
    public R save(@RequestBody SpuSaveVo spuSaveVo){
		//spuInfoService.save(spuInfo);
        spuInfoService.saveSpuInfo(spuSaveVo);
        return R.ok();
    }

3.SpuInfoService中添加saveSpuInfo方法

  void saveSpuInfo(SpuSaveVo spuSaveVo);

4.SpuInfoServiceImpl中saveSpuInfo方法实现分析

 @Transactional
 @Override
 public void saveSpuInfo(SpuSaveVo spuSaveVo) {
     //1、保存spu基本信息 pms_spu_info
   
     //2、保存Spu的描述图片 pms_spu_info_desc
   
     //3、保存spu的图片集 pms_spu_images
   
     //4、保存spu的规格参数;pms_product_attr_value
   
     //5、保存spu的积分信息;gulimall_sms->sms_spu_bounds

     //6、保存当前spu对应的所有sku信息;
     //6.1)、sku的基本信息;pms_sku_info
     //6.2)、sku的图片信息;pms_sku_image
     //6.3)、sku的销售属性信息:pms_sku_sale_attr_value
     //6.4)、sku的优惠、满减等信息;gulimall_sms->sms_sku_ladder\sms_sku_full_reduction\sms_member_price
 }

5.保存spu基本信息

5.1.SpuInfoService中添加saveBaseSpuInfo方法

void saveBaseSpuInfo(SpuInfoEntity infoEntity);

5.2.SpuInfoServiceImpl中添加saveBaseSpuInfo方法实现

 /**
   * 保存spu基本信息
   * @param infoEntity
   */
  @Override
  public void saveBaseSpuInfo(SpuInfoEntity infoEntity) {
      this.baseMapper.insert(infoEntity);
  }

6.保存Spu的描述图片

6.1.SpuInfoDescService中添加saveSpuInfoDesc方法

void saveSpuInfoDesc(SpuInfoDescEntity descEntity);

6.2.SpuInfoDescServiceImpl中saveSpuInfoDesc方法实现

/**
  * 保存Spu的描述图片
  * @param descEntity
  */
 @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方法实现

 /**
   * 保存spu的图片集
   * @param id
   * @param images
   */
  @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方法实现

/**
  * 保存spu的规格参数
  * @param collect
  */
 @Override
 public void saveProductAttr(List<ProductAttrValueEntity> collect) {
     this.saveBatch(collect);
 }

9.保存sku的基本信息

9.1.SkuInfoService添加saveSkuInfo方法

void saveSkuInfo(SkuInfoEntity skuInfoEntity);

9.2.SkuInfoServiceImpl添加saveSkuInfo方法实现

/**
  * 保存sku的基本信息
  * @param skuInfoEntity
  */
 @Override
 public void saveSkuInfo(SkuInfoEntity skuInfoEntity) {
     this.baseMapper.insert(skuInfoEntity);
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值