From 59b83acfa43cd4c5539cd37952283a9ecaabef68 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 20 Dec 2025 01:07:39 -0800 Subject: [PATCH] =?UTF-8?q?refactor(reporting-service):=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E4=BB=AA=E8=A1=A8=E6=9D=BF=E6=9C=80=E8=BF=91=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E7=9A=84=E6=A8=A1=E6=8B=9F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 无真实数据时返回空数组,不再生成假数据 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../services/dashboard-application.service.ts | 109 ++---------------- 1 file changed, 12 insertions(+), 97 deletions(-) diff --git a/backend/services/reporting-service/src/application/services/dashboard-application.service.ts b/backend/services/reporting-service/src/application/services/dashboard-application.service.ts index 627486a7..8e082d68 100644 --- a/backend/services/reporting-service/src/application/services/dashboard-application.service.ts +++ b/backend/services/reporting-service/src/application/services/dashboard-application.service.ts @@ -202,7 +202,7 @@ export class DashboardApplicationService { /** * 获取最近活动数据 - * 优先从数据库获取,若无则返回模拟数据 + * 从数据库获取真实数据,无数据时返回空数组 */ async getActivities(limit: number): Promise { this.logger.debug(`Fetching dashboard activities, limit: ${limit}`); @@ -210,26 +210,17 @@ export class DashboardApplicationService { // 从数据库获取活动记录 const dbActivities = await this.activityRepo.findRecent(limit); - let activities: DashboardActivityItemDto[]; - - if (dbActivities.length > 0) { - // 使用真实数据 - activities = dbActivities.map((activity) => ({ - id: String(activity.id), - type: activity.activityType as ActivityType, - icon: activity.icon || '📌', - title: activity.title, - description: activity.description, - timestamp: this.formatRelativeTime( - Math.floor((Date.now() - (activity.createdAt?.getTime() || Date.now())) / 60000), - ), - createdAt: activity.createdAt?.toISOString() || new Date().toISOString(), - })); - } else { - // 如果没有数据,返回模拟数据 - this.logger.debug('No activities found, generating mock data'); - activities = this.generateMockActivities(limit); - } + const activities: DashboardActivityItemDto[] = dbActivities.map((activity) => ({ + id: String(activity.id), + type: activity.activityType as ActivityType, + icon: activity.icon || '📌', + title: activity.title, + description: activity.description, + timestamp: this.formatRelativeTime( + Math.floor((Date.now() - (activity.createdAt?.getTime() || Date.now())) / 60000), + ), + createdAt: activity.createdAt?.toISOString() || new Date().toISOString(), + })); return { activities }; } @@ -300,82 +291,6 @@ export class DashboardApplicationService { return data; } - /** - * 生成模拟活动数据 - */ - private generateMockActivities(limit: number): DashboardActivityItemDto[] { - const activityTemplates: Array<{ - type: ActivityType; - icon: string; - title: string; - descriptionTemplate: string; - }> = [ - { - type: 'user_register', - icon: '👤', - title: '新用户注册', - descriptionTemplate: '用户 {name} 完成注册', - }, - { - type: 'company_authorization', - icon: '🏢', - title: '公司授权', - descriptionTemplate: '{province}省公司完成授权', - }, - { - type: 'planting_order', - icon: '🌳', - title: '认种订单', - descriptionTemplate: '用户 {name} 认种了 {count} 棵榴莲树', - }, - { - type: 'system_update', - icon: '⚙️', - title: '系统更新', - descriptionTemplate: '{feature} 已更新', - }, - { - type: 'report_generated', - icon: '📊', - title: '报表生成', - descriptionTemplate: '{month}月份运营报表已生成', - }, - ]; - - const names = ['张三', '李四', '王五', '赵六', '钱七']; - const provinces = ['广东', '浙江', '江苏', '山东', '四川']; - const features = ['龙虎榜规则', '结算规则', '授权流程']; - const months = ['1', '2', '3', '11', '12']; - - const activities: DashboardActivityItemDto[] = []; - const now = new Date(); - - for (let i = 0; i < limit; i++) { - const template = activityTemplates[i % activityTemplates.length]; - const minutesAgo = (i + 1) * 15 + Math.floor(Math.random() * 30); - const createdAt = new Date(now.getTime() - minutesAgo * 60 * 1000); - - let description = template.descriptionTemplate; - description = description.replace('{name}', names[Math.floor(Math.random() * names.length)]); - description = description.replace('{province}', provinces[Math.floor(Math.random() * provinces.length)]); - description = description.replace('{count}', String(Math.floor(Math.random() * 10) + 1)); - description = description.replace('{feature}', features[Math.floor(Math.random() * features.length)]); - description = description.replace('{month}', months[Math.floor(Math.random() * months.length)]); - - activities.push({ - id: String(i + 1), - type: template.type, - icon: template.icon, - title: template.title, - description, - timestamp: this.formatRelativeTime(minutesAgo), - createdAt: createdAt.toISOString(), - }); - } - - return activities; - } - /** * 格式化日期为 MM-DD 格式 */