!247 fix: 优化生成商品索引,取消检查库存不为0 优化es商品搜索及es商品特定查询条件的分页

Merge pull request !247 from OceansDeep/feature/pg
This commit is contained in:
OceansDeep 2022-10-24 06:40:33 +00:00 committed by Gitee
commit 0d7b44fe51
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 19 additions and 14 deletions

View File

@ -356,11 +356,8 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
EsGoodsIndex goodsIndex = this.settingUpGoodsIndexData(goods, goodsSku);
goodsIndex.setSkuSource(skuSource--);
log.info("goodsSku{}", goodsSku);
//如果商品库存不为0并且es中有数据
if (goodsSku.getQuantity() > 0) {
log.info("生成商品索引 {}", goodsIndex);
esGoodsIndices.add(goodsIndex);
}
log.info("生成商品索引 {}", goodsIndex);
esGoodsIndices.add(goodsIndex);
}
this.goodsIndexService.deleteIndex(MapUtil.builder(new HashMap<String, Object>()).put("goodsId", goods.getId()).build());
this.goodsIndexService.addIndex(esGoodsIndices);

View File

@ -90,9 +90,7 @@ public class FootprintServiceImpl extends ServiceImpl<FootprintMapper, FootPrint
return esGoodsIndexIPage;
} else {
List<EsGoodsIndex> list = esGoodsSearchService.getEsGoodsBySkuIds(
footPrintPages.getRecords().stream().map(FootPrint::getSkuId).collect(Collectors.toList()));
//去除为空的商品数据
list.removeIf(Objects::isNull);
footPrintPages.getRecords().stream().map(FootPrint::getSkuId).collect(Collectors.toList()), pageVO);
esGoodsIndexIPage.setPages(footPrintPages.getPages());
esGoodsIndexIPage.setRecords(list);

View File

@ -348,7 +348,7 @@ public class CartServiceImpl implements CartService {
if (tradeDTO.getSkuList() != null && !tradeDTO.getSkuList().isEmpty()) {
List<String> ids = tradeDTO.getSkuList().stream().filter(i -> Boolean.TRUE.equals(i.getChecked())).map(i -> i.getGoodsSku().getId()).collect(Collectors.toList());
List<EsGoodsIndex> esGoodsList = esGoodsSearchService.getEsGoodsBySkuIds(ids);
List<EsGoodsIndex> esGoodsList = esGoodsSearchService.getEsGoodsBySkuIds(ids, null);
for (EsGoodsIndex esGoodsIndex : esGoodsList) {
if (esGoodsIndex != null && esGoodsIndex.getPromotionMap() != null && !esGoodsIndex.getPromotionMap().isEmpty()) {
List<String> couponIds = esGoodsIndex.getPromotionMap().keySet().stream().filter(i -> i.contains(PromotionTypeEnum.COUPON.name())).map(i -> i.substring(i.lastIndexOf("-") + 1)).collect(Collectors.toList());

View File

@ -40,7 +40,7 @@ public interface EsGoodsSearchService {
* @param skuIds SkuId列表
* @return ES商品列表
*/
List<EsGoodsIndex> getEsGoodsBySkuIds(List<String> skuIds);
List<EsGoodsIndex> getEsGoodsBySkuIds(List<String> skuIds, PageVO pageVo);
/**
* 根据id获取商品索引

View File

@ -125,10 +125,19 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
}
@Override
public List<EsGoodsIndex> getEsGoodsBySkuIds(List<String> skuIds) {
public List<EsGoodsIndex> getEsGoodsBySkuIds(List<String> skuIds, PageVO pageVo) {
NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder();
NativeSearchQuery build = searchQueryBuilder.build();
build.setIds(skuIds);
if (pageVo != null) {
int pageNumber = pageVo.getPageNumber() - 1;
if (pageNumber < 0) {
pageNumber = 0;
}
Pageable pageable = PageRequest.of(pageNumber, pageVo.getPageSize());
//分页
searchQueryBuilder.withPageable(pageable);
}
return restTemplate.multiGet(build, EsGoodsIndex.class, restTemplate.getIndexCoordinatesFor(EsGoodsIndex.class));
}
@ -404,8 +413,8 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
/**
* 商品推荐
*
* @param filterBuilder
* @param searchDTO
* @param filterBuilder 过滤条件
* @param searchDTO 搜索条件
*/
private void recommended(BoolQueryBuilder filterBuilder, EsGoodsSearchDTO searchDTO) {
@ -565,7 +574,8 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
FunctionScoreQueryBuilder.FilterFunctionBuilder skuNoBuilder = new FunctionScoreQueryBuilder.FilterFunctionBuilder(skuNoScore);
filterFunctionBuilders.add(skuNoBuilder);
FieldValueFactorFunctionBuilder buyCountScore = ScoreFunctionBuilders.fieldValueFactorFunction("buyCount").modifier(FieldValueFactorFunction.Modifier.LOG1P).setWeight(3);
// 修改分数算法为无数字最大分数越高
FieldValueFactorFunctionBuilder buyCountScore = ScoreFunctionBuilders.fieldValueFactorFunction("buyCount").modifier(FieldValueFactorFunction.Modifier.NONE).setWeight(3);
FunctionScoreQueryBuilder.FilterFunctionBuilder buyCountBuilder = new FunctionScoreQueryBuilder.FilterFunctionBuilder(buyCountScore);
filterFunctionBuilders.add(buyCountBuilder);
return filterFunctionBuilders;