feat: 任务模型物理合并,发布+回收并为单任务双阶段
- tasks 新增 recovery_enabled/recovery_due_at/recovery_instructions/recovery_example_images,回收挂自己名下(先发布后交截图),不再置 complete - 存量 screenshot_collect 迁移并入父任务后删除(mysql/0020 含 DELETE,生产执行前务必备份) - 新 action task_enable_recovery:ghost 面板一键开通回收,截止默认=发布截止 - 企微催办双阶段(待发布/截图待提交);超期自动释放仅发布阶段 - admin 删 groupTaskMasters 聚合改单卡双面板;portal 详情页回收截图区块+批次回收进度 - 测试 309 全绿 + Playwright E2E 20/20
This commit is contained in:
@@ -102,6 +102,15 @@ function idList(value: unknown) {
|
||||
];
|
||||
}
|
||||
|
||||
function recoveryPayload(task: PartnerTask) {
|
||||
return {
|
||||
recoveryEnabled: Number(task?.recovery_enabled) === 1,
|
||||
recoveryDueAt: String(task?.recovery_due_at ?? ""),
|
||||
recoveryInstructions: String(task?.recovery_instructions ?? ""),
|
||||
recoveryExampleImages: publicImageAssets(task?.recovery_example_images),
|
||||
};
|
||||
}
|
||||
|
||||
function publicImageAssets(value: unknown): ImageAsset[] {
|
||||
try {
|
||||
const assets = JSON.parse(String(value ?? "[]")) as Array<
|
||||
@@ -137,13 +146,18 @@ type PartnerTask = {
|
||||
task_type: string;
|
||||
platform: string;
|
||||
content_format: string;
|
||||
recovery_enabled: number;
|
||||
recovery_due_at: string;
|
||||
recovery_instructions: string | null;
|
||||
recovery_example_images: string;
|
||||
};
|
||||
|
||||
async function findTask(taskToken: string) {
|
||||
return getRawDb()
|
||||
.prepare(
|
||||
`SELECT id, name, brand, quantity, claimed_quantity, due_at, status,
|
||||
task_type, platform, content_format
|
||||
task_type, platform, content_format,
|
||||
recovery_enabled, recovery_due_at, recovery_instructions, recovery_example_images
|
||||
FROM tasks WHERE share_token = ?`,
|
||||
)
|
||||
.bind(taskToken)
|
||||
@@ -164,6 +178,10 @@ async function findDelegationAccess(delegationToken: string) {
|
||||
t.task_type,
|
||||
t.platform,
|
||||
t.content_format,
|
||||
t.recovery_enabled,
|
||||
t.recovery_due_at,
|
||||
t.recovery_instructions,
|
||||
t.recovery_example_images,
|
||||
b.id AS bundle_id,
|
||||
b.label AS bundle_label,
|
||||
b.quantity AS bundle_quantity,
|
||||
@@ -398,7 +416,7 @@ async function handleGet(request: Request) {
|
||||
.all();
|
||||
delegation = {
|
||||
id: delegationAccess.bundle_id,
|
||||
label: task.task_type === "screenshot_collect" ? "转派截图任务包" : "转派发布包",
|
||||
label: "转派发布包",
|
||||
quantity: delegationAccess.bundle_quantity,
|
||||
createdAt: delegationAccess.bundle_created_at,
|
||||
assignments: assignments.results.map((assignment) => ({
|
||||
@@ -421,6 +439,8 @@ async function handleGet(request: Request) {
|
||||
type: task.task_type,
|
||||
platform: task.platform,
|
||||
contentFormat: task.content_format,
|
||||
recoveryEnabled: recoveryPayload(task).recoveryEnabled,
|
||||
recoveryDueAt: recoveryPayload(task).recoveryDueAt,
|
||||
}
|
||||
: {
|
||||
name: task.name,
|
||||
@@ -433,6 +453,7 @@ async function handleGet(request: Request) {
|
||||
platform: task.platform,
|
||||
contentFormat: task.content_format,
|
||||
availableQuantity: available?.count ?? 0,
|
||||
...recoveryPayload(task),
|
||||
},
|
||||
claim,
|
||||
delegation,
|
||||
@@ -534,8 +555,7 @@ async function handlePost(request: Request) {
|
||||
c.created_at,
|
||||
COUNT(d.id) AS note_count,
|
||||
SUM(CASE
|
||||
WHEN ? = 'screenshot_collect' AND d.result_submitted_at IS NOT NULL THEN 1
|
||||
WHEN ? != 'screenshot_collect' AND d.publish_url IS NOT NULL AND d.publish_url != '' THEN 1
|
||||
WHEN d.publish_url IS NOT NULL AND d.publish_url != '' THEN 1
|
||||
ELSE 0 END) AS completed_count,
|
||||
MIN(co.title) AS first_title
|
||||
FROM claims c
|
||||
@@ -548,7 +568,7 @@ async function handlePost(request: Request) {
|
||||
ORDER BY c.created_at DESC, c.id DESC
|
||||
LIMIT 20`,
|
||||
)
|
||||
.bind(task.task_type, task.task_type, task.id, ...partnerCandidates)
|
||||
.bind(task.id, ...partnerCandidates)
|
||||
.all<{
|
||||
claim_token: string;
|
||||
quantity: number;
|
||||
@@ -569,7 +589,7 @@ async function handlePost(request: Request) {
|
||||
quantity: claim.note_count || claim.quantity,
|
||||
completedCount: claim.completed_count || 0,
|
||||
createdAt: claim.created_at,
|
||||
firstTitle: claim.first_title || (task.task_type === "screenshot_collect" ? "领取的截图任务" : "领取的笔记"),
|
||||
firstTitle: claim.first_title || "领取的笔记",
|
||||
})),
|
||||
});
|
||||
}
|
||||
@@ -788,7 +808,7 @@ async function handlePost(request: Request) {
|
||||
}
|
||||
if (distributionIds.length === 0) {
|
||||
return Response.json(
|
||||
{ error: task.task_type === "screenshot_collect" ? "请至少选择一份待提交任务" : "请至少选择一篇待发布笔记" },
|
||||
{ error: "请至少选择一篇待发布笔记" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
@@ -823,13 +843,9 @@ async function handlePost(request: Request) {
|
||||
{ status: 403 },
|
||||
);
|
||||
}
|
||||
if (selected.results.some((item) =>
|
||||
task.task_type === "screenshot_collect"
|
||||
? item.result_submitted_at
|
||||
: item.publish_url,
|
||||
)) {
|
||||
if (selected.results.some((item) => item.publish_url)) {
|
||||
return Response.json(
|
||||
{ error: task.task_type === "screenshot_collect" ? "已提交的截图任务不能再次转派" : "已发布的笔记不能再次转派" },
|
||||
{ error: "已发布的笔记不能再次转派" },
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
@@ -942,7 +958,7 @@ async function handlePost(request: Request) {
|
||||
.first<{ count: number }>();
|
||||
if ((completed?.count ?? 0) > 0) {
|
||||
return Response.json(
|
||||
{ error: task.task_type === "screenshot_collect" ? "该分享包已有截图提交,不能撤销" : "该分享包已有笔记发布,需保留链接继续完成第7天数据回收" },
|
||||
{ error: "该分享包已有笔记发布,需保留链接继续完成第7天数据回收" },
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
@@ -968,9 +984,6 @@ async function handlePost(request: Request) {
|
||||
}
|
||||
|
||||
if (body.action === "submit") {
|
||||
if (task.task_type === "screenshot_collect") {
|
||||
return Response.json({ error: "截图回收任务无需填写发布链接" }, { status: 400 });
|
||||
}
|
||||
const claimToken = textValue(body.claimToken, 80);
|
||||
const distributionId = textValue(body.distributionId, 80);
|
||||
const publishInput = textValue(body.publishUrl, 5000);
|
||||
@@ -1193,9 +1206,6 @@ async function handlePost(request: Request) {
|
||||
}
|
||||
|
||||
if (body.action === "submit_creator_metrics") {
|
||||
if (task.task_type === "screenshot_collect") {
|
||||
return Response.json({ error: "截图回收任务不需要创作者数据" }, { status: 400 });
|
||||
}
|
||||
const claimToken = textValue(body.claimToken, 80);
|
||||
const distributionId = textValue(body.distributionId, 80);
|
||||
const exposure = creatorMetricValue(body.exposure);
|
||||
@@ -1244,8 +1254,8 @@ async function handlePost(request: Request) {
|
||||
}
|
||||
|
||||
if (body.action === "submit_screenshot_result") {
|
||||
if (task.task_type !== "screenshot_collect") {
|
||||
return Response.json({ error: "当前任务不支持这种回填方式" }, { status: 400 });
|
||||
if (Number(task.recovery_enabled) !== 1) {
|
||||
return Response.json({ error: "该任务未开通截图回收" }, { status: 400 });
|
||||
}
|
||||
const claimToken = textValue(body.claimToken, 80);
|
||||
const distributionId = textValue(body.distributionId, 80);
|
||||
@@ -1256,17 +1266,22 @@ async function handlePost(request: Request) {
|
||||
delegationToken,
|
||||
);
|
||||
if (!assignment) {
|
||||
return Response.json({ error: "任务与领取凭证不匹配" }, { status: 403 });
|
||||
return Response.json({ error: "笔记与领取凭证不匹配" }, { status: 403 });
|
||||
}
|
||||
if (!assignment.publish_url) {
|
||||
return Response.json(
|
||||
{ error: "请先回填这篇笔记的发布链接,再提交回收截图" },
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
if (!assignment.result_screenshot_key) {
|
||||
return Response.json({ error: "请先上传任务截图" }, { status: 400 });
|
||||
return Response.json({ error: "请先上传回收截图" }, { status: 400 });
|
||||
}
|
||||
const statements: DatabaseStatement[] = [
|
||||
db
|
||||
.prepare(
|
||||
`UPDATE distributions SET
|
||||
result_submitted_at = CURRENT_TIMESTAMP,
|
||||
status = 'complete',
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?`,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user