Skip to content

Commit

Permalink
完成的商品搜索和条件功能
Browse files Browse the repository at this point in the history
  • Loading branch information
YunaiV committed Aug 4, 2020
1 parent f3316d1 commit b83262a
Show file tree
Hide file tree
Showing 240 changed files with 246 additions and 859 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package cn.iocoder.common.framework.vo;

import java.io.Serializable;

/**
* 排序字段 DTO
*
* 类名加了 ing 的原因是,避免和 ES SortField 重名。
*/
public class SortingField {
public class SortingField implements Serializable {

/**
* 字段
*/
private String field;
/**
* 排序
* 顺序
*/
private String order;

// 空构造方法,解决反序列化
public SortingField() {
}

public SortingField(String field, String order) {
this.field = field;
this.order = order;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryUpdateReqDTO;

import java.util.Collection;
import java.util.List;

/**
Expand Down Expand Up @@ -49,7 +50,7 @@ public interface ProductCategoryRpc {
* @param productCategoryIds 商品分类编号列表
* @return 商品分类列表
*/
CommonResult<List<ProductCategoryRespDTO>> listProductCategories(List<Integer> productCategoryIds);
CommonResult<List<ProductCategoryRespDTO>> listProductCategories(Collection<Integer> productCategoryIds);

/**
* 获得符合条件的商品分类列表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
Expand Down Expand Up @@ -67,7 +68,7 @@ public ProductCategoryRespDTO getProductCategory(Integer productCategoryId) {
* @param productCategoryIds 商品分类编号列表
* @return 商品分类列表
*/
public List<ProductCategoryRespDTO> listProductCategories(List<Integer> productCategoryIds) {
public List<ProductCategoryRespDTO> listProductCategories(Collection<Integer> productCategoryIds) {
List<ProductCategoryBO> productCategoryBOs = productCategoryService.listProductCategories(productCategoryIds);
return ProductCategoryConvert.INSTANCE.convertList02(productCategoryBOs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collection;
import java.util.List;

import static cn.iocoder.common.framework.vo.CommonResult.success;
Expand Down Expand Up @@ -45,7 +46,7 @@ public CommonResult<ProductCategoryRespDTO> getProductCategory(Integer productCa
}

@Override
public CommonResult<List<ProductCategoryRespDTO>> listProductCategories(List<Integer> productCategoryIds) {
public CommonResult<List<ProductCategoryRespDTO>> listProductCategories(Collection<Integer> productCategoryIds) {
return success(productCategoryManager.listProductCategories(productCategoryIds));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.*;
Expand Down Expand Up @@ -102,7 +103,7 @@ public ProductCategoryBO getProductCategory(Integer productCategoryId) {
* @param productCategoryIds 商品分类编号列表
* @return 商品分类列表
*/
public List<ProductCategoryBO> listProductCategories(List<Integer> productCategoryIds) {
public List<ProductCategoryBO> listProductCategories(Collection<Integer> productCategoryIds) {
List<ProductCategoryDO> productCategoryDOs = productCategoryMapper.selectBatchIds(productCategoryIds);
return ProductCategoryConvert.INSTANCE.convertList(productCategoryDOs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public enum SearchProductConditionFieldEnum {
this.field = field;
}

public String getField() {
return field;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
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;

Expand All @@ -10,6 +12,20 @@
*/
public interface SearchProductRpc {

CommonResult<PageResult<SearchProductRespDTO>> pageSearchProduct(SearchProductPageReqDTO pageQueryReqDTO);
/**
* 获得商品搜索分页
*
* @param pageReqDTO 分页请求 DTO
* @return 商品搜索分页结果
*/
CommonResult<PageResult<SearchProductRespDTO>> pageSearchProduct(SearchProductPageReqDTO pageReqDTO);

/**
* 获得商品搜索条件
*
* @param conditionReqDTO 搜索条件 DTO
* @return 搜索条件
*/
CommonResult<SearchProductConditionRespDTO> getSearchProductCondition(SearchProductConditionReqDTO conditionReqDTO);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cn.iocoder.mall.searchservice.rpc.product.dto;

import cn.iocoder.mall.searchservice.enums.product.SearchProductConditionFieldEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Collection;

/**
* 商品搜索条件 Request DTO
*/
@Data
@Accessors(chain = true)
public class SearchProductConditionReqDTO implements Serializable {

/**
* 关键字
*/
private String keyword;
/**
* 需要返回的搜索条件
*
* 可选择的条件,见 {@link SearchProductConditionFieldEnum} 枚举类
*/
private Collection<String> fields;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cn.iocoder.mall.searchservice.rpc.product.dto;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
* 商品搜索条件 Response DTO
*/
@Data
@Accessors(chain = true)
public class SearchProductConditionRespDTO implements Serializable {

/**
* 商品分类数组
*/
private List<Integer> cids;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
* 搜索商品 Response DTO
*/
@Data
@Accessors(chain = true)
public class SearchProductRespDTO {
public class SearchProductRespDTO implements Serializable {

private Integer id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
import cn.iocoder.mall.searchservice.dal.es.dataobject.ESProductDO;
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 cn.iocoder.mall.searchservice.service.product.bo.SearchProductBO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductConditionBO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductPageQueryBO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductSaveBO;
import org.mapstruct.Mapper;
Expand Down Expand Up @@ -37,13 +39,15 @@ public interface SearchProductConvert {

List<SearchProductBO> convertList(List<ESProductDO> list);

default PageResult<SearchProductBO> convertPage(Page<ESProductDO> searchPage) {
return new PageResult<SearchProductBO>().setList(convertList(searchPage.getContent()))
.setTotal(searchPage.getTotalElements());
default PageResult<SearchProductBO> convertPage(Page<ESProductDO> page) {
return new PageResult<SearchProductBO>().setList(convertList(page.getContent()))
.setTotal(page.getTotalElements());
}

SearchProductPageQueryBO convert(SearchProductPageReqDTO bean);

PageResult<SearchProductRespDTO> convertPage(PageResult<SearchProductBO> pageResult);
PageResult<SearchProductRespDTO> convertPage(PageResult<SearchProductBO> page);

SearchProductConditionRespDTO convert(SearchProductConditionBO bean);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
import cn.iocoder.mall.searchservice.convert.product.SearchProductConvert;
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 cn.iocoder.mall.searchservice.service.product.SearchProductService;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductBO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductConditionBO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductSaveBO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
Expand Down Expand Up @@ -48,6 +51,12 @@ public PageResult<SearchProductRespDTO> pageSearchProduct(SearchProductPageReqDT
return SearchProductConvert.INSTANCE.convertPage(pageResult);
}

public SearchProductConditionRespDTO getSearchProductCondition(SearchProductConditionReqDTO conditionReqDTO) {
SearchProductConditionBO conditionBO =
searchProductService.getSearchProductCondition(conditionReqDTO.getKeyword(), conditionReqDTO.getFields());
return SearchProductConvert.INSTANCE.convert(conditionBO);
}

/**
* 重建所有商品的 ES 索引
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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;
Expand All @@ -17,8 +19,13 @@ public class SearchProductRpcImpl implements SearchProductRpc {
private SearchProductManager searchProductManager;

@Override
public CommonResult<PageResult<SearchProductRespDTO>> pageSearchProduct(SearchProductPageReqDTO pageQueryReqDTO) {
return success(searchProductManager.pageSearchProduct(pageQueryReqDTO));
public CommonResult<PageResult<SearchProductRespDTO>> pageSearchProduct(SearchProductPageReqDTO pageReqDTO) {
return success(searchProductManager.pageSearchProduct(pageReqDTO));
}

@Override
public CommonResult<SearchProductConditionRespDTO> getSearchProductCondition(SearchProductConditionReqDTO conditionReqDTO) {
return success(searchProductManager.getSearchProductCondition(conditionReqDTO));
}

}
37 changes: 0 additions & 37 deletions search/pom.xml

This file was deleted.

42 changes: 0 additions & 42 deletions search/search-rest/pom.xml

This file was deleted.

Loading

0 comments on commit b83262a

Please sign in to comment.