From 13e94db45003c7ee9688df85ed3fc6cb9f11b9d1 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 14 Jan 2026 02:10:47 -0800 Subject: [PATCH] feat(mining-admin): add /reports/daily endpoint for frontend reports page Add ReportsController with /reports/daily endpoint that maps the dashboard service data to the format expected by the frontend. Co-Authored-By: Claude Opus 4.5 --- .../src/api/api.module.ts | 2 + .../src/api/controllers/reports.controller.ts | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 backend/services/mining-admin-service/src/api/controllers/reports.controller.ts diff --git a/backend/services/mining-admin-service/src/api/api.module.ts b/backend/services/mining-admin-service/src/api/api.module.ts index 656a5a2d..2e5bd2cc 100644 --- a/backend/services/mining-admin-service/src/api/api.module.ts +++ b/backend/services/mining-admin-service/src/api/api.module.ts @@ -8,6 +8,7 @@ import { AuditController } from './controllers/audit.controller'; import { HealthController } from './controllers/health.controller'; import { UsersController } from './controllers/users.controller'; import { SystemAccountsController } from './controllers/system-accounts.controller'; +import { ReportsController } from './controllers/reports.controller'; @Module({ imports: [ApplicationModule], @@ -20,6 +21,7 @@ import { SystemAccountsController } from './controllers/system-accounts.controll HealthController, UsersController, SystemAccountsController, + ReportsController, ], }) export class ApiModule {} diff --git a/backend/services/mining-admin-service/src/api/controllers/reports.controller.ts b/backend/services/mining-admin-service/src/api/controllers/reports.controller.ts new file mode 100644 index 00000000..caf93aa1 --- /dev/null +++ b/backend/services/mining-admin-service/src/api/controllers/reports.controller.ts @@ -0,0 +1,59 @@ +import { Controller, Get, Query } from '@nestjs/common'; +import { + ApiTags, + ApiOperation, + ApiBearerAuth, + ApiQuery, +} from '@nestjs/swagger'; +import { DashboardService } from '../../application/services/dashboard.service'; + +@ApiTags('Reports') +@ApiBearerAuth() +@Controller('reports') +export class ReportsController { + constructor(private readonly dashboardService: DashboardService) {} + + @Get('daily') + @ApiOperation({ summary: '获取每日报表' }) + @ApiQuery({ name: 'page', required: false, type: Number }) + @ApiQuery({ name: 'pageSize', required: false, type: Number }) + @ApiQuery({ name: 'days', required: false, type: Number }) + async getDailyReports( + @Query('page') page?: number, + @Query('pageSize') pageSize?: number, + @Query('days') days?: number, + ) { + const result = await this.dashboardService.getReports( + page ?? 1, + pageSize ?? 30, + ); + + // 转换为前端期望的格式 + return { + items: result.data.map((report: any) => ({ + id: report.id, + reportDate: report.reportDate, + totalUsers: report.users?.total || 0, + newUsers: report.users?.new || 0, + adoptedUsers: report.adoptions?.total || 0, + newAdoptedUsers: report.adoptions?.new || 0, + totalContribution: report.contribution?.total || '0', + newContribution: report.contribution?.growth || '0', + totalDistributed: report.mining?.distributed || '0', + dailyDistributed: report.mining?.distributed || '0', + totalBurned: report.mining?.burned || '0', + dailyBurned: report.mining?.burned || '0', + openPrice: report.price?.open || '1', + closePrice: report.price?.close || '1', + highPrice: report.price?.high || '1', + lowPrice: report.price?.low || '1', + totalVolume: report.trading?.volume || '0', + dailyVolume: report.trading?.volume || '0', + })), + total: result.total, + page: result.pagination.page, + pageSize: result.pagination.pageSize, + totalPages: result.pagination.totalPages, + }; + } +}