店铺商品数量,店铺缓存数据2小时。优化
This commit is contained in:
@@ -465,6 +465,10 @@ public enum CachePrefix {
|
||||
*/
|
||||
INIT_INDEX_FLAG,
|
||||
|
||||
/**
|
||||
* 店铺
|
||||
*/
|
||||
STORE,
|
||||
/**
|
||||
* 店铺分类
|
||||
*/
|
||||
|
||||
@@ -212,5 +212,19 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
||||
*/
|
||||
List<String> getSkuIdsByGoodsId(String goodsId);
|
||||
|
||||
/**
|
||||
* 删除并且新增sku,即覆盖之前信息
|
||||
*
|
||||
* @param goodsSkus
|
||||
* @return
|
||||
*/
|
||||
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(
|
||||
new LambdaQueryWrapper<Goods>()
|
||||
.eq(Goods::getStoreId, storeId)
|
||||
.eq(Goods::getDeleteFlag, Boolean.FALSE)
|
||||
.eq(Goods::getAuthFlag, GoodsAuthEnum.PASS.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;
|
||||
}
|
||||
|
||||
@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 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.map.MapUtil;
|
||||
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.security.AuthUser;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
@@ -64,9 +66,17 @@ public class StoreDetailServiceImpl extends ServiceImpl<StoreDetailMapper, Store
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
@@ -270,12 +270,10 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStoreGoodsNum(String storeId) {
|
||||
//获取店铺已上架已审核通过商品数量
|
||||
long goodsNum = goodsService.countStoreGoodsNum(storeId);
|
||||
public void updateStoreGoodsNum(String storeId, Long num) {
|
||||
//修改店铺商品数量
|
||||
this.update(new LambdaUpdateWrapper<Store>()
|
||||
.set(Store::getGoodsNum, goodsNum)
|
||||
.set(Store::getGoodsNum, num)
|
||||
.eq(Store::getId, storeId));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user