/** * Reward Service HTTP 客户端 * [2026-01-04] 新增:用于系统账户报表统计 * 回滚方式:删除此文件 */ import { Injectable, Logger } from '@nestjs/common'; import { HttpService } from '@nestjs/axios'; import { ConfigService } from '@nestjs/config'; import { firstValueFrom } from 'rxjs'; export interface ExpiredRewardsSummary { totalAmount: number; totalCount: number; byMonth: Array<{ month: string; amount: number; count: number; }>; byRightType: Array<{ rightType: string; amount: number; count: number; }>; } @Injectable() export class RewardServiceClient { private readonly logger = new Logger(RewardServiceClient.name); private readonly baseUrl: string; constructor( private readonly httpService: HttpService, private readonly configService: ConfigService, ) { this.baseUrl = this.configService.get( 'REWARD_SERVICE_URL', 'http://reward-service:3004', ); } /** * 获取过期收益统计汇总 */ async getExpiredRewardsSummary(params?: { startDate?: string; endDate?: string; }): Promise { try { const queryParams = new URLSearchParams(); if (params?.startDate) queryParams.append('startDate', params.startDate); if (params?.endDate) queryParams.append('endDate', params.endDate); const url = `${this.baseUrl}/internal/statistics/expired-rewards-summary?${queryParams.toString()}`; this.logger.debug(`[getExpiredRewardsSummary] 请求: ${url}`); const response = await firstValueFrom( this.httpService.get(url), ); return response.data; } catch (error) { this.logger.error(`[getExpiredRewardsSummary] 失败: ${error.message}`); // 返回默认值,不阻塞报表 return { totalAmount: 0, totalCount: 0, byMonth: [], byRightType: [], }; } } }