feat: KOC详情弹窗 + 任务中心单入口改版 + 资源池默认合作方/采集兜底

KOC 详情弹窗(合作方/数据回收/工作台三处入口):
- 新增 KocDetailModal:基本信息 / 绑定KOC账号画像 / 参与任务记录 / 履约漏斗
- 工作台最近分发、回收队列账号名、截图回收合作方名、合作方页名称、分发详情头部合作方均可点开
- 分发表行点击仍打开分发详情(stopPropagation 隔离)

任务中心单入口改版(对齐"单任务双阶段"模型):
- 任务卡发布/回收面板整块可点,全卡仅保留一个「查看明细」,回收面板重复按钮移除
- 详情页自述身份:动态 label(任务详情·分发与回收一体/仅分发)+ 阶段徽章(含回收·截止/未开通回收)
- 内容分发表新增阶段筛选 chips(全部/待发布/已发布待数据/待收截图,未开通回收不显示截图项),筛选落空给专用空态文案
- 数据回收页入口文案改为「选择一个任务进入回收队列」,全站不再区分发布/回收两种任务类型

资源池 KOC 默认加入合作方 + 采集兜底:
- partners 新增 released_account_id(mysql/0023):显式解绑/被顶替的账号不再被默认合作方同步回填
- 任务未设置采集计划时,默认按发布时间起连续采集 7 天,等待文案显示「等待D1 · 默认7天」
This commit is contained in:
ABAPPLO
2026-10-12 11:11:31 +08:00
parent c11afd5f99
commit 87f4d4066d
20 changed files with 1472 additions and 195 deletions

View File

