店铺商品数量,店铺缓存数据2小时。优化

This commit is contained in:
Chopper
2022-06-02 09:16:30 +08:00
parent 90d3bbd79e
commit d4a13c8a82
10 changed files with 107 additions and 30 deletions

View File

@@ -60,11 +60,6 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
*/
@Autowired
private EsGoodsIndexService goodsIndexService;
/**
* 店铺
*/
@Autowired
private StoreService storeService;
/**
* 商品
*/
@@ -202,7 +197,6 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
//审核商品
case GOODS_AUDIT:
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
updateGoodsNum(goods);
updateGoodsIndex(goods);
break;
//删除商品
@@ -213,7 +207,6 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
Goods goodsById = this.goodsService.getById(goodsId);
if (goodsById != null) {
this.deleteGoods(goodsById);
this.updateGoodsNum(goodsById);
goodsIndexService.deleteIndex(MapUtil.builder(new HashMap<String, Object>()).put("goodsId", goodsId).build());
}
}
@@ -458,22 +451,6 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
distributionGoodsService.removeById(distributionGoods.getId());
}
}
/**
* 修改商品数量
*
* @param goods 信息体
*/
private void updateGoodsNum(Goods goods) {
try {
//更新店铺商品数量
assert goods != null;
storeService.updateStoreGoodsNum(goods.getStoreId());
} catch (Exception e) {
log.error("修改商品数量错误");
}
}
/**
* 商品购买完成
* 1.更新商品购买数量

View File

@@ -0,0 +1,49 @@
package cn.lili.timetask.handler.impl.store;
import cn.lili.modules.goods.service.GoodsSkuService;
import cn.lili.modules.store.entity.dos.Store;
import cn.lili.modules.store.entity.enums.StoreStatusEnum;
import cn.lili.modules.store.service.StoreService;
import cn.lili.timetask.handler.EveryDayExecute;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 店铺信息更新
*
* @author Chopper
* @since 2021/3/15 5:30 下午
*/
@Component
@Slf4j
public class StoreExecute implements EveryDayExecute {
/**
* 店铺
*/
@Autowired
private StoreService storeService;
@Autowired
private GoodsSkuService goodsSkuService;
@Override
public void execute() {
//获取所有开启的店铺
List<Store> storeList = storeService.list(new LambdaQueryWrapper<Store>().eq(Store::getStoreDisable, StoreStatusEnum.OPEN.name()));
for (Store store : storeList) {
try {
Long num = goodsSkuService.countSkuNum(store.getId());
storeService.updateStoreGoodsNum(store.getId(), num);
} catch (Exception e) {
log.error("店铺id为{},更新商品数量失败", store.getId(), e);
}
}
}
}

View File

@@ -1,4 +1,4 @@
package cn.lili.timetask.handler.impl.storerating;
package cn.lili.timetask.handler.impl.store;
import cn.lili.common.enums.SwitchEnum;
import cn.lili.modules.member.entity.dos.MemberEvaluation;