优化(半自动履约): 列表改为待办队列排序,并让更新时间只反映真实状态变更
现象:后台半自动履约列表按创建时间倒序,而页面展示的是「更新时间」,两者不一致; 系统对账还会把没有状态变化的行也推进 updated_at,导致列表看起来乱序且每次刷新都重排。 生产只读核对(2026-12-03 13:04):一次 Connector 对账推进了 18 条任务的 updated_at, 其中只有 2 条产生真实状态变化事件;5578 条任务里 5436 条是「客户从未开始」, 原来的排序会把这类从未开始的新任务盖在真正等客服处理的任务上面。 改动: - semi_auto_tasks.updated_at 收敛为「最近一次真实状态变更」:唯一写入口 convergeSemiAutoTaskState 先逐列比较补丁与库内值(空串与 NULL 同义、JSON 按键排序比较、 coalesce_now 已有值不算变化),完全相同就整条 UPDATE 都不执行。 轮询、Connector 对账、绑定决策重算不再制造假更新。 - 列表排序改为待办队列桶序:等客服履约 → 客服处理中 → 需客服修复 → 客户处理中 → 客户未开始 → 已完成 → 已取消;同桶按 updated_at 倒序并以 id 兜底。 分桶只读 execution_status / login_status / binding_status / customer_link_opened_at 这些正式字段,待办文案仍由 displayStatus 单点输出。 - 页面补一行排序口径说明,说明系统轮询不会刷新「更新时间」。 - 权威文档 3.4.2 记录队列排序与 updated_at 语义。 - 测试:新增无变化不推进 updated_at 的集成用例;排序集成用例改为覆盖桶序优先于时间; 单测覆盖空串/NULL、bigint 字符串、JSON 键序、coalesce_now 四类比较。 验证:backend check 通过(1564 用例 / fail 0),frontend check 通过, 半自动履约真实 PostgreSQL 集成测试 15/15 通过。
This commit is contained in:
@@ -62,6 +62,38 @@ import {
|
||||
SEMI_AUTO_NOW,
|
||||
} from './semi-auto-task-state-service.js'
|
||||
|
||||
/**
|
||||
* 后台半自动任务列表的队列顺序。
|
||||
*
|
||||
* 这是运营待办队列,不是审计流水:先按「谁在等我」分桶,同桶内按最近一次真实状态变更倒序。
|
||||
* 分桶只读正式状态字段(execution_status / login_status / binding_status /
|
||||
* customer_link_opened_at),不复制 displayStatus 的判定链;具体待办文案仍由
|
||||
* displayStatus 单点输出,页面不重新解释状态。
|
||||
*
|
||||
* 之前按 `created_at DESC` 排序,而页面展示的是「更新时间」,且 `updated_at` 会被
|
||||
* 无变化的轮询/对账推进,导致列表既与展示列不一致、又每次刷新都重排;
|
||||
* `updated_at` 已在写入口收敛为「真实状态变更」,可以直接作为同桶排序键。
|
||||
*/
|
||||
const SEMI_AUTO_TASK_QUEUE_ORDER_SQL = `
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN task.execution_status = 'waiting_operator' THEN 0
|
||||
WHEN task.execution_status = 'processing' THEN 1
|
||||
WHEN task.execution_status = 'failed' THEN 2
|
||||
WHEN task.execution_status = 'waiting_customer'
|
||||
AND (
|
||||
task.login_status <> 'waiting_login'
|
||||
OR task.binding_status <> 'not_started'
|
||||
OR task.customer_link_opened_at IS NOT NULL
|
||||
) THEN 3
|
||||
WHEN task.execution_status = 'waiting_customer' THEN 4
|
||||
WHEN task.execution_status = 'completed' THEN 8
|
||||
WHEN task.execution_status = 'cancelled' THEN 9
|
||||
ELSE 5
|
||||
END,
|
||||
task.updated_at DESC,
|
||||
task.id DESC`
|
||||
|
||||
export async function listAdminSemiAutoTasks(input: Record<string, unknown> = {}) {
|
||||
await ensureSemiAutoTasksForAdminList()
|
||||
const page = Math.max(1, Math.trunc(Number(input.page) || 1))
|
||||
@@ -116,7 +148,7 @@ export async function listAdminSemiAutoTasks(input: Record<string, unknown> = {}
|
||||
const result = await query<TaskRow>(
|
||||
`${TASK_SELECT}
|
||||
WHERE ${where}
|
||||
ORDER BY task.created_at DESC, task.id DESC
|
||||
${SEMI_AUTO_TASK_QUEUE_ORDER_SQL}
|
||||
LIMIT $${listParams.length - 1} OFFSET $${listParams.length}`,
|
||||
listParams,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user