!109 优化生成索引

Merge pull request !109 from OceansDeep/feature/pg
This commit is contained in:
OceansDeep 2022-01-07 10:24:02 +00:00 committed by Gitee
commit 5d96d434d6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 27 additions and 17 deletions

View File

@ -312,6 +312,8 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
GoodsSearchParams searchParams = new GoodsSearchParams();
searchParams.setGoodsId(goods.getId());
List<GoodsSku> goodsSkuList = this.goodsSkuService.getGoodsSkuByList(searchParams);
log.info("goods{}", goods);
log.info("goodsSkuList{}", goodsSkuList);
if (goods.getAuthFlag().equals(GoodsAuthEnum.PASS.name())
&& goods.getMarketEnable().equals(GoodsStatusEnum.UPPER.name())
&& Boolean.FALSE.equals(goods.getDeleteFlag())) {
@ -340,6 +342,8 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
EsGoodsIndex esGoodsOld = goodsIndexService.findById(goodsSku.getId());
EsGoodsIndex goodsIndex = this.settingUpGoodsIndexData(goods, goodsSku);
goodsIndex.setSkuSource(skuSource--);
log.info("goodsSku{}", goodsSku);
log.info("esGoodsOld{}", esGoodsOld);
//如果商品库存不为0并且es中有数据
if (goodsSku.getQuantity() > 0 && esGoodsOld == null) {
log.info("生成商品索引 {}", goodsIndex);

View File

@ -3,7 +3,6 @@ package cn.lili.modules.goods.serviceimpl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
@ -123,7 +122,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
}
this.updateStock(newSkuList);
generateEs(goods);
if (!newSkuList.isEmpty()) {
generateEs(goods);
}
}
@Override
@ -140,9 +141,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
//删除旧索引
for (GoodsSkuVO goodsSkuVO : goodsListByGoodsId) {
oldSkuIds.add(goodsSkuVO.getId());
goodsIndexService.deleteIndexById(goodsSkuVO.getId());
cache.remove(GoodsSkuService.getCacheKeys(goodsSkuVO.getId()));
}
goodsIndexService.deleteIndexByIds(oldSkuIds);
this.removeByIds(oldSkuIds);
//删除sku相册
goodsGalleryService.removeByIds(oldSkuIds);
@ -170,7 +171,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
this.updateBatchById(newSkuList);
}
this.updateStock(newSkuList);
generateEs(goods);
if (!newSkuList.isEmpty()) {
generateEs(goods);
}
}
/**
@ -329,7 +332,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
cache.remove(GoodsSkuService.getCacheKeys(sku.getId()));
cache.put(GoodsSkuService.getCacheKeys(sku.getId()), sku);
}
generateEs(goods);
if (!goodsSkus.isEmpty()) {
generateEs(goods);
}
}
}
@ -564,18 +569,19 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
if (!GoodsStatusEnum.UPPER.name().equals(goods.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goods.getAuthFlag())) {
return;
}
ThreadUtil.execAsync(() -> {
try {
// 延时执行防止商品未保存完成就去生成商品索引导致生成索引时找不到商品问题
Thread.sleep(2000);
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
//发送mq消息
rocketMQTemplate.asyncSend(destination, goods.getId(), RocketmqSendCallbackBuilder.commonCallback());
} catch (InterruptedException e) {
log.error("发送商品索引信息失败!", e);
Thread.currentThread().interrupt();
}
});
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
//发送mq消息
rocketMQTemplate.asyncSend(destination, goods.getId(), RocketmqSendCallbackBuilder.commonCallback());
// ThreadUtil.execAsync(() -> {
// try {
// // 延时执行防止商品未保存完成就去生成商品索引导致生成索引时找不到商品问题
// Thread.sleep(2000);
//
// } catch (InterruptedException e) {
// log.error("发送商品索引信息失败!", e);
// Thread.currentThread().interrupt();
// }
// });
}
/**