From a2adddbf3df129f450649e5745b4ceac59f5cb9c Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 14 Jan 2026 02:23:54 -0800 Subject: [PATCH] fix(mining-admin): transform dashboard API response to match frontend expected format Frontend expects flat DashboardStats and RealtimeData interfaces. Transform backend nested response to: - totalUsers, adoptedUsers, networkEffectiveContribution, etc. - currentMinuteDistribution, activeOrders, pendingTrades, etc. Co-Authored-By: Claude Opus 4.5 --- .../api/controllers/dashboard.controller.ts | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/backend/services/mining-admin-service/src/api/controllers/dashboard.controller.ts b/backend/services/mining-admin-service/src/api/controllers/dashboard.controller.ts index babc70e5..37b47aec 100644 --- a/backend/services/mining-admin-service/src/api/controllers/dashboard.controller.ts +++ b/backend/services/mining-admin-service/src/api/controllers/dashboard.controller.ts @@ -16,19 +16,50 @@ export class DashboardController { @Get() @ApiOperation({ summary: '获取仪表盘统计数据' }) async getStats() { - return this.dashboardService.getDashboardStats(); + const raw = await this.dashboardService.getDashboardStats(); + + // 计算24小时价格变化 + let priceChange24h = 0; + if (raw.latestPrice) { + const open = parseFloat(raw.latestPrice.open) || 1; + const close = parseFloat(raw.latestPrice.close) || 1; + priceChange24h = (close - open) / open; + } + + // 转换为前端期望的格式 + return { + totalUsers: raw.users?.total || 0, + adoptedUsers: raw.users?.adopted || 0, + networkEffectiveContribution: raw.contribution?.effectiveContribution || '0', + totalDistributed: raw.mining?.totalMined || '0', + totalBurned: raw.mining?.latestDailyStat?.totalBurned || '0', + circulationPool: raw.trading?.circulationPool?.totalShares || '0', + currentPrice: raw.latestPrice?.close || '1', + priceChange24h, + totalOrders: raw.trading?.totalAccounts || 0, + totalTrades: raw.trading?.totalAccounts || 0, + }; } @Get('stats') @ApiOperation({ summary: '获取仪表盘统计数据(别名)' }) async getStatsAlias() { - return this.dashboardService.getDashboardStats(); + return this.getStats(); } @Get('realtime') @ApiOperation({ summary: '获取实时数据' }) async getRealtimeStats() { - return this.dashboardService.getRealtimeStats(); + const raw = await this.dashboardService.getRealtimeStats(); + + // 转换为前端期望的格式 + return { + currentMinuteDistribution: raw.minuteDistribution || '0', + currentMinuteBurn: '0', // 暂无实时销毁数据 + activeOrders: 0, // 暂无实时订单数据 + pendingTrades: 0, // 暂无待处理交易数据 + lastPriceUpdateAt: raw.timestamp, + }; } @Get('reports')