feat: 项目总群自动建群+任务负责人后台视角+客户群活码进群+任务编辑
- 项目总群:≥3 人 appchat/create 自动建群(chatid=pgc+projectId),成员 diff 增删同步;DROP project_group_chats;推送改 appchat/send 群发、无群降级逐人 - 任务负责人:tasks.owner_userid(新建/编辑任务通讯录选人),task_set_owner 分配即预建 tgc 任务群发介绍,群主链接只归属负责人 - 任务编辑 task_update:基础字段+截图任务数量/关键词/说明,contents 调平只删 available 尾行 - 删除「一键推送」:task-one-click-push-service 整体移除(recordCardAck 移入 wecom-callback-events) - 负责人后台视角:users.wecom_userid 绑定,lib/owner-scope 行级过滤(undefined=全量/""=空范围/非空=过滤),~30 action 补 managerGate/taskOwnerGate,owner 登录仅见工作台/任务中心/数据回收/复盘报表 - 任务绑定客户群+进群活码:tasks 增 customer_chat_id/name、join_config_id、join_qr_code 4 列,join_way add/update/get/del(换绑走 update 保 config_id 活码不变),后台「客户群」弹窗,portal 认领后扫码自助进群(满员自动开新群) - 迁移 0013/0014/0015;催办支持按任务;企微可信域名 IP 验证文件 - 288 测试全绿;真机全链路验收通过(列群/活码四端点/portal 渲染/解绑清空)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { ensureSchema, getRawDb, uid } from "./mvp-db";
|
||||
import type { DatabaseClient } from "./database";
|
||||
import {
|
||||
readFeishuSource,
|
||||
type FeishuBindings,
|
||||
@@ -13,6 +14,7 @@ export type CreateDistributionTaskInput = {
|
||||
platform?: "小红书" | "抖音";
|
||||
contentFormat?: "image_text" | "video";
|
||||
projectId?: string;
|
||||
ownerUserid?: string;
|
||||
};
|
||||
|
||||
export type CreateScreenshotTaskInput = {
|
||||
@@ -24,6 +26,7 @@ export type CreateScreenshotTaskInput = {
|
||||
quantity: number;
|
||||
exampleImageKey?: string;
|
||||
projectId?: string;
|
||||
ownerUserid?: string;
|
||||
};
|
||||
|
||||
export type DistributionTaskCreation = {
|
||||
@@ -142,10 +145,10 @@ async function insertTaskFromSource(
|
||||
.prepare(
|
||||
`INSERT INTO tasks
|
||||
(id, name, brand, quantity, claimed_quantity, due_at, status,
|
||||
platform, content_format, project_id,
|
||||
platform, content_format, project_id, owner_userid,
|
||||
source_url, source_sheet_id, source_sheet_name, source_synced_at,
|
||||
share_token)
|
||||
VALUES (?, ?, ?, ?, 0, ?, 'importing', ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
VALUES (?, ?, ?, ?, 0, ?, 'importing', ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
)
|
||||
.bind(
|
||||
taskId,
|
||||
@@ -156,6 +159,7 @@ async function insertTaskFromSource(
|
||||
input.platform ?? "小红书",
|
||||
input.contentFormat ?? "image_text",
|
||||
input.projectId,
|
||||
input.ownerUserid,
|
||||
source.url,
|
||||
source.sheetId,
|
||||
source.sheetName,
|
||||
@@ -224,6 +228,7 @@ export async function createDistributionTask(
|
||||
platform: rawInput.platform === "抖音" ? "抖音" : "小红书",
|
||||
contentFormat: rawInput.contentFormat === "video" ? "video" : "image_text",
|
||||
projectId: normalizedValue(rawInput.projectId ?? ""),
|
||||
ownerUserid: normalizedValue(rawInput.ownerUserid ?? "").slice(0, 64),
|
||||
};
|
||||
if (!input.feishuUrl || !input.name || !input.brand) {
|
||||
throw new Error("请补全飞书链接、任务名称和品牌/项目");
|
||||
@@ -286,6 +291,7 @@ export async function createScreenshotTask(
|
||||
quantity: Math.floor(Number(rawInput.quantity)),
|
||||
exampleImageKey: normalizedValue(rawInput.exampleImageKey ?? ""),
|
||||
projectId: normalizedValue(rawInput.projectId ?? ""),
|
||||
ownerUserid: normalizedValue(rawInput.ownerUserid ?? "").slice(0, 64),
|
||||
};
|
||||
if (!input.name || !input.brand || !input.keyword || !input.instructions) {
|
||||
throw new Error("请补全任务名称、品牌/项目、搜索关键词和任务说明");
|
||||
@@ -309,9 +315,9 @@ export async function createScreenshotTask(
|
||||
.prepare(
|
||||
`INSERT INTO tasks
|
||||
(id, name, brand, quantity, claimed_quantity, due_at, status,
|
||||
task_type, project_id, source_url, source_sheet_id, source_sheet_name,
|
||||
task_type, project_id, owner_userid, source_url, source_sheet_id, source_sheet_name,
|
||||
share_token, collection_days)
|
||||
VALUES (?, ?, ?, ?, 0, ?, 'active', 'screenshot_collect', ?, '', '', '', ?, '[]')`,
|
||||
VALUES (?, ?, ?, ?, 0, ?, 'active', 'screenshot_collect', ?, ?, '', '', '', ?, '[]')`,
|
||||
)
|
||||
.bind(
|
||||
taskId,
|
||||
@@ -320,6 +326,7 @@ export async function createScreenshotTask(
|
||||
input.quantity,
|
||||
input.dueAt,
|
||||
input.projectId,
|
||||
input.ownerUserid,
|
||||
shareToken,
|
||||
)
|
||||
.run();
|
||||
@@ -363,6 +370,182 @@ export async function createScreenshotTask(
|
||||
};
|
||||
}
|
||||
|
||||
export type UpdateTaskInput = {
|
||||
taskId: string;
|
||||
name: string;
|
||||
brand: string;
|
||||
dueAt: string;
|
||||
projectId?: string;
|
||||
platform?: "小红书" | "抖音";
|
||||
contentFormat?: "image_text" | "video";
|
||||
quantity?: number;
|
||||
keyword?: string;
|
||||
instructions?: string;
|
||||
exampleImageKey?: string;
|
||||
};
|
||||
|
||||
export type TaskUpdateResult = {
|
||||
taskId: string;
|
||||
quantity: number;
|
||||
claimedQuantity: number;
|
||||
};
|
||||
|
||||
type UpdatableTaskRow = {
|
||||
id: string;
|
||||
task_type: "content_publish" | "screenshot_collect";
|
||||
quantity: number;
|
||||
claimed_quantity: number;
|
||||
platform: "小红书" | "抖音";
|
||||
content_format: "image_text" | "video";
|
||||
};
|
||||
|
||||
// 截图任务的 keyword/instructions 存在 contents 每行(title/body),数量与行数一一对应
|
||||
async function syncScreenshotContents(
|
||||
db: DatabaseClient,
|
||||
taskId: string,
|
||||
params: {
|
||||
oldQuantity: number;
|
||||
quantity: number;
|
||||
keyword: string;
|
||||
instructions: string;
|
||||
exampleImageKey: string;
|
||||
},
|
||||
) {
|
||||
const delta = params.quantity - params.oldQuantity;
|
||||
if (delta > 0) {
|
||||
const sample = await db
|
||||
.prepare(
|
||||
"SELECT image_assets FROM contents WHERE task_id = ? ORDER BY source_row LIMIT 1",
|
||||
)
|
||||
.bind(taskId)
|
||||
.first<{ image_assets: string }>();
|
||||
const imageAssets = sample?.image_assets ?? "[]";
|
||||
const statements = Array.from({ length: delta }, (_, index) =>
|
||||
db
|
||||
.prepare(
|
||||
`INSERT INTO contents
|
||||
(id, task_id, title, body, image_assets, video_assets, status, source, source_row)
|
||||
VALUES (?, ?, ?, ?, ?, '[]', 'available', '截图回收任务', ?)`,
|
||||
)
|
||||
.bind(
|
||||
uid("content"),
|
||||
taskId,
|
||||
params.keyword,
|
||||
params.instructions,
|
||||
imageAssets,
|
||||
params.oldQuantity + index + 1,
|
||||
),
|
||||
);
|
||||
for (let index = 0; index < statements.length; index += 100) {
|
||||
await db.batch(statements.slice(index, index + 100));
|
||||
}
|
||||
} else if (delta < 0) {
|
||||
// 只删未领取的尾部行,已领取(claimed)的保留
|
||||
await db
|
||||
.prepare(
|
||||
`DELETE FROM contents WHERE task_id = ? AND status = 'available'
|
||||
ORDER BY source_row DESC LIMIT ?`,
|
||||
)
|
||||
.bind(taskId, -delta)
|
||||
.run();
|
||||
}
|
||||
await db
|
||||
.prepare("UPDATE contents SET title = ?, body = ? WHERE task_id = ?")
|
||||
.bind(params.keyword, params.instructions, taskId)
|
||||
.run();
|
||||
if (params.exampleImageKey.startsWith("task-assets/")) {
|
||||
const imageAssets = JSON.stringify([
|
||||
{ index: 1, key: params.exampleImageKey, width: null, height: null },
|
||||
]);
|
||||
await db
|
||||
.prepare("UPDATE contents SET image_assets = ? WHERE task_id = ?")
|
||||
.bind(imageAssets, taskId)
|
||||
.run();
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateTask(
|
||||
rawInput: UpdateTaskInput,
|
||||
db: DatabaseClient = getRawDb(),
|
||||
): Promise<TaskUpdateResult> {
|
||||
const taskId = normalizedValue(rawInput.taskId);
|
||||
if (!taskId) throw new Error("缺少 taskId");
|
||||
const input = {
|
||||
name: normalizedValue(rawInput.name),
|
||||
brand: normalizedValue(rawInput.brand),
|
||||
dueAt: normalizedDueDate(rawInput.dueAt),
|
||||
projectId: normalizedValue(rawInput.projectId ?? ""),
|
||||
platform: rawInput.platform === "抖音" || rawInput.platform === "小红书"
|
||||
? rawInput.platform
|
||||
: undefined,
|
||||
contentFormat: rawInput.contentFormat === "video" || rawInput.contentFormat === "image_text"
|
||||
? rawInput.contentFormat
|
||||
: undefined,
|
||||
quantity: Math.floor(Number(rawInput.quantity ?? 0)),
|
||||
keyword: normalizedValue(rawInput.keyword ?? ""),
|
||||
instructions: normalizedValue(rawInput.instructions ?? ""),
|
||||
exampleImageKey: normalizedValue(rawInput.exampleImageKey ?? ""),
|
||||
};
|
||||
if (!input.name || !input.brand) {
|
||||
throw new Error("请补全任务名称和品牌");
|
||||
}
|
||||
|
||||
const row = await db
|
||||
.prepare(
|
||||
"SELECT id, task_type, quantity, claimed_quantity, platform, content_format FROM tasks WHERE id = ?",
|
||||
)
|
||||
.bind(taskId)
|
||||
.first<UpdatableTaskRow>();
|
||||
if (!row) throw new Error("任务不存在");
|
||||
|
||||
const claimed = Number(row.claimed_quantity);
|
||||
let quantity = Number(row.quantity);
|
||||
if (row.task_type === "screenshot_collect") {
|
||||
if (!input.keyword || !input.instructions) {
|
||||
throw new Error("请补全搜索关键词和任务说明");
|
||||
}
|
||||
if (
|
||||
!Number.isInteger(input.quantity) ||
|
||||
input.quantity < 1 ||
|
||||
input.quantity > 500
|
||||
) {
|
||||
throw new Error("任务数量需为 1—500 份");
|
||||
}
|
||||
if (input.quantity < claimed) {
|
||||
throw new Error(`任务数量不能低于已领取的 ${claimed} 份`);
|
||||
}
|
||||
quantity = input.quantity;
|
||||
await syncScreenshotContents(db, taskId, {
|
||||
oldQuantity: Number(row.quantity),
|
||||
quantity,
|
||||
keyword: input.keyword,
|
||||
instructions: input.instructions,
|
||||
exampleImageKey: input.exampleImageKey,
|
||||
});
|
||||
}
|
||||
|
||||
await db
|
||||
.prepare(
|
||||
`UPDATE tasks
|
||||
SET name = ?, brand = ?, due_at = ?, project_id = ?,
|
||||
platform = ?, content_format = ?, quantity = ?
|
||||
WHERE id = ?`,
|
||||
)
|
||||
.bind(
|
||||
input.name,
|
||||
input.brand,
|
||||
input.dueAt,
|
||||
input.projectId,
|
||||
input.platform ?? row.platform,
|
||||
input.contentFormat ?? row.content_format,
|
||||
quantity,
|
||||
taskId,
|
||||
)
|
||||
.run();
|
||||
|
||||
return { taskId, quantity, claimedQuantity: claimed };
|
||||
}
|
||||
|
||||
export function buildClaimUrl(portalOrigin: string, shareToken: string) {
|
||||
const origin = normalizedValue(portalOrigin).replace(/\/$/, "");
|
||||
if (!origin) throw new Error("KOC 领取站点地址尚未配置");
|
||||
|
||||
Reference in New Issue
Block a user