From 5e1eb3e03b93341360da861444b22c34e8d225c2 Mon Sep 17 00:00:00 2001 From: paulGao Date: Wed, 29 Dec 2021 19:48:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E4=BF=83=E9=94=80=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=83=A8=E5=88=86=E5=AD=97=E6=AE=B5=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E6=9B=B4=E6=96=B0=E3=80=82=E4=B8=8D=E5=9C=A8?= =?UTF-8?q?=E4=BB=A5=E5=88=B7=E6=96=B0=E7=B4=A2=E5=BC=95=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E6=9B=B4=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/lili/listener/GoodsMessageListener.java | 3 +-- .../serviceimpl/EsGoodsIndexServiceImpl.java | 16 +++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java index f7a369b0..69dfb622 100644 --- a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java +++ b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java @@ -2,7 +2,6 @@ package cn.lili.listener; import cn.hutool.core.map.MapUtil; import cn.hutool.core.text.CharSequenceUtil; -import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ClassLoaderUtil; import cn.hutool.json.JSONObject; @@ -141,7 +140,7 @@ public class GoodsMessageListener implements RocketMQListener { } break; case UPDATE_GOODS_INDEX_PROMOTIONS: - ThreadUtil.execAsync(() -> this.updateGoodsIndexPromotions(new String(messageExt.getBody()))); + this.updateGoodsIndexPromotions(new String(messageExt.getBody())); break; case DELETE_GOODS_INDEX_PROMOTIONS: BasePromotions promotions = JSONUtil.toBean(new String(messageExt.getBody()), BasePromotions.class); 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 67040823..629ae01a 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 @@ -619,7 +619,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements /** * 以更新部分字段的方式更新索引促销信息 * - * @param id 索引id + * @param id 索引id * @param promotionMap 促销信息 */ private void updatePromotionsByScript(String id, Map promotionMap) { @@ -628,10 +628,16 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements String s = jsonObject.toString(); String promotionsStr = s.replace("{", "[").replace("}", "]"); - UpdateByQueryRequest update = new UpdateByQueryRequest(getIndexName()); - update.setQuery(QueryBuilders.boolQuery().filter(QueryBuilders.termsQuery("id", id))); - update.setScript(new Script("ctx._source." + "promotionMap" + "=" + promotionsStr + ";")); - client.updateByQueryAsync(update, RequestOptions.DEFAULT, this.actionListener()); + UpdateRequest updateRequest = new UpdateRequest(); + updateRequest.index(getIndexName()); + updateRequest.id(id); + updateRequest.retryOnConflict(5); + updateRequest.script(new Script("ctx._source." + "promotionMap" + "=" + promotionsStr + ";")); + try { + client.update(updateRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + log.error("更新商品索引促销信息错误", e); + } } /**