将 onemall 老代码,统一到归档目录,后续不断迁移移除
This commit is contained in:
39
归档/product-service-project/pom.xml
Normal file
39
归档/product-service-project/pom.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>onemall</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>product-service-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>product-service-api</module>
|
||||
<module>product-service-app</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- onemall 基础 bom 文件 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>mall-dependencies</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 自身项目 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>product-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
36
归档/product-service-project/product-service-api/pom.xml
Normal file
36
归档/product-service-project/product-service-api/pom.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>product-service-project</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>product-service-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>common-framework</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 工具类相关 -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||
<version>RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.iocoder.mall.productservice.enums;
|
||||
|
||||
import cn.iocoder.common.framework.exception.ErrorCode;
|
||||
|
||||
/**
|
||||
* 错误码枚举类
|
||||
*
|
||||
* 商品系统,使用 1-003-000-000 段
|
||||
*/
|
||||
public interface ProductErrorCodeConstants {
|
||||
|
||||
// ========== PRODUCT CATEGORY 模块 ==========
|
||||
ErrorCode PRODUCT_CATEGORY_PARENT_NOT_EXISTS = new ErrorCode(1003001000, "父分类不存在");
|
||||
ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1003001001, "商品分类不存在");
|
||||
ErrorCode PRODUCT_CATEGORY_PARENT_NOT_SELF = new ErrorCode(1003001002, "不能设置自己为父分类");
|
||||
ErrorCode PRODUCT_CATEGORY_DELETE_ONLY_NO_CHILD = new ErrorCode(1002001004, "只有无子分类的商品分类才可以删除");
|
||||
ErrorCode PRODUCT_CATEGORY_MUST_ENABLE = new ErrorCode(1002001005, "只有开启的商品分类,才可以使用");
|
||||
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 只能添加在二级分类下");
|
||||
|
||||
// ========== PRODUCT ATTR + ATTR_VALUE 模块 ==========
|
||||
ErrorCode PRODUCT_ATTR_VALUE_NOT_EXIST = new ErrorCode(1003003000, "商品属性值不存在");
|
||||
ErrorCode PRODUCT_ATTR_KEY_NOT_EXIST = new ErrorCode(1003003001, "商品属性键不存在");
|
||||
ErrorCode PRODUCT_ATTR_KEY_EXISTS = new ErrorCode(1003003002, "商品规格键已经存在");
|
||||
ErrorCode PRODUCT_ATTR_VALUE_EXISTS = new ErrorCode(1003003004, "商品规格值已经存在");
|
||||
|
||||
// ========== PRODUCT BRAND模块 ==========
|
||||
ErrorCode PRODUCT_BRAND_NAME_EXIST = new ErrorCode(1003004000,"商品品牌的名字已经存在");
|
||||
ErrorCode PRODUCT_BRAND_NOT_FOUND = new ErrorCode(1003004001, "商品品牌不粗糙你在");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.iocoder.mall.productservice.enums.category;
|
||||
|
||||
/**
|
||||
* 商品分类的编号枚举
|
||||
*/
|
||||
public enum ProductCategoryIdEnum {
|
||||
|
||||
/**
|
||||
* 根节点
|
||||
*/
|
||||
ROOT(0);
|
||||
|
||||
private final Integer id;
|
||||
|
||||
ProductCategoryIdEnum(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.mall.productservice.enums.sku;
|
||||
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
|
||||
|
||||
/**
|
||||
* 商品 SKU 明细的字段枚举
|
||||
*
|
||||
* @see ProductSkuRespDTO
|
||||
*/
|
||||
public enum ProductSkuDetailFieldEnum {
|
||||
|
||||
SPU("spu"),
|
||||
ATTR("attr");
|
||||
|
||||
/**
|
||||
* 字段
|
||||
*/
|
||||
private final String field;
|
||||
|
||||
ProductSkuDetailFieldEnum(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public String getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.mall.productservice.enums.spu;
|
||||
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuDetailRespDTO;
|
||||
|
||||
/**
|
||||
* 商品 SPU 明细的字段枚举
|
||||
*
|
||||
* @see ProductSpuDetailRespDTO
|
||||
*/
|
||||
public enum ProductSpuDetailFieldEnum {
|
||||
|
||||
SKU("sku"),
|
||||
ATTR("attr");
|
||||
|
||||
/**
|
||||
* 字段
|
||||
*/
|
||||
private final String field;
|
||||
|
||||
ProductSpuDetailFieldEnum(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public String getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.*;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品规格 Rpc 接口
|
||||
*/
|
||||
@FeignClient(value = "product-service")
|
||||
public interface ProductAttrFeign {
|
||||
|
||||
/**
|
||||
* 创建商品规格键
|
||||
*
|
||||
* @param createDTO 创建商品规格键 DTO
|
||||
* @return 商品规格键编号
|
||||
*/
|
||||
@PostMapping(value = "/product/attr/createProductAttrKey")
|
||||
CommonResult<Integer> createProductAttrKey(@RequestBody ProductAttrKeyCreateReqDTO createDTO);
|
||||
|
||||
/**
|
||||
* 更新商品规格键
|
||||
*
|
||||
* @param updateDTO 更新商品规格键 DTO
|
||||
*/
|
||||
@PostMapping(value = "/product/attr/updateProductAttrKey")
|
||||
CommonResult<Boolean> updateProductAttrKey(@RequestBody ProductAttrKeyUpdateReqDTO updateDTO);
|
||||
|
||||
/**
|
||||
* 获得商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
* @return 商品规格键
|
||||
*/
|
||||
@GetMapping("/product/attr/getProductAttrKey")
|
||||
CommonResult<ProductAttrKeyRespDTO> getProductAttrKey(@RequestParam("productAttrKeyId") Integer productAttrKeyId);
|
||||
|
||||
/**
|
||||
* 获得商品规格键列表
|
||||
*
|
||||
* @param productAttrKeyIds 商品规格键编号列表
|
||||
* @return 商品规格键列表
|
||||
*/
|
||||
@GetMapping("/product/attr/listProductAttrKeys")
|
||||
CommonResult<List<ProductAttrKeyRespDTO>> listProductAttrKeys(@RequestParam("productAttrKeyIds") List<Integer> productAttrKeyIds);
|
||||
|
||||
/**
|
||||
* 获得商品规格键分页
|
||||
*
|
||||
* @param pageDTO 商品规格键分页查询
|
||||
* @return 商品规格键分页结果
|
||||
*/
|
||||
@PostMapping("/product/attr/pageProductAttrKey")
|
||||
CommonResult<PageResult<ProductAttrKeyRespDTO>> pageProductAttrKey(@RequestBody ProductAttrKeyPageReqDTO pageDTO);
|
||||
|
||||
/**
|
||||
* 创建商品规格值
|
||||
*
|
||||
* @param createDTO 创建商品规格值 DTO
|
||||
* @return 商品规格值编号
|
||||
*/
|
||||
@PostMapping("/product/attr/createProductAttrValue")
|
||||
CommonResult<Integer> createProductAttrValue(@RequestBody ProductAttrValueCreateReqDTO createDTO);
|
||||
|
||||
|
||||
/**
|
||||
* 更新商品规格值
|
||||
*
|
||||
* @param updateDTO 更新商品规格值 DTO
|
||||
*/
|
||||
@PostMapping("/product/attr/updateProductAttrValue")
|
||||
CommonResult<Boolean> updateProductAttrValue(@RequestBody ProductAttrValueUpdateReqDTO updateDTO);
|
||||
|
||||
/**
|
||||
* 获得商品规格值
|
||||
*
|
||||
* @param productAttrValueId 商品规格值编号
|
||||
* @return 商品规格值
|
||||
*/
|
||||
@GetMapping("/product/attr/getProductAttrValue")
|
||||
CommonResult<ProductAttrValueRespDTO> getProductAttrValue(@RequestParam("productAttrValueId") Integer productAttrValueId);
|
||||
|
||||
@PostMapping("/product/attr/listProductAttrValues")
|
||||
CommonResult<List<ProductAttrValueRespDTO>> listProductAttrValues(@RequestBody ProductAttrValueListQueryReqDTO queryDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品规格键创建 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyCreateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
@NotEmpty(message = "规格键名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品规格键分页 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyPageReqDTO extends PageParam {
|
||||
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品规格键 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品规格键更新 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyUpdateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
@NotNull(message = "规格键编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
@NotEmpty(message = "规格键名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品规格 KEY + VALUE 对的 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyValueRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格 KEY 编号
|
||||
*/
|
||||
private Integer attrKeyId;
|
||||
/**
|
||||
* 规格 KEY 名
|
||||
*/
|
||||
private String attrKeyName;
|
||||
/**
|
||||
* 规格 VALUE 编号
|
||||
*/
|
||||
private Integer attrValueId;
|
||||
/**
|
||||
* 规格 VALUE 名
|
||||
*/
|
||||
private String attrValueName;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品规格值创建 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrValueCreateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
@NotNull(message = "规格键编号不能为空")
|
||||
private Integer attrKeyId;
|
||||
/**
|
||||
* 规格值名字
|
||||
*/
|
||||
@NotEmpty(message = "规格值名字不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品规格值的列表查询条件 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrValueListQueryReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 商品规格值编号列表
|
||||
*/
|
||||
private List<Integer> productAttrValueIds;
|
||||
|
||||
/**
|
||||
* 商品规格键编号
|
||||
*/
|
||||
private Integer productAttrKeyId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品规格值 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrValueRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格值编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
private Integer attrKeyId;
|
||||
/**
|
||||
* 规格值名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品规格值更新 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrValueUpdateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格值编号
|
||||
*/
|
||||
@NotNull(message = "规格值编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格值名字
|
||||
*/
|
||||
@NotEmpty(message = "规格值名字不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandUpdateReqDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(value = "product-service")
|
||||
public interface ProductBrandFeign {
|
||||
/**
|
||||
* 创建商品品牌
|
||||
*
|
||||
* @param createDTO 创建商品品牌 DTO
|
||||
* @return 商品品牌编号
|
||||
*/
|
||||
@PostMapping("/product/brand/createProductBrand")
|
||||
CommonResult<Integer> createProductBrand(@RequestBody ProductBrandCreateReqDTO createDTO);
|
||||
|
||||
/**
|
||||
* 更新商品品牌
|
||||
*
|
||||
* @param updateDTO 更新商品品牌 DTO
|
||||
*/
|
||||
@PostMapping("/product/brand/updateProductBrand")
|
||||
CommonResult<Boolean> updateProductBrand(@RequestBody ProductBrandUpdateReqDTO updateDTO);
|
||||
|
||||
/**
|
||||
* 删除商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
*/
|
||||
@GetMapping("/product/brand/deleteProductBrand")
|
||||
CommonResult<Boolean> deleteProductBrand(@RequestParam("productBrandId") Integer productBrandId);
|
||||
/**
|
||||
* 获得商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
* @return 商品品牌
|
||||
*/
|
||||
@GetMapping("/product/brand/getProductBrand")
|
||||
CommonResult<ProductBrandRespDTO> getProductBrand(@RequestParam("productBrandId")Integer productBrandId);
|
||||
/**
|
||||
* 获得商品品牌列表
|
||||
*
|
||||
* @param productBrandIds 商品品牌编号列表
|
||||
* @return 商品品牌列表
|
||||
*/
|
||||
@GetMapping("/product/brand/listProductBrands")
|
||||
CommonResult<List<ProductBrandRespDTO>> listProductBrands(@RequestParam("productBrandIds") List<Integer> productBrandIds);
|
||||
|
||||
/**
|
||||
* 获得商品品牌分页
|
||||
*
|
||||
* @param pageDTO 商品品牌分页查询
|
||||
* @return 商品品牌分页结果
|
||||
*/
|
||||
@PostMapping("/product/brand/pageProductBrand")
|
||||
CommonResult<PageResult<ProductBrandRespDTO>> pageProductBrand(@RequestBody ProductBrandPageReqDTO pageDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品品牌创建 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandCreateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
@NotEmpty(message = "品牌名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand.dto;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品品牌分页 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandPageReqDTO extends PageParam {
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品品牌 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 品牌编号(主键)
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品品牌更新 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandUpdateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 品牌编号
|
||||
*/
|
||||
@NotNull(message = "品牌编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
@NotEmpty(message = "品牌名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package cn.iocoder.mall.productservice.rpc.category;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryUpdateReqDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(value = "product-service")
|
||||
public interface ProductCategoryFeign {
|
||||
|
||||
/**
|
||||
* 创建商品分类
|
||||
*
|
||||
* @param createDTO 创建商品分类 DTO
|
||||
* @return 商品分类编号
|
||||
*/
|
||||
@PostMapping("/product/category/createProductCategory")
|
||||
CommonResult<Integer> createProductCategory(@RequestBody ProductCategoryCreateReqDTO createDTO);
|
||||
/**
|
||||
* 更新商品分类
|
||||
*
|
||||
* @param updateDTO 更新商品分类 DTO
|
||||
*/
|
||||
@PostMapping("/product/category/updateProductCategory")
|
||||
CommonResult<Boolean> updateProductCategory(@RequestBody ProductCategoryUpdateReqDTO updateDTO);
|
||||
|
||||
/**
|
||||
* 删除商品分类
|
||||
*
|
||||
* @param productCategoryId 商品分类编号
|
||||
*/
|
||||
@GetMapping("/product/category/deleteProductCategory")
|
||||
CommonResult<Boolean> deleteProductCategory(@RequestParam("productCategoryId") Integer productCategoryId);
|
||||
/**
|
||||
* 获得商品分类
|
||||
*
|
||||
* @param productCategoryId 商品分类编号
|
||||
* @return 商品分类
|
||||
*/
|
||||
@GetMapping("/product/category/getProductCategory")
|
||||
CommonResult<ProductCategoryRespDTO> getProductCategory(@RequestParam("productCategoryId")Integer productCategoryId);
|
||||
/**
|
||||
* 获得商品分类列表
|
||||
*
|
||||
* @param productCategoryIds 商品分类编号列表
|
||||
* @return 商品分类列表
|
||||
*/
|
||||
@GetMapping("/product/category/listProductCategoriesByIds")
|
||||
CommonResult<List<ProductCategoryRespDTO>> listProductCategoriesByIds(@RequestParam("productCategoryIds")Collection<Integer> productCategoryIds);
|
||||
|
||||
/**
|
||||
* 获得符合条件的商品分类列表
|
||||
*
|
||||
* @return 商品分类列表
|
||||
*/
|
||||
@PostMapping("/product/category/listProductCategories")
|
||||
CommonResult<List<ProductCategoryRespDTO>> listProductCategories(@RequestBody ProductCategoryListQueryReqDTO listQueryReqDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package cn.iocoder.mall.productservice.rpc.category.dto;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品分类创建 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryCreateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
@NotNull(message = "父分类编号不能为空")
|
||||
private Integer pid;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
@NotEmpty(message = "分类名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 分类描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 分类排序
|
||||
*/
|
||||
@NotNull(message = "分类排序不能为空")
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.iocoder.mall.productservice.rpc.category.dto;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品分类列表查询 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryListQueryReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 父编号
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package cn.iocoder.mall.productservice.rpc.category.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品分类 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 分类描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 分类排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.iocoder.mall.productservice.rpc.category.dto;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品分类更新 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryUpdateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
@NotNull(message = "分类编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
@NotNull(message = "父分类编号不能为空")
|
||||
private Integer pid;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
@NotEmpty(message = "分类名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 分类描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 分类排序
|
||||
*/
|
||||
@NotNull(message = "分类排序不能为空")
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.iocoder.mall.productservice.rpc.sku;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(value = "product-service")
|
||||
public interface ProductSkuFeign {
|
||||
@GetMapping("/product/sku/getProductSku")
|
||||
CommonResult<ProductSkuRespDTO> getProductSku(@RequestParam("productSkuId") Integer productSkuId);
|
||||
|
||||
/**
|
||||
* 获得商品 SKU 列表
|
||||
*
|
||||
* @param queryReqDTO 商品 SKU 列表的查询请求 DTO
|
||||
* @return 商品 SKU 列表
|
||||
*/
|
||||
@PostMapping("/product/sku/listProductSkus")
|
||||
CommonResult<List<ProductSkuRespDTO>> listProductSkus(@RequestBody ProductSkuListQueryReqDTO queryReqDTO);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.iocoder.mall.productservice.rpc.sku.dto;
|
||||
|
||||
import cn.iocoder.mall.productservice.enums.sku.ProductSkuDetailFieldEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* 商品 SKU 列表查询 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSkuListQueryReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 商品 SKU 编号
|
||||
*/
|
||||
private Integer productSkuId;
|
||||
/**
|
||||
* 商品 SKU 编号数组
|
||||
*/
|
||||
private Collection<Integer> productSkuIds;
|
||||
/**
|
||||
* 商品 SPU 编号
|
||||
*/
|
||||
private Integer productSpuId;
|
||||
|
||||
/**
|
||||
* 额外返回字段
|
||||
*
|
||||
* @see ProductSkuDetailFieldEnum
|
||||
*/
|
||||
private Collection<String> fields = Collections.emptySet();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.iocoder.mall.productservice.rpc.sku.dto;
|
||||
|
||||
import cn.iocoder.mall.productservice.enums.sku.ProductSkuDetailFieldEnum;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyValueRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 SKU Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSkuRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* sku 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 商品编号
|
||||
*/
|
||||
private Integer spuId;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 规格值编号数组
|
||||
*/
|
||||
private List<Integer> attrValueIds;
|
||||
/**
|
||||
* 价格,单位:分
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 规格值数组
|
||||
*
|
||||
* 需要设置 {@link ProductSkuDetailFieldEnum#ATTR} 才返回
|
||||
*/
|
||||
private List<ProductAttrKeyValueRespDTO> attrs;
|
||||
/**
|
||||
* 商品 SPU 信息
|
||||
*
|
||||
* 需要设置 {@link ProductSkuDetailFieldEnum#SPU} 才返回
|
||||
*
|
||||
* // TODO 芋艿,后续考虑怎么优化下,目前是内嵌了别的 dto
|
||||
*/
|
||||
private ProductSpuRespDTO spu;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package cn.iocoder.mall.productservice.rpc.spu;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(value = "product-service")
|
||||
public interface ProductSpuFeign {
|
||||
/**
|
||||
* 获得商品 SPU
|
||||
*
|
||||
* @param productSpuId 商品 SPU 编号
|
||||
* @return 商品 SPU
|
||||
*/
|
||||
@GetMapping(value = "/product/spu/get")
|
||||
CommonResult<ProductSpuRespDTO> getProductSpu(@RequestParam("productSpuId") Integer productSpuId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建商品 SPU
|
||||
*
|
||||
* @param createDTO 创建商品 SPU DTO
|
||||
* @return 商品 SPU编号
|
||||
*/
|
||||
@PostMapping(value = "/product/spu/create")
|
||||
CommonResult<Integer> createProductSpu(@RequestBody ProductSpuAndSkuCreateReqDTO createDTO);
|
||||
|
||||
/**
|
||||
* 更新商品 SPU
|
||||
*
|
||||
* @param updateDTO 更新商品 SPU DTO
|
||||
*/
|
||||
@PostMapping(value = "/product/spu/update")
|
||||
CommonResult<Boolean> updateProductSpu(@RequestBody ProductSpuAndSkuUpdateReqDTO updateDTO);
|
||||
|
||||
|
||||
/**
|
||||
* 获得商品 SPU列表
|
||||
*
|
||||
* @param productSpuIds 商品 SPU 编号列表
|
||||
* @return 商品 SPU 列表
|
||||
*/
|
||||
@GetMapping(value = "/product/spu/list")
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpus(@RequestParam("productSpuIds") Collection<Integer> productSpuIds);
|
||||
|
||||
/**
|
||||
* 获得商品 SPU 分页
|
||||
*
|
||||
* @param pageDTO 商品 SPU 分页查询
|
||||
* @return 商品 SPU 分页结果
|
||||
*/
|
||||
@PostMapping(value = "/product/spu/page")
|
||||
CommonResult<PageResult<ProductSpuRespDTO>> pageProductSpu(@RequestBody ProductSpuPageReqDTO pageDTO);
|
||||
|
||||
/**
|
||||
* 顺序获得商品 SPU 编号数组
|
||||
*
|
||||
* @param lastSpuId 最后一个商品 SPU 编号
|
||||
* @param limit 数量
|
||||
* @return 商品 SPU 编号数组
|
||||
*/
|
||||
@GetMapping(value = "/product/spu/lislistProductSpuIdst")
|
||||
CommonResult<List<Integer>> listProductSpuIds(@RequestParam("lastSpuId")Integer lastSpuId, @RequestParam("limit")Integer limit);
|
||||
|
||||
@GetMapping(value = "/product/spu/getProductSpuDetail")
|
||||
CommonResult<ProductSpuDetailRespDTO> getProductSpuDetail(@RequestParam("productSpuId") Integer productSpuId,@RequestParam("fields") Collection<String> fields);
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
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 ProductSpuAndSkuUpdateReqDTO 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 编号
|
||||
*/
|
||||
@NotNull(message = "SPU 编号不能为空")
|
||||
private Integer id;
|
||||
|
||||
// ========== 基本信息 =========
|
||||
/**
|
||||
* 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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package cn.iocoder.mall.productservice.rpc.spu.dto;
|
||||
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyValueRespDTO;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 SPU 明细 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSpuDetailRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* SPU 编号
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
// ========== 基本信息 =========
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 卖点
|
||||
*/
|
||||
private String sellPoint;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 分类名
|
||||
*/
|
||||
private String categoryName;
|
||||
/**
|
||||
* 商品主图地址
|
||||
*
|
||||
* 数组,以逗号分隔
|
||||
*
|
||||
* 建议尺寸:800*800像素,你可以拖拽图片调整顺序,最多上传15张
|
||||
*/
|
||||
private List<String> picUrls;
|
||||
|
||||
// ========== 其他信息 =========
|
||||
/**
|
||||
* 是否上架商品(是否可见)。
|
||||
*
|
||||
* true 为已上架
|
||||
* false 为已下架
|
||||
*/
|
||||
private Boolean visible;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
// ========== SKU =========
|
||||
|
||||
/**
|
||||
* SKU 数组
|
||||
*/
|
||||
private List<Sku> skus;
|
||||
|
||||
/**
|
||||
* 商品 Sku 明细
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Sku implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
/**
|
||||
* 商品编号
|
||||
*/
|
||||
private Integer spuId;
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
private String picURL;
|
||||
/**
|
||||
* 规格值数组
|
||||
*/
|
||||
private List<ProductAttrKeyValueRespDTO> attrs;
|
||||
/**
|
||||
* 价格,单位:分
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.iocoder.mall.productservice.rpc.spu.dto;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品 SPU 分页 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductSpuPageReqDTO extends PageParam {
|
||||
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 是否可见
|
||||
*/
|
||||
private Boolean visible;
|
||||
/**
|
||||
* 是否有库存
|
||||
*/
|
||||
private Boolean hasQuantity;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package cn.iocoder.mall.productservice.rpc.spu.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 SPU 信息 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSpuRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 商品 SPU 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 卖点
|
||||
*/
|
||||
private String sellPoint;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 商品主图地址
|
||||
*/
|
||||
private List<String> picUrls;
|
||||
/**
|
||||
* 是否上架商品
|
||||
*/
|
||||
private Boolean visible;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 价格
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
123
归档/product-service-project/product-service-app/pom.xml
Normal file
123
归档/product-service-project/product-service-app/pom.xml
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>product-service-project</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>product-service-app</artifactId>
|
||||
<dependencies>
|
||||
<!-- RPC 相关 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>mall-spring-boot-starter-dubbo</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<!-- 系统服务 -->
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>system-service-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<!-- 商品服务 -->
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>product-service-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Web 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId> <!-- 需要开启 Web 容器,因为 Actuator 需要使用到 -->
|
||||
</dependency>
|
||||
|
||||
<!-- MQ 相关 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>mall-spring-boot-starter-rocketmq</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Registry 和 Config 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- DB 相关 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>mall-spring-boot-starter-mybatis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 监控相关 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 工具类相关 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-jdk8</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.9.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<!-- 设置构建的 jar 包名 -->
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<!-- 使用 spring-boot-maven-plugin 插件打包 -->
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.iocoder.mall.productservice;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class ProductServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ProductServiceApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package cn.iocoder.mall.productservice.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
|
||||
/**
|
||||
* Spring Aop 配置类
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
|
||||
public class AopConfiguration {
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.mall.productservice.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@MapperScan("cn.iocoder.mall.productservice.dal.mysql.mapper") // 扫描对应的 Mapper 接口
|
||||
@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
// 数据库连接池 Druid
|
||||
|
||||
@Bean
|
||||
public ISqlInjector sqlInjector() {
|
||||
return new DefaultSqlInjector(); // MyBatis Plus 逻辑删除
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor(); // MyBatis Plus 分页插件
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package cn.iocoder.mall.productservice.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.manager.attr.ProductAttrManager;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/product/attr")
|
||||
@Api("商品属性")
|
||||
public class ProductAttrController {
|
||||
@Autowired
|
||||
private ProductAttrManager productAttrManager;
|
||||
|
||||
@PostMapping("/createProductAttrKey")
|
||||
@ApiOperation("创建商品规格键")
|
||||
CommonResult<Integer> createProductAttrKey(@RequestBody ProductAttrKeyCreateReqDTO createDTO){
|
||||
return success(productAttrManager.createProductAttrKey(createDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品规格键
|
||||
*
|
||||
* @param updateDTO 更新商品规格键 DTO
|
||||
*/
|
||||
@PostMapping("/updateProductAttrKey")
|
||||
@ApiOperation("更新商品规格键")
|
||||
CommonResult<Boolean> updateProductAttrKey(@RequestBody ProductAttrKeyUpdateReqDTO updateDTO){
|
||||
productAttrManager.updateProductAttrKey(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
* @return 商品规格键
|
||||
*/
|
||||
@GetMapping("/getProductAttrKey")
|
||||
@ApiOperation("获得商品规格键")
|
||||
CommonResult<ProductAttrKeyRespDTO> getProductAttrKey(@RequestParam("productAttrKeyId") Integer productAttrKeyId){
|
||||
return success(productAttrManager.getProductAttrKey(productAttrKeyId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得商品规格键列表
|
||||
*
|
||||
* @param productAttrKeyIds 商品规格键编号列表
|
||||
* @return 商品规格键列表
|
||||
*/
|
||||
@GetMapping("/listProductAttrKeys")
|
||||
@ApiOperation("获得商品规格键列表")
|
||||
CommonResult<List<ProductAttrKeyRespDTO>> listProductAttrKeys(@RequestParam("productAttrKeyIds") List<Integer> productAttrKeyIds){
|
||||
return success(productAttrManager.listProductAttrKeys(productAttrKeyIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键分页
|
||||
*
|
||||
* @param pageDTO 商品规格键分页查询
|
||||
* @return 商品规格键分页结果
|
||||
*/
|
||||
@PostMapping("/pageProductAttrKey")
|
||||
@ApiOperation("获得商品规格键分页")
|
||||
CommonResult<PageResult<ProductAttrKeyRespDTO>> pageProductAttrKey(@RequestBody ProductAttrKeyPageReqDTO pageDTO){
|
||||
return success(productAttrManager.pageProductAttrKey(pageDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品规格值
|
||||
*
|
||||
* @param createDTO 创建商品规格值 DTO
|
||||
* @return 商品规格值编号
|
||||
*/
|
||||
@PostMapping("/createProductAttrValue")
|
||||
@ApiOperation("创建商品规格值")
|
||||
CommonResult<Integer> createProductAttrValue(@RequestBody ProductAttrValueCreateReqDTO createDTO){
|
||||
return success(productAttrManager.createProductAttrValue(createDTO));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 更新商品规格值
|
||||
*
|
||||
* @param updateDTO 更新商品规格值 DTO
|
||||
*/
|
||||
@PostMapping("/updateProductAttrValue")
|
||||
@ApiOperation("更新商品规格值")
|
||||
CommonResult<Boolean> updateProductAttrValue(@RequestBody ProductAttrValueUpdateReqDTO updateDTO){
|
||||
productAttrManager.updateProductAttrValue(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格值
|
||||
*
|
||||
* @param productAttrValueId 商品规格值编号
|
||||
* @return 商品规格值
|
||||
*/
|
||||
@GetMapping("/getProductAttrValue")
|
||||
@ApiOperation("获得商品规格值")
|
||||
CommonResult<ProductAttrValueRespDTO> getProductAttrValue(@RequestParam("productAttrValueId") Integer productAttrValueId){
|
||||
return success(productAttrManager.getProductAttrValue(productAttrValueId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格值列表
|
||||
*
|
||||
* @param queryDTO 商品规格值的列表查询条件 DTO
|
||||
* @return 商品规格值列表
|
||||
*/
|
||||
@PostMapping("/listProductAttrValues")
|
||||
@ApiOperation("获得商品规格值列表")
|
||||
CommonResult<List<ProductAttrValueRespDTO>> listProductAttrValues(@RequestBody ProductAttrValueListQueryReqDTO queryDTO){
|
||||
return success(productAttrManager.listProductAttrValues(queryDTO));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package cn.iocoder.mall.productservice.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.manager.brand.ProductBrandManager;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandUpdateReqDTO;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* Title:
|
||||
* Description:
|
||||
*
|
||||
* @author zhuyang
|
||||
* @version 1.0 2021/10/7
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/product/brand")
|
||||
@Api("商品品牌")
|
||||
public class ProductBrandController {
|
||||
@Autowired
|
||||
private ProductBrandManager productBrandManager;
|
||||
|
||||
/**
|
||||
* 创建商品品牌
|
||||
*
|
||||
* @param createDTO 创建商品品牌 DTO
|
||||
* @return 商品品牌编号
|
||||
*/
|
||||
@PostMapping("createProductBrand")
|
||||
CommonResult<Integer> createProductBrand(@RequestBody ProductBrandCreateReqDTO createDTO){
|
||||
return success(productBrandManager.createProductBrand(createDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品品牌
|
||||
*
|
||||
* @param updateDTO 更新商品品牌 DTO
|
||||
*/
|
||||
@PostMapping("updateProductBrand")
|
||||
CommonResult<Boolean> updateProductBrand(@RequestBody ProductBrandUpdateReqDTO updateDTO){
|
||||
productBrandManager.updateProductBrand(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
*/
|
||||
@GetMapping("deleteProductBrand")
|
||||
CommonResult<Boolean> deleteProductBrand(@RequestParam("productBrandId") Integer productBrandId){
|
||||
productBrandManager.deleteProductBrand(productBrandId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
* @return 商品品牌
|
||||
*/
|
||||
@GetMapping("getProductBrand")
|
||||
CommonResult<ProductBrandRespDTO> getProductBrand(@RequestParam("productBrandId")Integer productBrandId){
|
||||
return success(productBrandManager.getProductBrand(productBrandId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌列表
|
||||
*
|
||||
* @param productBrandIds 商品品牌编号列表
|
||||
* @return 商品品牌列表
|
||||
*/
|
||||
@GetMapping("listProductBrands")
|
||||
CommonResult<List<ProductBrandRespDTO>> listProductBrands(@RequestParam("productBrandIds") List<Integer> productBrandIds){
|
||||
return success(productBrandManager.listProductBrands(productBrandIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌分页
|
||||
*
|
||||
* @param pageDTO 商品品牌分页查询
|
||||
* @return 商品品牌分页结果
|
||||
*/
|
||||
@PostMapping("pageProductBrand")
|
||||
CommonResult<PageResult<ProductBrandRespDTO>> pageProductBrand(@RequestBody ProductBrandPageReqDTO pageDTO){
|
||||
return success(productBrandManager.pageProductBrand(pageDTO));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package cn.iocoder.mall.productservice.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.manager.brand.ProductBrandManager;
|
||||
import cn.iocoder.mall.productservice.manager.category.ProductCategoryManager;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryUpdateReqDTO;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* Title:
|
||||
* Description:
|
||||
*
|
||||
* @author zhuyang
|
||||
* @version 1.0 2021/10/7
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/product/category")
|
||||
@Api("商品品牌")
|
||||
public class ProductCategoryController {
|
||||
@Autowired
|
||||
private ProductCategoryManager productCategoryManager;
|
||||
|
||||
|
||||
/**
|
||||
* 创建商品分类
|
||||
*
|
||||
* @param createDTO 创建商品分类 DTO
|
||||
* @return 商品分类编号
|
||||
*/
|
||||
@PostMapping("createProductCategory")
|
||||
CommonResult<Integer> createProductCategory(@RequestBody ProductCategoryCreateReqDTO createDTO){
|
||||
return success(productCategoryManager.createProductCategory(createDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品分类
|
||||
*
|
||||
* @param updateDTO 更新商品分类 DTO
|
||||
*/
|
||||
@PostMapping("updateProductCategory")
|
||||
CommonResult<Boolean> updateProductCategory(@RequestBody ProductCategoryUpdateReqDTO updateDTO){
|
||||
productCategoryManager.updateProductCategory(updateDTO);
|
||||
return success(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品分类
|
||||
*
|
||||
* @param productCategoryId 商品分类编号
|
||||
*/
|
||||
@GetMapping("deleteProductCategory")
|
||||
CommonResult<Boolean> deleteProductCategory(@RequestParam("productCategoryId") Integer productCategoryId){
|
||||
productCategoryManager.deleteProductCategory(productCategoryId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品分类
|
||||
*
|
||||
* @param productCategoryId 商品分类编号
|
||||
* @return 商品分类
|
||||
*/
|
||||
@GetMapping("getProductCategory")
|
||||
CommonResult<ProductCategoryRespDTO> getProductCategory(@RequestParam("productCategoryId")Integer productCategoryId){
|
||||
return success(productCategoryManager.getProductCategory(productCategoryId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品分类列表
|
||||
*
|
||||
* @param productCategoryIds 商品分类编号列表
|
||||
* @return 商品分类列表
|
||||
*/
|
||||
@GetMapping("listProductCategoriesByIds")
|
||||
CommonResult<List<ProductCategoryRespDTO>> listProductCategoriesByIds(@RequestParam("productCategoryIds")Collection<Integer> productCategoryIds){
|
||||
return success(productCategoryManager.listProductCategories(productCategoryIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得符合条件的商品分类列表
|
||||
*
|
||||
* @return 商品分类列表
|
||||
*/
|
||||
@PostMapping("listProductCategories")
|
||||
CommonResult<List<ProductCategoryRespDTO>> listProductCategories(@RequestBody ProductCategoryListQueryReqDTO listQueryReqDTO){
|
||||
return success(productCategoryManager.listProductCategories(listQueryReqDTO));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.iocoder.mall.productservice.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.manager.attr.ProductAttrManager;
|
||||
import cn.iocoder.mall.productservice.manager.sku.ProductSkuManager;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.*;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/product/sku")
|
||||
@Api("商品sku")
|
||||
public class ProductSkuController {
|
||||
@Autowired
|
||||
private ProductSkuManager productSkuManager;
|
||||
/**
|
||||
* 获得商品 SKU
|
||||
*
|
||||
* @param productSkuId 商品 SKU 编号
|
||||
* @return 商品 SKU
|
||||
*/
|
||||
@GetMapping("getProductSku")
|
||||
CommonResult<ProductSkuRespDTO> getProductSku(@RequestParam("productSkuId") Integer productSkuId){
|
||||
return success(productSkuManager.getProductSku(productSkuId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SKU 列表
|
||||
*
|
||||
* @param queryReqDTO 商品 SKU 列表的查询请求 DTO
|
||||
* @return 商品 SKU 列表
|
||||
*/
|
||||
@PostMapping("listProductSkus")
|
||||
CommonResult<List<ProductSkuRespDTO>> listProductSkus(@RequestBody ProductSkuListQueryReqDTO queryReqDTO){
|
||||
return success(productSkuManager.listProductSkus(queryReqDTO));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
### /product/spu/get 获得商品 SPU
|
||||
GET http://localhost:38082/product/spu/get?productSpuId=32
|
||||
###
|
||||
|
||||
### /product/spu/get 获得商品 SPU
|
||||
GET http://localhost:38082/product/spu/lislistProductSpuIdst?lastSpuId=30&limit=10
|
||||
###
|
||||
|
||||
|
||||
### /product/spu/get 获得商品 SPU
|
||||
GET http://localhost:38082/product/spu/getProductSpuDetail?productSpuId=32&fields=attr,sku
|
||||
###
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package cn.iocoder.mall.productservice.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.manager.spu.ProductSpuManager;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/product/spu")
|
||||
@Api("商品spu")
|
||||
public class ProductSpuController {
|
||||
@Autowired
|
||||
private ProductSpuManager productSpuManager;
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得商品 SPU")
|
||||
@ApiImplicitParam(name = "productSpuId", value = "商品 SPU 编号", required = true)
|
||||
public CommonResult<ProductSpuRespDTO> getProductSpu(@RequestParam(value="productSpuId") Integer productSpuId) {
|
||||
return success(productSpuManager.getProductSpu(productSpuId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品 SPU
|
||||
*
|
||||
* @param updateDTO 更新商品 SPU DTO
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("更新商品 SPU")
|
||||
public CommonResult<Boolean> updateProductSpu(@Valid @RequestBody ProductSpuAndSkuUpdateReqDTO updateDTO) {
|
||||
productSpuManager.updateProductSpu(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建商品 SPU")
|
||||
public CommonResult<Integer> createProductSpu(@Valid @RequestBody ProductSpuAndSkuCreateReqDTO createDTO) {
|
||||
return success(productSpuManager.createProductSpu(createDTO));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得商品 SPU 列表")
|
||||
@ApiImplicitParam(name = "productSpuIds", value = "商品 SPU 编号列表", required = true)
|
||||
public CommonResult<List<ProductSpuRespDTO>> listProductSpus(@RequestParam("productSpuIds") List<Integer> productSpuIds) {
|
||||
return success(productSpuManager.listProductSpus(productSpuIds));
|
||||
}
|
||||
|
||||
@PostMapping("/page")
|
||||
@ApiOperation("获得商品 SPU 分页")
|
||||
public CommonResult<PageResult<ProductSpuRespDTO>> pageProductSpu(@RequestBody ProductSpuPageReqDTO pageVO) {
|
||||
// 全部:无搜索条件
|
||||
// 在售中:visible = true && hasQuantity = true
|
||||
// 已售罄:visible = true && hasQuantity = false
|
||||
// 仓库中:visible = false
|
||||
return success(productSpuManager.pageProductSpu(pageVO));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 顺序获得商品 SPU 编号数组
|
||||
*
|
||||
* @param lastSpuId 最后一个商品 SPU 编号
|
||||
* @param limit 数量
|
||||
* @return 商品 SPU 编号数组
|
||||
*/
|
||||
@GetMapping("/lislistProductSpuIdst")
|
||||
public CommonResult<List<Integer>> lislistProductSpuIdst(@RequestParam("lastSpuId")Integer lastSpuId, @RequestParam("limit")Integer limit) {
|
||||
// 全部:无搜索条件
|
||||
// 在售中:visible = true && hasQuantity = true
|
||||
// 已售罄:visible = true && hasQuantity = false
|
||||
// 仓库中:visible = false
|
||||
return success(productSpuManager.listProductSpuIds(lastSpuId, limit));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/getProductSpuDetail")
|
||||
public CommonResult<ProductSpuDetailRespDTO> getProductSpuDetail(@RequestParam("productSpuId") Integer productSpuId,@RequestParam("fields") Collection<String> fields) {
|
||||
return success(productSpuManager.getProductSpuDetail(productSpuId,fields));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package cn.iocoder.mall.productservice.convert.attr;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrKeyDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrValueDO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.*;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.*;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductAttrConvert {
|
||||
|
||||
ProductAttrConvert INSTANCE = Mappers.getMapper(ProductAttrConvert.class);
|
||||
|
||||
ProductAttrKeyDO convert(ProductAttrKeyCreateBO bean);
|
||||
|
||||
ProductAttrKeyBO convert(ProductAttrKeyDO bean);
|
||||
|
||||
ProductAttrKeyDO convert(ProductAttrKeyUpdateBO bean);
|
||||
|
||||
List<ProductAttrKeyBO> convertList(List<ProductAttrKeyDO> list);
|
||||
|
||||
@Mapping(source = "records", target = "list")
|
||||
PageResult<ProductAttrKeyBO> convertPage(IPage<ProductAttrKeyDO> page);
|
||||
|
||||
ProductAttrKeyCreateBO convert(ProductAttrKeyCreateReqDTO bean);
|
||||
|
||||
ProductAttrKeyUpdateBO convert(ProductAttrKeyUpdateReqDTO bean);
|
||||
|
||||
ProductAttrKeyRespDTO convert(ProductAttrKeyBO bean);
|
||||
|
||||
List<ProductAttrKeyRespDTO> convertList02(List<ProductAttrKeyBO> list);
|
||||
|
||||
ProductAttrKeyPageBO convert(ProductAttrKeyPageReqDTO bean);
|
||||
|
||||
PageResult<ProductAttrKeyRespDTO> convertPage(PageResult<ProductAttrKeyBO> page);
|
||||
|
||||
ProductAttrValueDO convert(ProductAttrValueCreateBO bean);
|
||||
|
||||
ProductAttrValueBO convert(ProductAttrValueDO bean);
|
||||
|
||||
ProductAttrValueDO convert(ProductAttrValueUpdateBO bean);
|
||||
|
||||
List<ProductAttrValueBO> convertList03(List<ProductAttrValueDO> list);
|
||||
|
||||
ProductAttrValueCreateBO convert(ProductAttrValueCreateReqDTO bean);
|
||||
|
||||
ProductAttrValueUpdateBO convert(ProductAttrValueUpdateReqDTO bean);
|
||||
|
||||
ProductAttrValueRespDTO convert(ProductAttrValueBO bean);
|
||||
|
||||
List<ProductAttrValueRespDTO> convertList04(List<ProductAttrValueBO> list);
|
||||
|
||||
ProductAttrValueListQueryBO convert(ProductAttrValueListQueryReqDTO bean);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.iocoder.mall.productservice.convert.brand;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.brand.ProductBrandDO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandPageBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandUpdateBO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductBrandConvert {
|
||||
|
||||
ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class);
|
||||
|
||||
ProductBrandDO convert(ProductBrandCreateBO bean);
|
||||
|
||||
ProductBrandBO convert(ProductBrandDO bean);
|
||||
|
||||
ProductBrandDO convert(ProductBrandUpdateBO bean);
|
||||
|
||||
List<ProductBrandBO> convertList(List<ProductBrandDO> list);
|
||||
|
||||
@Mapping(source = "records", target = "list")
|
||||
PageResult<ProductBrandBO> convertPage(IPage<ProductBrandDO> page);
|
||||
|
||||
ProductBrandCreateBO convert(ProductBrandCreateReqDTO bean);
|
||||
|
||||
ProductBrandUpdateBO convert(ProductBrandUpdateReqDTO bean);
|
||||
|
||||
ProductBrandRespDTO convert(ProductBrandBO bean);
|
||||
|
||||
List<ProductBrandRespDTO> convertList02(List<ProductBrandBO> list);
|
||||
|
||||
ProductBrandPageBO convert(ProductBrandPageReqDTO bean);
|
||||
|
||||
PageResult<ProductBrandRespDTO> convertPage(PageResult<ProductBrandBO> page);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package cn.iocoder.mall.productservice.convert.category;
|
||||
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.category.ProductCategoryDO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryBO;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryListQueryBO;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryUpdateBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductCategoryConvert {
|
||||
|
||||
ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
|
||||
|
||||
ProductCategoryDO convert(ProductCategoryCreateBO bean);
|
||||
|
||||
ProductCategoryBO convert(ProductCategoryDO bean);
|
||||
|
||||
List<ProductCategoryBO> convertList(List<ProductCategoryDO> list);
|
||||
|
||||
ProductCategoryDO convert(ProductCategoryUpdateBO bean);
|
||||
|
||||
ProductCategoryCreateBO convert(ProductCategoryCreateReqDTO bean);
|
||||
|
||||
ProductCategoryUpdateBO convert(ProductCategoryUpdateReqDTO bean);
|
||||
|
||||
ProductCategoryRespDTO convert(ProductCategoryBO bean);
|
||||
|
||||
List<ProductCategoryRespDTO> convertList02(List<ProductCategoryBO> list);
|
||||
|
||||
ProductCategoryListQueryBO convert(ProductCategoryListQueryReqDTO bean);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package cn.iocoder.mall.productservice.convert.sku;
|
||||
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.common.framework.util.StringUtils;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.sku.ProductSkuDO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyValueRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyValueBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuCreateOrUpdateBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuListQueryBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Named;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface ProductSkuConvert {
|
||||
|
||||
ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class);
|
||||
|
||||
List<ProductSkuDO> convertList(List<ProductSkuCreateOrUpdateBO> list);
|
||||
|
||||
@Mapping(source = "attrValueIds", target = "attrs", qualifiedByName = "translatePicUrlsFromStringList")
|
||||
ProductSkuDO convert(ProductSkuCreateOrUpdateBO bean);
|
||||
|
||||
@Mapping(source = "attrs", target = "attrValueIds", qualifiedByName = "translateAttrValueIdsFromString")
|
||||
ProductSkuBO convert(ProductSkuDO bean);
|
||||
|
||||
List<ProductSkuBO> convertList02(List<ProductSkuDO> list);
|
||||
|
||||
ProductSkuRespDTO convert(ProductSkuBO bean);
|
||||
|
||||
ProductSkuListQueryBO convert(ProductSkuListQueryReqDTO bean);
|
||||
|
||||
ProductSpuRespDTO convert(ProductSpuBO bean);
|
||||
|
||||
ProductAttrKeyValueRespDTO convert(ProductAttrKeyValueBO bean);
|
||||
|
||||
default List<ProductSkuRespDTO> convertList(List<ProductSkuBO> skuBOs, List<ProductSpuBO> spuBOs,
|
||||
List<ProductAttrKeyValueBO> attrBOs) {
|
||||
// 创建 ProductAttrDetailBO 的映射。其中,KEY 为 ProductAttrDetailBO.attrValueId ,即规格值的编号
|
||||
Map<Integer, ProductAttrKeyValueBO> attrDetailBOMap = CollectionUtils.convertMap(attrBOs,
|
||||
ProductAttrKeyValueBO::getAttrValueId);
|
||||
// 构建 ProductSpuBO 的映射。
|
||||
Map<Integer, ProductSpuBO> spuBOMap = CollectionUtils.convertMap(spuBOs, ProductSpuBO::getId);
|
||||
// 拼接数据
|
||||
List<ProductSkuRespDTO> skuRespDTOs = new ArrayList<>(skuBOs.size());
|
||||
skuBOs.forEach(skuBO -> {
|
||||
ProductSkuRespDTO skuRespDTO = convert(skuBO);
|
||||
skuRespDTOs.add(skuRespDTO);
|
||||
// 拼接商品 SPU
|
||||
skuRespDTO.setSpu(convert(spuBOMap.get(skuBO.getSpuId())));
|
||||
// 拼接商品 Attr
|
||||
skuRespDTO.setAttrs(new ArrayList<>());
|
||||
skuBO.getAttrValueIds().forEach(attrValueId -> skuRespDTO.getAttrs().add(convert(attrDetailBOMap.get(attrValueId))));
|
||||
});
|
||||
return skuRespDTOs;
|
||||
}
|
||||
|
||||
@Named("translateAttrValueIdsFromString")
|
||||
default List<Integer> translateAttrValueIdsFromString(String attrValueIdsStar) {
|
||||
return StringUtils.splitToInt(attrValueIdsStar, ",");
|
||||
}
|
||||
|
||||
@Named("translateAttrValueIdsFromList")
|
||||
default String translateAttrValueIdsFromList(List<Integer> attrValueIds) {
|
||||
return StringUtils.join(attrValueIds, ",");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package cn.iocoder.mall.productservice.convert.spu;
|
||||
|
||||
import cn.iocoder.common.framework.util.StringUtils;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyValueRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyValueBO;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuCreateOrUpdateBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuPageBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuUpdateBO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Named;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Mapper
|
||||
public interface ProductSpuConvert {
|
||||
|
||||
ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class);
|
||||
|
||||
@Mapping(source = "picUrls", target = "picUrls", qualifiedByName = "translatePicUrlsFromStringList")
|
||||
ProductSpuDO convert(ProductSpuCreateBO bean);
|
||||
|
||||
@Mapping(source = "picUrls", target = "picUrls", qualifiedByName = "translatePicUrlsFromString")
|
||||
ProductSpuBO convert(ProductSpuDO bean);
|
||||
|
||||
@Mapping(source = "picUrls", target = "picUrls", qualifiedByName = "translatePicUrlsFromStringList")
|
||||
ProductSpuDO convert(ProductSpuUpdateBO bean);
|
||||
|
||||
List<ProductSpuBO> convertList(List<ProductSpuDO> list);
|
||||
|
||||
@Mapping(source = "records", target = "list")
|
||||
PageResult<ProductSpuBO> convertPage(IPage<ProductSpuDO> page);
|
||||
|
||||
ProductSpuCreateBO convert(ProductSpuAndSkuCreateReqDTO bean);
|
||||
|
||||
ProductSpuUpdateBO convert(ProductSpuAndSkuUpdateReqDTO bean);
|
||||
|
||||
ProductSpuRespDTO convert(ProductSpuBO bean);
|
||||
ProductSpuDetailRespDTO convert2(ProductSpuBO bean);
|
||||
|
||||
List<ProductSpuRespDTO> convertList02(List<ProductSpuBO> list);
|
||||
|
||||
ProductSpuPageBO convert(ProductSpuPageReqDTO bean);
|
||||
|
||||
PageResult<ProductSpuRespDTO> convertPage(PageResult<ProductSpuBO> page);
|
||||
|
||||
List<ProductSkuCreateOrUpdateBO> convert(List<ProductSpuAndSkuCreateReqDTO.Sku> list);
|
||||
List<ProductSkuCreateOrUpdateBO> convert02(List<ProductSpuAndSkuUpdateReqDTO.Sku> list);
|
||||
|
||||
ProductSpuDetailRespDTO.Sku convert(ProductSkuBO bean);
|
||||
|
||||
ProductAttrKeyValueRespDTO convert(ProductAttrKeyValueBO bean);
|
||||
|
||||
default ProductSpuDetailRespDTO convert(ProductSpuBO spuBO, List<ProductSkuBO> skuBOs,
|
||||
List<ProductAttrKeyValueBO> attrBOs, ProductCategoryBO categoryBO) {
|
||||
// 创建并转换 ProductSpuDetailBO 对象
|
||||
ProductSpuDetailRespDTO spuDetailDTO = this.convert2(spuBO);
|
||||
// 创建 ProductAttrDetailBO 的映射。其中,KEY 为 ProductAttrDetailBO.attrValueId ,即规格值的编号
|
||||
Map<Integer, ProductAttrKeyValueBO> attrDetailBOMap = attrBOs.stream().collect(
|
||||
Collectors.toMap(ProductAttrKeyValueBO::getAttrValueId, attrBO -> attrBO));
|
||||
// 创建并转换 ProductSpuDetailBO 数组
|
||||
spuDetailDTO.setSkus(new ArrayList<>());
|
||||
skuBOs.forEach(skuBO -> {
|
||||
// 创建 ProductSpuDetailBO 对象
|
||||
ProductSpuDetailRespDTO.Sku skuDetail = convert(skuBO).setAttrs(new ArrayList<>());
|
||||
spuDetailDTO.getSkus().add(skuDetail);
|
||||
// 设置 ProductSpuDetailBO 的 attrs 规格属性
|
||||
skuBO.getAttrValueIds().forEach(attrValueId -> skuDetail.getAttrs().add(convert(attrDetailBOMap.get(attrValueId))));
|
||||
});
|
||||
// 设置分类名
|
||||
spuDetailDTO.setCategoryName(categoryBO.getName());
|
||||
// 返回
|
||||
return spuDetailDTO;
|
||||
}
|
||||
|
||||
@Named("translatePicUrlsFromString")
|
||||
default List<String> translatePicUrlsFromList(String picUrls) {
|
||||
return StringUtils.split(picUrls, ",");
|
||||
}
|
||||
|
||||
@Named("translatePicUrlsFromStringList")
|
||||
default String translatePicUrlsFromList(List<String> picUrls) {
|
||||
return StringUtils.join(picUrls, ",");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.dataobject.attr;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* Product 规格键 DO
|
||||
*/
|
||||
@TableName("product_attr_key")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ProductAttrKeyDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 规格编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.dataobject.attr;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品规格值 DO
|
||||
*/
|
||||
@TableName("product_attr_value")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrValueDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 规格值编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键编号
|
||||
*
|
||||
* 外键 {@link ProductAttrKeyDO#getId()}
|
||||
*/
|
||||
private Integer attrKeyId;
|
||||
/**
|
||||
* 规格值名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.dataobject.brand;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品品牌
|
||||
*/
|
||||
@TableName("product_brand")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 品牌编号(主键)
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.dataobject.category;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品分类 DO
|
||||
*/
|
||||
@TableName("product_category")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 分类描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 分类排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.dataobject.sku;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrValueDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品 SKU
|
||||
*/
|
||||
@TableName("product_sku")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductSkuDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* sku 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 商品编号
|
||||
*/
|
||||
private Integer spuId;
|
||||
|
||||
// TODO 店铺编号
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 规格值({@link ProductAttrValueDO#getId()})数组
|
||||
*
|
||||
* 数组,以逗号分隔
|
||||
*/
|
||||
private String attrs;
|
||||
/**
|
||||
* 价格,单位:分
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
// /**
|
||||
// * 商品在付款减库存的状态下,该Sku上未付款的订单数量
|
||||
// */
|
||||
// private Integer withHoldQuantity;
|
||||
// /**
|
||||
// * 销量
|
||||
// */
|
||||
// private Integer soldNum;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.dataobject.spu;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品 SPU
|
||||
*
|
||||
* TODO 芋艿,后面增加商品普通参数。例如说,正面材料,背面材料,屏幕尺寸。
|
||||
*/
|
||||
@TableName("product_spu")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductSpuDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* SPU 编号
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
// TODO 店铺编号 先不考虑,因为第一个版本,不做 B2B2C
|
||||
|
||||
// ========== 基本信息 =========
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 卖点
|
||||
*/
|
||||
private String sellPoint;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 商品主图地址
|
||||
*
|
||||
* 数组,以逗号分隔
|
||||
*
|
||||
* 建议尺寸:800*800像素,你可以拖拽图片调整顺序,最多上传15张
|
||||
*/
|
||||
private String picUrls;
|
||||
|
||||
// TODO 运费信息
|
||||
|
||||
// ========== 其他信息 =========
|
||||
/**
|
||||
* 是否上架商品(是否可见)。
|
||||
*
|
||||
* true 为已上架
|
||||
* false 为已下架
|
||||
*/
|
||||
private Boolean visible;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
// ========== Sku 相关字段 =========
|
||||
/**
|
||||
* 价格
|
||||
*
|
||||
* 目前的计算方式是,以 Sku 最小价格为准
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*
|
||||
* 目前的计算方式是,以 Sku 库存累加为准
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.mapper.attr;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrKeyDO;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyPageBO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProductAttrKeyMapper extends BaseMapper<ProductAttrKeyDO> {
|
||||
|
||||
default IPage<ProductAttrKeyDO> selectPage(ProductAttrKeyPageBO pageBO) {
|
||||
return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
|
||||
new QueryWrapperX<ProductAttrKeyDO>().likeIfPresent("name", pageBO.getName())
|
||||
.eqIfPresent("status", pageBO.getStatus()));
|
||||
}
|
||||
|
||||
default ProductAttrKeyDO selectByName(String name) {
|
||||
return selectOne(new QueryWrapper<ProductAttrKeyDO>().eq("name", name));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.mapper.attr;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrValueDO;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrValueListQueryBO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ProductAttrValueMapper extends BaseMapper<ProductAttrValueDO> {
|
||||
|
||||
default ProductAttrValueDO selectByAttrKeyIdAndName(Integer attrKeyId, String name) {
|
||||
return selectOne(new QueryWrapper<ProductAttrValueDO>().eq("attr_key_id", attrKeyId).eq("name", name));
|
||||
}
|
||||
|
||||
default List<ProductAttrValueDO> selectList(ProductAttrValueListQueryBO queryBO) {
|
||||
return selectList(new QueryWrapperX<ProductAttrValueDO>().inIfPresent("id", queryBO.getProductAttrValueIds())
|
||||
.eqIfPresent("attr_key_id", queryBO.getProductAttrKeyId()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.mapper.brand;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.brand.ProductBrandDO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandPageBO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProductBrandMapper extends BaseMapper<ProductBrandDO> {
|
||||
|
||||
default IPage<ProductBrandDO> selectPage(ProductBrandPageBO pageBO) {
|
||||
return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
|
||||
new QueryWrapperX<ProductBrandDO>().likeIfPresent("name", pageBO.getName())
|
||||
.eqIfPresent("status", pageBO.getStatus()));
|
||||
}
|
||||
|
||||
default ProductBrandDO selectByName(String name) {
|
||||
return selectOne(new QueryWrapper<ProductBrandDO>().eq("name", name));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.mapper.category;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.category.ProductCategoryDO;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryListQueryBO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ProductCategoryMapper extends BaseMapper<ProductCategoryDO> {
|
||||
|
||||
default Integer selectCountByPid(Integer pid) {
|
||||
return selectCount(new QueryWrapper<ProductCategoryDO>().eq("pid", pid));
|
||||
}
|
||||
|
||||
default List<ProductCategoryDO> selectList(ProductCategoryListQueryBO listQueryBO) {
|
||||
return selectList(new QueryWrapperX<ProductCategoryDO>().eqIfPresent("pid", listQueryBO.getPid())
|
||||
.eqIfPresent("status", listQueryBO.getStatus()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.mapper.sku;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.sku.ProductSkuDO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuListQueryBO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ProductSkuMapper extends BaseMapper<ProductSkuDO> {
|
||||
|
||||
default List<ProductSkuDO> selectListBySpuIdAndStatus(Integer spuId, Integer status) {
|
||||
return selectList(new QueryWrapperX<ProductSkuDO>().eq("spu_id", spuId)
|
||||
.eq("status", status));
|
||||
}
|
||||
|
||||
void insertList(@Param("productSkuDOs") List<ProductSkuDO> productSkuDOs);
|
||||
|
||||
default List<ProductSkuDO> selectList(ProductSkuListQueryBO queryBO) {
|
||||
return selectList(new QueryWrapperX<ProductSkuDO>().eqIfPresent("id", queryBO.getProductSkuId())
|
||||
.inIfPresent("id", queryBO.getProductSkuIds())
|
||||
.eqIfPresent("spu_id", queryBO.getProductSpuId())
|
||||
.eqIfPresent("status", queryBO.getProductSkuStatus()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.mapper.spu;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuPageBO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ProductSpuMapper extends BaseMapper<ProductSpuDO> {
|
||||
|
||||
default IPage<ProductSpuDO> selectPage(ProductSpuPageBO pageBO) {
|
||||
QueryWrapperX<ProductSpuDO> query = new QueryWrapperX<ProductSpuDO>().likeIfPresent("name", pageBO.getName())
|
||||
.eqIfPresent("cid", pageBO.getCid()).eqIfPresent("visible", pageBO.getVisible());
|
||||
// 库存过滤
|
||||
if (pageBO.getHasQuantity() != null) {
|
||||
if (pageBO.getHasQuantity()) {
|
||||
query.gt("quantity", 0);
|
||||
} else {
|
||||
query.eq("quantity", 0);
|
||||
}
|
||||
}
|
||||
return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()), query);
|
||||
}
|
||||
|
||||
default List<ProductSpuDO> selectListByIdGt(Integer id, Integer limit) {
|
||||
return selectList(new QueryWrapperX<ProductSpuDO>().gtIfPresent("id", id)
|
||||
.orderByAsc("id").last("LIMIT " + limit));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package cn.iocoder.mall.productservice.manager.attr;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.attr.ProductAttrConvert;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.*;
|
||||
import cn.iocoder.mall.productservice.service.attr.ProductAttrService;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyBO;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrValueBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品规格 Manager
|
||||
*/
|
||||
@Service
|
||||
public class ProductAttrManager {
|
||||
|
||||
@Autowired
|
||||
private ProductAttrService productAttrService;
|
||||
|
||||
/**
|
||||
* 创建商品规格键
|
||||
*
|
||||
* @param createDTO 创建商品规格键 DTO
|
||||
* @return 商品规格键
|
||||
*/
|
||||
public Integer createProductAttrKey(ProductAttrKeyCreateReqDTO createDTO) {
|
||||
ProductAttrKeyBO productAttrKeyBO = productAttrService.createProductAttrKey(ProductAttrConvert.INSTANCE.convert(createDTO));
|
||||
return productAttrKeyBO.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品规格键
|
||||
*
|
||||
* @param updateDTO 更新商品规格键 DTO
|
||||
*/
|
||||
public void updateProductAttrKey(ProductAttrKeyUpdateReqDTO updateDTO) {
|
||||
productAttrService.updateProductAttrKey(ProductAttrConvert.INSTANCE.convert(updateDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
* @return 商品规格键
|
||||
*/
|
||||
public ProductAttrKeyRespDTO getProductAttrKey(Integer productAttrKeyId) {
|
||||
ProductAttrKeyBO productAttrKeyBO = productAttrService.getProductAttrKey(productAttrKeyId);
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrKeyBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键列表
|
||||
*
|
||||
* @param productAttrKeyIds 商品规格键编号列表
|
||||
* @return 商品规格键列表
|
||||
*/
|
||||
public List<ProductAttrKeyRespDTO> listProductAttrKeys(List<Integer> productAttrKeyIds) {
|
||||
List<ProductAttrKeyBO> productAttrKeyBOs = productAttrService.listProductAttrKeys(productAttrKeyIds);
|
||||
return ProductAttrConvert.INSTANCE.convertList02(productAttrKeyBOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键分页
|
||||
*
|
||||
* @param pageDTO 商品规格键分页查询
|
||||
* @return 商品规格键分页结果
|
||||
*/
|
||||
public PageResult<ProductAttrKeyRespDTO> pageProductAttrKey(ProductAttrKeyPageReqDTO pageDTO) {
|
||||
PageResult<ProductAttrKeyBO> pageResultBO = productAttrService.pageProductAttrKey(ProductAttrConvert.INSTANCE.convert(pageDTO));
|
||||
return ProductAttrConvert.INSTANCE.convertPage(pageResultBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品规格值
|
||||
*
|
||||
* @param createDTO 创建商品规格值 DTO
|
||||
* @return 商品规格值
|
||||
*/
|
||||
public Integer createProductAttrValue(ProductAttrValueCreateReqDTO createDTO) {
|
||||
ProductAttrValueBO productAttrValueBO = productAttrService.createProductAttrValue(ProductAttrConvert.INSTANCE.convert(createDTO));
|
||||
return productAttrValueBO.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品规格值
|
||||
*
|
||||
* @param updateDTO 更新商品规格值 DTO
|
||||
*/
|
||||
public void updateProductAttrValue(ProductAttrValueUpdateReqDTO updateDTO) {
|
||||
productAttrService.updateProductAttrValue(ProductAttrConvert.INSTANCE.convert(updateDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格值
|
||||
*
|
||||
* @param productAttrValueId 商品规格值编号
|
||||
* @return 商品规格值
|
||||
*/
|
||||
public ProductAttrValueRespDTO getProductAttrValue(Integer productAttrValueId) {
|
||||
ProductAttrValueBO productAttrValueBO = productAttrService.getProductAttrValue(productAttrValueId);
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrValueBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格值列表
|
||||
*
|
||||
* @param queryDTO 商品规格值的列表查询条件 DTO
|
||||
* @return 商品规格值列表
|
||||
*/
|
||||
public List<ProductAttrValueRespDTO> listProductAttrValues(ProductAttrValueListQueryReqDTO queryDTO) {
|
||||
List<ProductAttrValueBO> productAttrValueBOs = productAttrService.listProductAttrValues(ProductAttrConvert.INSTANCE.convert(queryDTO));
|
||||
return ProductAttrConvert.INSTANCE.convertList04(productAttrValueBOs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package cn.iocoder.mall.productservice.manager.brand;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.brand.ProductBrandConvert;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.service.brand.ProductBrandService;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品品牌 Manager
|
||||
*/
|
||||
@Service
|
||||
public class ProductBrandManager {
|
||||
|
||||
@Autowired
|
||||
private ProductBrandService productBrandService;
|
||||
|
||||
/**
|
||||
* 创建商品品牌
|
||||
*
|
||||
* @param createDTO 创建商品品牌 DTO
|
||||
* @return 商品品牌
|
||||
*/
|
||||
public Integer createProductBrand(ProductBrandCreateReqDTO createDTO) {
|
||||
ProductBrandBO productBrandBO = productBrandService.createProductBrand(ProductBrandConvert.INSTANCE.convert(createDTO));
|
||||
return productBrandBO.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品品牌
|
||||
*
|
||||
* @param updateDTO 更新商品品牌 DTO
|
||||
*/
|
||||
public void updateProductBrand(ProductBrandUpdateReqDTO updateDTO) {
|
||||
productBrandService.updateProductBrand(ProductBrandConvert.INSTANCE.convert(updateDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
*/
|
||||
public void deleteProductBrand(Integer productBrandId) {
|
||||
productBrandService.deleteProductBrand(productBrandId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
* @return 商品品牌
|
||||
*/
|
||||
public ProductBrandRespDTO getProductBrand(Integer productBrandId) {
|
||||
ProductBrandBO productBrandBO = productBrandService.getProductBrand(productBrandId);
|
||||
return ProductBrandConvert.INSTANCE.convert(productBrandBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌列表
|
||||
*
|
||||
* @param productBrandIds 商品品牌编号列表
|
||||
* @return 商品品牌列表
|
||||
*/
|
||||
public List<ProductBrandRespDTO> listProductBrands(List<Integer> productBrandIds) {
|
||||
List<ProductBrandBO> productBrandBOs = productBrandService.listProductBrands(productBrandIds);
|
||||
return ProductBrandConvert.INSTANCE.convertList02(productBrandBOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌分页
|
||||
*
|
||||
* @param pageDTO 商品品牌分页查询
|
||||
* @return 商品品牌分页结果
|
||||
*/
|
||||
public PageResult<ProductBrandRespDTO> pageProductBrand(ProductBrandPageReqDTO pageDTO) {
|
||||
PageResult<ProductBrandBO> pageResultBO = productBrandService.pageProductBrand(ProductBrandConvert.INSTANCE.convert(pageDTO));
|
||||
return ProductBrandConvert.INSTANCE.convertPage(pageResultBO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.iocoder.mall.productservice.manager.category;
|
||||
|
||||
import cn.iocoder.mall.productservice.convert.category.ProductCategoryConvert;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.service.category.ProductCategoryService;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品分类 Manager
|
||||
*/
|
||||
@Service
|
||||
public class ProductCategoryManager {
|
||||
|
||||
@Autowired
|
||||
private ProductCategoryService productCategoryService;
|
||||
|
||||
/**
|
||||
* 创建商品分类
|
||||
*
|
||||
* @param createDTO 创建商品分类 DTO
|
||||
* @return 商品分类
|
||||
*/
|
||||
public Integer createProductCategory(ProductCategoryCreateReqDTO createDTO) {
|
||||
ProductCategoryBO productCategoryBO = productCategoryService.createProductCategory(ProductCategoryConvert.INSTANCE.convert(createDTO));
|
||||
return productCategoryBO.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品分类
|
||||
*
|
||||
* @param updateDTO 更新商品分类 DTO
|
||||
*/
|
||||
public void updateProductCategory(ProductCategoryUpdateReqDTO updateDTO) {
|
||||
productCategoryService.updateProductCategory(ProductCategoryConvert.INSTANCE.convert(updateDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品分类
|
||||
*
|
||||
* @param productCategoryId 商品分类编号
|
||||
*/
|
||||
public void deleteProductCategory(Integer productCategoryId) {
|
||||
productCategoryService.deleteProductCategory(productCategoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品分类
|
||||
*
|
||||
* @param productCategoryId 商品分类编号
|
||||
* @return 商品分类
|
||||
*/
|
||||
public ProductCategoryRespDTO getProductCategory(Integer productCategoryId) {
|
||||
ProductCategoryBO productCategoryBO = productCategoryService.getProductCategory(productCategoryId);
|
||||
return ProductCategoryConvert.INSTANCE.convert(productCategoryBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品分类列表
|
||||
*
|
||||
* @param productCategoryIds 商品分类编号列表
|
||||
* @return 商品分类列表
|
||||
*/
|
||||
public List<ProductCategoryRespDTO> listProductCategories(Collection<Integer> productCategoryIds) {
|
||||
List<ProductCategoryBO> productCategoryBOs = productCategoryService.listProductCategories(productCategoryIds);
|
||||
return ProductCategoryConvert.INSTANCE.convertList02(productCategoryBOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品分类全列表
|
||||
*
|
||||
* @return 商品分类全列表
|
||||
*/
|
||||
public List<ProductCategoryRespDTO> listProductCategories(ProductCategoryListQueryReqDTO listQueryReqDTO) {
|
||||
List<ProductCategoryBO> productCategoryBOs = productCategoryService.listProductCategories(
|
||||
ProductCategoryConvert.INSTANCE.convert(listQueryReqDTO));
|
||||
return ProductCategoryConvert.INSTANCE.convertList02(productCategoryBOs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package cn.iocoder.mall.productservice.manager.sku;
|
||||
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.mall.productservice.convert.sku.ProductSkuConvert;
|
||||
import cn.iocoder.mall.productservice.enums.sku.ProductSkuDetailFieldEnum;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
|
||||
import cn.iocoder.mall.productservice.service.attr.ProductAttrService;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyValueBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.ProductSkuService;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.ProductSpuService;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 商品 SKU Manager
|
||||
*/
|
||||
@Service
|
||||
public class ProductSkuManager {
|
||||
|
||||
@Autowired
|
||||
private ProductSkuService productSkuService;
|
||||
@Autowired
|
||||
private ProductSpuService productSpuService;
|
||||
@Autowired
|
||||
private ProductAttrService productAttrService;
|
||||
|
||||
/**
|
||||
* 获得商品 SKU
|
||||
*
|
||||
* @param productSkuId 商品 SKU编号
|
||||
* @return 商品 SKU
|
||||
*/
|
||||
public ProductSkuRespDTO getProductSku(Integer productSkuId) {
|
||||
ProductSkuBO productSkuBO = productSkuService.getProductSku(productSkuId);
|
||||
return ProductSkuConvert.INSTANCE.convert(productSkuBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SKU 列表
|
||||
*
|
||||
* @param queryReqDTO 商品 SKU 列表的查询请求 DTO
|
||||
* @return 商品 SKU列表
|
||||
*/
|
||||
public List<ProductSkuRespDTO> listProductSkus(ProductSkuListQueryReqDTO queryReqDTO) {
|
||||
// 获得商品 SKU 列表
|
||||
List<ProductSkuBO> skuBOs = productSkuService.listProductSkus(
|
||||
ProductSkuConvert.INSTANCE.convert(queryReqDTO));
|
||||
if (CollectionUtils.isEmpty(skuBOs)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 获得商品 SPU 列表
|
||||
List<ProductSpuBO> spuBOs = Collections.emptyList();
|
||||
if (queryReqDTO.getFields().contains(ProductSkuDetailFieldEnum.SPU.getField())) {
|
||||
spuBOs = productSpuService.listProductSpus(
|
||||
CollectionUtils.convertSet(skuBOs, ProductSkuBO::getSpuId));
|
||||
}
|
||||
// 获取商品 SKU 的规格数组
|
||||
List<ProductAttrKeyValueBO> attrBOs = Collections.emptyList();
|
||||
if (queryReqDTO.getFields().contains(ProductSkuDetailFieldEnum.ATTR.getField())) {
|
||||
Set<Integer> attrValueIds = new HashSet<>();
|
||||
skuBOs.forEach(sku -> attrValueIds.addAll(sku.getAttrValueIds()));
|
||||
attrBOs = productAttrService.validProductAttr(attrValueIds, false); // 读取规格时,不考虑规格是否被禁用
|
||||
}
|
||||
// 拼接最终返回
|
||||
return ProductSkuConvert.INSTANCE.convertList(skuBOs, spuBOs, attrBOs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
package cn.iocoder.mall.productservice.manager.spu;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.spu.ProductSpuConvert;
|
||||
import cn.iocoder.mall.productservice.enums.category.ProductCategoryIdEnum;
|
||||
import cn.iocoder.mall.productservice.enums.spu.ProductSpuDetailFieldEnum;
|
||||
import cn.iocoder.mall.productservice.mq.producer.ProductMQProducer;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
import cn.iocoder.mall.productservice.service.attr.ProductAttrService;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyValueBO;
|
||||
import cn.iocoder.mall.productservice.service.category.ProductCategoryService;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.ProductSkuService;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuCreateOrUpdateBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuListQueryBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.ProductSpuService;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuUpdateBO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.aop.framework.AopContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 商品 SPU Manager
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ProductSpuManager {
|
||||
|
||||
@Autowired
|
||||
private ProductSpuService productSpuService;
|
||||
@Autowired
|
||||
private ProductSkuService productSkuService;
|
||||
@Autowired
|
||||
private ProductCategoryService productCategoryService;
|
||||
@Autowired
|
||||
private ProductAttrService productAttrService;
|
||||
|
||||
@Autowired
|
||||
private ProductMQProducer productMQProducer;
|
||||
|
||||
private static ProductSpuManager self() {
|
||||
return (ProductSpuManager) AopContext.currentProxy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品 SPU 和 SKU
|
||||
*
|
||||
* @param createDTO 创建商品 SPU 和 SKU DTO
|
||||
* @return 商品 SPU
|
||||
*/
|
||||
public Integer createProductSpu(ProductSpuAndSkuCreateReqDTO createDTO) {
|
||||
// 创建商品 SPU 和 SKU。注意,这里要调用 self() 方法,因为需要创建事务,否则会失效
|
||||
Integer spuId = self().createProductSpu0(createDTO);
|
||||
// 发送商品创建的 MQ 消息
|
||||
productMQProducer.sendProductUpdateMessage(spuId);
|
||||
return spuId;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Integer createProductSpu0(ProductSpuAndSkuCreateReqDTO createDTO) {
|
||||
// 校验商品分类是否合法
|
||||
this.checkProductCategory(createDTO.getCid());
|
||||
// 创建商品 SKU 对象,并进行校验
|
||||
List<ProductSkuCreateOrUpdateBO> skuBOs = ProductSpuConvert.INSTANCE.convert(createDTO.getSkus());
|
||||
this.checkProductAttr(skuBOs);
|
||||
// 插入商品 SPU 记录
|
||||
ProductSpuCreateBO spuCreateBO = ProductSpuConvert.INSTANCE.convert(createDTO).setSort(0);
|
||||
spuCreateBO.setPrice(skuBOs.stream().min(Comparator.comparing(ProductSkuCreateOrUpdateBO::getPrice)).get().getPrice()); // 求最小价格
|
||||
spuCreateBO.setQuantity(skuBOs.stream().mapToInt(ProductSkuCreateOrUpdateBO::getQuantity).sum()); // 求库存之和
|
||||
ProductSpuBO spuBO = productSpuService.createProductSpu(spuCreateBO);
|
||||
// 插入商品 SKU 记录
|
||||
productSkuService.createProductSkus(spuBO.getId(), skuBOs);
|
||||
return spuBO.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品 SPU
|
||||
*
|
||||
* @param updateDTO 更新商品 SPU DTO
|
||||
*/
|
||||
public void updateProductSpu(ProductSpuAndSkuUpdateReqDTO updateDTO) {
|
||||
// 更新商品 SPU 和 SKU。注意,这里要调用 self() 方法,因为需要创建事务,否则会失效
|
||||
self().updateProductSpu0(updateDTO);
|
||||
// 发送商品创建的 MQ 消息
|
||||
productMQProducer.sendProductUpdateMessage(updateDTO.getId());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateProductSpu0(ProductSpuAndSkuUpdateReqDTO updateDTO) {
|
||||
// 校验商品分类是否合法
|
||||
this.checkProductCategory(updateDTO.getCid());
|
||||
// 创建商品 SKU 对象,并进行校验
|
||||
List<ProductSkuCreateOrUpdateBO> skuBOs = ProductSpuConvert.INSTANCE.convert02(updateDTO.getSkus());
|
||||
this.checkProductAttr(skuBOs);
|
||||
// 更新商品 SPU 记录
|
||||
ProductSpuUpdateBO spuUpdateBO = ProductSpuConvert.INSTANCE.convert(updateDTO);
|
||||
spuUpdateBO.setPrice(skuBOs.stream().min(Comparator.comparing(ProductSkuCreateOrUpdateBO::getPrice)).get().getPrice()); // 求最小价格
|
||||
spuUpdateBO.setQuantity(skuBOs.stream().mapToInt(ProductSkuCreateOrUpdateBO::getQuantity).sum()); // 求库存之和
|
||||
productSpuService.updateProductSpu(spuUpdateBO);
|
||||
// 更新商品 SKU 记录
|
||||
productSkuService.updateProductSkus(updateDTO.getId(), skuBOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SPU
|
||||
*
|
||||
* @param productSpuId 商品 SPU编号
|
||||
* @return 商品 SPU
|
||||
*/
|
||||
public ProductSpuRespDTO getProductSpu(Integer productSpuId) {
|
||||
ProductSpuBO productSpuBO = productSpuService.getProductSpu(productSpuId);
|
||||
return ProductSpuConvert.INSTANCE.convert(productSpuBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SPU列表
|
||||
*
|
||||
* @param productSpuIds 商品 SPU编号列表
|
||||
* @return 商品 SPU列表
|
||||
*/
|
||||
public List<ProductSpuRespDTO> listProductSpus(Collection<Integer> productSpuIds) {
|
||||
List<ProductSpuBO> productSpuBOs = productSpuService.listProductSpus(productSpuIds);
|
||||
return ProductSpuConvert.INSTANCE.convertList02(productSpuBOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SPU分页
|
||||
*
|
||||
* @param pageDTO 商品 SPU分页查询
|
||||
* @return 商品 SPU分页结果
|
||||
*/
|
||||
public PageResult<ProductSpuRespDTO> pageProductSpu(ProductSpuPageReqDTO pageDTO) {
|
||||
PageResult<ProductSpuBO> pageResultBO = productSpuService.pageProductSpu(ProductSpuConvert.INSTANCE.convert(pageDTO));
|
||||
return ProductSpuConvert.INSTANCE.convertPage(pageResultBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加或修改商品 SPU 时,校验商品分类是否合法
|
||||
*
|
||||
* @param cid 商品分类编号
|
||||
* @return 商品分类
|
||||
*/
|
||||
private ProductCategoryBO checkProductCategory(Integer cid) {
|
||||
ProductCategoryBO categoryBO = productCategoryService.getProductCategory(cid);
|
||||
if (categoryBO == null) {
|
||||
// 不存在
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
||||
}
|
||||
if (ProductCategoryIdEnum.ROOT.getId().equals(categoryBO.getPid())) {
|
||||
// 商品只能添加到二级分类下
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_SPU_CATEGORY_MUST_BE_LEVEL2);
|
||||
}
|
||||
return categoryBO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 顺序获得商品 SPU 编号数组
|
||||
*
|
||||
* @param lastSpuId 最后一个商品 SPU 编号
|
||||
* @param limit 数量
|
||||
* @return 商品 SPU 编号数组
|
||||
*/
|
||||
public List<Integer> listProductSpuIds(Integer lastSpuId, Integer limit) {
|
||||
return productSpuService.listProductSpuIds(lastSpuId, limit);
|
||||
}
|
||||
|
||||
private List<ProductAttrKeyValueBO> checkProductAttr(List<ProductSkuCreateOrUpdateBO> skuBOs) {
|
||||
// 第一步,校验 SKU 使用到的规格是否存在
|
||||
Set<Integer> attrValueIds = new HashSet<>();
|
||||
skuBOs.forEach(sku -> attrValueIds.addAll(sku.getAttrValueIds()));
|
||||
List<ProductAttrKeyValueBO> attrKeyValueBOs = productAttrService.validProductAttr(attrValueIds, true);
|
||||
// 第二步,校验 SKU 设置的规格是否合法,例如说数量是否一致,是否重复等等
|
||||
// 创建 ProductAttrDetailBO 的映射。其中,KEY 为 ProductAttrDetailBO.attrValueId ,即规格值的编号
|
||||
Map<Integer, ProductAttrKeyValueBO> productAttrDetailBOMap = attrKeyValueBOs.stream().collect(
|
||||
Collectors.toMap(ProductAttrKeyValueBO::getAttrValueId, productAttrDetailBO -> productAttrDetailBO));
|
||||
// 1. 先校验,一个 Sku 下,没有重复的规格。校验方式是,遍历每个 Sku ,看看是否有重复的规格 attrId
|
||||
for (ProductSkuCreateOrUpdateBO sku : skuBOs) {
|
||||
Set<Integer> attrIds = sku.getAttrValueIds().stream().map(attrValueId -> productAttrDetailBOMap.get(attrValueId).getAttrKeyId())
|
||||
.collect(Collectors.toSet());
|
||||
if (attrIds.size() != sku.getAttrValueIds().size()) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_SKU_ATTR_CANT_NOT_DUPLICATE);
|
||||
}
|
||||
}
|
||||
// 2. 再校验,每个 Sku 的规格值的数量,是一致的。
|
||||
int attrValueIdsSize = skuBOs.get(0).getAttrValueIds().size();
|
||||
for (int i = 1; i < skuBOs.size(); i++) {
|
||||
if (attrValueIdsSize != skuBOs.get(i).getAttrValueIds().size()) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_SPU_ATTR_NUMBERS_MUST_BE_EQUALS);
|
||||
}
|
||||
}
|
||||
// 3. 最后校验,每个 Sku 之间不是重复的
|
||||
Set<Set<Integer>> skuAttrValues = new HashSet<>(); // 每个元素,都是一个 Sku 的 attrValueId 集合。这样,通过最外层的 Set ,判断是否有重复的.
|
||||
for (ProductSkuCreateOrUpdateBO sku : skuBOs) {
|
||||
if (!skuAttrValues.add(new HashSet<>(sku.getAttrValueIds()))) { // 添加失败,说明重复
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_SPU_SKU_NOT_DUPLICATE);
|
||||
}
|
||||
}
|
||||
return attrKeyValueBOs;
|
||||
}
|
||||
|
||||
public ProductSpuDetailRespDTO getProductSpuDetail(Integer productSpuId, Collection<String> fields) {
|
||||
// 获得商品 SPU 信息
|
||||
ProductSpuBO spuBO = productSpuService.getProductSpu(productSpuId);
|
||||
if (spuBO == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_SPU_NOT_EXISTS);
|
||||
}
|
||||
// 获取商品分类
|
||||
ProductCategoryBO categoryBO = productCategoryService.getProductCategory(spuBO.getCid());
|
||||
if (categoryBO == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
||||
}
|
||||
// 获得商品 SKU 数组
|
||||
List<ProductSkuBO> skuBOs = Collections.emptyList();
|
||||
if (fields.contains(ProductSpuDetailFieldEnum.SKU.getField())) {
|
||||
skuBOs = productSkuService.listProductSkus(new ProductSkuListQueryBO().setProductSpuId(productSpuId)
|
||||
.setProductSkuStatus(CommonStatusEnum.ENABLE.getValue()));
|
||||
}
|
||||
// 获取商品 SKU 的规格数组
|
||||
List<ProductAttrKeyValueBO> attrBOs = Collections.emptyList();
|
||||
if (fields.contains(ProductSpuDetailFieldEnum.ATTR.getField()) && !CollectionUtils.isEmpty(skuBOs)) {
|
||||
Set<Integer> attrValueIds = new HashSet<>();
|
||||
skuBOs.forEach(sku -> attrValueIds.addAll(sku.getAttrValueIds()));
|
||||
attrBOs = productAttrService.validProductAttr(attrValueIds, false); // 读取规格时,不考虑规格是否被禁用
|
||||
}
|
||||
// 拼接最终返回
|
||||
return ProductSpuConvert.INSTANCE.convert(spuBO, skuBOs, attrBOs, categoryBO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.iocoder.mall.productservice.mq.producer;
|
||||
|
||||
import cn.iocoder.mall.productservice.mq.producer.message.ProductUpdateMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.client.producer.SendStatus;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ProductMQProducer {
|
||||
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
public void sendProductUpdateMessage(Integer id) {
|
||||
// TODO 芋艿:后续优化下,考虑下一致性
|
||||
try {
|
||||
SendResult sendResult = rocketMQTemplate.syncSend(ProductUpdateMessage.TOPIC, new ProductUpdateMessage().setId(id));
|
||||
if (!SendStatus.SEND_OK.equals(sendResult.getSendStatus())) {
|
||||
log.error("[sendProductUpdateMessage][product({}) 发送更新消息失败,结果为({})]", id, sendResult);
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
log.error("[sendProductUpdateMessage][product({}) 发送更新消息失败,发生异常]", id, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.iocoder.mall.productservice.mq.producer.message;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品更新(包括创建)消息
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductUpdateMessage {
|
||||
|
||||
public static final String TOPIC = "ProductUpdate";
|
||||
|
||||
/**
|
||||
* 商品编号
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
package cn.iocoder.mall.productservice.service.attr;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.attr.ProductAttrConvert;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrKeyDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrValueDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.mapper.attr.ProductAttrKeyMapper;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.mapper.attr.ProductAttrValueMapper;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.*;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 商品规格 Service
|
||||
*
|
||||
* 包括商品键和值
|
||||
*/
|
||||
@Service
|
||||
@Valid
|
||||
public class ProductAttrService {
|
||||
|
||||
@Autowired
|
||||
private ProductAttrKeyMapper productAttrKeyMapper;
|
||||
@Autowired
|
||||
private ProductAttrValueMapper productAttrValueMapper;
|
||||
|
||||
public List<ProductAttrKeyValueBO> validProductAttr(Set<Integer> productAttrValueIds, boolean validStatus) {
|
||||
// 首先,校验规格 Value
|
||||
List<ProductAttrValueDO> attrValues = productAttrValueMapper.selectBatchIds(productAttrValueIds);
|
||||
if (attrValues.size() != productAttrValueIds.size()) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_VALUE_NOT_EXIST);
|
||||
}
|
||||
if (validStatus) {
|
||||
for (ProductAttrValueDO attrValue : attrValues) { // 同时,校验下状态
|
||||
if (CommonStatusEnum.DISABLE.getValue().equals(attrValue.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_VALUE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 然后,校验规 Key
|
||||
Set<Integer> attrKeyIds = CollectionUtils.convertSet(attrValues, ProductAttrValueDO::getAttrKeyId);
|
||||
List<ProductAttrKeyDO> attrKeys = productAttrKeyMapper.selectBatchIds(attrKeyIds);
|
||||
if (attrKeys.size() != attrKeyIds.size()) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_NOT_EXIST);
|
||||
}
|
||||
if (validStatus) {
|
||||
for (ProductAttrKeyDO attrKey : attrKeys) { // 同时,校验下状态
|
||||
if (CommonStatusEnum.DISABLE.getValue().equals(attrKey.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 返回成功
|
||||
Map<Integer, ProductAttrKeyDO> attrKeyMap = CollectionUtils.convertMap(attrKeys,
|
||||
ProductAttrKeyDO::getId, attrKeyDO -> attrKeyDO); // ProductAttrDO 的映射,方便查找。
|
||||
return attrValues.stream().map(attrValueDO -> new ProductAttrKeyValueBO()
|
||||
.setAttrKeyId(attrValueDO.getAttrKeyId()).setAttrKeyName(attrKeyMap.get(attrValueDO.getAttrKeyId()).getName())
|
||||
.setAttrValueId(attrValueDO.getId()).setAttrValueName(attrValueDO.getName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品规格键
|
||||
*
|
||||
* @param createBO 创建商品规格键 BO
|
||||
* @return 商品规格键
|
||||
*/
|
||||
public ProductAttrKeyBO createProductAttrKey(@Valid ProductAttrKeyCreateBO createBO) {
|
||||
// 校验规格键的名字是否重复
|
||||
if (productAttrKeyMapper.selectByName(createBO.getName()) != null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_EXISTS);
|
||||
}
|
||||
// 插入到数据库
|
||||
ProductAttrKeyDO productAttrKeyDO = ProductAttrConvert.INSTANCE.convert(createBO);
|
||||
productAttrKeyMapper.insert(productAttrKeyDO);
|
||||
// 返回
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrKeyDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品规格键
|
||||
*
|
||||
* @param updateBO 更新商品规格键 BO
|
||||
*/
|
||||
public void updateProductAttrKey(@Valid ProductAttrKeyUpdateBO updateBO) {
|
||||
// 校验规格键的名字是否重复
|
||||
ProductAttrKeyDO attrKeyDOByName = productAttrKeyMapper.selectByName(updateBO.getName());
|
||||
if (attrKeyDOByName != null && !attrKeyDOByName.getId().equals(updateBO.getId())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_EXISTS);
|
||||
}
|
||||
// 校验更新的商品规格键是否存在
|
||||
if (productAttrKeyMapper.selectById(updateBO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_NOT_EXIST);
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductAttrKeyDO updateObject = ProductAttrConvert.INSTANCE.convert(updateBO);
|
||||
productAttrKeyMapper.updateById(updateObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
* @return 商品规格键
|
||||
*/
|
||||
public ProductAttrKeyBO getProductAttrKey(Integer productAttrKeyId) {
|
||||
ProductAttrKeyDO productAttrKeyDO = productAttrKeyMapper.selectById(productAttrKeyId);
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrKeyDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键列表
|
||||
*
|
||||
* @param productAttrKeyIds 商品规格键编号列表
|
||||
* @return 商品规格键列表
|
||||
*/
|
||||
public List<ProductAttrKeyBO> listProductAttrKeys(List<Integer> productAttrKeyIds) {
|
||||
List<ProductAttrKeyDO> productAttrKeyDOs = productAttrKeyMapper.selectBatchIds(productAttrKeyIds);
|
||||
return ProductAttrConvert.INSTANCE.convertList(productAttrKeyDOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键分页
|
||||
*
|
||||
* @param pageBO 商品规格键分页查询
|
||||
* @return 商品规格键分页结果
|
||||
*/
|
||||
public PageResult<ProductAttrKeyBO> pageProductAttrKey(ProductAttrKeyPageBO pageBO) {
|
||||
IPage<ProductAttrKeyDO> productAttrKeyDOPage = productAttrKeyMapper.selectPage(pageBO);
|
||||
return ProductAttrConvert.INSTANCE.convertPage(productAttrKeyDOPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品规格值
|
||||
*
|
||||
* @param createBO 创建商品规格值 BO
|
||||
* @return 商品规格值
|
||||
*/
|
||||
public ProductAttrValueBO createProductAttrValue(@Valid ProductAttrValueCreateBO createBO) {
|
||||
// 校验规格键是否存在
|
||||
if (productAttrKeyMapper.selectById(createBO.getAttrKeyId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_NOT_EXIST);
|
||||
}
|
||||
// 校验规格值的名字是否重复
|
||||
if (productAttrValueMapper.selectByAttrKeyIdAndName(createBO.getAttrKeyId(), createBO.getName()) != null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_VALUE_EXISTS);
|
||||
}
|
||||
// 插入到数据库
|
||||
ProductAttrValueDO productAttrValueDO = ProductAttrConvert.INSTANCE.convert(createBO);
|
||||
productAttrValueMapper.insert(productAttrValueDO);
|
||||
// 返回
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrValueDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品规格值
|
||||
*
|
||||
* @param updateBO 更新商品规格值 BO
|
||||
*/
|
||||
public void updateProductAttrValue(@Valid ProductAttrValueUpdateBO updateBO) {
|
||||
// 校验更新的商品规格值是否存在
|
||||
ProductAttrValueDO attrValueDO = productAttrValueMapper.selectById(updateBO.getId());
|
||||
if (attrValueDO == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_VALUE_NOT_EXIST);
|
||||
}
|
||||
// 校验规格值的名字是否重复
|
||||
ProductAttrValueDO attrValueDOByName = productAttrValueMapper.selectByAttrKeyIdAndName(
|
||||
attrValueDO.getAttrKeyId(), updateBO.getName());
|
||||
if (attrValueDOByName != null && !attrValueDOByName.getId().equals(updateBO.getId())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_VALUE_EXISTS);
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductAttrValueDO updateObject = ProductAttrConvert.INSTANCE.convert(updateBO);
|
||||
productAttrValueMapper.updateById(updateObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格值
|
||||
*
|
||||
* @param productAttrValueId 商品规格值编号
|
||||
* @return 商品规格值
|
||||
*/
|
||||
public ProductAttrValueBO getProductAttrValue(Integer productAttrValueId) {
|
||||
ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueId);
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrValueDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格值列表
|
||||
*
|
||||
* @param queryBO 商品规格值的列表查询条件 BO
|
||||
* @return 商品规格值列表
|
||||
*/
|
||||
public List<ProductAttrValueBO> listProductAttrValues(ProductAttrValueListQueryBO queryBO) {
|
||||
List<ProductAttrValueDO> productAttrValueDOs = productAttrValueMapper.selectList(queryBO);
|
||||
return ProductAttrConvert.INSTANCE.convertList03(productAttrValueDOs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品规格键 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyBO {
|
||||
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品规格键创建 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyCreateBO {
|
||||
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
@NotEmpty(message = "规格键名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品规格键分页 BO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyPageBO extends PageParam {
|
||||
|
||||
/**
|
||||
* 规格键名称,模糊匹配
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品规格键更新 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyUpdateBO {
|
||||
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
@NotNull(message = "规格键编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
@NotEmpty(message = "规格键名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品规格键值对 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyValueBO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格 Key 编号
|
||||
*/
|
||||
private Integer attrKeyId;
|
||||
/**
|
||||
* 规格 Key 名字
|
||||
*/
|
||||
private String attrKeyName;
|
||||
/**
|
||||
* 规格 Value 编号
|
||||
*/
|
||||
private Integer attrValueId;
|
||||
/**
|
||||
* 规格 Value 名字
|
||||
*/
|
||||
private String attrValueName;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品规格值 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrValueBO {
|
||||
|
||||
/**
|
||||
* 规格值编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
private Integer attrKeyId;
|
||||
/**
|
||||
* 规格值名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品规格值创建 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrValueCreateBO {
|
||||
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
@NotNull(message = "规格键编号不能为空")
|
||||
private Integer attrKeyId;
|
||||
/**
|
||||
* 规格值名字
|
||||
*/
|
||||
@NotEmpty(message = "规格值名字不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品规格值的列表查询条件 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrValueListQueryBO {
|
||||
|
||||
/**
|
||||
* 商品规格值编号列表
|
||||
*/
|
||||
private List<Integer> productAttrValueIds;
|
||||
|
||||
/**
|
||||
* 商品规格键编号
|
||||
*/
|
||||
private Integer productAttrKeyId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品规格值更新 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrValueUpdateBO {
|
||||
|
||||
/**
|
||||
* 规格值编号
|
||||
*/
|
||||
@NotNull(message = "规格值编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
@NotNull(message = "规格键编号不能为空")
|
||||
private Integer attrKeyId;
|
||||
/**
|
||||
* 规格值名字
|
||||
*/
|
||||
@NotEmpty(message = "规格值名字不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package cn.iocoder.mall.productservice.service.brand;
|
||||
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.brand.ProductBrandConvert;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.brand.ProductBrandDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.mapper.brand.ProductBrandMapper;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandPageBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandUpdateBO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.PRODUCT_BRAND_NAME_EXIST;
|
||||
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.PRODUCT_BRAND_NOT_FOUND;
|
||||
|
||||
/**
|
||||
* 商品品牌 Service
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductBrandService {
|
||||
|
||||
@Autowired
|
||||
private ProductBrandMapper productBrandMapper;
|
||||
|
||||
/**
|
||||
* 创建商品品牌
|
||||
*
|
||||
* @param createBO 创建商品品牌 BO
|
||||
* @return 商品品牌
|
||||
*/
|
||||
public ProductBrandBO createProductBrand(@Valid ProductBrandCreateBO createBO) {
|
||||
// 校验商品品牌的名字是否已经使用
|
||||
if (productBrandMapper.selectByName(createBO.getName()) != null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_BRAND_NAME_EXIST);
|
||||
}
|
||||
// 插入到数据库
|
||||
ProductBrandDO productBrandDO = ProductBrandConvert.INSTANCE.convert(createBO);
|
||||
productBrandMapper.insert(productBrandDO);
|
||||
// 返回
|
||||
return ProductBrandConvert.INSTANCE.convert(productBrandDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品品牌
|
||||
*
|
||||
* @param updateBO 更新商品品牌 BO
|
||||
*/
|
||||
public void updateProductBrand(@Valid ProductBrandUpdateBO updateBO) {
|
||||
// 校验更新的商品品牌是否存在
|
||||
if (productBrandMapper.selectById(updateBO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_BRAND_NOT_FOUND);
|
||||
}
|
||||
// 校验商品品牌的名字是否已经使用
|
||||
ProductBrandDO productBrandDOByName = productBrandMapper.selectByName(updateBO.getName());
|
||||
if (productBrandDOByName != null && !updateBO.getId().equals(productBrandDOByName.getId())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_BRAND_NAME_EXIST);
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductBrandDO updateObject = ProductBrandConvert.INSTANCE.convert(updateBO);
|
||||
productBrandMapper.updateById(updateObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
*/
|
||||
public void deleteProductBrand(Integer productBrandId) {
|
||||
// 校验删除的商品品牌是否存在
|
||||
if (productBrandMapper.selectById(productBrandId) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_BRAND_NOT_FOUND);
|
||||
}
|
||||
// TODO 功能点:需要品牌下没有分类
|
||||
// 标记删除
|
||||
productBrandMapper.deleteById(productBrandId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
* @return 商品品牌
|
||||
*/
|
||||
public ProductBrandBO getProductBrand(Integer productBrandId) {
|
||||
ProductBrandDO productBrandDO = productBrandMapper.selectById(productBrandId);
|
||||
return ProductBrandConvert.INSTANCE.convert(productBrandDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌列表
|
||||
*
|
||||
* @param productBrandIds 商品品牌编号列表
|
||||
* @return 商品品牌列表
|
||||
*/
|
||||
public List<ProductBrandBO> listProductBrands(List<Integer> productBrandIds) {
|
||||
List<ProductBrandDO> productBrandDOs = productBrandMapper.selectBatchIds(productBrandIds);
|
||||
return ProductBrandConvert.INSTANCE.convertList(productBrandDOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌分页
|
||||
*
|
||||
* @param pageBO 商品品牌分页查询
|
||||
* @return 商品品牌分页结果
|
||||
*/
|
||||
public PageResult<ProductBrandBO> pageProductBrand(ProductBrandPageBO pageBO) {
|
||||
IPage<ProductBrandDO> productBrandDOPage = productBrandMapper.selectPage(pageBO);
|
||||
return ProductBrandConvert.INSTANCE.convertPage(productBrandDOPage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package cn.iocoder.mall.productservice.service.brand.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品品牌 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandBO {
|
||||
|
||||
/**
|
||||
* 品牌编号(主键)
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.iocoder.mall.productservice.service.brand.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品品牌创建 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandCreateBO {
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
@NotEmpty(message = "品牌名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.iocoder.mall.productservice.service.brand.bo;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品品牌分页 BO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandPageBO extends PageParam {
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*
|
||||
* 模糊匹配
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package cn.iocoder.mall.productservice.service.brand.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品品牌更新 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandUpdateBO {
|
||||
|
||||
/**
|
||||
* 品牌编号(主键)
|
||||
*/
|
||||
@NotNull(message = "品牌编号(主键)不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
@NotEmpty(message = "品牌名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package cn.iocoder.mall.productservice.service.category;
|
||||
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.mall.productservice.convert.category.ProductCategoryConvert;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.category.ProductCategoryDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.mapper.category.ProductCategoryMapper;
|
||||
import cn.iocoder.mall.productservice.enums.category.ProductCategoryIdEnum;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryBO;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryListQueryBO;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryUpdateBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 商品分类 Service
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductCategoryService {
|
||||
|
||||
@Autowired
|
||||
private ProductCategoryMapper productCategoryMapper;
|
||||
|
||||
/**
|
||||
* 创建商品分类
|
||||
*
|
||||
* @param createBO 创建商品分类 BO
|
||||
* @return 商品分类
|
||||
*/
|
||||
public ProductCategoryBO createProductCategory(@Valid ProductCategoryCreateBO createBO) {
|
||||
// 校验父分类
|
||||
validParent(createBO.getPid());
|
||||
// 插入到数据库
|
||||
ProductCategoryDO productCategoryDO = ProductCategoryConvert.INSTANCE.convert(createBO);
|
||||
productCategoryMapper.insert(productCategoryDO);
|
||||
// 返回
|
||||
return ProductCategoryConvert.INSTANCE.convert(productCategoryDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品分类
|
||||
*
|
||||
* @param updateBO 更新商品分类 BO
|
||||
*/
|
||||
public void updateProductCategory(@Valid ProductCategoryUpdateBO updateBO) {
|
||||
// 校验父分类
|
||||
validParent(updateBO.getPid());
|
||||
// 校验不能设置自己为父分类
|
||||
if (updateBO.getId().equals(updateBO.getPid())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_SELF);
|
||||
}
|
||||
// 校验更新的商品分类是否存在
|
||||
if (productCategoryMapper.selectById(updateBO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductCategoryDO updateObject = ProductCategoryConvert.INSTANCE.convert(updateBO);
|
||||
productCategoryMapper.updateById(updateObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品分类
|
||||
*
|
||||
* @param productCategoryId 商品分类编号
|
||||
*/
|
||||
public void deleteProductCategory(Integer productCategoryId) {
|
||||
// 校验删除的商品分类是否存在
|
||||
if (productCategoryMapper.selectById(productCategoryId) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
||||
}
|
||||
// 只有不存在子分类才可以删除
|
||||
Integer childCount = productCategoryMapper.selectCountByPid(productCategoryId);
|
||||
if (childCount > 0) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_DELETE_ONLY_NO_CHILD);
|
||||
}
|
||||
// TODO 芋艿 补充只有不存在商品才可以删除
|
||||
// 标记删除
|
||||
productCategoryMapper.deleteById(productCategoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品分类
|
||||
*
|
||||
* @param productCategoryId 商品分类编号
|
||||
* @return 商品分类
|
||||
*/
|
||||
public ProductCategoryBO getProductCategory(Integer productCategoryId) {
|
||||
ProductCategoryDO productCategoryDO = productCategoryMapper.selectById(productCategoryId);
|
||||
return ProductCategoryConvert.INSTANCE.convert(productCategoryDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品分类列表
|
||||
*
|
||||
* @param productCategoryIds 商品分类编号列表
|
||||
* @return 商品分类列表
|
||||
*/
|
||||
public List<ProductCategoryBO> listProductCategories(Collection<Integer> productCategoryIds) {
|
||||
List<ProductCategoryDO> productCategoryDOs = productCategoryMapper.selectBatchIds(productCategoryIds);
|
||||
return ProductCategoryConvert.INSTANCE.convertList(productCategoryDOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品分类全列表
|
||||
*
|
||||
* @return 商品分类全列表
|
||||
*/
|
||||
public List<ProductCategoryBO> listProductCategories(ProductCategoryListQueryBO listQueryBO) {
|
||||
List<ProductCategoryDO> resourceDOs = productCategoryMapper.selectList(listQueryBO);
|
||||
return ProductCategoryConvert.INSTANCE.convertList(resourceDOs);
|
||||
}
|
||||
|
||||
private void validParent(Integer pid) {
|
||||
if (!ProductCategoryIdEnum.ROOT.getId().equals(pid)) {
|
||||
ProductCategoryDO parentCategory = productCategoryMapper.selectById(pid);
|
||||
// 校验父分类是否存在
|
||||
if (parentCategory == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS);
|
||||
}
|
||||
// 父分类必须是一级分类
|
||||
if (!ProductCategoryIdEnum.ROOT.getId().equals(parentCategory.getPid())) {
|
||||
throw ServiceExceptionUtil.exception((PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.iocoder.mall.productservice.service.category.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品分类 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryBO {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 分类描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 分类排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.iocoder.mall.productservice.service.category.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品分类创建 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryCreateBO {
|
||||
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
@NotNull(message = "父分类编号不能为空")
|
||||
private Integer pid;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
@NotEmpty(message = "分类名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 分类描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 分类排序
|
||||
*/
|
||||
@NotNull(message = "分类排序不能为空")
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.service.category.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品分类列表查询 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryListQueryBO {
|
||||
|
||||
/**
|
||||
* 父编号
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package cn.iocoder.mall.productservice.service.category.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品分类更新 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryUpdateBO {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
@NotNull(message = "分类编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
@NotNull(message = "父分类编号不能为空")
|
||||
private Integer pid;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
@NotEmpty(message = "分类名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 分类描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 分类排序
|
||||
*/
|
||||
@NotNull(message = "分类排序不能为空")
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package cn.iocoder.mall.productservice.service.sku;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.common.framework.util.StringUtils;
|
||||
import cn.iocoder.mall.productservice.convert.sku.ProductSkuConvert;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.sku.ProductSkuDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.mapper.sku.ProductSkuMapper;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuCreateOrUpdateBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuListQueryBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ProductSkuService {
|
||||
|
||||
@Autowired
|
||||
private ProductSkuMapper productSkuMapper;
|
||||
|
||||
public void createProductSkus(Integer spuId, List<ProductSkuCreateOrUpdateBO> createSkuBOs) {
|
||||
List<ProductSkuDO> skus = ProductSkuConvert.INSTANCE.convertList(createSkuBOs);
|
||||
skus.forEach(sku -> {
|
||||
sku.setStatus(CommonStatusEnum.ENABLE.getValue());
|
||||
sku.setSpuId(spuId);
|
||||
});
|
||||
productSkuMapper.insertList(skus);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateProductSkus(Integer spuId, List<ProductSkuCreateOrUpdateBO> skuUpdateBOs) {
|
||||
List<ProductSkuDO> existsSkus = productSkuMapper.selectListBySpuIdAndStatus(spuId,
|
||||
CommonStatusEnum.ENABLE.getValue());
|
||||
List<ProductSkuDO> insertSkus = new ArrayList<>(); // 1、找不到,进行插入
|
||||
List<Integer> deleteSkus = new ArrayList<>(); // 2、多余的,删除
|
||||
List<ProductSkuDO> updateSkus = new ArrayList<>(); // 3、找的到,进行更新。
|
||||
for (ProductSkuCreateOrUpdateBO skuUpdateDTO : skuUpdateBOs) {
|
||||
ProductSkuDO existsSku = findProductSku(skuUpdateDTO.getAttrValueIds(), existsSkus);
|
||||
// 3、找的到,进行更新。
|
||||
if (existsSku != null) {
|
||||
// 移除
|
||||
existsSkus.remove(existsSku);
|
||||
// 创建 ProductSkuDO
|
||||
updateSkus.add(ProductSkuConvert.INSTANCE.convert(skuUpdateDTO).setId(existsSku.getId()));
|
||||
continue;
|
||||
}
|
||||
// 1、找不到,进行插入
|
||||
ProductSkuDO insertSku = ProductSkuConvert.INSTANCE.convert(skuUpdateDTO)
|
||||
.setSpuId(spuId).setStatus(CommonStatusEnum.ENABLE.getValue());
|
||||
insertSkus.add(insertSku);
|
||||
}
|
||||
// 2、多余的,删除
|
||||
if (!existsSkus.isEmpty()) {
|
||||
deleteSkus.addAll(existsSkus.stream().map(ProductSkuDO::getId).collect(Collectors.toList()));
|
||||
}
|
||||
// 执行修改 Sku
|
||||
if (!insertSkus.isEmpty()) {
|
||||
productSkuMapper.insertList(insertSkus);
|
||||
}
|
||||
if (!updateSkus.isEmpty()) {
|
||||
updateSkus.forEach(productSkuDO -> productSkuMapper.updateById(productSkuDO));
|
||||
}
|
||||
if (!deleteSkus.isEmpty()) {
|
||||
productSkuMapper.deleteBatchIds(deleteSkus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 sku 数组中,指定规格的 sku
|
||||
*
|
||||
* @param attrValueIds 指定规格 Value 的编号数组
|
||||
* @param skus sku 数组
|
||||
* @return 符合条件的 sku
|
||||
*/
|
||||
private ProductSkuDO findProductSku(Collection<Integer> attrValueIds, List<ProductSkuDO> skus) {
|
||||
if (CollectionUtils.isEmpty(skus)) {
|
||||
return null;
|
||||
}
|
||||
// 创建成 Set ,方便后面比较
|
||||
attrValueIds = new HashSet<>(attrValueIds);
|
||||
for (ProductSkuDO sku : skus) {
|
||||
Set<Integer> skuAttrValueIds = StringUtils.split(sku.getAttrs(), ",")
|
||||
.stream().map(Integer::parseInt).collect(Collectors.toSet());
|
||||
if (attrValueIds.equals(skuAttrValueIds)) {
|
||||
return sku;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SKU
|
||||
*
|
||||
* @param productSkuId 商品 SKU 编号
|
||||
* @return 商品 SKU
|
||||
*/
|
||||
public ProductSkuBO getProductSku(Integer productSkuId) {
|
||||
ProductSkuDO productSkuDO = productSkuMapper.selectById(productSkuId);
|
||||
return ProductSkuConvert.INSTANCE.convert(productSkuDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SKU 列表
|
||||
*
|
||||
* @param queryBO 商品 SKU 列表查询条件 BO
|
||||
* @return 商品 SKU 列表
|
||||
*/
|
||||
public List<ProductSkuBO> listProductSkus(ProductSkuListQueryBO queryBO) {
|
||||
// TODO FROM 芋艿:可能要考虑下,是不是要必须传递条件
|
||||
List<ProductSkuDO> productSkuDOs = productSkuMapper.selectList(queryBO);
|
||||
return ProductSkuConvert.INSTANCE.convertList02(productSkuDOs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package cn.iocoder.mall.productservice.service.sku.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 SKU BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSkuBO {
|
||||
|
||||
/**
|
||||
* sku 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 商品编号
|
||||
*/
|
||||
private Integer spuId;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 1-正常
|
||||
* 2-禁用
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 规格值编号数组
|
||||
*/
|
||||
private List<Integer> attrValueIds;
|
||||
/**
|
||||
* 价格,单位:分
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 最后更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Integer deleted;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.iocoder.mall.productservice.service.sku.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 SKU 创建或者修改 BO
|
||||
*
|
||||
* 注意,目前该对象是搭配 {@link}
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSkuCreateOrUpdateBO {
|
||||
|
||||
/**
|
||||
* 规格值数组
|
||||
*/
|
||||
@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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.iocoder.mall.productservice.service.sku.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 商品 SKU 列表查询 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSkuListQueryBO {
|
||||
|
||||
/**
|
||||
* 商品 SKU 编号
|
||||
*/
|
||||
private Integer productSkuId;
|
||||
/**
|
||||
* 商品 SKU 编号数组
|
||||
*/
|
||||
private Collection<Integer> productSkuIds;
|
||||
/**
|
||||
* 商品 SPU 编号
|
||||
*/
|
||||
private Integer productSpuId;
|
||||
/**
|
||||
* 商品 SKU 状态
|
||||
*/
|
||||
private Integer productSkuStatus;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package cn.iocoder.mall.productservice.service.spu;
|
||||
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.spu.ProductSpuConvert;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.mapper.spu.ProductSpuMapper;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuPageBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuUpdateBO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.PRODUCT_SPU_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 商品 SPU Service
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductSpuService {
|
||||
|
||||
@Autowired
|
||||
private ProductSpuMapper productSpuMapper;
|
||||
|
||||
/**
|
||||
* 创建商品 SPU
|
||||
*
|
||||
* @param createBO 创建商品 SPU BO
|
||||
* @return 商品 SPU
|
||||
*/
|
||||
public ProductSpuBO createProductSpu(@Valid ProductSpuCreateBO createBO) {
|
||||
// 插入到数据库
|
||||
ProductSpuDO productSpuDO = ProductSpuConvert.INSTANCE.convert(createBO);
|
||||
productSpuMapper.insert(productSpuDO);
|
||||
// 返回
|
||||
return ProductSpuConvert.INSTANCE.convert(productSpuDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品 SPU
|
||||
*
|
||||
* @param updateBO 更新商品 SPU BO
|
||||
*/
|
||||
public void updateProductSpu(@Valid ProductSpuUpdateBO updateBO) {
|
||||
// 校验更新的商品 SPU是否存在
|
||||
if (productSpuMapper.selectById(updateBO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_SPU_NOT_EXISTS);
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductSpuDO updateObject = ProductSpuConvert.INSTANCE.convert(updateBO);
|
||||
productSpuMapper.updateById(updateObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SPU
|
||||
*
|
||||
* @param productSpuId 商品 SPU编号
|
||||
* @return 商品 SPU
|
||||
*/
|
||||
public ProductSpuBO getProductSpu(Integer productSpuId) {
|
||||
ProductSpuDO productSpuDO = productSpuMapper.selectById(productSpuId);
|
||||
return ProductSpuConvert.INSTANCE.convert(productSpuDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SPU列表
|
||||
*
|
||||
* @param productSpuIds 商品 SPU编号列表
|
||||
* @return 商品 SPU列表
|
||||
*/
|
||||
public List<ProductSpuBO> listProductSpus(Collection<Integer> productSpuIds) {
|
||||
List<ProductSpuDO> productSpuDOs = productSpuMapper.selectBatchIds(productSpuIds);
|
||||
return ProductSpuConvert.INSTANCE.convertList(productSpuDOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SPU分页
|
||||
*
|
||||
* @param pageBO 商品 SPU分页查询
|
||||
* @return 商品 SPU分页结果
|
||||
*/
|
||||
public PageResult<ProductSpuBO> pageProductSpu(ProductSpuPageBO pageBO) {
|
||||
IPage<ProductSpuDO> productSpuDOPage = productSpuMapper.selectPage(pageBO);
|
||||
return ProductSpuConvert.INSTANCE.convertPage(productSpuDOPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 顺序获得商品 SPU 编号数组
|
||||
*
|
||||
* 一般情况下,该接口我们用于提供顺序的 SPU 编号数组,以便调用方进一步根据自己需要获取商品信息
|
||||
* 例如说,搜索服务会不断获取商品编号,重建该商品编号的索引
|
||||
*
|
||||
* @param lastSpuId 最后一个商品 SPU 编号
|
||||
* @param limit 数量
|
||||
* @return 商品 SPU 编号数组
|
||||
*/
|
||||
public List<Integer> listProductSpuIds(Integer lastSpuId, Integer limit) {
|
||||
return CollectionUtils.convertList(productSpuMapper.selectListByIdGt(lastSpuId, limit), ProductSpuDO::getId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package cn.iocoder.mall.productservice.service.spu.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 SPU 信息 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSpuBO {
|
||||
|
||||
/**
|
||||
* 商品 SPU 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 卖点
|
||||
*/
|
||||
private String sellPoint;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 商品主图地址
|
||||
*/
|
||||
private List<String> picUrls;
|
||||
/**
|
||||
* 是否上架商品
|
||||
*/
|
||||
private Boolean visible;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 价格
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.iocoder.mall.productservice.service.spu.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 SPU 创建 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSpuCreateBO {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
@NotNull(message = "排序字段不能为空")
|
||||
private Integer sort;
|
||||
/**
|
||||
* 价格
|
||||
*/
|
||||
@NotNull(message = "价格不能为空")
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
@NotNull(message = "库存数量不能为空")
|
||||
private Integer quantity;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.iocoder.mall.productservice.service.spu.bo;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品 SPU 分页 BO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductSpuPageBO extends PageParam {
|
||||
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 是否可见
|
||||
*/
|
||||
private Boolean visible;
|
||||
/**
|
||||
* 是否有库存
|
||||
*/
|
||||
private Boolean hasQuantity;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.iocoder.mall.productservice.service.spu.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 SPU 更新 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSpuUpdateBO {
|
||||
|
||||
/**
|
||||
* 商品 SPU 编号
|
||||
*/
|
||||
@NotNull(message = "商品 SPU 编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 价格
|
||||
*/
|
||||
@NotNull(message = "价格不能为空")
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
@NotNull(message = "库存数量不能为空")
|
||||
private Integer quantity;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
spring:
|
||||
# 数据源配置项
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/mall_product?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: root
|
||||
password: zhuyang
|
||||
# Spring Cloud 配置项
|
||||
cloud:
|
||||
nacos:
|
||||
# Spring Cloud Nacos Discovery 配置项
|
||||
discovery:
|
||||
server-addr: localhost:8848 # Nacos 服务器地址
|
||||
namespace: dev # Nacos 命名空间
|
||||
|
||||
# Dubbo 配置项
|
||||
dubbo:
|
||||
# Dubbo 注册中心
|
||||
registry:
|
||||
# address: spring-cloud://localhost:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
address: nacos://localhost:8848?namespace=dev # 指定 Dubbo 服务注册中心的地址
|
||||
@@ -0,0 +1,24 @@
|
||||
spring:
|
||||
# 数据源配置项
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/mall_product?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: root
|
||||
password: zhuyang
|
||||
# Spring Cloud 配置项
|
||||
cloud:
|
||||
nacos:
|
||||
# Spring Cloud Nacos Discovery 配置项
|
||||
discovery:
|
||||
server-addr: localhost:8848 # Nacos 服务器地址
|
||||
namespace: dev # Nacos 命名空间
|
||||
|
||||
# Dubbo 配置项
|
||||
dubbo:
|
||||
# Dubbo 注册中心
|
||||
registry:
|
||||
# address: spring-cloud://localhost:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
address: nacos://localhost:8848?namespace=dev # 指定 Dubbo 服务注册中心的地址
|
||||
# Dubbo 服务提供者的配置
|
||||
provider:
|
||||
tag: ${DUBBO_TAG} # Dubbo 路由分组
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user