瀏覽代碼

企业账户表添加版本字段,更新操作加锁机制(充值、提现、支付)

ZhangWenQiang 5 年之前
父節點
當前提交
aeeb3dc5a0

+ 23 - 2
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/hlwpayment/service/impl/HlwPaymentServiceImpl.java

@@ -472,7 +472,17 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
         hlwCompanyAccount.setTotalPayment(businessAccountUtils.add(hlwCompanyAccount.getTotalPayment(), hlwPayment.getTotalPayment()));
         hlwCompanyAccount.setTotalServiceFee(businessAccountUtils.add(hlwCompanyAccount.getTotalServiceFee(), hlwPayment.getServiceFee()));
         hlwCompanyAccount.setBalance(businessAccountUtils.sub(hlwCompanyAccount.getBalance(), hlwPayment.getTotalPayment()));
-        hlwCompanyAccountService.updateById(hlwCompanyAccount);
+        boolean update = hlwCompanyAccountService.updateById(hlwCompanyAccount);
+        while (!update) {
+            /**
+             * 更新失败,则重新获取
+             */
+            HlwCompanyAccount hlwCompanyAccountNew = hlwCompanyAccountService.getOne(queryWrapper);
+            hlwCompanyAccountNew.setTotalPayment(businessAccountUtils.add(hlwCompanyAccountNew.getTotalPayment(), hlwPayment.getTotalPayment()));
+            hlwCompanyAccountNew.setTotalServiceFee(businessAccountUtils.add(hlwCompanyAccountNew.getTotalServiceFee(), hlwPayment.getServiceFee()));
+            hlwCompanyAccountNew.setBalance(businessAccountUtils.sub(hlwCompanyAccountNew.getBalance(), hlwPayment.getTotalPayment()));
+            update = hlwCompanyAccountService.updateById(hlwCompanyAccountNew);
+        }
         //企业账户明细表(插入)
         HlwCompanyAccountDetail hlwCompanyAccountDetail = new HlwCompanyAccountDetail();
         hlwCompanyAccountDetail.setCompanyAccountId(hlwCompanyAccount.getId());
@@ -528,7 +538,18 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
         hlwCompanyAccount.setTotalPayment(businessAccountUtils.add(hlwCompanyAccount.getTotalPayment(), hlwPayment.getTotalPayment()));
         hlwCompanyAccount.setTotalServiceFee(businessAccountUtils.add(hlwCompanyAccount.getTotalServiceFee(), hlwPayment.getServiceFee()));
         hlwCompanyAccount.setBalance(businessAccountUtils.sub(hlwCompanyAccount.getBalance(), hlwPayment.getTotalPayment()));
-        hlwCompanyAccountService.updateById(hlwCompanyAccount);
+        boolean update = hlwCompanyAccountService.updateById(hlwCompanyAccount);
+        while (!update) {
+            /**
+             * 更新失败,则重新获取
+             */
+            HlwCompanyAccount hlwCompanyAccountNew = hlwCompanyAccountService.getOne(queryWrapper);
+            hlwCompanyAccountNew.setTotalPayment(businessAccountUtils.add(hlwCompanyAccountNew.getTotalPayment(), hlwPayment.getTotalPayment()));
+            hlwCompanyAccountNew.setTotalServiceFee(businessAccountUtils.add(hlwCompanyAccountNew.getTotalServiceFee(), hlwPayment.getServiceFee()));
+            hlwCompanyAccountNew.setBalance(businessAccountUtils.sub(hlwCompanyAccountNew.getBalance(), hlwPayment.getTotalPayment()));
+            update = hlwCompanyAccountService.updateById(hlwCompanyAccountNew);
+        }
+
         //企业账户明细表(插入)
         HlwCompanyAccountDetail hlwCompanyAccountDetail = new HlwCompanyAccountDetail();
         hlwCompanyAccountDetail.setCompanyAccountId(hlwCompanyAccount.getId());