From 7dbbd412d8371c4c2fb081c2ffe686cc8dec29c5 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Tue, 28 Jul 2020 23:15:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E8=A7=84=E6=A0=BC=20key=20?= =?UTF-8?q?=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/ProductAttrController.java | 67 ++++++++++++ .../product/ProductSpuController.java | 10 +- .../vo/attr/ProductAttrKeyCreateReqVO.java | 24 ++++ .../vo/attr/ProductAttrKeyPageReqVO.java | 22 ++++ .../product/vo/attr/ProductAttrKeyRespVO.java | 20 ++++ .../vo/attr/ProductAttrKeyUpdateReqVO.java | 27 +++++ .../product/ProductAttrKeyConvert.java | 34 ++++++ .../product/ProductAttrKeyManager.java | 97 +++++++++++++++++ .../src/main/resources/application.yml | 2 + .../enums/ProductErrorCodeConstants.java | 6 +- .../rpc/attr/ProductAttrRpc.java | 63 +++++++++++ .../attr/dto/ProductAttrKeyCreateReqDTO.java | 28 +++++ .../attr/dto/ProductAttrKeyPageReqDTO.java | 25 +++++ .../rpc/attr/dto/ProductAttrKeyRespDTO.java | 33 ++++++ .../attr/dto/ProductAttrKeyUpdateReqDTO.java | 33 ++++++ .../convert/attr/ProductAttrConvert.java | 46 ++++++++ .../mapper/attr/ProductAttrKeyMapper.java | 15 +++ .../manager/attr/ProductAttrManager.java | 87 +++++++++++++++ .../rpc/attr/ProductAttrRpcImpl.java | 58 ++++++++++ .../rpc/brand/ProductBrandRpcImpl.java | 4 +- .../rpc/category/ProductCategoryRpcImpl.java | 2 +- .../rpc/spu/ProductSpuRpcImpl.java | 4 +- .../service/attr/ProductAttrService.java | 103 +++++++++++++++++- .../service/attr/bo/ProductAttrKeyBO.java | 32 ++++++ .../attr/bo/ProductAttrKeyCreateBO.java | 30 +++++ .../service/attr/bo/ProductAttrKeyPageBO.java | 25 +++++ .../attr/bo/ProductAttrKeyUpdateBO.java | 35 ++++++ .../src/main/resources/application.yaml | 7 +- .../brand/AdminsProductBrandController.java | 93 ++++++++++++++++ .../mall/product/api/ProductAttrService.java | 7 -- .../service/ProductAttrServiceImpl.java | 52 --------- .../admins/AdminsProductSpuController.java | 93 ---------------- 32 files changed, 1010 insertions(+), 174 deletions(-) create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductAttrController.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyCreateReqVO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyPageReqVO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyRespVO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyUpdateReqVO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/product/ProductAttrKeyConvert.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/product/ProductAttrKeyManager.java create mode 100644 product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/ProductAttrRpc.java create mode 100644 product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyCreateReqDTO.java create mode 100644 product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyPageReqDTO.java create mode 100644 product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyRespDTO.java create mode 100644 product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyUpdateReqDTO.java create mode 100644 product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/convert/attr/ProductAttrConvert.java create mode 100644 product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/attr/ProductAttrManager.java create mode 100644 product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/attr/ProductAttrRpcImpl.java create mode 100644 product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyBO.java create mode 100644 product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyCreateBO.java create mode 100644 product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyPageBO.java create mode 100644 product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyUpdateBO.java create mode 100644 product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/brand/AdminsProductBrandController.java diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductAttrController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductAttrController.java new file mode 100644 index 000000000..aa1a589c9 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductAttrController.java @@ -0,0 +1,67 @@ +package cn.iocoder.mall.managementweb.controller.product; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyCreateReqVO; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyPageReqVO; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyRespVO; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyUpdateReqVO; +import cn.iocoder.mall.managementweb.manager.product.ProductAttrKeyManager; +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.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** + * 商品规格键 Controller + */ +@RestController +@RequestMapping("/product-attr/") +@Api(tags = "商品规格键") +@Validated +public class ProductAttrController { + + @Autowired + private ProductAttrKeyManager productAttrKeyManager; + + @PostMapping("/key/create") + @ApiOperation("创建商品规格键") + public CommonResult createProductAttrKey(@Valid ProductAttrKeyCreateReqVO createVO) { + return success(productAttrKeyManager.createProductAttrKey(createVO)); + } + + @PostMapping("/key/update") + @ApiOperation("更新商品规格键") + public CommonResult updateProductAttrKey(@Valid ProductAttrKeyUpdateReqVO updateVO) { + productAttrKeyManager.updateProductAttrKey(updateVO); + return success(true); + } + + @GetMapping("/key/get") + @ApiOperation("获得商品规格键") + @ApiImplicitParam(name = "productAttrKeyId", value = "商品规格键编号", required = true) + public CommonResult getProductAttrKey(@RequestParam("productAttrKeyId") Integer productAttrKeyId) { + return success(productAttrKeyManager.getProductAttrKey(productAttrKeyId)); + } + + @GetMapping("/key/list") + @ApiOperation("获得商品规格键列表") + @ApiImplicitParam(name = "productAttrKeyIds", value = "商品规格键编号列表", required = true) + public CommonResult> listProductAttrKeys(@RequestParam("productAttrKeyIds") List productAttrKeyIds) { + return success(productAttrKeyManager.listProductAttrKeys(productAttrKeyIds)); + } + + @GetMapping("/key/page") + @ApiOperation("获得商品规格键分页") + public CommonResult> pageProductAttrKey(ProductAttrKeyPageReqVO pageVO) { + return success(productAttrKeyManager.pageProductAttrKey(pageVO)); + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductSpuController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductSpuController.java index dc9f34d2c..a306591e8 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductSpuController.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductSpuController.java @@ -61,10 +61,14 @@ public class ProductSpuController { @GetMapping("/page") @ApiOperation("获得商品 SPU 分页") public CommonResult> pageProductSpu(ProductSpuPageReqVO pageVO) { - // - // - // + // 全部:无搜索条件 + // 在售中:visible = true && hasQuantity = true + // 已售罄:visible = true && hasQuantity = false + // 仓库中:visible = false return success(productSpuManager.pageProductSpu(pageVO)); } + // TODO 芋艿,删除功能暂时不做。主要原因是,关联的数据太多。删除带来的问题会比较大 + + } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyCreateReqVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyCreateReqVO.java new file mode 100644 index 000000000..8c34ad510 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyCreateReqVO.java @@ -0,0 +1,24 @@ +package cn.iocoder.mall.managementweb.controller.product.vo.attr; + +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@ApiModel("商品规格键创建 Request VO") +@Data +public class ProductAttrKeyCreateReqVO { + + @ApiModelProperty(value = "规格键名称", required = true, example = "尺寸") + @NotEmpty(message = "规格键名称不能为空") + private String name; + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举") + @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyPageReqVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyPageReqVO.java new file mode 100644 index 000000000..2ef4b106d --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyPageReqVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.managementweb.controller.product.vo.attr; + +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.common.framework.vo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel("商品规格键分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +public class ProductAttrKeyPageReqVO extends PageParam { + + @ApiModelProperty(value = "规格键名称", required = true, example = "尺寸", notes = "模糊匹配") + private String name; + @ApiModelProperty(value = "状态", example = "1", notes = "见 CommonStatusEnum 枚举") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyRespVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyRespVO.java new file mode 100644 index 000000000..9b88b6861 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyRespVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.managementweb.controller.product.vo.attr; + +import lombok.*; +import io.swagger.annotations.*; +import java.util.*; + +@ApiModel("商品规格键 Response VO") +@Data +public class ProductAttrKeyRespVO { + + @ApiModelProperty(value = "规格键编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "规格键名称", required = true, example = "尺寸") + private String name; + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举") + private Integer status; + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyUpdateReqVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyUpdateReqVO.java new file mode 100644 index 000000000..c7d3f2454 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/vo/attr/ProductAttrKeyUpdateReqVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.mall.managementweb.controller.product.vo.attr; + +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@ApiModel("商品规格键更新 Request VO") +@Data +public class ProductAttrKeyUpdateReqVO { + + @ApiModelProperty(value = "规格键编号", required = true, example = "1") + @NotNull(message = "规格键编号不能为空") + private Integer id; + @ApiModelProperty(value = "规格键名称", required = true, example = "尺寸") + @NotEmpty(message = "规格键名称不能为空") + private String name; + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举") + @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/product/ProductAttrKeyConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/product/ProductAttrKeyConvert.java new file mode 100644 index 000000000..693de6dd0 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/product/ProductAttrKeyConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.managementweb.convert.product; + +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyCreateReqVO; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyPageReqVO; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyRespVO; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyUpdateReqVO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyCreateReqDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyPageReqDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyUpdateReqDTO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface ProductAttrKeyConvert { + + ProductAttrKeyConvert INSTANCE = Mappers.getMapper(ProductAttrKeyConvert.class); + + ProductAttrKeyCreateReqDTO convert(ProductAttrKeyCreateReqVO bean); + + ProductAttrKeyUpdateReqDTO convert(ProductAttrKeyUpdateReqVO bean); + + ProductAttrKeyRespVO convert(ProductAttrKeyRespDTO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + ProductAttrKeyPageReqDTO convert(ProductAttrKeyPageReqVO bean); + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/product/ProductAttrKeyManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/product/ProductAttrKeyManager.java new file mode 100644 index 000000000..37510922d --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/product/ProductAttrKeyManager.java @@ -0,0 +1,97 @@ +package cn.iocoder.mall.managementweb.manager.product; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyCreateReqVO; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyPageReqVO; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyRespVO; +import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyUpdateReqVO; +import cn.iocoder.mall.managementweb.convert.product.ProductAttrKeyConvert; +import cn.iocoder.mall.productservice.rpc.attr.ProductAttrRpc; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO; +import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** +* 商品规格 Manager +*/ +@Service +public class ProductAttrKeyManager { + + @DubboReference(version = "${dubbo.consumer.ProductAttrRpc.version}") + private ProductAttrRpc productAttrKeyRpc; + + /** + * 创建商品规格键 + * + * @param createVO 创建商品规格键 VO + * @return 商品规格键 + */ + public Integer createProductAttrKey(ProductAttrKeyCreateReqVO createVO) { + CommonResult createProductAttrKeyResult = productAttrKeyRpc.createProductAttrKey( + ProductAttrKeyConvert.INSTANCE.convert(createVO)); + createProductAttrKeyResult.checkError(); + return createProductAttrKeyResult.getData(); + } + + /** + * 更新商品规格键 + * + * @param updateVO 更新商品规格键 VO + */ + public void updateProductAttrKey(ProductAttrKeyUpdateReqVO updateVO) { + CommonResult updateProductAttrKeyResult = productAttrKeyRpc.updateProductAttrKey( + ProductAttrKeyConvert.INSTANCE.convert(updateVO)); + updateProductAttrKeyResult.checkError(); + } + + /** + * 删除商品规格键 + * + * @param productAttrKeyId 商品规格键编号 + */ + public void deleteProductAttrKey(Integer productAttrKeyId) { + CommonResult deleteProductAttrKeyResult = productAttrKeyRpc.deleteProductAttrKey(productAttrKeyId); + deleteProductAttrKeyResult.checkError(); + } + + /** + * 获得商品规格键 + * + * @param productAttrKeyId 商品规格键编号 + * @return 商品规格键 + */ + public ProductAttrKeyRespVO getProductAttrKey(Integer productAttrKeyId) { + CommonResult getProductAttrKeyResult = productAttrKeyRpc.getProductAttrKey(productAttrKeyId); + getProductAttrKeyResult.checkError(); + return ProductAttrKeyConvert.INSTANCE.convert(getProductAttrKeyResult.getData()); + } + + /** + * 获得商品规格键列表 + * + * @param productAttrKeyIds 商品规格键编号列表 + * @return 商品规格键列表 + */ + public List listProductAttrKeys(List productAttrKeyIds) { + CommonResult> listProductAttrKeyResult = productAttrKeyRpc.listProductAttrKeys(productAttrKeyIds); + listProductAttrKeyResult.checkError(); + return ProductAttrKeyConvert.INSTANCE.convertList(listProductAttrKeyResult.getData()); + } + + /** + * 获得商品规格键分页 + * + * @param pageVO 商品规格键分页查询 + * @return 商品规格键分页结果 + */ + public PageResult pageProductAttrKey(ProductAttrKeyPageReqVO pageVO) { + CommonResult> pageProductAttrKeyResult = productAttrKeyRpc.pageProductAttrKey( + ProductAttrKeyConvert.INSTANCE.convert(pageVO)); + pageProductAttrKeyResult.checkError(); + return ProductAttrKeyConvert.INSTANCE.convertPage(pageProductAttrKeyResult.getData()); + } + +} diff --git a/management-web-app/src/main/resources/application.yml b/management-web-app/src/main/resources/application.yml index caeaea2e3..9a55f0fc0 100644 --- a/management-web-app/src/main/resources/application.yml +++ b/management-web-app/src/main/resources/application.yml @@ -55,6 +55,8 @@ dubbo: version: 1.0.0 ProductSpuRpc: version: 1.0.0 + ProductAttrRpc: + version: 1.0.0 # Swagger 配置项 swagger: diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/enums/ProductErrorCodeConstants.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/enums/ProductErrorCodeConstants.java index 509f5dd59..2c43d8797 100644 --- a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/enums/ProductErrorCodeConstants.java +++ b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/enums/ProductErrorCodeConstants.java @@ -26,11 +26,9 @@ public interface ProductErrorCodeConstants { // ========== 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_EXISTS = new ErrorCode(1003003002, "商品规格已经存在"); - ErrorCode PRODUCT_ATTR_STATUS_EQUALS = new ErrorCode(1003003003, "商品规格已经是该状态"); + 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, "商品规格值已经存在"); - ErrorCode PRODUCT_ATTR_VALUE_STATUS_EQUALS = new ErrorCode(1003003005, "商品规格值已经是该状态"); // ========== PRODUCT BRAND模块 ========== ErrorCode PRODUCT_BRAND_NAME_EXIST = new ErrorCode(1003004000,"商品品牌的名字已经存在"); diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/ProductAttrRpc.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/ProductAttrRpc.java new file mode 100644 index 000000000..81989b0ff --- /dev/null +++ b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/ProductAttrRpc.java @@ -0,0 +1,63 @@ +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.ProductAttrKeyCreateReqDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyPageReqDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyUpdateReqDTO; + +import java.util.List; + +/** + * 商品规格 Rpc 接口 + */ +public interface ProductAttrRpc { + + /** + * 创建商品规格键 + * + * @param createDTO 创建商品规格键 DTO + * @return 商品规格键编号 + */ + CommonResult createProductAttrKey(ProductAttrKeyCreateReqDTO createDTO); + + /** + * 更新商品规格键 + * + * @param updateDTO 更新商品规格键 DTO + */ + CommonResult updateProductAttrKey(ProductAttrKeyUpdateReqDTO updateDTO); + + /** + * 删除商品规格键 + * + * @param productAttrKeyId 商品规格键编号 + */ + CommonResult deleteProductAttrKey(Integer productAttrKeyId); + + /** + * 获得商品规格键 + * + * @param productAttrKeyId 商品规格键编号 + * @return 商品规格键 + */ + CommonResult getProductAttrKey(Integer productAttrKeyId); + + /** + * 获得商品规格键列表 + * + * @param productAttrKeyIds 商品规格键编号列表 + * @return 商品规格键列表 + */ + CommonResult> listProductAttrKeys(List productAttrKeyIds); + + /** + * 获得商品规格键分页 + * + * @param pageDTO 商品规格键分页查询 + * @return 商品规格键分页结果 + */ + CommonResult> pageProductAttrKey(ProductAttrKeyPageReqDTO pageDTO); + +} diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyCreateReqDTO.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyCreateReqDTO.java new file mode 100644 index 000000000..17dd0a69b --- /dev/null +++ b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyCreateReqDTO.java @@ -0,0 +1,28 @@ +package cn.iocoder.mall.productservice.rpc.attr.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 ProductAttrKeyCreateReqDTO implements Serializable { + + /** + * 规格键名称 + */ + @NotEmpty(message = "规格键名称不能为空") + private String name; + /** + * 状态 + */ + @NotNull(message = "状态不能为空") + private Integer status; + +} diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyPageReqDTO.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyPageReqDTO.java new file mode 100644 index 000000000..742ecc26c --- /dev/null +++ b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyPageReqDTO.java @@ -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; + +} diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyRespDTO.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyRespDTO.java new file mode 100644 index 000000000..c6a1677cc --- /dev/null +++ b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyRespDTO.java @@ -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; + +} diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyUpdateReqDTO.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyUpdateReqDTO.java new file mode 100644 index 000000000..c323943cf --- /dev/null +++ b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/attr/dto/ProductAttrKeyUpdateReqDTO.java @@ -0,0 +1,33 @@ +package cn.iocoder.mall.productservice.rpc.attr.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 ProductAttrKeyUpdateReqDTO implements Serializable { + + /** + * 规格键编号 + */ + @NotNull(message = "规格键编号不能为空") + private Integer id; + /** + * 规格键名称 + */ + @NotEmpty(message = "规格键名称不能为空") + private String name; + /** + * 状态 + */ + @NotNull(message = "状态不能为空") + private Integer status; + +} diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/convert/attr/ProductAttrConvert.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/convert/attr/ProductAttrConvert.java new file mode 100644 index 000000000..90a55889e --- /dev/null +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/convert/attr/ProductAttrConvert.java @@ -0,0 +1,46 @@ +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.rpc.attr.dto.ProductAttrKeyCreateReqDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyPageReqDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyUpdateReqDTO; +import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyBO; +import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyCreateBO; +import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyPageBO; +import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyUpdateBO; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.mapstruct.Mapper; +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 convertList(List list); + + PageResult convertPage(IPage page); + + ProductAttrKeyCreateBO convert(ProductAttrKeyCreateReqDTO bean); + + ProductAttrKeyUpdateBO convert(ProductAttrKeyUpdateReqDTO bean); + + ProductAttrKeyRespDTO convert(ProductAttrKeyBO bean); + + List convertList02(List list); + + ProductAttrKeyPageBO convert(ProductAttrKeyPageReqDTO bean); + + PageResult convertPage(PageResult page); + +} diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/attr/ProductAttrKeyMapper.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/attr/ProductAttrKeyMapper.java index fba7c685e..f9083143e 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/attr/ProductAttrKeyMapper.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/attr/ProductAttrKeyMapper.java @@ -1,10 +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 { + default IPage selectPage(ProductAttrKeyPageBO pageBO) { + return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()), + new QueryWrapperX().likeIfPresent("name", pageBO.getName()) + .eqIfPresent("status", pageBO.getStatus())); + } + + default ProductAttrKeyDO selectByName(String name) { + return selectOne(new QueryWrapper().eq("name", name)); + } + } diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/attr/ProductAttrManager.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/attr/ProductAttrManager.java new file mode 100644 index 000000000..447356b87 --- /dev/null +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/attr/ProductAttrManager.java @@ -0,0 +1,87 @@ +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.ProductAttrKeyCreateReqDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyPageReqDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyUpdateReqDTO; +import cn.iocoder.mall.productservice.service.attr.ProductAttrService; +import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyBO; +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 商品规格键编号 + */ + public void deleteProductAttrKey(Integer productAttrKeyId) { + productAttrService.deleteProductAttrKey(productAttrKeyId); + } + + /** + * 获得商品规格键 + * + * @param productAttrKeyId 商品规格键编号 + * @return 商品规格键 + */ + public ProductAttrKeyRespDTO getProductAttrKey(Integer productAttrKeyId) { + ProductAttrKeyBO productAttrKeyBO = productAttrService.getProductAttrKey(productAttrKeyId); + return ProductAttrConvert.INSTANCE.convert(productAttrKeyBO); + } + + /** + * 获得商品规格键列表 + * + * @param productAttrKeyIds 商品规格键编号列表 + * @return 商品规格键列表 + */ + public List listProductAttrKeys(List productAttrKeyIds) { + List productAttrKeyBOs = productAttrService.listProductAttrKeys(productAttrKeyIds); + return ProductAttrConvert.INSTANCE.convertList02(productAttrKeyBOs); + } + + /** + * 获得商品规格键分页 + * + * @param pageDTO 商品规格键分页查询 + * @return 商品规格键分页结果 + */ + public PageResult pageProductAttrKey(ProductAttrKeyPageReqDTO pageDTO) { + PageResult pageResultBO = productAttrService.pageProductAttrKey(ProductAttrConvert.INSTANCE.convert(pageDTO)); + return ProductAttrConvert.INSTANCE.convertPage(pageResultBO); + } + +} diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/attr/ProductAttrRpcImpl.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/attr/ProductAttrRpcImpl.java new file mode 100644 index 000000000..a753af142 --- /dev/null +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/attr/ProductAttrRpcImpl.java @@ -0,0 +1,58 @@ +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.manager.attr.ProductAttrManager; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyCreateReqDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyPageReqDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO; +import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyUpdateReqDTO; +import org.apache.dubbo.config.annotation.DubboService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** + * 商品规格 Rpc 实现类 + */ +@DubboService +public class ProductAttrRpcImpl implements ProductAttrRpc { + + @Autowired + private ProductAttrManager productAttrManager; + + @Override + public CommonResult createProductAttrKey(ProductAttrKeyCreateReqDTO createDTO) { + return success(productAttrManager.createProductAttrKey(createDTO)); + } + + @Override + public CommonResult updateProductAttrKey(ProductAttrKeyUpdateReqDTO updateDTO) { + productAttrManager.updateProductAttrKey(updateDTO); + return success(true); + } + + @Override + public CommonResult deleteProductAttrKey(Integer productAttrKeyId) { + productAttrManager.deleteProductAttrKey(productAttrKeyId); + return success(true); + } + + @Override + public CommonResult getProductAttrKey(Integer productAttrKeyId) { + return success(productAttrManager.getProductAttrKey(productAttrKeyId)); + } + + @Override + public CommonResult> listProductAttrKeys(List productAttrKeyIds) { + return success(productAttrManager.listProductAttrKeys(productAttrKeyIds)); + } + + @Override + public CommonResult> pageProductAttrKey(ProductAttrKeyPageReqDTO pageDTO) { + return success(productAttrManager.pageProductAttrKey(pageDTO)); + } + +} diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/brand/ProductBrandRpcImpl.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/brand/ProductBrandRpcImpl.java index ada6bb285..4d9bc930c 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/brand/ProductBrandRpcImpl.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/brand/ProductBrandRpcImpl.java @@ -7,7 +7,7 @@ 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.apache.dubbo.config.annotation.Service; +import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; @@ -17,7 +17,7 @@ import static cn.iocoder.common.framework.vo.CommonResult.success; /** * 商品品牌 Rpc 实现类 */ -@Service(version = "${dubbo.provider.ProductBrandRpc.version}") +@DubboService public class ProductBrandRpcImpl implements ProductBrandRpc { @Autowired diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/category/ProductCategoryRpcImpl.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/category/ProductCategoryRpcImpl.java index 65eb1ed20..b35a55e5b 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/category/ProductCategoryRpcImpl.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/category/ProductCategoryRpcImpl.java @@ -16,7 +16,7 @@ import static cn.iocoder.common.framework.vo.CommonResult.success; /** * 商品分类 Rpc 实现类 */ -@DubboService(version = "${dubbo.provider.ProductCategoryRpc.version}") +@DubboService public class ProductCategoryRpcImpl implements ProductCategoryRpc { @Autowired diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java index a1b568cbc..85079c666 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java @@ -7,7 +7,7 @@ import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuCreateReqDTO; import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuUpdateReqDTO; import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuPageReqDTO; import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO; -import org.apache.dubbo.config.annotation.Service; +import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; @@ -17,7 +17,7 @@ import static cn.iocoder.common.framework.vo.CommonResult.success; /** * 商品 SPU Rpc 实现类 */ -@Service(version = "${dubbo.provider.ProductSpuRpc.version}") +@DubboService public class ProductSpuRpcImpl implements ProductSpuRpc { @Autowired diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/ProductAttrService.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/ProductAttrService.java index 7bc877d96..8121bc30d 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/ProductAttrService.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/ProductAttrService.java @@ -3,23 +3,32 @@ 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.ProductAttrKeyValueBO; +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.PRODUCT_ATTR_KEY_NOT_EXIST; -import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.PRODUCT_ATTR_VALUE_NOT_EXIST; +import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.*; +/** + * 商品规格 Service + * + * 包括商品键和值 + */ @Service +@Valid public class ProductAttrService { @Autowired @@ -54,11 +63,97 @@ public class ProductAttrService { } } // 返回成功 - Map attrKeyMap = CollectionUtils.convertMap(attrKeys, ProductAttrKeyDO::getId, attrKeyDO -> attrKeyDO); // ProductAttrDO 的映射,方便查找。 + Map attrKeyMap = CollectionUtils.convertMap(attrKeys, + ProductAttrKeyDO::getId, attrKeyDO -> attrKeyDO); // ProductAttrDO 的映射,方便查找。 return attrValues.stream().map(attrValueDO -> new ProductAttrKeyValueBO() .setAttrKeyId(attrValueDO.getAttrId()).setAttrKeyName(attrKeyMap.get(attrValueDO.getAttrId()).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 商品规格键编号 + */ + public void deleteProductAttrKey(Integer productAttrKeyId) { + // 校验删除的商品规格键是否存在 + if (productAttrKeyMapper.selectById(productAttrKeyId) == null) { + throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_NOT_EXIST); + } + // 标记删除 + productAttrKeyMapper.deleteById(productAttrKeyId); + } + + /** + * 获得商品规格键 + * + * @param productAttrKeyId 商品规格键编号 + * @return 商品规格键 + */ + public ProductAttrKeyBO getProductAttrKey(Integer productAttrKeyId) { + ProductAttrKeyDO productAttrKeyDO = productAttrKeyMapper.selectById(productAttrKeyId); + return ProductAttrConvert.INSTANCE.convert(productAttrKeyDO); + } + + /** + * 获得商品规格键列表 + * + * @param productAttrKeyIds 商品规格键编号列表 + * @return 商品规格键列表 + */ + public List listProductAttrKeys(List productAttrKeyIds) { + List productAttrKeyDOs = productAttrKeyMapper.selectBatchIds(productAttrKeyIds); + return ProductAttrConvert.INSTANCE.convertList(productAttrKeyDOs); + } + + /** + * 获得商品规格键分页 + * + * @param pageBO 商品规格键分页查询 + * @return 商品规格键分页结果 + */ + public PageResult pageProductAttrKey(ProductAttrKeyPageBO pageBO) { + IPage productAttrKeyDOPage = productAttrKeyMapper.selectPage(pageBO); + return ProductAttrConvert.INSTANCE.convertPage(productAttrKeyDOPage); + } + } diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyBO.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyBO.java new file mode 100644 index 000000000..684653dfe --- /dev/null +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyBO.java @@ -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; + +} diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyCreateBO.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyCreateBO.java new file mode 100644 index 000000000..0dc28ed9b --- /dev/null +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyCreateBO.java @@ -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; + +} diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyPageBO.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyPageBO.java new file mode 100644 index 000000000..9a5a41194 --- /dev/null +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyPageBO.java @@ -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; + +} diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyUpdateBO.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyUpdateBO.java new file mode 100644 index 000000000..5992e0c36 --- /dev/null +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/bo/ProductAttrKeyUpdateBO.java @@ -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; + +} diff --git a/product-service-project/product-service-app/src/main/resources/application.yaml b/product-service-project/product-service-app/src/main/resources/application.yaml index f79c0380a..aed565dff 100644 --- a/product-service-project/product-service-app/src/main/resources/application.yaml +++ b/product-service-project/product-service-app/src/main/resources/application.yaml @@ -34,12 +34,7 @@ dubbo: provider: filter: -exception validation: true # 开启 Provider 参数校验 - ProductCategoryRpc: - version: 1.0.0 - ProductBrandRpc: - version: 1.0.0 - ProductSpuRpc: - version: 1.0.0 + version: 1.0.0 # 服务的版本号 # Dubbo 服务消费者的配置 consumer: ErrorCodeRpc: diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/brand/AdminsProductBrandController.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/brand/AdminsProductBrandController.java new file mode 100644 index 000000000..79814d9f3 --- /dev/null +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/brand/AdminsProductBrandController.java @@ -0,0 +1,93 @@ +package cn.iocoder.mall.product.rest.controller.brand; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO; +import cn.iocoder.mall.product.biz.dto.brand.ProductBrandAddDTO; +import cn.iocoder.mall.product.biz.dto.brand.ProductBrandPageDTO; +import cn.iocoder.mall.product.biz.dto.brand.ProductBrandUpdateDTO; +import cn.iocoder.mall.product.biz.service.brand.ProductBrandService; +import cn.iocoder.mall.product.rest.convert.brand.ProductBrandConvert; +import cn.iocoder.mall.product.rest.request.brand.ProductBrandAddRequest; +import cn.iocoder.mall.product.rest.request.brand.ProductBrandPageRequest; +import cn.iocoder.mall.product.rest.request.brand.ProductBrandUpdateRequest; +import cn.iocoder.mall.product.rest.response.brand.AdminsProductBrandResponse; +import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +@RestController +@RequestMapping("admins/brand") +@Api("管理员 - 商品品牌 API") +@AllArgsConstructor +public class AdminsProductBrandController { + + private final ProductBrandService productBrandService; + + @PostMapping("/add") + @ApiOperation("创建品牌") + public CommonResult add(@Validated ProductBrandAddRequest addRequest) { + // 创建 ProductBrandAddDTO 对象 + ProductBrandAddDTO productBrandAddDTO = ProductBrandConvert.INSTANCE.convertAdd(addRequest); + // 保存品牌 + ProductBrandBO result = productBrandService.addProductBrand(AdminSecurityContextHolder.getContext().getAdminId(), productBrandAddDTO); + // 返回结果 + return success(ProductBrandConvert.INSTANCE.convert(result)); + } + + @PostMapping("/update") + @ApiOperation("更新商品") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "品牌主键", required = true, example = "1"), + @ApiImplicitParam(name = "name", value = "品牌名称", required = true, example = "安踏"), + @ApiImplicitParam(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋"), + @ApiImplicitParam(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn"), + @ApiImplicitParam(name = "status", value = "状态 1开启 2禁用", required = true, example = "1") + }) + // TODO FROM 芋艿 to q2118cs:只要改成了 bean 接收,就不用在写 @ApiImplicitParam 注解啦,直接在 bean 里写就 ok 啦 + public CommonResult update(@Validated ProductBrandUpdateRequest updateRequest) { + // 创建 productBrandUpdateDTO 对象 + ProductBrandUpdateDTO productBrandUpdateDTO = ProductBrandConvert.INSTANCE.convertUpdate(updateRequest); + // 更新商品 + return success(productBrandService.updateProductBrand(AdminSecurityContextHolder.getContext().getAdminId(), productBrandUpdateDTO)); + } + + @GetMapping("/get") + @ApiOperation("获取品牌") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "品牌主键", required = true, example = "1") + }) + public CommonResult add(@RequestParam("id") Integer id) { + // 保存商品 + ProductBrandBO result = productBrandService.getProductBrand(id); + // 返回结果 + return success(ProductBrandConvert.INSTANCE.convert(result)); + } + + @GetMapping("/page") + @ApiOperation("获得品牌分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = "name", value = "品牌名称", required = true, example = "安踏"), + @ApiImplicitParam(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋"), + @ApiImplicitParam(name = "status", value = "状态 1开启 2禁用", required = true, example = "1"), + @ApiImplicitParam(name = "pageNo", value = "页码", required = true, example = "1"), + @ApiImplicitParam(name = "pageSize", value = "页面大小", required = true, example = "10") + }) + public CommonResult> attrPage(ProductBrandPageRequest pageRequest) { + // 创建 ProductBrandPageDTO 对象 + ProductBrandPageDTO productBrandPageDTO = ProductBrandConvert.INSTANCE.convertPageRequest(pageRequest); + // 查询分页 + PageResult productBrandPage = productBrandService.getProductBrandPage(productBrandPageDTO); + PageResult adminPageResponse = ProductBrandConvert.INSTANCE.convertPage(productBrandPage); + return CommonResult.success(adminPageResponse); + } + + +} diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductAttrService.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductAttrService.java index 286de763d..55f58a212 100644 --- a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductAttrService.java +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductAttrService.java @@ -23,13 +23,6 @@ public interface ProductAttrService { */ List getProductAttrList(); - ProductAttrBO addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO); - - Boolean updateProductAttr(Integer adminId, ProductAttrUpdateDTO productAttrUpdateDTO); - - Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId, - @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status); - ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO); Boolean updateProductAttrValue(Integer adminId, ProductAttrValueUpdateDTO productAttrValueUpdateDTO); diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java index 8e7870f1b..34308e742 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java @@ -74,58 +74,6 @@ public class ProductAttrServiceImpl implements ProductAttrService { return attrs; } - @Override - public ProductAttrBO addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO) { - // 校验规格名不重复 - if (productAttrMapper.selectByName(productAttrAddDTO.getName()) != null) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode()); - } - // 插入到数据库 - ProductAttrDO productAttrDO = ProductAttrConvert.INSTANCE.convert(productAttrAddDTO) - .setStatus(ProductAttrConstants.ATTR_STATUS_ENABLE); - productAttrDO.setCreateTime(new Date()); - productAttrDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); - productAttrMapper.insert(productAttrDO); - // 返回成功 - return ProductAttrConvert.INSTANCE.convert(productAttrDO); - } - - @Override - public Boolean updateProductAttr(Integer adminId, ProductAttrUpdateDTO productAttrUpdateDTO) { - // 校验存在 - if (productAttrMapper.selectById(productAttrUpdateDTO.getId()) == null) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode()); - } - // 校验规格名不重复 - ProductAttrDO existsAttrDO = productAttrMapper.selectByName(productAttrUpdateDTO.getName()); - if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrUpdateDTO.getId())) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode()); - } - // 更新到数据库 - ProductAttrDO updateProductAttr = ProductAttrConvert.INSTANCE.convert(productAttrUpdateDTO); - productAttrMapper.update(updateProductAttr); - // 返回成功 - return true; - } - - @Override - public Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId, Integer status) { - // 校验存在 - ProductAttrDO productAttrDO = productAttrMapper.selectById(productAttrId); - if (productAttrDO == null) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode()); - } - // 校验状态 - if (productAttrDO.getStatus().equals(status)) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_STATUS_EQUALS.getCode()); - } - // 更新到数据库 - ProductAttrDO updateProductAttr = new ProductAttrDO().setId(productAttrId).setStatus(status); - productAttrMapper.update(updateProductAttr); - // 返回成功 - return true; - } - @Override public ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO) { // 校验规格名不重复 diff --git a/product/product-start/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductSpuController.java b/product/product-start/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductSpuController.java index 305f93072..5f16bd7e1 100644 --- a/product/product-start/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductSpuController.java +++ b/product/product-start/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductSpuController.java @@ -29,66 +29,6 @@ import static cn.iocoder.common.framework.vo.CommonResult.success; @Api("商品 SPU + SKU") public class AdminsProductSpuController { - @Reference(validation = "true", version = "${dubbo.provider.ProductSpuService.version}") - private ProductSpuService productSpuService; - - @PostMapping("/spu/add") - @ApiOperation("创建商品") - @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "SPU 名字", required = true, example = "厮大牛逼"), - @ApiImplicitParam(name = "sellPoint", value = "卖点", required = true, example = "各种 MQ 骚操作"), - @ApiImplicitParam(name = "description", value = "描述", required = true, example = "你就说强不强 MQ 骚操作"), - @ApiImplicitParam(name = "cid", value = "分类编号", required = true, example = "反正我是信了"), - @ApiImplicitParam(name = "picUrls", value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn"), - @ApiImplicitParam(name = "visible", value = "是否上架商品(是否可见)", required = true, example = "true"), - @ApiImplicitParam(name = "skuStr", value = "SKU 字符串", required = true, example = "[{\"attrs\": [1,3 ], \"price\": 1, \"quantity\": 100, \"picUrl\": \"http://www.iocoder.cn\"}]"), - }) - public CommonResult add(@RequestParam("name") String name, - @RequestParam("sellPoint") String sellPoint, - @RequestParam("description") String description, - @RequestParam("cid") Integer cid, - @RequestParam("picUrls") List picUrls, - @RequestParam("visible") Boolean visible, - @RequestParam("skuStr") String skuStr) { // TODO 芋艿,因为考虑不使用 json 接受参数,所以这里手动转。 - // 创建 ProductSpuAddDTO 对象 - ProductSpuAddDTO productSpuAddDTO = new ProductSpuAddDTO().setName(name).setSellPoint(sellPoint) - .setDescription(description).setCid(cid).setPicUrls(picUrls).setVisible(visible) - .setSkus(parseSkus(skuStr, ProductSkuAddOrUpdateDTO.class)); - // 保存商品 - ProductSpuDetailBO result = productSpuService.addProductSpu(AdminSecurityContextHolder.getContext().getAdminId(), productSpuAddDTO); - // 返回结果 - return success(ProductSpuConvert.INSTANCE.convert(result)); - } - - @PostMapping("/spu/update") - @ApiOperation("更新商品") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "SPU 编号", required = true, example = "100"), - @ApiImplicitParam(name = "name", value = "SPU 名字", required = true, example = "厮大牛逼"), - @ApiImplicitParam(name = "sellPoint", value = "卖点", required = true, example = "各种 MQ 骚操作"), - @ApiImplicitParam(name = "description", value = "描述", required = true, example = "你就说强不强 MQ 骚操作"), - @ApiImplicitParam(name = "cid", value = "分类编号", required = true, example = "反正我是信了"), - @ApiImplicitParam(name = "picUrls", value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn"), - @ApiImplicitParam(name = "visible", value = "是否上架商品(是否可见)", required = true, example = "true"), - @ApiImplicitParam(name = "skuStr", value = "SKU 字符串", required = true, example = "[{\"attrs\": [1,3 ], \"price\": 1, \"quantity\": 100, \"picUrl\": \"http://www.iocoder.cn\"}]"), - }) - public CommonResult update(@RequestParam("id") Integer id, - @RequestParam("name") String name, - @RequestParam("sellPoint") String sellPoint, - @RequestParam("description") String description, - @RequestParam("cid") Integer cid, - @RequestParam("picUrls") List picUrls, - @RequestParam("visible") Boolean visible, - @RequestParam("skuStr") String skuStr) { // TODO 芋艿,因为考虑不使用 json 接受参数,所以这里手动转。 - // 创建 ProductSpuUpdateDTO 对象 - ProductSpuUpdateDTO productSpuUpdateDTO = new ProductSpuUpdateDTO().setId(id).setName(name).setSellPoint(sellPoint) - .setDescription(description).setCid(cid).setPicUrls(picUrls).setVisible(visible) - .setSkus(parseSkus(skuStr, ProductSkuAddOrUpdateDTO.class)); - // 更新商品 - productSpuService.updateProductSpu(AdminSecurityContextHolder.getContext().getAdminId(), productSpuUpdateDTO); - return success(true); - } - @PostMapping("/spu/update_sort") @ApiOperation("更新商品的排序") public CommonResult updateSort(@RequestParam("id") Integer id, @@ -96,39 +36,6 @@ public class AdminsProductSpuController { return success(productSpuService.updateProductSpuSort(AdminSecurityContextHolder.getContext().getAdminId(), id, sort)); } - // TODO 芋艿,删除功能暂时不做。主要原因是,关联的数据太多。删除带来的问题会比较大 - - @GetMapping("/spu/page") - @ApiOperation("商品 SPU 分页列表") - @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "商品名称,模糊匹配", example = "小王"), - @ApiImplicitParam(name = "status", value = "状态", example = "可选值:1-在售中;2-已售罄;3-仓库中;"), - @ApiImplicitParam(name = "cid", value = "商品分类编号", example = "10"), - @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), - }) - public CommonResult spuPage(@RequestParam(value = "name", required = false) String name, - @RequestParam(value = "status") Integer status, - @RequestParam(value = "cid", required = false) Integer cid, - @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, - @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { - // 创建 ProductSpuPageDTO 对象 - ProductSpuPageDTO productSpuPageDTO = new ProductSpuPageDTO().setName(name).setCid(cid).setPageNo(pageNo).setPageSize(pageSize); - switch (status) { - case 1: - productSpuPageDTO.setVisible(true).setHasQuantity(true); - break; - case 2: - productSpuPageDTO.setVisible(true).setHasQuantity(false); - break; - case 3: - productSpuPageDTO.setVisible(false); - break; - } - ProductSpuPageBO result = productSpuService.getProductSpuPage(productSpuPageDTO); - return success(ProductSpuConvert.INSTANCE.convert2(result)); - } - @GetMapping("/spu/search_list") @ApiOperation("商品 SPU 搜索列表") @ApiImplicitParams({