解决商品购买但是商品页面的库存显示不正确的问题
This commit is contained in:
@@ -189,17 +189,15 @@ 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))) {
|
||||
goodsSku.setQuantity(Convert.toInt(quantity));
|
||||
this.updateById(goodsSku);
|
||||
}
|
||||
} else {
|
||||
stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(id), goodsSku.getQuantity().toString());
|
||||
}
|
||||
|
||||
//如果sku缓存的库存与库存缓存不符则按照库存缓存进行
|
||||
if (quantity == null) {
|
||||
goodsSku.setQuantity(Convert.toInt(quantity));
|
||||
cache.put(GoodsSkuService.getCacheKeys(goodsSku.getId()), goodsSku);
|
||||
}
|
||||
return goodsSku;
|
||||
}
|
||||
|
||||
@@ -437,7 +435,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
quantity += goodsSku.getQuantity();
|
||||
}
|
||||
}
|
||||
//保存商品库存结果 这里在for循环中调用数据库保存不太好,需要优化
|
||||
//保存商品库存结果
|
||||
goodsService.updateStock(goodsId, quantity);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user