|
@@ -34,6 +34,7 @@ interface PlatformStatItem {
|
|
|
likesCount: number;
|
|
likesCount: number;
|
|
|
commentsCount: number;
|
|
commentsCount: number;
|
|
|
collectsCount: number;
|
|
collectsCount: number;
|
|
|
|
|
+ updateTime?: string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
interface WorkStatisticsItem {
|
|
interface WorkStatisticsItem {
|
|
@@ -319,7 +320,7 @@ export class WorkDayStatisticsService {
|
|
|
where: { userId },
|
|
where: { userId },
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // 按平台聚合数据:Map<platform, { fansCount, fansIncrease, viewsCount, likesCount, commentsCount, collectsCount }>
|
|
|
|
|
|
|
+ // 按平台聚合数据:Map<platform, { fansCount, fansIncrease, viewsCount, likesCount, commentsCount, collectsCount, latestUpdateTime }>
|
|
|
const platformMap = new Map<string, {
|
|
const platformMap = new Map<string, {
|
|
|
fansCount: number;
|
|
fansCount: number;
|
|
|
fansIncrease: number;
|
|
fansIncrease: number;
|
|
@@ -327,6 +328,7 @@ export class WorkDayStatisticsService {
|
|
|
likesCount: number;
|
|
likesCount: number;
|
|
|
commentsCount: number;
|
|
commentsCount: number;
|
|
|
collectsCount: number;
|
|
collectsCount: number;
|
|
|
|
|
+ latestUpdateTime: Date | null;
|
|
|
}>();
|
|
}>();
|
|
|
|
|
|
|
|
// 遍历每个账号,计算该账号的数据,然后累加到对应平台
|
|
// 遍历每个账号,计算该账号的数据,然后累加到对应平台
|
|
@@ -396,6 +398,7 @@ export class WorkDayStatisticsService {
|
|
|
likesCount: 0,
|
|
likesCount: 0,
|
|
|
commentsCount: 0,
|
|
commentsCount: 0,
|
|
|
collectsCount: 0,
|
|
collectsCount: 0,
|
|
|
|
|
+ latestUpdateTime: null,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -406,18 +409,48 @@ export class WorkDayStatisticsService {
|
|
|
platformStat.likesCount += accountLikesIncrease;
|
|
platformStat.likesCount += accountLikesIncrease;
|
|
|
platformStat.commentsCount += accountCommentsIncrease;
|
|
platformStat.commentsCount += accountCommentsIncrease;
|
|
|
platformStat.collectsCount += accountCollectsIncrease;
|
|
platformStat.collectsCount += accountCollectsIncrease;
|
|
|
|
|
+
|
|
|
|
|
+ // 查询该账号在当前时间段内的最晚 updated_at
|
|
|
|
|
+ const latestUserStat = await this.userDayStatisticsRepository
|
|
|
|
|
+ .createQueryBuilder('uds')
|
|
|
|
|
+ .where('uds.account_id = :accountId', { accountId: account.id })
|
|
|
|
|
+ .andWhere('DATE(uds.record_date) >= :startDate', { startDate: startDateStr })
|
|
|
|
|
+ .andWhere('DATE(uds.record_date) <= :endDate', { endDate: endDateStr })
|
|
|
|
|
+ .orderBy('uds.updated_at', 'DESC')
|
|
|
|
|
+ .getOne();
|
|
|
|
|
+
|
|
|
|
|
+ if (latestUserStat && latestUserStat.updatedAt) {
|
|
|
|
|
+ // 更新平台的最晚更新时间
|
|
|
|
|
+ if (!platformStat.latestUpdateTime || latestUserStat.updatedAt > platformStat.latestUpdateTime) {
|
|
|
|
|
+ platformStat.latestUpdateTime = latestUserStat.updatedAt;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 转换为数组格式,按粉丝数降序排序
|
|
// 转换为数组格式,按粉丝数降序排序
|
|
|
- const platformData: PlatformStatItem[] = Array.from(platformMap.entries()).map(([platform, stat]) => ({
|
|
|
|
|
- platform,
|
|
|
|
|
- fansCount: stat.fansCount,
|
|
|
|
|
- fansIncrease: stat.fansIncrease,
|
|
|
|
|
- viewsCount: stat.viewsCount,
|
|
|
|
|
- likesCount: stat.likesCount,
|
|
|
|
|
- commentsCount: stat.commentsCount,
|
|
|
|
|
- collectsCount: stat.collectsCount,
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+ const platformData: PlatformStatItem[] = Array.from(platformMap.entries()).map(([platform, stat]) => {
|
|
|
|
|
+ // 格式化更新时间为 "MM-DD HH:mm" 格式
|
|
|
|
|
+ let updateTime: string | undefined;
|
|
|
|
|
+ if (stat.latestUpdateTime) {
|
|
|
|
|
+ const date = new Date(stat.latestUpdateTime);
|
|
|
|
|
+ const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
|
|
|
+ const day = String(date.getDate()).padStart(2, '0');
|
|
|
|
|
+ const hours = String(date.getHours()).padStart(2, '0');
|
|
|
|
|
+ const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
|
|
|
+ updateTime = `${month}-${day} ${hours}:${minutes}`;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ platform,
|
|
|
|
|
+ fansCount: stat.fansCount,
|
|
|
|
|
+ fansIncrease: stat.fansIncrease,
|
|
|
|
|
+ viewsCount: stat.viewsCount,
|
|
|
|
|
+ likesCount: stat.likesCount,
|
|
|
|
|
+ commentsCount: stat.commentsCount,
|
|
|
|
|
+ collectsCount: stat.collectsCount,
|
|
|
|
|
+ updateTime,
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
platformData.sort((a, b) => b.fansCount - a.fansCount);
|
|
platformData.sort((a, b) => b.fansCount - a.fansCount);
|
|
|
|
|
|