feat: 复盘报表视图与 CSV 导出(manager 专属)
This commit is contained in:
@@ -872,6 +872,79 @@ export async function getDashboardData() {
|
||||
};
|
||||
}
|
||||
|
||||
export type TaskReportRow = {
|
||||
id: string;
|
||||
name: string;
|
||||
task_type: string;
|
||||
brand: string;
|
||||
platform: string;
|
||||
status: string;
|
||||
due_at: string;
|
||||
created_at: string;
|
||||
quantity: number;
|
||||
project_name: string | null;
|
||||
claimed_count: number;
|
||||
published_count: number;
|
||||
completed_count: number;
|
||||
exposure_total: number | null;
|
||||
views_total: number | null;
|
||||
d2_likes: number | null;
|
||||
d2_comments: number | null;
|
||||
d2_collects: number | null;
|
||||
d5_likes: number | null;
|
||||
d5_comments: number | null;
|
||||
d5_collects: number | null;
|
||||
d7_likes: number | null;
|
||||
d7_comments: number | null;
|
||||
d7_collects: number | null;
|
||||
latest_likes: number | null;
|
||||
latest_comments: number | null;
|
||||
latest_collects: number | null;
|
||||
latest_shares: number | null;
|
||||
};
|
||||
|
||||
export async function getTaskReportData(db: DatabaseClient) {
|
||||
const result = await db
|
||||
.prepare(
|
||||
`SELECT
|
||||
t.id,
|
||||
t.name,
|
||||
t.task_type,
|
||||
t.brand,
|
||||
t.platform,
|
||||
t.status,
|
||||
t.due_at,
|
||||
t.created_at,
|
||||
t.quantity,
|
||||
p.name AS project_name,
|
||||
COUNT(d.id) AS claimed_count,
|
||||
SUM(CASE WHEN TRIM(COALESCE(d.publish_url, '')) != '' THEN 1 ELSE 0 END) AS published_count,
|
||||
SUM(CASE WHEN d.status = 'complete' THEN 1 ELSE 0 END) AS completed_count,
|
||||
SUM(d.exposure) AS exposure_total,
|
||||
SUM(d.views) AS views_total,
|
||||
SUM(d.d2_likes) AS d2_likes,
|
||||
SUM(d.d2_comments) AS d2_comments,
|
||||
SUM(d.d2_collects) AS d2_collects,
|
||||
SUM(d.d5_likes) AS d5_likes,
|
||||
SUM(d.d5_comments) AS d5_comments,
|
||||
SUM(d.d5_collects) AS d5_collects,
|
||||
SUM(d.d7_likes) AS d7_likes,
|
||||
SUM(d.d7_comments) AS d7_comments,
|
||||
SUM(d.d7_collects) AS d7_collects,
|
||||
SUM(d.latest_likes) AS latest_likes,
|
||||
SUM(d.latest_comments) AS latest_comments,
|
||||
SUM(d.latest_collects) AS latest_collects,
|
||||
SUM(d.latest_shares) AS latest_shares
|
||||
FROM tasks t
|
||||
LEFT JOIN distributions d ON d.task_id = t.id
|
||||
LEFT JOIN projects p ON p.id = t.project_id
|
||||
GROUP BY t.id
|
||||
ORDER BY t.created_at DESC`,
|
||||
)
|
||||
.all<TaskReportRow>();
|
||||
return result.results;
|
||||
}
|
||||
|
||||
export function uid(prefix: string) {
|
||||
return `${prefix}-${crypto.randomUUID().slice(0, 8)}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user