店铺商品数量,店铺缓存数据2小时。优化
This commit is contained in:
parent
90d3bbd79e
commit
d4a13c8a82
@ -60,11 +60,6 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private EsGoodsIndexService goodsIndexService;
|
private EsGoodsIndexService goodsIndexService;
|
||||||
/**
|
|
||||||
* 店铺
|
|
||||||
*/
|
|
||||||
@Autowired
|
|
||||||
private StoreService storeService;
|
|
||||||
/**
|
/**
|
||||||
* 商品
|
* 商品
|
||||||
*/
|
*/
|
||||||
@ -202,7 +197,6 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
//审核商品
|
//审核商品
|
||||||
case GOODS_AUDIT:
|
case GOODS_AUDIT:
|
||||||
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
|
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
|
||||||
updateGoodsNum(goods);
|
|
||||||
updateGoodsIndex(goods);
|
updateGoodsIndex(goods);
|
||||||
break;
|
break;
|
||||||
//删除商品
|
//删除商品
|
||||||
@ -213,7 +207,6 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
Goods goodsById = this.goodsService.getById(goodsId);
|
Goods goodsById = this.goodsService.getById(goodsId);
|
||||||
if (goodsById != null) {
|
if (goodsById != null) {
|
||||||
this.deleteGoods(goodsById);
|
this.deleteGoods(goodsById);
|
||||||
this.updateGoodsNum(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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -458,22 +451,6 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
distributionGoodsService.removeById(distributionGoods.getId());
|
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.更新商品购买数量
|
* 1.更新商品购买数量
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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.common.enums.SwitchEnum;
|
||||||
import cn.lili.modules.member.entity.dos.MemberEvaluation;
|
import cn.lili.modules.member.entity.dos.MemberEvaluation;
|
@ -465,6 +465,10 @@ public enum CachePrefix {
|
|||||||
*/
|
*/
|
||||||
INIT_INDEX_FLAG,
|
INIT_INDEX_FLAG,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺
|
||||||
|
*/
|
||||||
|
STORE,
|
||||||
/**
|
/**
|
||||||
* 店铺分类
|
* 店铺分类
|
||||||
*/
|
*/
|
||||||
|
@ -212,5 +212,19 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
|||||||
*/
|
*/
|
||||||
List<String> getSkuIdsByGoodsId(String goodsId);
|
List<String> getSkuIdsByGoodsId(String goodsId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除并且新增sku,即覆盖之前信息
|
||||||
|
*
|
||||||
|
* @param goodsSkus
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
boolean deleteAndInsertGoodsSkus(List<GoodsSku> goodsSkus);
|
boolean deleteAndInsertGoodsSkus(List<GoodsSku> goodsSkus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计sku总数
|
||||||
|
*
|
||||||
|
* @param storeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Long countSkuNum(String storeId);
|
||||||
}
|
}
|
@ -469,11 +469,23 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|||||||
return this.count(
|
return this.count(
|
||||||
new LambdaQueryWrapper<Goods>()
|
new LambdaQueryWrapper<Goods>()
|
||||||
.eq(Goods::getStoreId, storeId)
|
.eq(Goods::getStoreId, storeId)
|
||||||
|
.eq(Goods::getDeleteFlag, Boolean.FALSE)
|
||||||
.eq(Goods::getAuthFlag, GoodsAuthEnum.PASS.name())
|
.eq(Goods::getAuthFlag, GoodsAuthEnum.PASS.name())
|
||||||
.eq(Goods::getMarketEnable, GoodsStatusEnum.UPPER.name()));
|
.eq(Goods::getMarketEnable, GoodsStatusEnum.UPPER.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新店铺商品数量
|
||||||
|
*
|
||||||
|
* @param storeId 信息体
|
||||||
|
*/
|
||||||
|
void updateGoodsNum(String storeId) {
|
||||||
|
Long num = goodsSkuService.countSkuNum(storeId);
|
||||||
|
storeService.updateStoreGoodsNum(storeId, num);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新商品状态
|
* 更新商品状态
|
||||||
*
|
*
|
||||||
|
@ -601,6 +601,18 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
return count > 0;
|
return count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long countSkuNum(String storeId) {
|
||||||
|
LambdaQueryWrapper<GoodsSku> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
queryWrapper
|
||||||
|
.eq(GoodsSku::getStoreId, storeId)
|
||||||
|
.eq(GoodsSku::getDeleteFlag, Boolean.FALSE)
|
||||||
|
.eq(GoodsSku::getAuthFlag, GoodsAuthEnum.PASS.name())
|
||||||
|
.eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name());
|
||||||
|
return this.count(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改库存
|
* 修改库存
|
||||||
*
|
*
|
||||||
|
@ -106,8 +106,9 @@ public interface StoreService extends IService<Store> {
|
|||||||
* 更新店铺商品数量
|
* 更新店铺商品数量
|
||||||
*
|
*
|
||||||
* @param storeId 店铺ID
|
* @param storeId 店铺ID
|
||||||
|
* @param num 商品数量
|
||||||
*/
|
*/
|
||||||
void updateStoreGoodsNum(String storeId);
|
void updateStoreGoodsNum(String storeId, Long num);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新店铺收藏数量
|
* 更新店铺收藏数量
|
||||||
|
@ -3,6 +3,8 @@ package cn.lili.modules.store.serviceimpl;
|
|||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import cn.lili.cache.Cache;
|
||||||
|
import cn.lili.cache.CachePrefix;
|
||||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||||
import cn.lili.common.security.AuthUser;
|
import cn.lili.common.security.AuthUser;
|
||||||
import cn.lili.common.security.context.UserContext;
|
import cn.lili.common.security.context.UserContext;
|
||||||
@ -64,9 +66,17 @@ public class StoreDetailServiceImpl extends ServiceImpl<StoreDetailMapper, Store
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RocketMQTemplate rocketMQTemplate;
|
private RocketMQTemplate rocketMQTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Cache cache;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StoreDetailVO getStoreDetailVO(String storeId) {
|
public StoreDetailVO getStoreDetailVO(String storeId) {
|
||||||
return this.baseMapper.getStoreDetail(storeId);
|
StoreDetailVO storeDetailVO = (StoreDetailVO) cache.get(CachePrefix.STORE.getPrefix() + storeId);
|
||||||
|
if (storeDetailVO == null) {
|
||||||
|
storeDetailVO = this.baseMapper.getStoreDetail(storeId);
|
||||||
|
cache.put(CachePrefix.STORE.getPrefix() + storeId, storeDetailVO, 7200L);
|
||||||
|
}
|
||||||
|
return storeDetailVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -270,12 +270,10 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateStoreGoodsNum(String storeId) {
|
public void updateStoreGoodsNum(String storeId, Long num) {
|
||||||
//获取店铺已上架已审核通过商品数量
|
|
||||||
long goodsNum = goodsService.countStoreGoodsNum(storeId);
|
|
||||||
//修改店铺商品数量
|
//修改店铺商品数量
|
||||||
this.update(new LambdaUpdateWrapper<Store>()
|
this.update(new LambdaUpdateWrapper<Store>()
|
||||||
.set(Store::getGoodsNum, goodsNum)
|
.set(Store::getGoodsNum, num)
|
||||||
.eq(Store::getId, storeId));
|
.eq(Store::getId, storeId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user