解决商品购买但是商品页面的库存显示不正确的问题

This commit is contained in:
lifenlong 2021-07-20 20:25:57 +08:00
parent f35ae5b1ee
commit 44fb0601a6
3 changed files with 12 additions and 16 deletions

View File

@ -5,7 +5,6 @@ import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException; import cn.lili.common.exception.ServiceException;
import cn.lili.common.vo.PageVO; import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage; import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.distribution.service.DistributionService;
import cn.lili.modules.goods.entity.dos.Goods; import cn.lili.modules.goods.entity.dos.Goods;
import cn.lili.modules.goods.entity.dto.GoodsSearchParams; import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.entity.vos.GoodsVO;
@ -61,12 +60,6 @@ public class GoodsBuyerController {
*/ */
@Autowired @Autowired
private EsGoodsSearchService goodsSearchService; private EsGoodsSearchService goodsSearchService;
/**
* 分销员
*/
@Autowired
private DistributionService distributionService;
@ApiOperation(value = "通过id获取商品信息") @ApiOperation(value = "通过id获取商品信息")
@ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, paramType = "path", dataType = "Long") @ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, paramType = "path", dataType = "Long")

View File

@ -161,6 +161,11 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
/** /**
* 同步库存和促销库存 * 同步库存和促销库存
* *
* 需修改DB商品库存Sku商品库存活动商品库存
* 1.获取需要修改的Sku列表活动商品列表
* 2.写入sku商品库存批量修改
* 3.写入促销商品的卖出数量剩余数量,批量修改
* 4.调用方法修改商品库存
* @param order 订单 * @param order 订单
*/ */
private void synchroDB(OrderDetailVO order) { private void synchroDB(OrderDetailVO order) {

View File

@ -189,17 +189,15 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
} }
cache.put(GoodsSkuService.getCacheKeys(id), goodsSku); cache.put(GoodsSkuService.getCacheKeys(id), goodsSku);
} }
//获取商品库存 //获取商品库存
String quantity = stringRedisTemplate.opsForValue().get(GoodsSkuService.getStockCacheKey(id)); 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; return goodsSku;
} }
@ -437,7 +435,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
quantity += goodsSku.getQuantity(); quantity += goodsSku.getQuantity();
} }
} }
//保存商品库存结果 这里在for循环中调用数据库保存不太好需要优化 //保存商品库存结果
goodsService.updateStock(goodsId, quantity); goodsService.updateStock(goodsId, quantity);
} }