docs: 添加充值审批余额验证工具和紧急修复文档

新增文件:
1. EMERGENCY_BALANCE_FIX.md - 充值审批余额未更新的紧急修复方案
2. verify_balance.sh - 自动化余额验证脚本

改进内容:
- 添加详细的诊断步骤
- 添加数据库验证SQL
- 添加日志检查方法
- 添加服务重启指南

这些工具用于帮助诊断和修复充值审批后资金账户余额未更新的问题
This commit is contained in:
2026-03-24 11:54:24 +08:00
parent 06f546f534
commit fb7bef6424
3 changed files with 558 additions and 6 deletions

View File

@@ -333,17 +333,32 @@ public class FundService {
if (status == 2) {
// 审批通过
System.out.println("[FundService.approve] 步骤4: 处理审批通过逻辑...");
if (order.getType() == 1) {
// 充值通过:增加余额 - 使用 LambdaUpdateWrapper 显式更新
System.out.println("[FundService.approve] 处理充值通过...");
BigDecimal balanceBefore = fund.getBalance();
BigDecimal totalDepositBefore = fund.getTotalDeposit();
// 处理可能的 null 值
BigDecimal currentBalance = fund.getBalance();
BigDecimal currentTotalDeposit = fund.getTotalDeposit();
if (currentBalance == null) {
currentBalance = BigDecimal.ZERO;
System.out.println(" - 警告: 账户余额为 null已设置为 0");
}
if (currentTotalDeposit == null) {
currentTotalDeposit = BigDecimal.ZERO;
System.out.println(" - 警告: 累计充值为 null已设置为 0");
}
BigDecimal balanceBefore = currentBalance;
BigDecimal totalDepositBefore = currentTotalDeposit;
System.out.println(" - 审批前余额: " + balanceBefore);
System.out.println(" - 审批前累计充值: " + totalDepositBefore);
System.out.println(" - 账户ID: " + fund.getId());
System.out.println(" - 用户ID: " + fund.getUserId());
BigDecimal newBalance = fund.getBalance().add(order.getAmount());
BigDecimal newTotalDeposit = fund.getTotalDeposit().add(order.getAmount());
BigDecimal newBalance = currentBalance.add(order.getAmount());
BigDecimal newTotalDeposit = currentTotalDeposit.add(order.getAmount());
LocalDateTime updateTime = LocalDateTime.now();
System.out.println(" - 准备更新账户余额: " + newBalance);
@@ -364,11 +379,19 @@ public class FundService {
throw new RuntimeException("充值审批更新账户余额失败");
}
// 验证更新结果
// 验证更新结果 - 使用新的查询确保从数据库读取
AccountFund verifyFund = accountFundMapper.selectById(fund.getId());
System.out.println(" - 验证更新后余额: " + verifyFund.getBalance());
System.out.println(" - 验证更新后累计充值: " + verifyFund.getTotalDeposit());
if (verifyFund.getBalance() == null || !verifyFund.getBalance().equals(newBalance)) {
System.err.println("[FundService.approve] 严重错误: 账户余额更新验证失败!");
System.err.println(" - 期望余额: " + newBalance);
System.err.println(" - 实际余额: " + verifyFund.getBalance());
throw new RuntimeException("账户余额更新验证失败");
}
System.out.println(" - 余额验证通过 ✓");
// 更新本地对象状态
fund.setBalance(newBalance);
fund.setTotalDeposit(newTotalDeposit);
@@ -559,6 +582,27 @@ public class FundService {
throw new RuntimeException("订单更新失败");
}
// 最终验证:确保账户余额正确更新(仅在审批通过时)
if (status == 2) {
System.out.println("[FundService.approve] 步骤7: 最终验证账户余额...");
AccountFund finalVerifyFund = accountFundMapper.selectById(fund.getId());
System.out.println(" - 最终账户余额: " + finalVerifyFund.getBalance());
System.out.println(" - 最终累计充值: " + finalVerifyFund.getTotalDeposit());
if (order.getType() == 1) {
// 充值订单:验证余额是否正确增加
BigDecimal expectedBalance = fund.getBalance();
if (finalVerifyFund.getBalance() == null ||
finalVerifyFund.getBalance().compareTo(expectedBalance) != 0) {
System.err.println("[FundService.approve] 严重错误: 最终验证发现账户余额不一致!");
System.err.println(" - 期望余额: " + expectedBalance);
System.err.println(" - 实际余额: " + finalVerifyFund.getBalance());
throw new RuntimeException("账户余额最终验证失败,数据可能不一致");
}
System.out.println(" - 账户余额最终验证通过 ✓");
}
}
System.out.println("[审批完成] 订单号: " + orderNo + ", 订单类型: " + (order.getType() == 1 ? "充值" : "提现") +
", 审批结果: " + (status == 2 ? "通过" : "驳回") + ", 最终状态: " + finalStatus +
", 审批人: " + adminName);