This commit is contained in:
lifenlong 2021-07-20 19:27:48 +08:00
commit f35ae5b1ee
2 changed files with 9 additions and 0 deletions

View File

@ -8,6 +8,9 @@ import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
import cn.lili.modules.goods.entity.vos.GoodsVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.util.List;
@ -17,6 +20,7 @@ import java.util.List;
* @author pikachu
* @date 2020-02-23 16:18:56
*/
@CacheConfig(cacheNames = "{goods}")
public interface GoodsService extends IService<Goods> {
@ -48,6 +52,7 @@ public interface GoodsService extends IService<Goods> {
* @param goodsOperationDTO 商品查询条件
* @param goodsId 商品ID
*/
@CacheEvict(key = "#goodsId")
void editGoods(GoodsOperationDTO goodsOperationDTO, String goodsId);
/**
@ -56,6 +61,7 @@ public interface GoodsService extends IService<Goods> {
* @param goodsId 商品id
* @return 商品VO
*/
@Cacheable(key = "#goodsId")
GoodsVO getGoodsVO(String goodsId);
/**

View File

@ -179,7 +179,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
@Override
public GoodsSku getGoodsSkuByIdFromCache(String id) {
//获取缓存中的sku
GoodsSku goodsSku = cache.get(GoodsSkuService.getCacheKeys(id));
//如果缓存中没有信息则查询数据库然后写入缓存
if (goodsSku == null) {
goodsSku = this.getById(id);
if (goodsSku == null) {
@ -187,6 +189,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
}
cache.put(GoodsSkuService.getCacheKeys(id), goodsSku);
}
//获取商品库存
String quantity = stringRedisTemplate.opsForValue().get(GoodsSkuService.getStockCacheKey(id));
if (quantity != null) {
if (goodsSku.getQuantity().equals(Convert.toInt(quantity))) {