@@ -16,7 +16,8 @@ type DistributionForCollection = {
type ScheduledTask = {
id: string;
collection_start_date: string;
task_type: string | null;
collection_start_date: string | null;
collection_days: string;
};
@@ -63,9 +64,9 @@ function dateForScheduleDay(startDate: string, scheduleDay: number) {
.slice(0, 10);
}
function parseDays(value: string) {
function parseDays(value: string | null | undefined) {
try {
const parsed = JSON.parse(value) as unknown;
const parsed = JSON.parse(value ?? "[]") as unknown;
if (!Array.isArray(parsed)) return [];
return [...new Set(parsed.map(Number))]
.filter((day) => Number.isInteger(day) && day >= 1 && day <= 7)
@@ -75,12 +76,35 @@ function parseDays(value: string) {
}
}
export function parseCollectionDays(value: string | null | undefined) {
return parseDays(value);
}
// 数据回收(自动采集)兜底:任务未设置采集日时默认连续采集 7 天。
export const DEFAULT_COLLECTION_DAYS = [1, 2, 3, 4, 5, 6, 7];
export function effectiveCollectionDays(value: string | null | undefined) {
const days = parseDays(value);
return days.length > 0 ? days : [...DEFAULT_COLLECTION_DAYS];
}
export function shanghaiDateFromTimestamp(timestamp: number) {
return new Date(timestamp + 8 * 60 * 60 * 1000)
.toISOString()
.slice(0, 10);
}
// publish_time 等列以 UTC 文本存储(CURRENT_TIMESTAMP),统一换算成上海日期。
function shanghaiDateFromSqlTimestamp(value: string | null | undefined) {
if (!value) return null;
const normalized = value.includes("T")
? value
: `${value.replace(" ", "T")}Z`;
const epoch = Date.parse(normalized);
if (Number.isNaN(epoch)) return null;
return shanghaiDateFromTimestamp(epoch);
}
function shanghaiHourFromTimestamp(timestamp: number) {
return Number(
new Date(timestamp + 8 * 60 * 60 * 1000)
@@ -392,6 +416,42 @@ export async function runScheduledCollections(
);
}
async function distributionIdsNeedingCollection(
db: DatabaseClient,
taskId: string,
scheduledDate: string,
distributionId?: string,
) {
const scoped = distributionId ? "AND d.id = ?" : "";
const { results } = await db
.prepare(
`SELECT d.id FROM distributions d
WHERE d.task_id = ?
AND d.publish_url IS NOT NULL
AND d.publish_url != ''
${scoped}
AND NOT EXISTS (
SELECT 1 FROM collection_runs r
WHERE r.distribution_id = d.id
AND r.scheduled_date = ?
AND (
r.status = 'success'
OR (
r.status = 'collecting'
AND r.started_at >= datetime('now', '-30 minutes')
)
OR (
r.status = 'failed'
AND r.completed_at >= datetime('now', '-15 minutes')
)
)
)`,
)
.bind(...(distributionId ? [taskId, distributionId, scheduledDate] : [taskId, scheduledDate]))
.all<{ id: string }>();
return results.map((row) => row.id);
}
export async function runDueScheduledCollections(
db: DatabaseClient,
timestamp: number,
@@ -402,12 +462,9 @@ export async function runDueScheduledCollections(
const currentDate = shanghaiDateFromTimestamp(timestamp);
const tasks = await db
.prepare(
`SELECT id, collection_start_date, collection_days
`SELECT id, task_type, collection_start_date, collection_days
FROM tasks
WHERE collection_start_date IS NOT NULL
AND collection_start_date != ''
AND collection_days IS NOT NULL
AND collection_days != '[]'
WHERE COALESCE(task_type, 'content_publish') != 'screenshot_collect'
AND (? IS NULL OR id = ?)`,
)
.bind(onlyTaskId ?? null, onlyTaskId ?? null)
@@ -417,46 +474,25 @@ export async function runDueScheduledCollections(
let succeeded = 0;
let failed = 0;
for (const task of tasks.results) {
const schedules = dueSchedules(
task.collection_start_date,
parseDays(task.collection_days),
timestamp,
);
const collectDue = async (
taskId: string,
schedules: { scheduleDay: number; scheduledDate: string }[],
distributionId?: string,
) => {
for (const { scheduleDay, scheduledDate } of schedules) {
dueTasks += 1;
const distributions = await db
.prepare(
`SELECT d.id FROM distributions d
WHERE d.task_id = ?
AND d.publish_url IS NOT NULL
AND d.publish_url != ''
AND NOT EXISTS (
SELECT 1 FROM collection_runs r
WHERE r.distribution_id = d.id
AND r.scheduled_date = ?
AND (
r.status = 'success'
OR (
r.status = 'collecting'
AND r.started_at >= datetime('now', '-30 minutes')
)
OR (
r.status = 'failed'
AND r.completed_at >= datetime('now', '-15 minutes')
)
)
)`,
)
.bind(task.id, scheduledDate)
.all<{ id: string }>();
for (const distribution of distributions.results) {
const ids = await distributionIdsNeedingCollection(
db,
taskId,
scheduledDate,
distributionId,
);
for (const id of ids) {
attempted += 1;
try {
await collectDistributionMetrics(
db,
distribution.id,
id,
scheduledDate,
scheduleDay,
source,
@@ -468,6 +504,47 @@ export async function runDueScheduledCollections(
}
}
}
};
for (const task of tasks.results) {
const parsedDays = parseDays(task.collection_days);
if (task.collection_start_date && parsedDays.length > 0) {
await collectDue(
task.id,
dueSchedules(task.collection_start_date, parsedDays, timestamp),
);
continue;
}
// 未设置采集计划:默认按每篇作品的发布时间起连续采集 7 天。
const days = effectiveCollectionDays(task.collection_days);
const published = await db
.prepare(
`SELECT d.id, COALESCE(d.publish_time, d.claimed_at) AS publish_anchor
FROM distributions d
WHERE d.task_id = ?
AND d.publish_url IS NOT NULL
AND d.publish_url != ''`,
)
.bind(task.id)
.all<{ id: string; publish_anchor: string | null }>();
for (const distribution of published.results) {
const anchorDate = shanghaiDateFromSqlTimestamp(
distribution.publish_anchor,
);
if (!anchorDate) continue;
const windowEndDate = dateForScheduleDay(
anchorDate,
days[days.length - 1],
);
// 默认窗口已过(发布超过 7 天且从未配置计划)不再补采历史天,
// 避免 D1 快照与真实发布时间脱节;确需补采时由管理员设置明确计划。
if (!windowEndDate || currentDate > windowEndDate) continue;
await collectDue(
task.id,
dueSchedules(anchorDate, days, timestamp),
distribution.id,
);
}
}
return { currentDate, dueTasks, attempted, succeeded, failed };