优化商品索引,如数据库中无当前商品则删除商品索引
This commit is contained in:
parent
f01236cc96
commit
1a221eefe3
@ -32,7 +32,6 @@ import cn.lili.modules.promotion.service.PromotionGoodsService;
|
|||||||
import cn.lili.modules.promotion.service.PromotionService;
|
import cn.lili.modules.promotion.service.PromotionService;
|
||||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||||
import cn.lili.modules.search.service.EsGoodsIndexService;
|
import cn.lili.modules.search.service.EsGoodsIndexService;
|
||||||
import cn.lili.modules.store.service.StoreService;
|
|
||||||
import cn.lili.rocketmq.tags.GoodsTagsEnum;
|
import cn.lili.rocketmq.tags.GoodsTagsEnum;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.rocketmq.common.message.MessageExt;
|
import org.apache.rocketmq.common.message.MessageExt;
|
||||||
@ -204,13 +203,8 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
try {
|
try {
|
||||||
String goodsIdsJsonStr = new String(messageExt.getBody());
|
String goodsIdsJsonStr = new String(messageExt.getBody());
|
||||||
for (String goodsId : JSONUtil.toList(goodsIdsJsonStr, String.class)) {
|
for (String goodsId : JSONUtil.toList(goodsIdsJsonStr, String.class)) {
|
||||||
Goods goodsById = this.goodsService.getById(goodsId);
|
goodsIndexService.deleteIndex(MapUtil.builder(new HashMap<String, Object>()).put("goodsId", goodsId).build());
|
||||||
if (goodsById != null) {
|
|
||||||
this.deleteGoods(goodsById);
|
|
||||||
goodsIndexService.deleteIndex(MapUtil.builder(new HashMap<String, Object>()).put("goodsId", goodsId).build());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("删除商品索引事件执行异常,商品信息: " + new String(messageExt.getBody()), e);
|
log.error("删除商品索引事件执行异常,商品信息: " + new String(messageExt.getBody()), e);
|
||||||
}
|
}
|
||||||
@ -451,6 +445,7 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
distributionGoodsService.removeById(distributionGoods.getId());
|
distributionGoodsService.removeById(distributionGoods.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品购买完成
|
* 商品购买完成
|
||||||
* 1.更新商品购买数量
|
* 1.更新商品购买数量
|
||||||
|
@ -250,11 +250,16 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
GoodsSku goodsSku = this.getGoodsSkuByIdFromCache(skuId);
|
GoodsSku goodsSku = this.getGoodsSkuByIdFromCache(skuId);
|
||||||
//如果使用商品ID无法查询SKU则返回错误
|
//如果使用商品ID无法查询SKU则返回错误
|
||||||
if (goodsVO == null || goodsSku == null) {
|
if (goodsVO == null || goodsSku == null) {
|
||||||
|
//发送mq消息
|
||||||
|
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name();
|
||||||
|
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsId)), RocketmqSendCallbackBuilder.commonCallback());
|
||||||
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
|
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
//商品下架||商品未审核通过||商品删除,则提示:商品已下架
|
//商品下架||商品未审核通过||商品删除,则提示:商品已下架
|
||||||
if (GoodsStatusEnum.DOWN.name().equals(goodsVO.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goodsVO.getAuthFlag()) || Boolean.TRUE.equals(goodsVO.getDeleteFlag())) {
|
if (GoodsStatusEnum.DOWN.name().equals(goodsVO.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goodsVO.getAuthFlag()) || Boolean.TRUE.equals(goodsVO.getDeleteFlag())) {
|
||||||
|
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name();
|
||||||
|
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsId)), RocketmqSendCallbackBuilder.commonCallback());
|
||||||
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
|
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user