Skip to content

Commit

Permalink
进行商品添加的迁移
Browse files Browse the repository at this point in the history
  • Loading branch information
YunaiV committed Jul 27, 2020
1 parent be4b34c commit e107b42
Show file tree
Hide file tree
Showing 49 changed files with 553 additions and 1,042 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,21 @@ GET {{baseUrl}}/product-spu/page?pageNo=1&pageSize=10
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer {{accessToken}}

###
### /product-spu/page 成功(有库存 + 上架)
GET {{baseUrl}}/product-spu/page?pageNo=1&pageSize=10&hasQuantity=true&visible=true
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer {{accessToken}}

### /product-spu/page 成功(无库存 + 下架)
GET {{baseUrl}}/product-spu/page?pageNo=1&pageSize=10&hasQuantity=false&visible=false
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer {{accessToken}}

### /product-spu/create 成功
POST {{baseUrl}}/product-spu/create
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer {{accessToken}}

name=测试商品标题&description=测试商品描述&cid=637&sellPoint=丑&picUrls=1,2,3&visible=true&skus[0].price=1&skus[0].quantity=100&skus[0].attrValueIds=1,3

###
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public CommonResult<List<ProductSpuRespVO>> listProductSpus(@RequestParam("produ
@GetMapping("/page")
@ApiOperation("获得商品 SPU 分页")
public CommonResult<PageResult<ProductSpuRespVO>> pageProductSpu(ProductSpuPageReqVO pageVO) {
//
//
//
return success(productSpuManager.pageProductSpu(pageVO));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,45 @@
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

@ApiModel("商品 SPU创建 Request VO")
@ApiModel("商品 SPU 创建 Request VO")
@Data
public class ProductSpuCreateReqVO {

/**
* SKU 信息
*/
@Data
@Accessors(chain = true)
public static class Sku {

/**
* 规格值数组
*/
@NotNull(message = "规格值数组不能为空")
private List<Integer> attrValueIds;
/**
* 价格,单位:分
*/
@NotNull(message = "价格不能为空")
@Min(value = 1L, message = "最小价格为 1")
private Integer price;
/**
* 库存数量
*/
@NotNull(message = "库存数量不能为空")
@Min(value = 1L, message = "最小库存为 1")
private Integer quantity;

}

@ApiModelProperty(value = "SPU 名字", required = true)
@NotEmpty(message = "SPU 名字不能为空")
private String name;
Expand All @@ -30,14 +60,14 @@ public class ProductSpuCreateReqVO {
@ApiModelProperty(value = "是否上架商品", required = true)
@NotNull(message = "是否上架商品不能为空")
private Boolean visible;
@ApiModelProperty(value = "排序字段", required = true)
@NotNull(message = "排序字段不能为空")
private Integer sort;
@ApiModelProperty(value = "价格", required = true)
@NotNull(message = "价格不能为空")
private Integer price;
@ApiModelProperty(value = "库存数量", required = true)
@NotNull(message = "库存数量不能为空")
private Integer quantity;

// ========== SKU =========

/**
* SKU 数组
*/
@NotNull(message = "SKU 不能为空")
@Valid
private List<Sku> skus;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,13 @@
@EqualsAndHashCode(callSuper = true)
public class ProductSpuPageReqVO extends PageParam {

@ApiModelProperty(value = "SPU 名字", required = true)
@ApiModelProperty(value = "SPU 名字", notes = "模糊匹配", example = "艿艿")
private String name;
@ApiModelProperty(value = "卖点", required = true)
private String sellPoint;
@ApiModelProperty(value = "描述", required = true)
private String description;
@ApiModelProperty(value = "分类编号", required = true)
@ApiModelProperty(value = "分类编号", example = "1024")
private Integer cid;
@ApiModelProperty(value = "商品主图地址", required = true)
private String picUrls;
@ApiModelProperty(value = "是否上架商品", required = true)
private Integer visible;
@ApiModelProperty(value = "排序字段", required = true)
private Integer sort;
@ApiModelProperty(value = "价格", required = true)
private Integer price;
@ApiModelProperty(value = "库存数量", required = true)
private Integer quantity;
@ApiModelProperty(value = "是否上架商品", example = "true")
private Boolean visible;
@ApiModelProperty(value = "是否有库存", example = "true")
private Boolean hasQuantity;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import cn.iocoder.mall.managementweb.controller.product.vo.spu.ProductSpuPageReqVO;
import cn.iocoder.mall.managementweb.controller.product.vo.spu.ProductSpuRespVO;
import cn.iocoder.mall.managementweb.controller.product.vo.spu.ProductSpuUpdateReqVO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuCreateReqDTO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuCreateReqDTO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuPageReqDTO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuUpdateReqDTO;
Expand All @@ -19,7 +19,7 @@ public interface ProductSpuConvert {

ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class);

ProductSpuCreateReqDTO convert(ProductSpuCreateReqVO bean);
ProductSpuAndSkuCreateReqDTO convert(ProductSpuCreateReqVO bean);

ProductSpuUpdateReqDTO convert(ProductSpuUpdateReqVO bean);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public interface ProductErrorCodeConstants {
ErrorCode PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2 = new ErrorCode(1002001005, "父分类必须是一级分类");

// ========== PRODUCT SPU + SKU 模块 ==========
ErrorCode PRODUCT_SKU_ATTR_CANT_NOT_DUPLICATE = new ErrorCode(1003002000, "一个 Sku 下,不能有重复的规格");
ErrorCode PRODUCT_SPU_ATTR_NUMBERS_MUST_BE_EQUALS = new ErrorCode(1003002001, "一个 Spu 下的每个 Sku ,其规格数必须一致");
ErrorCode PRODUCT_SPU_SKU__NOT_DUPLICATE = new ErrorCode(1003002002, "一个 Spu 下的每个 Sku ,必须不重复");
ErrorCode PRODUCT_SPU_NOT_EXISTS = new ErrorCode(1003002003, "Spu 不存在");
ErrorCode PRODUCT_SPU_CATEGORY_MUST_BE_LEVEL2 = new ErrorCode(1003002003, "Spu 只能添加在二级分类下");
ErrorCode PRODUCT_SKU_ATTR_CANT_NOT_DUPLICATE = new ErrorCode(1003002000, "一个 SKU 下,不能有重复的规格");
ErrorCode PRODUCT_SPU_ATTR_NUMBERS_MUST_BE_EQUALS = new ErrorCode(1003002001, "一个 Spu 下的每个 SKU ,其规格数必须一致");
ErrorCode PRODUCT_SPU_SKU_NOT_DUPLICATE = new ErrorCode(1003002002, "一个 SPU 下的每个 SKU ,必须不重复");
ErrorCode PRODUCT_SPU_NOT_EXISTS = new ErrorCode(1003002003, "SPU 不存在");
ErrorCode PRODUCT_SPU_CATEGORY_MUST_BE_LEVEL2 = new ErrorCode(1003002003, "SPU 只能添加在二级分类下");

// ========== PRODUCT ATTR + ATTR_VALUE 模块 ==========
ErrorCode PRODUCT_ATTR_VALUE_NOT_EXIST = new ErrorCode(1003003000, "商品属性值不存在");
ErrorCode PRODUCT_ATTR_NOT_EXIST = new ErrorCode(1003003001, "商品属性值不存在");
ErrorCode PRODUCT_ATTR_VALUE_NOT_EXIST = new ErrorCode(1003003000, "商品属性值不存在");
ErrorCode PRODUCT_ATTR_KEY_NOT_EXIST = new ErrorCode(1003003001, "商品属性值不存在");
ErrorCode PRODUCT_ATTR_EXISTS = new ErrorCode(1003003002, "商品规格已经存在");
ErrorCode PRODUCT_ATTR_STATUS_EQUALS = new ErrorCode(1003003003, "商品规格已经是该状态");
ErrorCode PRODUCT_ATTR_VALUE_EXISTS = new ErrorCode(1003003004, "商品规格值已经存在");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuCreateReqDTO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuCreateReqDTO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuPageReqDTO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuUpdateReqDTO;
Expand All @@ -20,7 +20,7 @@ public interface ProductSpuRpc {
* @param createDTO 创建商品 SPU DTO
* @return 商品 SPU编号
*/
CommonResult<Integer> createProductSpu(ProductSpuCreateReqDTO createDTO);
CommonResult<Integer> createProductSpu(ProductSpuAndSkuCreateReqDTO createDTO);

/**
* 更新商品 SPU
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package cn.iocoder.mall.productservice.rpc.spu.dto;

import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;

/**
* 商品 SPU 和 SKU 创建 Request DTO
*/
@Data
@Accessors(chain = true)
public class ProductSpuAndSkuCreateReqDTO implements Serializable {

/**
* SKU 信息
*/
@Data
@Accessors(chain = true)
public static class Sku implements Serializable {

/**
* 规格值数组
*/
@NotNull(message = "规格值数组不能为空")
private List<Integer> attrValueIds;
/**
* 价格,单位:分
*/
@NotNull(message = "价格不能为空")
@Min(value = 1L, message = "最小价格为 1")
private Integer price;
/**
* 库存数量
*/
@NotNull(message = "库存数量不能为空")
@Min(value = 1L, message = "最小库存为 1")
private Integer quantity;

}

// ========== 基本信息 =========
/**
* SPU 名字
*/
@NotEmpty(message = "SPU 名字不能为空")
private String name;
/**
* 卖点
*/
@NotEmpty(message = "卖点不能为空")
private String sellPoint;
/**
* 描述
*/
@NotEmpty(message = "描述不能为空")
private String description;
/**
* 分类编号
*/
@NotNull(message = "分类编号不能为空")
private Integer cid;
/**
* 商品主图地址
*/
@NotEmpty(message = "商品主图地址不能为空")
private List<String> picUrls;

// ========== 其他信息 =========
/**
* 是否上架商品
*/
@NotNull(message = "是否上架商品不能为空")
private Boolean visible;

// ========== SKU =========

/**
* SKU 数组
*/
@NotNull(message = "SKU 不能为空")
@Valid
private List<Sku> skus;

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public class ProductSpuPageReqDTO extends PageParam {
* SPU 名字
*/
private String name;
/**
* 分类编号
*/
private Integer cid;
/**
* 是否可见
*/
private Boolean visible;
/**
* 是否有库存
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cn.iocoder.mall.productservice.convert.sku;

import cn.iocoder.common.framework.util.StringUtils;
import cn.iocoder.mall.productservice.dal.mysql.dataobject.spu.ProductSkuDO;
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuCreateOrUpdateBO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface ProductSkuConvert {

ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class);

List<ProductSkuDO> convertList(List<ProductSkuCreateOrUpdateBO> list);

@Mapping(source = "attrValueIds", target = "attrs", qualifiedByName = "translatePicUrlsFromStringList")
ProductSkuDO convertList(ProductSkuCreateOrUpdateBO bean);

@Named("translateAttrValueIdsFromString")
default List<String> translateAttrValueIdsFromString(String attrValueIdsStar) {
return StringUtils.split(attrValueIdsStar, ",");
}

@Named("translateAttrValueIdsFromList")
default String translateAttrValueIdsFromList(List<Integer> attrValueIds) {
return StringUtils.join(attrValueIds, ",");
}

}
Loading

0 comments on commit e107b42

Please sign in to comment.