80 lines
2.7 KiB
TypeScript
80 lines
2.7 KiB
TypeScript
import { Controller, Get, Query } from '@nestjs/common';
|
|
import {
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiBearerAuth,
|
|
ApiQuery,
|
|
} from '@nestjs/swagger';
|
|
import { DashboardService } from '../../application/services/dashboard.service';
|
|
|
|
@ApiTags('Dashboard')
|
|
@ApiBearerAuth()
|
|
@Controller('dashboard')
|
|
export class DashboardController {
|
|
constructor(private readonly dashboardService: DashboardService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: '获取仪表盘统计数据' })
|
|
async getStats() {
|
|
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,
|
|
totalTrees: raw.contribution?.totalTrees || 0,
|
|
networkEffectiveContribution: raw.contribution?.effectiveContribution || '0',
|
|
networkTotalContribution: raw.contribution?.totalContribution || '0',
|
|
networkLevelPending: raw.contribution?.teamLevelContribution || '0',
|
|
networkBonusPending: raw.contribution?.teamBonusContribution || '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.getStats();
|
|
}
|
|
|
|
@Get('realtime')
|
|
@ApiOperation({ summary: '获取实时数据' })
|
|
async getRealtimeStats() {
|
|
const raw = await this.dashboardService.getRealtimeStats();
|
|
|
|
// 转换为前端期望的格式
|
|
return {
|
|
currentMinuteDistribution: raw.minuteDistribution || '0',
|
|
currentMinuteBurn: '0', // 暂无实时销毁数据
|
|
activeOrders: 0, // 暂无实时订单数据
|
|
pendingTrades: 0, // 暂无待处理交易数据
|
|
lastPriceUpdateAt: raw.timestamp,
|
|
};
|
|
}
|
|
|
|
@Get('reports')
|
|
@ApiOperation({ summary: '获取每日报表' })
|
|
@ApiQuery({ name: 'page', required: false, type: Number })
|
|
@ApiQuery({ name: 'pageSize', required: false, type: Number })
|
|
async getReports(
|
|
@Query('page') page?: number,
|
|
@Query('pageSize') pageSize?: number,
|
|
) {
|
|
return this.dashboardService.getReports(page ?? 1, pageSize ?? 30);
|
|
}
|
|
}
|