|
@@ -284,28 +284,31 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
//更新订单信息
|
|
|
String orderId = goodsPayOrderForm.getFkOrderId();
|
|
|
GoodsOrderInfo goodsOrderInfo = goodsOrderInfoMapper.selectByPrimaryKey(orderId);
|
|
|
- goodsOrderInfo.setOrderStatus(state);
|
|
|
- goodsOrderInfo.setModifiedTime(new Date());
|
|
|
- int i = goodsOrderInfoMapper.updateByPrimaryKeySelective(goodsOrderInfo);
|
|
|
- if (i > 0) {
|
|
|
- //更新支付订单信息
|
|
|
- goodsPayOrderForm.setPayStatus(state);
|
|
|
- goodsPayOrderForm.setPayTime(new Date());
|
|
|
- int j = orderPayService.modifyByPrimaryKeySelective(goodsPayOrderForm);
|
|
|
- if (j == 0) {
|
|
|
- throw new RuntimeException();
|
|
|
+ if(!StringUtils.isEmpty(goodsOrderInfo)){
|
|
|
+ goodsOrderInfo.setOrderStatus(state);
|
|
|
+ goodsOrderInfo.setModifiedTime(new Date());
|
|
|
+ int i = goodsOrderInfoMapper.updateByPrimaryKeySelective(goodsOrderInfo);
|
|
|
+ if (i > 0) {
|
|
|
+ //更新支付订单信息
|
|
|
+ goodsPayOrderForm.setPayStatus(state);
|
|
|
+ goodsPayOrderForm.setPayTime(new Date());
|
|
|
+ int j = orderPayService.modifyByPrimaryKeySelective(goodsPayOrderForm);
|
|
|
+ if (j == 0) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ //更新农户收入信息
|
|
|
+ updateFarmerSaleInfo(orderId);
|
|
|
+ //生成证书信息
|
|
|
+ applicationContext.publishEvent(new CredentialInfoEvent(this, orderId));
|
|
|
+ //生成购买碳汇数据
|
|
|
+ applicationContext.publishEvent(new CustomerCarbonValEvent(this, orderId));
|
|
|
+
|
|
|
+ return i;
|
|
|
}
|
|
|
- //更新农户收入信息
|
|
|
- updateFarmerSaleInfo(orderId);
|
|
|
- //生成证书信息
|
|
|
- applicationContext.publishEvent(new CredentialInfoEvent(this, orderId));
|
|
|
- //生成购买碳汇数据
|
|
|
- applicationContext.publishEvent(new CustomerCarbonValEvent(this, orderId));
|
|
|
-
|
|
|
- return i;
|
|
|
- } else {
|
|
|
- throw new RuntimeException();
|
|
|
+ }else{
|
|
|
+ log.info("订单不存在无法更新!");
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -546,6 +549,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 +580,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);
|
|
|
}
|