From dfd25c151669a41996204016b7bc658c15811e1c Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Wed, 5 Aug 2020 00:21:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20search=20=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=20dev=20dubbo=20=E9=85=8D=E7=BD=AE=20?= =?UTF-8?q?=E5=AE=8C=E6=88=90=20product=20=E8=AF=A6=E6=83=85=20rest=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/config/MQStreamConfiguration.java | 10 --- .../users/UsersProductAttrAndValuePairVO.java | 22 ------- .../vo/users/UsersProductSkuDetailVO.java | 29 --------- .../vo/users/UsersProductSpuDetailVO.java | 37 ----------- .../rpc/spu/dto/ProductSpuDetailRespDTO.java | 3 - .../src/main/resources/application-dev.yaml | 3 +- .../product/ProductSpuController.java | 8 +++ .../vo/attr/ProductAttrKeyValueRespVO.java | 22 +++++++ .../vo/product/ProductSpuDetailRespVO.java | 61 +++++++++++++++++++ .../product/vo/product/ProductSpuRespVO.java | 2 +- .../convert/product/ProductSpuConvert.java | 4 ++ .../manager/product/ProductSpuManager.java | 15 +++++ .../src/main/resources/application.yml | 2 + 13 files changed, 115 insertions(+), 103 deletions(-) delete mode 100644 moved/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/config/MQStreamConfiguration.java delete mode 100644 moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductAttrAndValuePairVO.java delete mode 100644 moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSkuDetailVO.java delete mode 100644 moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuDetailVO.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/attr/ProductAttrKeyValueRespVO.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/product/ProductSpuDetailRespVO.java diff --git a/moved/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/config/MQStreamConfiguration.java b/moved/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/config/MQStreamConfiguration.java deleted file mode 100644 index a80ffadd..00000000 --- a/moved/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/config/MQStreamConfiguration.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.mall.product.biz.config; - -import cn.iocoder.mall.product.biz.message.MQStreamProducer; -import org.springframework.cloud.stream.annotation.EnableBinding; -import org.springframework.context.annotation.Configuration; - -@Configuration -@EnableBinding(MQStreamProducer.class) -public class MQStreamConfiguration { -} diff --git a/moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductAttrAndValuePairVO.java b/moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductAttrAndValuePairVO.java deleted file mode 100644 index 2902980b..00000000 --- a/moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductAttrAndValuePairVO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.mall.product.application.vo.users; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -@ApiModel(value = "商品规格属性和值对 VO") -@Data -@Accessors(chain = true) -public class UsersProductAttrAndValuePairVO { - - @ApiModelProperty(value = "规格编号", required = true, example = "1") - private Integer attrId; - @ApiModelProperty(value = "规格名", required = true, example = "颜色") - private String attrName; - @ApiModelProperty(value = "规格值", required = true, example = "10") - private Integer attrValueId; - @ApiModelProperty(value = "规格值名", required = true, example = "红色") - private String attrValueName; - -} diff --git a/moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSkuDetailVO.java b/moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSkuDetailVO.java deleted file mode 100644 index 338209ff..00000000 --- a/moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSkuDetailVO.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.mall.product.application.vo.users; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.List; - -/** - * 商品 Sku 明细 BO - */ -@Data -@Accessors(chain = true) -public class UsersProductSkuDetailVO { - - @ApiModelProperty(value = "sku 编号", required = true, example = "1") - private Integer id; - @ApiModelProperty(value = "SPU 编号", required = true, example = "1") - private Integer spuId; - @ApiModelProperty(value = "图片地址", required = true, example = "http://www.iocoder.cn") - private String picURL; - @ApiModelProperty(value = "规格值数组", required = true) - private List attrs; - @ApiModelProperty(value = "价格,单位:分", required = true, example = "100") - private Integer price; - @ApiModelProperty(value = "库存数量", required = true, example = "100") - private Integer quantity; - -} diff --git a/moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuDetailVO.java b/moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuDetailVO.java deleted file mode 100644 index 1d56f802..00000000 --- a/moved/product/product-start/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuDetailVO.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.mall.product.application.vo.users; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.List; - -@ApiModel(value = "商品 SPU 详细 VO", description = "包括 SKU 信息 VO") -@Data -@Accessors(chain = true) -public class UsersProductSpuDetailVO { - - @ApiModelProperty(value = "SPU 编号", required = true, example = "1") - private Integer id; - - // ========== 基本信息 ========= - @ApiModelProperty(value = "SPU 名字", required = true, example = "厮大牛逼") - private String name; - @ApiModelProperty(value = "卖点", required = true, example = "各种 MQ 骚操作") - private String sellPoint; - @ApiModelProperty(value = "描述", required = true, example = "你就说强不强") - private String description; - @ApiModelProperty(value = "分类编号", required = true, example = "反正我是信了") - private Integer cid; - @ApiModelProperty(value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn") - private List picUrls; - - // ========== SKU ========= - - /** - * SKU 数组 - */ - private List skus; - -} diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuDetailRespDTO.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuDetailRespDTO.java index a8b3f440..1dfbee6c 100644 --- a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuDetailRespDTO.java +++ b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuDetailRespDTO.java @@ -76,9 +76,6 @@ public class ProductSpuDetailRespDTO implements Serializable { @Accessors(chain = true) public static class Sku implements Serializable { - /** - * sku 编号 - */ private Integer id; /** * 商品编号 diff --git a/search-service-project/search-service-app/src/main/resources/application-dev.yaml b/search-service-project/search-service-app/src/main/resources/application-dev.yaml index 4cfe1567..2e26cd38 100644 --- a/search-service-project/search-service-app/src/main/resources/application-dev.yaml +++ b/search-service-project/search-service-app/src/main/resources/application-dev.yaml @@ -11,4 +11,5 @@ spring: dubbo: # Dubbo 注册中心 registry: - address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 + # address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 + address: nacos://400-infra.server.iocoder.cn:8848?namespace=dev # 指定 Dubbo 服务注册中心的地址 diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSpuController.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSpuController.java index 146a6243..b7fdc072 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSpuController.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSpuController.java @@ -2,6 +2,7 @@ package cn.iocoder.mall.shopweb.controller.product; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuDetailRespVO; import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuPageReqVO; import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO; import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuSearchConditionRespVO; @@ -41,4 +42,11 @@ public class ProductSpuController { return success(productSpuManager.getProductSpuSearchCondition(keyword)); } + @GetMapping("/get_detail") + @ApiOperation("获得商品 SPU 的明细,包括 SKU 等等信息") + @ApiImplicitParam(name = "id", required = true, value = "商品 SPU 编号", example = "1024") + public CommonResult getProductSpuDetail(@RequestParam("id") Integer id) { + return success(productSpuManager.getProductSpuDetail(id)); + } + } diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/attr/ProductAttrKeyValueRespVO.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/attr/ProductAttrKeyValueRespVO.java new file mode 100644 index 00000000..ece6087b --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/attr/ProductAttrKeyValueRespVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.shopweb.controller.product.vo.attr; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +@ApiModel(value = "商品规格 KEY + VALUE 对的 Response VO") +@Data +@Accessors(chain = true) +public class ProductAttrKeyValueRespVO { + + @ApiModelProperty(value = "规格 KEY 编号", required = true, example = "1") + private Integer attrKeyId; + @ApiModelProperty(value = "规格 KEY 名字", required = true, example = "颜色") + private String attrKeyName; + @ApiModelProperty(value = "规格 VALUE 值", required = true, example = "10") + private Integer attrValueId; + @ApiModelProperty(value = "规格 VALUE 名字", required = true, example = "红色") + private String attrValueName; + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/product/ProductSpuDetailRespVO.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/product/ProductSpuDetailRespVO.java new file mode 100644 index 00000000..f07a0629 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/product/ProductSpuDetailRespVO.java @@ -0,0 +1,61 @@ +package cn.iocoder.mall.shopweb.controller.product.vo.product; + +import cn.iocoder.mall.shopweb.controller.product.vo.attr.ProductAttrKeyValueRespVO; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.List; + +@ApiModel(value = "商品 SPU 详细 Response VO", description = "包括 SKU 信息 VO") +@Data +@Accessors(chain = true) +public class ProductSpuDetailRespVO { + + @ApiModelProperty(value = "SPU 编号", required = true, example = "1") + private Integer id; + + // ========== 基本信息 ========= + @ApiModelProperty(value = "SPU 名字", required = true, example = "芋艿") + private String name; + @ApiModelProperty(value = "卖点", required = true, example = "好吃好玩") + private String sellPoint; + @ApiModelProperty(value = "描述", required = true, example = "我是哈哈哈") + private String description; + @ApiModelProperty(value = "分类编号", required = true, example = "1") + private Integer cid; + @ApiModelProperty(value = "商品主图地址", required = true, example = "http://www.iocoder.cn/xxx.jpg", notes = "多个之间,使用逗号分隔") + private List picUrls; + + // ========== SKU ========= + + /** + * SKU 数组 + */ + private List skus; + + @ApiModel("商品 SKU 详细 Response VO") + @Data + @Accessors(chain = true) + public static class Sku implements Serializable { + + @ApiModelProperty(value = "sku 编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "SPU 编号", required = true, example = "1") + private Integer spuId; + @ApiModelProperty(value = "图片地址", required = true, example = "http://www.iocoder.cn") + private String picURL; + /** + * 规格值数组 + */ + private List attrs; + @ApiModelProperty(value = "价格,单位:分", required = true, example = "100") + private Integer price; + @ApiModelProperty(value = "库存数量", required = true, example = "100") + private Integer quantity; + + } + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/product/ProductSpuRespVO.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/product/ProductSpuRespVO.java index a728f3b3..aa1c824e 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/product/ProductSpuRespVO.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/product/ProductSpuRespVO.java @@ -12,7 +12,7 @@ import java.util.List; @Accessors(chain = true) public class ProductSpuRespVO { - @ApiModelProperty(value = "SPU 编号", required = true) + @ApiModelProperty(value = "SPU 编号", required = true, example = "1") private Integer id; // ========== 基本信息 ========= diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/product/ProductSpuConvert.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/product/ProductSpuConvert.java index 552048f6..976b763b 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/product/ProductSpuConvert.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/product/ProductSpuConvert.java @@ -4,8 +4,10 @@ import cn.iocoder.common.framework.util.StringUtils; import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.common.framework.vo.SortingField; import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO; +import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuDetailRespDTO; import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductPageReqDTO; import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO; +import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuDetailRespVO; import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuPageReqVO; import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO; import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuSearchConditionRespVO; @@ -34,4 +36,6 @@ public interface ProductSpuConvert { List convertList(List list); + ProductSpuDetailRespVO convert(ProductSpuDetailRespDTO bean); + } diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/product/ProductSpuManager.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/product/ProductSpuManager.java index 74bc8c48..0330187f 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/product/ProductSpuManager.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/product/ProductSpuManager.java @@ -3,13 +3,17 @@ package cn.iocoder.mall.shopweb.manager.product; import cn.iocoder.common.framework.util.CollectionUtils; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.productservice.enums.spu.ProductSpuDetailFieldEnum; import cn.iocoder.mall.productservice.rpc.category.ProductCategoryRpc; import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO; +import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc; +import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuDetailRespDTO; import cn.iocoder.mall.searchservice.enums.product.SearchProductConditionFieldEnum; import cn.iocoder.mall.searchservice.rpc.product.SearchProductRpc; import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductConditionReqDTO; import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductConditionRespDTO; import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO; +import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuDetailRespVO; import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuPageReqVO; import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO; import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuSearchConditionRespVO; @@ -18,6 +22,7 @@ import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -34,6 +39,9 @@ public class ProductSpuManager { @DubboReference(version = "${dubbo.consumer.ProductCategoryRpc.version}") private ProductCategoryRpc productCategoryRpc; + @DubboReference(version = "${dubbo.consumer.ProductSpuRpc.version}") + private ProductSpuRpc productSpuRpc; + public PageResult pageProductSpu(ProductSpuPageReqVO pageReqVO) { CommonResult> pageResult = searchProductRpc.pageSearchProduct(ProductSpuConvert.INSTANCE.convert(pageReqVO)); @@ -60,4 +68,11 @@ public class ProductSpuManager { return conditionRespVO; } + public ProductSpuDetailRespVO getProductSpuDetail(Integer id) { + CommonResult getProductSpuDetailResult = productSpuRpc.getProductSpuDetail(id, + Arrays.asList(ProductSpuDetailFieldEnum.SKU.getField(), ProductSpuDetailFieldEnum.ATTR.getField())); + getProductSpuDetailResult.checkError(); + return ProductSpuConvert.INSTANCE.convert(getProductSpuDetailResult.getData()); + } + } diff --git a/shop-web-app/src/main/resources/application.yml b/shop-web-app/src/main/resources/application.yml index ad9aadc1..a09b6edc 100644 --- a/shop-web-app/src/main/resources/application.yml +++ b/shop-web-app/src/main/resources/application.yml @@ -35,6 +35,8 @@ dubbo: version: 1.0.0 ProductCategoryRpc: version: 1.0.0 + ProductSpuRpc: + version: 1.0.0 SearchProductRpc: version: 1.0.0