优化商品索引,如数据库中无当前商品则删除商品索引

This commit is contained in:
paulGao
2022-06-22 18:42:04 +08:00
parent f01236cc96
commit 1a221eefe3
2 changed files with 7 additions and 7 deletions

View File

@@ -32,7 +32,6 @@ import cn.lili.modules.promotion.service.PromotionGoodsService;
import cn.lili.modules.promotion.service.PromotionService;
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
import cn.lili.modules.search.service.EsGoodsIndexService;
import cn.lili.modules.store.service.StoreService;
import cn.lili.rocketmq.tags.GoodsTagsEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
@@ -204,13 +203,8 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
try {
String goodsIdsJsonStr = new String(messageExt.getBody());
for (String goodsId : JSONUtil.toList(goodsIdsJsonStr, String.class)) {
Goods goodsById = this.goodsService.getById(goodsId);
if (goodsById != null) {
this.deleteGoods(goodsById);
goodsIndexService.deleteIndex(MapUtil.builder(new HashMap<String, Object>()).put("goodsId", goodsId).build());
}
goodsIndexService.deleteIndex(MapUtil.builder(new HashMap<String, Object>()).put("goodsId", goodsId).build());
}
} catch (Exception e) {
log.error("删除商品索引事件执行异常,商品信息: " + new String(messageExt.getBody()), e);
}
@@ -451,6 +445,7 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
distributionGoodsService.removeById(distributionGoods.getId());
}
}
/**
* 商品购买完成
* 1.更新商品购买数量