v1.1 充值-支付锁boolean

This commit is contained in:
2022-11-01 14:38:02 +08:00
parent ded242e043
commit 12fb21354c
2 changed files with 16 additions and 5 deletions

View File

@@ -45,8 +45,13 @@ public class GooglePlayBillingService {
public void verifyOrder(String chargeRecordId, String packageName, String googlePlayProdId, String purchaseToken) {
String lockKey = RedisKey.lock_pay_callback_notify.getKey(chargeRecordId);
RLock lock = redissonClient.getLock(lockKey);
boolean isLocked = false;
try {
lock.tryLock(5L, TimeUnit.SECONDS);
isLocked = lock.tryLock(5L, TimeUnit.SECONDS);
if (!isLocked){
log.error("[google play billing]加锁失败。chargeRecordId: {}", chargeRecordId);
throw new ServiceException(BusiStatus.SERVER_BUSY);
}
ChargeRecord chargeRecord = chargeRecordService.getChargeRecordById(chargeRecordId);
if (chargeRecord == null) {
@@ -95,7 +100,7 @@ public class GooglePlayBillingService {
throw new ServiceException(BusiStatus.BUSIERROR);
}
} finally {
if (lock.isLocked()){
if (isLocked || lock.isLocked()){
lock.unlock();
}
}

View File

@@ -2,6 +2,8 @@ package com.accompany.business.controller.apppay;
import com.accompany.business.service.ChargeService;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.status.BusiStatus;
import com.accompany.core.exception.ServiceException;
import com.accompany.payment.constant.PayConstant;
import com.accompany.payment.model.ChargeRecord;
import com.accompany.payment.payermax.config.PayermaxConfig;
@@ -80,9 +82,13 @@ public class PayermaxPayController {
String lockKey = RedisKey.lock_pay_callback_notify.getKey(chargeRecordId);
RLock lock = redissonClient.getLock(lockKey);
boolean isLocked = false;
try {
lock.tryLock(5L, TimeUnit.SECONDS);
isLocked = lock.tryLock(5L, TimeUnit.SECONDS);
if (!isLocked){
log.error("【payermax支付回调】加锁失败 chargeRecordId: {}", chargeRecordId);
throw new ServiceException(BusiStatus.SERVER_BUSY);
}
ChargeRecord chargeRecord = chargeRecordService.getChargeRecordById(chargeRecordId);
if (chargeRecord == null) {
@@ -127,7 +133,7 @@ public class PayermaxPayController {
map.put("message", "Exception happened " + e.getMessage());
return map;
} finally {
if (lock.isLocked()){
if (isLocked || lock.isLocked()){
lock.unlock();
}
}