搜索改造
parent
53a33e4999
commit
b5480816ef
|
@ -64,6 +64,7 @@
|
|||
<guava.version>27.0.1-jre</guava.version>
|
||||
<org.projectlombok.version>1.16.14</org.projectlombok.version>
|
||||
<org.mapstruct.version>1.3.0.Final</org.mapstruct.version>
|
||||
<spring-cloud.feign.version>3.0.4</spring-cloud.feign.version>
|
||||
</properties>
|
||||
|
||||
<!-- 依赖管理 -->
|
||||
|
@ -381,6 +382,12 @@
|
|||
<version>${hibernate-validator.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||
<version>${spring-cloud.feign.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||
<version>RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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<PageResult<SearchProductRespDTO>> pageSearchProduct(SearchProductPageReqDTO pageReqDTO);
|
||||
@PostMapping("/search/product//pageSearchProduct")
|
||||
CommonResult<PageResult<SearchProductRespDTO>> pageSearchProduct(@RequestBody SearchProductPageReqDTO pageReqDTO);
|
||||
|
||||
|
||||
/**
|
||||
* 获得商品搜索条件
|
||||
|
@ -26,6 +35,6 @@ public interface SearchProductRpc {
|
|||
* @param conditionReqDTO 搜索条件 DTO
|
||||
* @return 搜索条件
|
||||
*/
|
||||
CommonResult<SearchProductConditionRespDTO> getSearchProductCondition(SearchProductConditionReqDTO conditionReqDTO);
|
||||
|
||||
@PostMapping("/search/product/getSearchProductCondition")
|
||||
CommonResult<SearchProductConditionRespDTO> getSearchProductCondition(@RequestBody SearchProductConditionReqDTO conditionReqDTO);
|
||||
}
|
|
@ -105,6 +105,10 @@
|
|||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -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<PageResult<SearchProductRespDTO>> pageSearchProduct(@RequestBody SearchProductPageReqDTO pageReqDTO){
|
||||
return success(searchProductManager.pageSearchProduct(pageReqDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品搜索条件
|
||||
*
|
||||
* @param conditionReqDTO 搜索条件 DTO
|
||||
* @return 搜索条件
|
||||
*/
|
||||
@PostMapping("/getSearchProductCondition")
|
||||
CommonResult<SearchProductConditionRespDTO> getSearchProductCondition(@RequestBody SearchProductConditionReqDTO conditionReqDTO){
|
||||
return success(searchProductManager.getSearchProductCondition(conditionReqDTO));
|
||||
}
|
||||
|
||||
}
|
|
@ -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<PageResult<SearchProductRespDTO>> pageSearchProduct(SearchProductPageReqDTO pageReqDTO) {
|
||||
return success(searchProductManager.pageSearchProduct(pageReqDTO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<SearchProductConditionRespDTO> getSearchProductCondition(SearchProductConditionReqDTO conditionReqDTO) {
|
||||
return success(searchProductManager.getSearchProductCondition(conditionReqDTO));
|
||||
}
|
||||
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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<ProductSpuRespVO> pageProductSpu(ProductSpuPageReqVO pageReqVO) {
|
||||
CommonResult<PageResult<SearchProductRespDTO>> 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<SearchProductConditionRespDTO> getSearchProductConditionResult =
|
||||
searchProductRpc.getSearchProductCondition(new SearchProductConditionReqDTO().setKeyword(keyword)
|
||||
searchProductFeign.getSearchProductCondition(new SearchProductConditionReqDTO().setKeyword(keyword)
|
||||
.setFields(Collections.singletonList(SearchProductConditionFieldEnum.CATEGORY.getField())));
|
||||
getSearchProductConditionResult.checkError();
|
||||
// 拼接结果
|
||||
|
|
Loading…
Reference in New Issue