From b5480816ef3de11bef410ac0d64ea52b5b0c5283 Mon Sep 17 00:00:00 2001 From: zhuyang <1qazxsw2> Date: Sat, 9 Oct 2021 21:49:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mall-dependencies/pom.xml | 7 +++ .../product-service-api/pom.xml | 1 - .../search-service-api/pom.xml | 4 ++ ...roductRpc.java => SearchProductFeign.java} | 21 +++++--- .../search-service-app/pom.xml | 4 ++ .../controller/SearchProductController.java | 54 +++++++++++++++++++ .../rpc/product/SearchProductRpcImpl.java | 31 ----------- .../mall/shopweb/ShopWebApplication.java | 2 +- .../service/product/ProductSpuManager.java | 12 ++--- 9 files changed, 90 insertions(+), 46 deletions(-) rename search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/product/{SearchProductRpc.java => SearchProductFeign.java} (60%) create mode 100644 search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/controller/SearchProductController.java delete mode 100644 search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/rpc/product/SearchProductRpcImpl.java diff --git a/mall-dependencies/pom.xml b/mall-dependencies/pom.xml index 7e29514c7..7b1953d1c 100644 --- a/mall-dependencies/pom.xml +++ b/mall-dependencies/pom.xml @@ -64,6 +64,7 @@ 27.0.1-jre 1.16.14 1.3.0.Final + 3.0.4 @@ -381,6 +382,12 @@ ${hibernate-validator.version} + + org.springframework.cloud + spring-cloud-openfeign-core + ${spring-cloud.feign.version} + + diff --git a/product-service-project/product-service-api/pom.xml b/product-service-project/product-service-api/pom.xml index 1cbc81a0c..9e48aed2e 100644 --- a/product-service-project/product-service-api/pom.xml +++ b/product-service-project/product-service-api/pom.xml @@ -29,7 +29,6 @@ org.springframework.cloud spring-cloud-openfeign-core - RELEASE diff --git a/search-service-project/search-service-api/pom.xml b/search-service-project/search-service-api/pom.xml index 7df14779d..07f7d26c7 100644 --- a/search-service-project/search-service-api/pom.xml +++ b/search-service-project/search-service-api/pom.xml @@ -26,6 +26,10 @@ org.projectlombok lombok + + org.springframework.cloud + spring-cloud-openfeign-core + diff --git a/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/product/SearchProductRpc.java b/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/product/SearchProductFeign.java similarity index 60% rename from search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/product/SearchProductRpc.java rename to search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/product/SearchProductFeign.java index c2ecc7ec6..bbf7aa249 100644 --- a/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/product/SearchProductRpc.java +++ b/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/product/SearchProductFeign.java @@ -6,19 +6,28 @@ import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductConditionReqDT import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductConditionRespDTO; import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductPageReqDTO; import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; /** - * 商品搜索 RPC 接口 + * Title: + * Description: + * + * @author zhuyang + * @version 1.0 2021/10/9 */ -public interface SearchProductRpc { - +@FeignClient(value = "search-service") +public interface SearchProductFeign { /** * 获得商品搜索分页 * * @param pageReqDTO 分页请求 DTO * @return 商品搜索分页结果 */ - CommonResult> pageSearchProduct(SearchProductPageReqDTO pageReqDTO); + @PostMapping("/search/product//pageSearchProduct") + CommonResult> pageSearchProduct(@RequestBody SearchProductPageReqDTO pageReqDTO); + /** * 获得商品搜索条件 @@ -26,6 +35,6 @@ public interface SearchProductRpc { * @param conditionReqDTO 搜索条件 DTO * @return 搜索条件 */ - CommonResult getSearchProductCondition(SearchProductConditionReqDTO conditionReqDTO); - + @PostMapping("/search/product/getSearchProductCondition") + CommonResult getSearchProductCondition(@RequestBody SearchProductConditionReqDTO conditionReqDTO); } diff --git a/search-service-project/search-service-app/pom.xml b/search-service-project/search-service-app/pom.xml index 45b0bbb42..71ff669e6 100644 --- a/search-service-project/search-service-app/pom.xml +++ b/search-service-project/search-service-app/pom.xml @@ -105,6 +105,10 @@ org.springframework.cloud spring-cloud-starter-openfeign + + io.swagger + swagger-annotations + diff --git a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/controller/SearchProductController.java b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/controller/SearchProductController.java new file mode 100644 index 000000000..864523634 --- /dev/null +++ b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/controller/SearchProductController.java @@ -0,0 +1,54 @@ +package cn.iocoder.mall.searchservice.controller; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.searchservice.manager.product.SearchProductManager; +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.SearchProductPageReqDTO; +import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** + * Title: + * Description: + * + * @author zhuyang + * @version 1.0 2021/10/9 + */ +@RestController +@RequestMapping("/search/product") +@Api("商品搜索") +public class SearchProductController { + @Autowired + private SearchProductManager searchProductManager; + /** + * 获得商品搜索分页 + * + * @param pageReqDTO 分页请求 DTO + * @return 商品搜索分页结果 + */ + @PostMapping("/pageSearchProduct") + CommonResult> pageSearchProduct(@RequestBody SearchProductPageReqDTO pageReqDTO){ + return success(searchProductManager.pageSearchProduct(pageReqDTO)); + } + + /** + * 获得商品搜索条件 + * + * @param conditionReqDTO 搜索条件 DTO + * @return 搜索条件 + */ + @PostMapping("/getSearchProductCondition") + CommonResult getSearchProductCondition(@RequestBody SearchProductConditionReqDTO conditionReqDTO){ + return success(searchProductManager.getSearchProductCondition(conditionReqDTO)); + } + +} diff --git a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/rpc/product/SearchProductRpcImpl.java b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/rpc/product/SearchProductRpcImpl.java deleted file mode 100644 index 897a57fb7..000000000 --- a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/rpc/product/SearchProductRpcImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.mall.searchservice.rpc.product; - -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.common.framework.vo.PageResult; -import cn.iocoder.mall.searchservice.manager.product.SearchProductManager; -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.SearchProductPageReqDTO; -import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO; -import org.apache.dubbo.config.annotation.DubboService; -import org.springframework.beans.factory.annotation.Autowired; - -import static cn.iocoder.common.framework.vo.CommonResult.success; - -@DubboService -public class SearchProductRpcImpl implements SearchProductRpc { - - @Autowired - private SearchProductManager searchProductManager; - - @Override - public CommonResult> pageSearchProduct(SearchProductPageReqDTO pageReqDTO) { - return success(searchProductManager.pageSearchProduct(pageReqDTO)); - } - - @Override - public CommonResult getSearchProductCondition(SearchProductConditionReqDTO conditionReqDTO) { - return success(searchProductManager.getSearchProductCondition(conditionReqDTO)); - } - -} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java index ec1fbd429..b72ad2964 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java @@ -7,7 +7,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication @EnableDiscoveryClient -@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc"}) +@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc","cn.iocoder.mall.searchservice.rpc"}) public class ShopWebApplication { public static void main(String[] args) { diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/product/ProductSpuManager.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/product/ProductSpuManager.java index b8d44c3ee..574905c38 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/product/ProductSpuManager.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/product/ProductSpuManager.java @@ -9,7 +9,7 @@ import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO; import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign; 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.SearchProductFeign; 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; @@ -18,7 +18,6 @@ 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; import cn.iocoder.mall.shopweb.convert.product.ProductSpuConvert; -import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -34,9 +33,8 @@ import java.util.List; @Validated public class ProductSpuManager { - @DubboReference(version = "${dubbo.consumer.SearchProductRpc.version}") - private SearchProductRpc searchProductRpc; - + @Autowired + private SearchProductFeign searchProductFeign; @Autowired private ProductCategoryFeign productCategoryFeign; @@ -45,7 +43,7 @@ public class ProductSpuManager { public PageResult pageProductSpu(ProductSpuPageReqVO pageReqVO) { CommonResult> pageResult = - searchProductRpc.pageSearchProduct(ProductSpuConvert.INSTANCE.convert(pageReqVO)); + searchProductFeign.pageSearchProduct(ProductSpuConvert.INSTANCE.convert(pageReqVO)); pageResult.checkError(); return ProductSpuConvert.INSTANCE.convertPage(pageResult.getData()); } @@ -53,7 +51,7 @@ public class ProductSpuManager { public ProductSpuSearchConditionRespVO getProductSpuSearchCondition(String keyword) { // 获得搜索条件 CommonResult getSearchProductConditionResult = - searchProductRpc.getSearchProductCondition(new SearchProductConditionReqDTO().setKeyword(keyword) + searchProductFeign.getSearchProductCondition(new SearchProductConditionReqDTO().setKeyword(keyword) .setFields(Collections.singletonList(SearchProductConditionFieldEnum.CATEGORY.getField()))); getSearchProductConditionResult.checkError(); // 拼接结果