|
@@ -546,6 +546,8 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
List<GoodsOrderDetail> dataList = new ArrayList<>();
|
|
|
for (CreateOrderDetailFrom good : goods) {
|
|
|
String goodsId = good.getGoodsId();
|
|
|
+
|
|
|
+
|
|
|
//购买的碳汇量
|
|
|
BigDecimal carbonVal = good.getCarbonVal();
|
|
|
//获取销售信息
|
|
@@ -575,8 +577,18 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
// goodsInfo.setCarbonVal(reCarbonVal);
|
|
|
// goodsInfoMapper.updateByPrimaryKeySelective(goodsInfo);
|
|
|
|
|
|
- updateGoods(carbonVal, goodsInfoGuid);
|
|
|
-
|
|
|
+ RLock lock = redissonClient.getLock(goodsId);
|
|
|
+ try {
|
|
|
+ //加锁 操作很类似Java的ReentrantLock机制
|
|
|
+ lock.lock();
|
|
|
+ updateGoods(carbonVal, goodsInfoGuid);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ throw new RuntimeException("请重新抢购!");
|
|
|
+ } finally {
|
|
|
+ //解锁
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
//获取小订单
|
|
|
addGoodsOrderDetail(customerId, orderId, dataList, good, goodsInfo, sum);
|
|
|
}
|