From 210d56447c0e0d79a8fce43498b1fa4f75fd928b Mon Sep 17 00:00:00 2001 From: paulGao Date: Wed, 30 Mar 2022 17:21:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E5=95=86=E5=93=81=E7=B4=A2=E5=BC=95=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/EsGoodsIndexServiceImpl.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java index b249984e..8ae29f80 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java @@ -431,24 +431,26 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements */ @Override public void updateEsGoodsIndexAllByList(BasePromotions promotion, String key) { - List goodsIndices = new ArrayList<>(); - //如果storeId不为空,则表示是店铺活动 - if (promotion.getStoreId() != null && !promotion.getStoreId().equals(PromotionTools.PLATFORM_ID)) { - EsGoodsSearchDTO searchDTO = new EsGoodsSearchDTO(); - searchDTO.setStoreId(promotion.getStoreId()); - //查询出店铺商品 - SearchPage esGoodsIndices = goodsSearchService.searchGoods(searchDTO, null); - for (SearchHit searchHit : esGoodsIndices.getContent()) { - goodsIndices.add(searchHit.getContent()); + ThreadUtil.execAsync(() -> { + List goodsIndices = new ArrayList<>(); + //如果storeId不为空,则表示是店铺活动 + if (promotion.getStoreId() != null && !promotion.getStoreId().equals(PromotionTools.PLATFORM_ID)) { + EsGoodsSearchDTO searchDTO = new EsGoodsSearchDTO(); + searchDTO.setStoreId(promotion.getStoreId()); + //查询出店铺商品 + SearchPage esGoodsIndices = goodsSearchService.searchGoods(searchDTO, null); + for (SearchHit searchHit : esGoodsIndices.getContent()) { + goodsIndices.add(searchHit.getContent()); + } + } else { + //否则是平台活动 + Iterable all = goodsIndexRepository.findAll(); + //查询出全部商品 + goodsIndices = new ArrayList<>(IterableUtil.toCollection(all)); } - } else { - //否则是平台活动 - Iterable all = goodsIndexRepository.findAll(); - //查询出全部商品 - goodsIndices = new ArrayList<>(IterableUtil.toCollection(all)); - } - List skuIds = goodsIndices.stream().map(EsGoodsIndex::getId).collect(Collectors.toList()); - this.updateEsGoodsIndexPromotions(skuIds, promotion, key); + List skuIds = goodsIndices.stream().map(EsGoodsIndex::getId).collect(Collectors.toList()); + this.updateEsGoodsIndexPromotions(skuIds, promotion, key); + }); } @Override @@ -482,14 +484,16 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements */ @Override public void deleteEsGoodsPromotionByPromotionKey(String promotionsKey) { - BulkRequest bulkRequest = new BulkRequest(); - for (EsGoodsIndex goodsIndex : this.goodsIndexRepository.findAll()) { - UpdateRequest updateRequest = this.removePromotionByPromotionKey(goodsIndex, promotionsKey); - if (updateRequest != null) { - bulkRequest.add(updateRequest); + ThreadUtil.execAsync(() -> { + BulkRequest bulkRequest = new BulkRequest(); + for (EsGoodsIndex goodsIndex : this.goodsIndexRepository.findAll()) { + UpdateRequest updateRequest = this.removePromotionByPromotionKey(goodsIndex, promotionsKey); + if (updateRequest != null) { + bulkRequest.add(updateRequest); + } } - } - this.executeBulkUpdateRequest(bulkRequest); + this.executeBulkUpdateRequest(bulkRequest); + }); } /**