refactor(reporting-service): 移除仪表板最近活动的模拟数据
无真实数据时返回空数组,不再生成假数据 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
7896be6062
commit
59b83acfa4
|
|
@ -202,7 +202,7 @@ export class DashboardApplicationService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取最近活动数据
|
* 获取最近活动数据
|
||||||
* 优先从数据库获取,若无则返回模拟数据
|
* 从数据库获取真实数据,无数据时返回空数组
|
||||||
*/
|
*/
|
||||||
async getActivities(limit: number): Promise<DashboardActivitiesResponseDto> {
|
async getActivities(limit: number): Promise<DashboardActivitiesResponseDto> {
|
||||||
this.logger.debug(`Fetching dashboard activities, limit: ${limit}`);
|
this.logger.debug(`Fetching dashboard activities, limit: ${limit}`);
|
||||||
|
|
@ -210,26 +210,17 @@ export class DashboardApplicationService {
|
||||||
// 从数据库获取活动记录
|
// 从数据库获取活动记录
|
||||||
const dbActivities = await this.activityRepo.findRecent(limit);
|
const dbActivities = await this.activityRepo.findRecent(limit);
|
||||||
|
|
||||||
let activities: DashboardActivityItemDto[];
|
const activities: DashboardActivityItemDto[] = dbActivities.map((activity) => ({
|
||||||
|
id: String(activity.id),
|
||||||
if (dbActivities.length > 0) {
|
type: activity.activityType as ActivityType,
|
||||||
// 使用真实数据
|
icon: activity.icon || '📌',
|
||||||
activities = dbActivities.map((activity) => ({
|
title: activity.title,
|
||||||
id: String(activity.id),
|
description: activity.description,
|
||||||
type: activity.activityType as ActivityType,
|
timestamp: this.formatRelativeTime(
|
||||||
icon: activity.icon || '📌',
|
Math.floor((Date.now() - (activity.createdAt?.getTime() || Date.now())) / 60000),
|
||||||
title: activity.title,
|
),
|
||||||
description: activity.description,
|
createdAt: activity.createdAt?.toISOString() || new Date().toISOString(),
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { activities };
|
return { activities };
|
||||||
}
|
}
|
||||||
|
|
@ -300,82 +291,6 @@ export class DashboardApplicationService {
|
||||||
return data;
|
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 格式
|
* 格式化日期为 MM-DD 格式
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue