|
@@ -1200,7 +1200,18 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
goods.setStockCount(updateStock);
|
|
|
updateGoods.add(goods);
|
|
|
}
|
|
|
- goodsDao.updateStock(updateGoods);
|
|
|
+ // 处理同一个商品,多个子商品同时更新库存,取最小的库存
|
|
|
+ Map<Integer, Optional<Goods>> collect = updateGoods.stream().collect(Collectors.groupingBy(Goods::getId, Collectors.minBy(Comparator.comparingInt(Goods::getStockCount))));
|
|
|
+ List<Goods> collect1 = collect.entrySet().stream().map(next -> {
|
|
|
+ if (next.getValue().isPresent()) {
|
|
|
+ Goods goods = new Goods();
|
|
|
+ goods.setId(next.getKey());
|
|
|
+ goods.setStockCount(next.getValue().get().getStockCount());
|
|
|
+ return goods;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ goodsDao.updateStock(collect1);
|
|
|
return true;
|
|
|
}
|
|
|
|