fix: release transfer locks and allow agent self transfer

This commit is contained in:
ZuoZuo 2026-05-01 17:29:05 +08:00
parent d9d67b8839
commit fc7d248171
3 changed files with 65 additions and 60 deletions

View File

@ -89,12 +89,12 @@ public class UserBankTransferGoldCmdExe {
boolean freight = freightBalanceService.existsBalance(cmd.getAcceptUserId()); boolean freight = freightBalanceService.existsBalance(cmd.getAcceptUserId());
ResponseAssert.isTrue(WalletErrorCode.TARGET_USER_NOT_RECHARGE_AGENCY, freight); ResponseAssert.isTrue(WalletErrorCode.TARGET_USER_NOT_RECHARGE_AGENCY, freight);
ResponseAssert.isTrue(WalletErrorCode.NOT_TRANSFER_YOURSELF, !Objects.equals(cmd.getAcceptUserId(), cmd.requiredReqUserId()));
// 上锁 // 上锁
String key = "UBWTransferGold:" + cmd.requiredReqUserId(); String key = "UBWTransferGold:" + cmd.requiredReqUserId();
ResponseAssert.isTrue(CommonErrorCode.REQUEST_LIMITING, redisService.lock(key, 60)); ResponseAssert.isTrue(CommonErrorCode.REQUEST_LIMITING, redisService.lock(key, 60));
try {
BigDecimal balance = userBankBalanceService.getBalance(cmd.requiredReqUserId()) BigDecimal balance = userBankBalanceService.getBalance(cmd.requiredReqUserId())
.getAccurateBalance(); .getAccurateBalance();
@ -141,10 +141,12 @@ public class UserBankTransferGoldCmdExe {
// 发送金额 // 发送金额
sendGold(cmd, freight, goldQuantity, bankRunWaterId, "转账金币"); sendGold(cmd, freight, goldQuantity, bankRunWaterId, "转账金币");
redisService.unlock(key);
return new UserBankWithdrawResultCO() return new UserBankWithdrawResultCO()
.setBankBalance(decrUserBankBalanceDTO.getAccurateBalance()) .setBankBalance(decrUserBankBalanceDTO.getAccurateBalance())
.setWithdrawAmount(Objects.toString(cmd.getAmount())); .setWithdrawAmount(Objects.toString(cmd.getAmount()));
} finally {
redisService.unlock(key);
}
} }
private void sendGold(UserBankWithdrawTransferCmd cmd, boolean freight, BigDecimal goldQuantity, private void sendGold(UserBankWithdrawTransferCmd cmd, boolean freight, BigDecimal goldQuantity,

View File

@ -44,11 +44,13 @@ public class UserBankSearchUserProfileQryExe {
return null; return null;
} }
if (isTransfer(cmd)) { boolean transfer = isTransfer(cmd);
if (Objects.equals(cmd.getReqUserId(), userProfile.getId())) { boolean sameUser = Objects.equals(cmd.getReqUserId(), userProfile.getId());
boolean freightAgent = cmd.typeEqAgent()
&& Boolean.TRUE.equals(freightBalanceService.checkFreightAgent(userProfile.getId()));
if (transfer && sameUser && !freightAgent) {
return null; return null;
} }
}
if (cmd.typeEqBD()) { if (cmd.typeEqBD()) {
return return
@ -67,11 +69,10 @@ public class UserBankSearchUserProfileQryExe {
} }
if (cmd.typeEqAgent()) { if (cmd.typeEqAgent()) {
Boolean freightAgent = freightBalanceService.checkFreightAgent(userProfile.getId());
if (freightAgent) { if (freightAgent) {
return userProfile; return userProfile;
} }
if (isTransfer(cmd)) { if (transfer) {
return null; return null;
} }

View File

@ -81,12 +81,12 @@ public class SalaryTransferGoldCmdExe {
boolean freight = freightBalanceService.existsBalance(cmd.getAcceptUserId()); boolean freight = freightBalanceService.existsBalance(cmd.getAcceptUserId());
ResponseAssert.isTrue(WalletErrorCode.TARGET_USER_NOT_RECHARGE_AGENCY, freight); ResponseAssert.isTrue(WalletErrorCode.TARGET_USER_NOT_RECHARGE_AGENCY, freight);
ResponseAssert.isTrue(WalletErrorCode.NOT_TRANSFER_YOURSELF, !Objects.equals(cmd.getAcceptUserId(), cmd.requiredReqUserId()));
// 上锁 // 上锁
String key = "USTransferGold:" + cmd.requiredReqUserId(); String key = "USTransferGold:" + cmd.requiredReqUserId();
ResponseAssert.isTrue(CommonErrorCode.REQUEST_LIMITING, redisService.lock(key, 60)); ResponseAssert.isTrue(CommonErrorCode.REQUEST_LIMITING, redisService.lock(key, 60));
try {
BigDecimal balance = salaryAccountGateway.getAvailableBalance(cmd.getReqUserId(), SalaryType.of(cmd.getSalaryType())).getDollarAmount(); BigDecimal balance = salaryAccountGateway.getAvailableBalance(cmd.getReqUserId(), SalaryType.of(cmd.getSalaryType())).getDollarAmount();
ResponseAssert.isTrue(WalletErrorCode.INSUFFICIENT_BALANCE, ResponseAssert.isTrue(WalletErrorCode.INSUFFICIENT_BALANCE,
@ -113,10 +113,12 @@ public class SalaryTransferGoldCmdExe {
// 发送金额 // 发送金额
sendGold(cmd, freight, goldQuantity, bankRunWaterId, "转账金币"); sendGold(cmd, freight, goldQuantity, bankRunWaterId, "转账金币");
redisService.unlock(key);
return new UserBankWithdrawResultCO() return new UserBankWithdrawResultCO()
.setBankBalance(salaryReceiptRes.getAvailableBalance().getDollarAmount()) .setBankBalance(salaryReceiptRes.getAvailableBalance().getDollarAmount())
.setWithdrawAmount(Objects.toString(cmd.getAmount())); .setWithdrawAmount(Objects.toString(cmd.getAmount()));
} finally {
redisService.unlock(key);
}
} }
private void sendGold(SalaryWithdrawCmd cmd, boolean freight, BigDecimal goldQuantity, private void sendGold(SalaryWithdrawCmd cmd, boolean freight, BigDecimal goldQuantity,