fix: 修复Flutter资产页面API接口字段名称不匹配问题

主要修改:
1. AssetService.java - 修改getOverview()方法返回字段
   - totalAssets → totalAsset (总资产)
   - tradeValue → tradeBalance (交易余额)
   - 新增 totalProfit 字段 (总盈亏)
   - 移除 fundFrozen 和 positions 字段 (Flutter不需要)

2. 新增诊断工具和文档:
   - ASSET_API_DIAGNOSIS.md - API接口问题诊断报告
   - DATABASE_SCHEMA.md - 数据库表结构说明
   - test_asset_api.sh - API接口测试脚本
   - query_fund_accounts.sh - 用户资金账户查询脚本
   - fix_asset_api.sh - 自动修复脚本

修复后API返回格式:
{
  "totalAsset": 15500.0,      // 总资产
  "fundBalance": 15500.0,     // 资金余额
  "tradeBalance": 0,          // 交易余额
  "totalProfit": 0            // 总盈亏
}

影响范围:
- Flutter前端资产页面现在可以正确显示用户资产
- 充值审批后余额正确更新
- 资金账户数据查询正常
This commit is contained in:
2026-03-24 14:08:59 +08:00
parent 62d8c81857
commit a4423e044b
6 changed files with 916 additions and 17 deletions

View File

@@ -44,12 +44,13 @@ public class AssetService {
// 资金账户
AccountFund fund = getOrCreateFundAccount(userId);
result.put("fundBalance", fund.getBalance());
result.put("fundFrozen", fund.getFrozen());
BigDecimal fundBalance = fund.getBalance();
result.put("fundBalance", fundBalance);
// 交易账户
BigDecimal tradeValue = BigDecimal.ZERO;
List<Map<String, Object>> positions = new ArrayList<>();
BigDecimal tradeBalance = BigDecimal.ZERO;
BigDecimal totalCost = BigDecimal.ZERO; // 累计成本
BigDecimal totalValue = BigDecimal.ZERO; // 当前价值
LambdaQueryWrapper<AccountTrade> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AccountTrade::getUserId, userId)
@@ -61,25 +62,24 @@ public class AssetService {
if (coin != null) {
BigDecimal value = trade.getQuantity().multiply(coin.getPrice())
.setScale(8, RoundingMode.DOWN);
tradeValue = tradeValue.add(value);
tradeBalance = tradeBalance.add(value);
Map<String, Object> position = new HashMap<>();
position.put("coinCode", trade.getCoinCode());
position.put("coinName", coin.getName());
position.put("quantity", trade.getQuantity());
position.put("price", coin.getPrice());
position.put("value", value);
position.put("avgPrice", trade.getAvgPrice());
positions.add(position);
// 计算成本和盈亏
BigDecimal cost = trade.getQuantity().multiply(trade.getAvgPrice());
totalCost = totalCost.add(cost);
totalValue = totalValue.add(value);
}
}
result.put("tradeValue", tradeValue);
result.put("positions", positions);
result.put("tradeBalance", tradeBalance);
// 总资产
BigDecimal totalAssets = fund.getBalance().add(tradeValue);
result.put("totalAssets", totalAssets);
BigDecimal totalAsset = fundBalance.add(tradeBalance);
result.put("totalAsset", totalAsset);
// 总盈亏 = 当前价值 - 累计成本
BigDecimal totalProfit = totalValue.subtract(totalCost);
result.put("totalProfit", totalProfit);
return result;
}