|
|
@@ -608,6 +608,7 @@ export class WorkDayStatisticsService {
|
|
|
groupId: number | null;
|
|
|
groupName?: string | null;
|
|
|
fansCount: number;
|
|
|
+ worksCount: number | null;
|
|
|
totalIncome: number | null;
|
|
|
yesterdayIncome: number | null;
|
|
|
totalViews: number | null;
|
|
|
@@ -620,6 +621,7 @@ export class WorkDayStatisticsService {
|
|
|
}>;
|
|
|
summary: {
|
|
|
totalAccounts: number;
|
|
|
+ totalWorks: number;
|
|
|
totalIncome: number;
|
|
|
yesterdayIncome: number;
|
|
|
totalViews: number;
|
|
|
@@ -703,6 +705,7 @@ export class WorkDayStatisticsService {
|
|
|
// 汇总统计数据
|
|
|
let totalIncome = 0;
|
|
|
let yesterdayIncome = 0;
|
|
|
+ let totalWorks = 0;
|
|
|
let totalViews = 0;
|
|
|
let yesterdayViews = 0;
|
|
|
let totalFans = 0;
|
|
|
@@ -715,6 +718,7 @@ export class WorkDayStatisticsService {
|
|
|
const yesterdayUds = yesterdayUdsMap.get(account.id);
|
|
|
|
|
|
const accountFansCount = account.fansCount || 0;
|
|
|
+ const accountWorksCount = account.worksCount || 0;
|
|
|
const accountYesterdayViews = yesterdayUds?.playCount ?? 0;
|
|
|
const accountYesterdayComments = yesterdayUds?.commentCount ?? 0;
|
|
|
const accountYesterdayLikes = yesterdayUds?.likeCount ?? 0;
|
|
|
@@ -731,6 +735,7 @@ export class WorkDayStatisticsService {
|
|
|
groupId: account.groupId,
|
|
|
groupName: account.group?.name ?? null,
|
|
|
fansCount: accountFansCount,
|
|
|
+ worksCount: accountWorksCount,
|
|
|
totalIncome: null,
|
|
|
yesterdayIncome: null,
|
|
|
totalViews: accountTotalViews,
|
|
|
@@ -742,6 +747,7 @@ export class WorkDayStatisticsService {
|
|
|
status: account.status,
|
|
|
});
|
|
|
|
|
|
+ totalWorks += accountWorksCount;
|
|
|
totalViews += accountTotalViews;
|
|
|
totalFans += accountFansCount;
|
|
|
yesterdayViews += accountYesterdayViews;
|
|
|
@@ -754,6 +760,7 @@ export class WorkDayStatisticsService {
|
|
|
accounts: accountList,
|
|
|
summary: {
|
|
|
totalAccounts,
|
|
|
+ totalWorks,
|
|
|
totalIncome,
|
|
|
yesterdayIncome,
|
|
|
totalViews,
|
|
|
@@ -1232,7 +1239,7 @@ export class WorkDayStatisticsService {
|
|
|
const startDateStr = startDate;
|
|
|
const endDateStr = endDate;
|
|
|
|
|
|
- // 基础查询:当前用户的作品
|
|
|
+ // 基础查询:当前用户的作品(先不分页,后面在内存中做分页,避免部分数据库在 GROUP BY + JOIN 场景下忽略 skip/take)
|
|
|
const qb = this.workRepository
|
|
|
.createQueryBuilder('w')
|
|
|
.leftJoin(WorkDayStatistics, 'wds', 'wds.work_id = w.id AND wds.record_date >= :wStart AND wds.record_date <= :wEnd', {
|
|
|
@@ -1275,33 +1282,12 @@ export class WorkDayStatisticsService {
|
|
|
// 排序:统一按发布时间倒序(最新的在前)
|
|
|
qb.orderBy('w.publish_time', 'DESC');
|
|
|
|
|
|
- // 统计总数(作品数)
|
|
|
- const countQb = this.workRepository
|
|
|
- .createQueryBuilder('w')
|
|
|
- .innerJoin(PlatformAccount, 'pa', 'pa.id = w.accountId')
|
|
|
- .where('w.userId = :userId', { userId });
|
|
|
+ // 先获取全部满足条件的作品聚合行,再在内存中做分页和汇总
|
|
|
+ const allRows = await qb.getRawMany();
|
|
|
|
|
|
- if (platform) {
|
|
|
- countQb.andWhere('w.platform = :platform', { platform });
|
|
|
- }
|
|
|
- if (accountIds && accountIds.length > 0) {
|
|
|
- countQb.andWhere('w.accountId IN (:...accountIds)', { accountIds });
|
|
|
- }
|
|
|
- if (groupId) {
|
|
|
- countQb.andWhere('pa.groupId = :groupId', { groupId });
|
|
|
- }
|
|
|
- if (keyword && keyword.trim()) {
|
|
|
- const kw = `%${keyword.trim()}%`;
|
|
|
- countQb.andWhere('(w.title LIKE :kw OR pa.accountName LIKE :kw)', { kw });
|
|
|
- }
|
|
|
-
|
|
|
- const total = await countQb.getCount();
|
|
|
-
|
|
|
- // 分页
|
|
|
+ const total = allRows.length;
|
|
|
const offset = (page - 1) * pageSize;
|
|
|
- qb.skip(offset).take(pageSize);
|
|
|
-
|
|
|
- const rows = await qb.getRawMany();
|
|
|
+ const pagedRows = allRows.slice(offset, offset + pageSize);
|
|
|
|
|
|
let totalViews = 0;
|
|
|
let totalComments = 0;
|
|
|
@@ -1309,7 +1295,8 @@ export class WorkDayStatisticsService {
|
|
|
let totalCollects = 0;
|
|
|
let totalLikes = 0;
|
|
|
|
|
|
- const works = rows.map((row) => {
|
|
|
+ // 汇总统计使用所有作品(而不是当前页),确保顶部统计口径统一
|
|
|
+ for (const row of allRows) {
|
|
|
const views = Number(row.viewsCount) || 0;
|
|
|
const comments = Number(row.commentsCount) || 0;
|
|
|
const shares = Number(row.sharesCount) || 0;
|
|
|
@@ -1321,6 +1308,15 @@ export class WorkDayStatisticsService {
|
|
|
totalShares += shares;
|
|
|
totalCollects += collects;
|
|
|
totalLikes += likes;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当前页作品列表只返回分页后的数据
|
|
|
+ const works = pagedRows.map((row) => {
|
|
|
+ const views = Number(row.viewsCount) || 0;
|
|
|
+ const comments = Number(row.commentsCount) || 0;
|
|
|
+ const shares = Number(row.sharesCount) || 0;
|
|
|
+ const collects = Number(row.collectsCount) || 0;
|
|
|
+ const likes = Number(row.likesCount) || 0;
|
|
|
|
|
|
const publishTime =
|
|
|
row.publishTime instanceof Date
|