feat: KOC详情弹窗 + 任务中心单入口改版 + 资源池默认合作方/采集兜底
KOC 详情弹窗(合作方/数据回收/工作台三处入口): - 新增 KocDetailModal:基本信息 / 绑定KOC账号画像 / 参与任务记录 / 履约漏斗 - 工作台最近分发、回收队列账号名、截图回收合作方名、合作方页名称、分发详情头部合作方均可点开 - 分发表行点击仍打开分发详情(stopPropagation 隔离) 任务中心单入口改版(对齐"单任务双阶段"模型): - 任务卡发布/回收面板整块可点,全卡仅保留一个「查看明细」,回收面板重复按钮移除 - 详情页自述身份:动态 label(任务详情·分发与回收一体/仅分发)+ 阶段徽章(含回收·截止/未开通回收) - 内容分发表新增阶段筛选 chips(全部/待发布/已发布待数据/待收截图,未开通回收不显示截图项),筛选落空给专用空态文案 - 数据回收页入口文案改为「选择一个任务进入回收队列」,全站不再区分发布/回收两种任务类型 资源池 KOC 默认加入合作方 + 采集兜底: - partners 新增 released_account_id(mysql/0023):显式解绑/被顶替的账号不再被默认合作方同步回填 - 任务未设置采集计划时,默认按发布时间起连续采集 7 天,等待文案显示「等待D1 · 默认7天」
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
import {
|
||||
collectDistributionMetrics,
|
||||
createCollectionRunTasks,
|
||||
parseCollectionDays,
|
||||
retryFailedCollections,
|
||||
runDueScheduledCollections,
|
||||
shanghaiDateFromTimestamp,
|
||||
@@ -118,6 +119,38 @@ async function assignOwnerQuietly(taskId: string, ownerUserid: unknown) {
|
||||
}
|
||||
}
|
||||
|
||||
type PartnerAccountHolderRow = {
|
||||
id: string;
|
||||
name: string;
|
||||
partner_type: string | null;
|
||||
wecom_external_user_id: string | null;
|
||||
wecom_userid: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 占用方是否只是资源池默认同步生成的空壳合作方:
|
||||
* 无企微绑定、无领取和分发记录。空壳可在换绑时直接让位。
|
||||
*/
|
||||
async function isShellAccountHolder(
|
||||
db: ReturnType<typeof getRawDb>,
|
||||
holder: PartnerAccountHolderRow,
|
||||
) {
|
||||
if ((holder.partner_type ?? "external_koc") !== "external_koc") return false;
|
||||
if ((holder.wecom_external_user_id ?? "").trim() || holder.wecom_userid.trim()) {
|
||||
return false;
|
||||
}
|
||||
const claim = await db
|
||||
.prepare("SELECT 1 FROM claims WHERE partner_id = ? LIMIT 1")
|
||||
.bind(holder.id)
|
||||
.first();
|
||||
if (claim) return false;
|
||||
const distribution = await db
|
||||
.prepare("SELECT 1 FROM distributions WHERE partner_id = ? LIMIT 1")
|
||||
.bind(holder.id)
|
||||
.first();
|
||||
return !distribution;
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
if (!(await isAdminRequest(request))) return adminForbidden();
|
||||
try {
|
||||
@@ -338,20 +371,7 @@ export async function POST(request: Request) {
|
||||
if (current.publish_url === publishUrl) {
|
||||
return Response.json(await getDashboardData());
|
||||
}
|
||||
let collectionDays: number[] = [];
|
||||
try {
|
||||
const parsed = JSON.parse(current.collection_days || "[]");
|
||||
if (Array.isArray(parsed)) {
|
||||
collectionDays = [...new Set(parsed.map(Number))]
|
||||
.filter(
|
||||
(day) =>
|
||||
Number.isInteger(day) && day >= 1 && day <= 7,
|
||||
)
|
||||
.sort((a, b) => a - b);
|
||||
}
|
||||
} catch {
|
||||
collectionDays = [];
|
||||
}
|
||||
const collectionDays = parseCollectionDays(current.collection_days);
|
||||
const isScheduled = Boolean(
|
||||
current.collection_start_date && collectionDays.length > 0,
|
||||
);
|
||||
@@ -384,10 +404,10 @@ export async function POST(request: Request) {
|
||||
)
|
||||
.bind(
|
||||
publishUrl,
|
||||
isScheduled ? "scheduled" : "pending",
|
||||
"scheduled",
|
||||
isScheduled
|
||||
? `管理员已更新链接,等待${collectionDays.length}个采集日`
|
||||
: "管理员已更新链接,等待设置采集计划",
|
||||
: "管理员已更新链接,默认发布后7天自动采集",
|
||||
distributionId,
|
||||
),
|
||||
db
|
||||
@@ -412,19 +432,20 @@ export async function POST(request: Request) {
|
||||
current.collection_start_date,
|
||||
collectionDays,
|
||||
);
|
||||
runInBackground(
|
||||
runDueScheduledCollections(
|
||||
db,
|
||||
Date.now(),
|
||||
resolveCollectionMcpConfig(
|
||||
env as unknown as CollectionMcpBindings,
|
||||
),
|
||||
"catchup",
|
||||
current.task_id,
|
||||
).catch(() => undefined),
|
||||
"collection catchup after publish URL update",
|
||||
);
|
||||
}
|
||||
// 未设置计划的任务同样追采:调度器会按默认 7 天(自发布日起)执行。
|
||||
runInBackground(
|
||||
runDueScheduledCollections(
|
||||
db,
|
||||
Date.now(),
|
||||
resolveCollectionMcpConfig(
|
||||
env as unknown as CollectionMcpBindings,
|
||||
),
|
||||
"catchup",
|
||||
current.task_id,
|
||||
).catch(() => undefined),
|
||||
"collection catchup after publish URL update",
|
||||
);
|
||||
runInBackground(
|
||||
enrichDistributionAccount(
|
||||
db,
|
||||
@@ -772,8 +793,10 @@ export async function POST(request: Request) {
|
||||
}
|
||||
if (!accountId) {
|
||||
await db
|
||||
.prepare("UPDATE partners SET account_id = '' WHERE id = ?")
|
||||
.bind(partnerId)
|
||||
.prepare(
|
||||
"UPDATE partners SET account_id = '', released_account_id = ? WHERE id = ?",
|
||||
)
|
||||
.bind((partner.account_id ?? "").trim(), partnerId)
|
||||
.run();
|
||||
return Response.json({ partnerId, accountId: "" });
|
||||
}
|
||||
@@ -784,21 +807,39 @@ export async function POST(request: Request) {
|
||||
if (!account) return Response.json({ error: "KOC 资源不存在" }, { status: 404 });
|
||||
const holder = await db
|
||||
.prepare(
|
||||
"SELECT id, name FROM partners WHERE account_id = ? AND id != ? LIMIT 1",
|
||||
`SELECT id, name, partner_type, wecom_external_user_id, wecom_userid
|
||||
FROM partners WHERE account_id = ? AND id != ? LIMIT 1`,
|
||||
)
|
||||
.bind(accountId, partnerId)
|
||||
.first<{ id: string; name: string }>();
|
||||
.first<PartnerAccountHolderRow>();
|
||||
let displacedShellName: string | null = null;
|
||||
if (holder) {
|
||||
return Response.json(
|
||||
{ error: `该 KOC 资源已绑定合作方「${holder.name}」,请先在对方条目上解绑` },
|
||||
{ status: 400 },
|
||||
);
|
||||
if (!(await isShellAccountHolder(db, holder))) {
|
||||
return Response.json(
|
||||
{ error: `该 KOC 资源已绑定合作方「${holder.name}」,请先在对方条目上解绑` },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
displacedShellName = holder.name;
|
||||
await db
|
||||
.prepare(
|
||||
"UPDATE partners SET account_id = '', released_account_id = ? WHERE id = ?",
|
||||
)
|
||||
.bind(accountId, holder.id)
|
||||
.run();
|
||||
}
|
||||
await db
|
||||
.prepare("UPDATE partners SET account_id = ? WHERE id = ?")
|
||||
.prepare(
|
||||
"UPDATE partners SET account_id = ?, released_account_id = '' WHERE id = ?",
|
||||
)
|
||||
.bind(accountId, partnerId)
|
||||
.run();
|
||||
return Response.json({ partnerId, accountId, nickname: account.nickname });
|
||||
return Response.json({
|
||||
partnerId,
|
||||
accountId,
|
||||
nickname: account.nickname,
|
||||
displacedShellName,
|
||||
});
|
||||
} else if (body.action === "partner_create_from_account") {
|
||||
const forbidden = managerGate();
|
||||
if (forbidden) return forbidden;
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
getRawDb,
|
||||
seedIfEmpty,
|
||||
} from "../../../lib/mvp-db";
|
||||
import { ensurePartnersForPoolAccounts } from "../../../lib/resource-write";
|
||||
import { authForbidden, getRequestPrincipal } from "../../../lib/user-auth";
|
||||
import { getOwnerScope, ownerScopeUserid } from "../../../lib/owner-scope";
|
||||
|
||||
@@ -23,6 +24,13 @@ export async function GET(request: Request) {
|
||||
try {
|
||||
await ensureSchema();
|
||||
await seedIfEmpty();
|
||||
// 资源池 KOC 默认加入合作方:在返回面板数据前补齐,失败不阻塞看板
|
||||
await ensurePartnersForPoolAccounts().catch((error) => {
|
||||
console.error(
|
||||
"KOC pool partner sync failed",
|
||||
error instanceof Error ? error.message : "unknown error",
|
||||
);
|
||||
});
|
||||
const db = getRawDb();
|
||||
const mcpConfig = resolveCollectionMcpConfig(
|
||||
env as unknown as CollectionMcpBindings,
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
import { enrichDistributionAccount } from "../../../lib/account-enrichment-service";
|
||||
import {
|
||||
createCollectionRunTasks,
|
||||
parseCollectionDays,
|
||||
runDueScheduledCollections,
|
||||
} from "../../../lib/collection-service";
|
||||
import { normalizeWorkbookImage } from "../../../lib/workbook-image";
|
||||
@@ -664,49 +665,48 @@ async function handlePost(request: Request) {
|
||||
updatedRows += 1;
|
||||
}
|
||||
}
|
||||
if (
|
||||
(publishedCount > 0 || publishUrlChangedCount > 0) &&
|
||||
access.task.collection_start_date &&
|
||||
access.task.collection_days !== "[]"
|
||||
) {
|
||||
let collectionDays: number[] = [];
|
||||
try {
|
||||
const parsed = JSON.parse(access.task.collection_days);
|
||||
if (Array.isArray(parsed)) collectionDays = parsed.map(Number);
|
||||
} catch {
|
||||
collectionDays = [];
|
||||
}
|
||||
if (collectionDays.length > 0) {
|
||||
await db
|
||||
.prepare(
|
||||
`UPDATE distributions SET collection_status = 'scheduled',
|
||||
collection_status_description = ?
|
||||
WHERE task_id = ? AND publish_url IS NOT NULL AND publish_url != ''`,
|
||||
)
|
||||
.bind(
|
||||
`已安排${collectionDays.length}个采集日,每日09:00执行`,
|
||||
access.task.id,
|
||||
)
|
||||
.run();
|
||||
if (publishedCount > 0 || publishUrlChangedCount > 0) {
|
||||
const collectionDays = parseCollectionDays(
|
||||
access.task.collection_days,
|
||||
);
|
||||
const isScheduled = Boolean(
|
||||
access.task.collection_start_date &&
|
||||
collectionDays.length > 0,
|
||||
);
|
||||
await db
|
||||
.prepare(
|
||||
`UPDATE distributions SET collection_status = 'scheduled',
|
||||
collection_status_description = ?
|
||||
WHERE task_id = ? AND publish_url IS NOT NULL AND publish_url != ''`,
|
||||
)
|
||||
.bind(
|
||||
isScheduled
|
||||
? `已安排${collectionDays.length}个采集日,每日09:00执行`
|
||||
: "默认发布后7天自动采集,每日09:00执行",
|
||||
access.task.id,
|
||||
)
|
||||
.run();
|
||||
if (isScheduled && access.task.collection_start_date) {
|
||||
await createCollectionRunTasks(
|
||||
db,
|
||||
access.task.id,
|
||||
access.task.collection_start_date,
|
||||
collectionDays,
|
||||
);
|
||||
runInBackground(
|
||||
runDueScheduledCollections(
|
||||
db,
|
||||
Date.now(),
|
||||
resolveCollectionMcpConfig(
|
||||
env as unknown as CollectionMcpBindings,
|
||||
),
|
||||
"catchup",
|
||||
access.task.id,
|
||||
).catch(() => undefined),
|
||||
"collection catchup after batch publish update",
|
||||
);
|
||||
}
|
||||
// 未设置计划时调度器同样兜底:默认自发布日起 7 天自动采集。
|
||||
runInBackground(
|
||||
runDueScheduledCollections(
|
||||
db,
|
||||
Date.now(),
|
||||
resolveCollectionMcpConfig(
|
||||
env as unknown as CollectionMcpBindings,
|
||||
),
|
||||
"catchup",
|
||||
access.task.id,
|
||||
).catch(() => undefined),
|
||||
"collection catchup after batch publish update",
|
||||
);
|
||||
}
|
||||
for (const enrichment of enrichments) {
|
||||
runInBackground(
|
||||
|
||||
@@ -6,6 +6,7 @@ const env = getRuntimeEnv();
|
||||
import { enrichDistributionAccount } from "../../../lib/account-enrichment-service";
|
||||
import {
|
||||
createCollectionRunTasks,
|
||||
parseCollectionDays,
|
||||
runDueScheduledCollections,
|
||||
} from "../../../lib/collection-service";
|
||||
import {
|
||||
@@ -1153,47 +1154,47 @@ async function handlePost(request: Request) {
|
||||
collection_start_date: string | null;
|
||||
collection_days: string;
|
||||
}>();
|
||||
if (
|
||||
collectionSchedule?.collection_start_date &&
|
||||
collectionSchedule.collection_days !== "[]"
|
||||
) {
|
||||
let collectionDays: number[] = [];
|
||||
try {
|
||||
const parsed = JSON.parse(collectionSchedule.collection_days);
|
||||
if (Array.isArray(parsed)) collectionDays = parsed.map(Number);
|
||||
} catch {
|
||||
collectionDays = [];
|
||||
}
|
||||
if (collectionDays.length > 0) {
|
||||
await db
|
||||
.prepare(
|
||||
`UPDATE distributions SET collection_status = 'scheduled',
|
||||
collection_status_description = ? WHERE id = ?`,
|
||||
)
|
||||
.bind(
|
||||
`已安排${collectionDays.length}个采集日,每日09:00执行`,
|
||||
assignment.id,
|
||||
)
|
||||
.run();
|
||||
if (collectionSchedule) {
|
||||
const collectionDays = parseCollectionDays(
|
||||
collectionSchedule.collection_days,
|
||||
);
|
||||
const isScheduled = Boolean(
|
||||
collectionSchedule.collection_start_date &&
|
||||
collectionDays.length > 0,
|
||||
);
|
||||
await db
|
||||
.prepare(
|
||||
`UPDATE distributions SET collection_status = 'scheduled',
|
||||
collection_status_description = ? WHERE id = ?`,
|
||||
)
|
||||
.bind(
|
||||
isScheduled
|
||||
? `已安排${collectionDays.length}个采集日,每日09:00执行`
|
||||
: "默认发布后7天自动采集,每日09:00执行",
|
||||
assignment.id,
|
||||
)
|
||||
.run();
|
||||
if (isScheduled && collectionSchedule.collection_start_date) {
|
||||
await createCollectionRunTasks(
|
||||
db,
|
||||
task.id,
|
||||
collectionSchedule.collection_start_date,
|
||||
collectionDays,
|
||||
);
|
||||
runInBackground(
|
||||
runDueScheduledCollections(
|
||||
db,
|
||||
Date.now(),
|
||||
resolveCollectionMcpConfig(
|
||||
env as unknown as CollectionMcpBindings,
|
||||
),
|
||||
"catchup",
|
||||
task.id,
|
||||
).catch(() => undefined),
|
||||
"collection catchup after partner publish update",
|
||||
);
|
||||
}
|
||||
// 未设置计划时调度器同样兜底:默认自发布日起 7 天自动采集。
|
||||
runInBackground(
|
||||
runDueScheduledCollections(
|
||||
db,
|
||||
Date.now(),
|
||||
resolveCollectionMcpConfig(
|
||||
env as unknown as CollectionMcpBindings,
|
||||
),
|
||||
"catchup",
|
||||
task.id,
|
||||
).catch(() => undefined),
|
||||
"collection catchup after partner publish update",
|
||||
);
|
||||
}
|
||||
const enrichment = enrichDistributionAccount(
|
||||
db,
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from "../../../lib/resource-import";
|
||||
import {
|
||||
analyzeRows,
|
||||
ensurePartnersForPoolAccounts,
|
||||
enrichRows,
|
||||
loadAccounts,
|
||||
mergeExistingFields,
|
||||
@@ -137,6 +138,10 @@ export async function POST(request: Request) {
|
||||
tagUntaggedAccounts(importableRows),
|
||||
"resource account tagging",
|
||||
);
|
||||
runInBackground(
|
||||
ensurePartnersForPoolAccounts(),
|
||||
"pool partner sync after resource import",
|
||||
);
|
||||
if (deferredEnrichment > 0) {
|
||||
const importableSourceRows = rows.filter((row) =>
|
||||
importableRowNumbers.has(row.rowNumber),
|
||||
|
||||
@@ -3,6 +3,7 @@ import { runInBackground } from "../../../lib/background";
|
||||
import { buildManualRow, type ManualResourceInput } from "../../../lib/resource-import";
|
||||
import {
|
||||
analyzeRows,
|
||||
ensurePartnersForPoolAccounts,
|
||||
enrichRows,
|
||||
loadAccounts,
|
||||
tagUntaggedAccounts,
|
||||
@@ -54,6 +55,10 @@ export async function POST(request: Request) {
|
||||
tagUntaggedAccounts(analyzed),
|
||||
"resource account tagging",
|
||||
);
|
||||
runInBackground(
|
||||
ensurePartnersForPoolAccounts(),
|
||||
"pool partner sync after manual resource insert",
|
||||
);
|
||||
const result = analyzed[0];
|
||||
const outcome: InsertResult = {
|
||||
action: result.action === "update" ? "update" : "create",
|
||||
|
||||
Reference in New Issue
Block a user