调整(半自动履约): 去掉后台「领取」,任一客服均可操作
- 删除 POST /admin/semi-auto/tasks/:taskId/claim 与 claimAdminSemiAutoTask; 前端列表行与详情抽屉的「领取」按钮、claim 服务封装一并移除。 - 去掉三处「该任务已被其他客服领取」409 门禁(重新授权、开浏览器会话、完成履约), 任一有半自动权限的客服都能直接操作。 - assigned_admin_user_id 保留为「最近操作客服」:开浏览器会话与完成履约时写当前操作人, 列表/详情的列名改为「最近操作」,未操作过显示「—」。 - 权威文档改为「不设任务领取人门禁」,CK 导出与注入说明同步去掉领取人口径。 - 集成测试补断言:客服 A 开过会话后客服 B 仍可注入,且任务记录的是最近操作人。
This commit is contained in:
@@ -2,7 +2,6 @@ import { Router } from 'express'
|
||||
|
||||
import {
|
||||
cancelAdminSemiAutoTask,
|
||||
claimAdminSemiAutoTask,
|
||||
completeAdminSemiAutoTask,
|
||||
createAdminBrowserSession,
|
||||
exportAdminSemiAutoCredential,
|
||||
@@ -90,21 +89,6 @@ router.post(
|
||||
),
|
||||
)
|
||||
|
||||
router.post(
|
||||
'/semi-auto/tasks/:taskId/claim',
|
||||
createJsonHandler((req) => claimAdminSemiAutoTask(req.params.taskId, sessionOf(req)), {
|
||||
successMessage: '任务已领取',
|
||||
errorMessage: '领取半自动履约任务失败',
|
||||
scope: '[admin/semi-auto/tasks/:taskId/claim]',
|
||||
audit: (req) => ({
|
||||
action: 'semi_auto_task_claimed',
|
||||
targetType: 'semi_auto_task',
|
||||
targetId: String(req.params.taskId || ''),
|
||||
data: {},
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
router.post(
|
||||
'/semi-auto/tasks/:taskId/sync',
|
||||
createJsonHandler((req) => syncAdminSemiAutoTask(req.params.taskId), {
|
||||
|
||||
@@ -270,40 +270,6 @@ export async function exportAdminSemiAutoCredential(taskIdInput: unknown) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function claimAdminSemiAutoTask(taskIdInput: unknown, session: AdminSession) {
|
||||
const taskId = normalizeId(taskIdInput)
|
||||
const adminUserId = Number(session.userId || 0)
|
||||
let orderId = 0
|
||||
await withTransaction(async (client) => {
|
||||
const task = await loadTaskForUpdateWithClient(client, taskId)
|
||||
if (task.execution_status === 'completed' || task.execution_status === 'cancelled') {
|
||||
throw createHttpError('当前任务已结束,不能领取', {
|
||||
statusCode: 409,
|
||||
errorCode:
|
||||
task.execution_status === 'completed'
|
||||
? 'semi_auto_task_completed'
|
||||
: 'semi_auto_task_cancelled',
|
||||
})
|
||||
}
|
||||
if (task.assigned_admin_user_id && Number(task.assigned_admin_user_id) !== adminUserId) {
|
||||
throw createHttpError('该任务已被其他客服领取', {
|
||||
statusCode: 409,
|
||||
errorCode: 'semi_auto_task_claimed',
|
||||
})
|
||||
}
|
||||
orderId = Number(task.order_id)
|
||||
await convergeSemiAutoTaskState(client, taskId, {
|
||||
reason: 'task_claimed',
|
||||
actor: 'admin',
|
||||
actorId: String(adminUserId),
|
||||
patch: { assignedAdminUserId: adminUserId },
|
||||
event: { eventType: 'task_claimed' },
|
||||
})
|
||||
})
|
||||
publishSemiAutoTaskRealtimeChange(taskId, orderId)
|
||||
return getAdminSemiAutoTask(taskId)
|
||||
}
|
||||
|
||||
export async function syncAdminSemiAutoTask(taskIdInput: unknown) {
|
||||
const taskId = normalizeId(taskIdInput)
|
||||
let task = await ensureConnectorSessionForTask(await loadTask(taskId))
|
||||
@@ -777,12 +743,6 @@ export async function requestAdminSemiAutoCustomerReauth(
|
||||
})
|
||||
}
|
||||
const adminUserId = Number(session.userId || 0)
|
||||
if (task.assigned_admin_user_id && Number(task.assigned_admin_user_id) !== adminUserId) {
|
||||
throw createHttpError('该任务已被其他客服领取', {
|
||||
statusCode: 409,
|
||||
errorCode: 'semi_auto_task_claimed',
|
||||
})
|
||||
}
|
||||
if (task.connector_session_id) {
|
||||
await revokeSessionForTask(task, task.connector_session_id).catch(() => undefined)
|
||||
}
|
||||
@@ -803,12 +763,6 @@ export async function createAdminBrowserSession(
|
||||
const taskId = normalizeId(taskIdInput)
|
||||
const task = await ensureConnectorSessionForTask(await loadTask(taskId))
|
||||
const adminUserId = Number(session.userId || 0)
|
||||
if (task.assigned_admin_user_id && Number(task.assigned_admin_user_id) !== adminUserId) {
|
||||
throw createHttpError('该任务已被其他客服领取', {
|
||||
statusCode: 409,
|
||||
errorCode: 'semi_auto_task_claimed',
|
||||
})
|
||||
}
|
||||
if (!task.connector_session_id || task.login_status !== 'authenticated') {
|
||||
throw createHttpError('客户尚未完成登录,或登录会话已失效', {
|
||||
statusCode: 409,
|
||||
@@ -873,10 +827,8 @@ export async function createAdminBrowserSession(
|
||||
actor: 'admin',
|
||||
actorId: String(adminUserId),
|
||||
patch: {
|
||||
// 已领取任务保持原领取人(原 COALESCE 语义)。
|
||||
assignedAdminUserId: current.assigned_admin_user_id
|
||||
? Number(current.assigned_admin_user_id)
|
||||
: adminUserId,
|
||||
// 不设领取人:任何客服都能操作,这里只记录最近一次操作人。
|
||||
assignedAdminUserId: adminUserId,
|
||||
executionStatus:
|
||||
current.execution_status === 'waiting_operator' ? 'processing' : current.execution_status,
|
||||
},
|
||||
@@ -993,12 +945,6 @@ export async function completeAdminSemiAutoTask(
|
||||
errorCode: 'weibo_binding_not_confirmed',
|
||||
})
|
||||
}
|
||||
if (task.assigned_admin_user_id && Number(task.assigned_admin_user_id) !== adminUserId) {
|
||||
throw createHttpError('该任务已被其他客服领取', {
|
||||
statusCode: 409,
|
||||
errorCode: 'semi_auto_task_claimed',
|
||||
})
|
||||
}
|
||||
|
||||
await confirmManualFulfillment(
|
||||
{
|
||||
@@ -1016,10 +962,8 @@ export async function completeAdminSemiAutoTask(
|
||||
actor: 'admin',
|
||||
actorId: String(adminUserId),
|
||||
patch: {
|
||||
// 已领取任务保持原领取人(原 COALESCE 语义)。
|
||||
assignedAdminUserId: task.assigned_admin_user_id
|
||||
? Number(task.assigned_admin_user_id)
|
||||
: adminUserId,
|
||||
// 不设领取人:任何客服都能完成,这里只记录最近一次操作人。
|
||||
assignedAdminUserId: adminUserId,
|
||||
executionStatus: 'completed',
|
||||
completedQuantity: Number(task.target_quantity || 0),
|
||||
completedAt: SEMI_AUTO_NOW,
|
||||
|
||||
@@ -1181,6 +1181,26 @@ test(
|
||||
role: 'support',
|
||||
displayName: '集成测试客服',
|
||||
} as never)
|
||||
|
||||
// 后台没有「领取」动作:另一个客服也能直接操作同一任务,不会被领取人挡住。
|
||||
const secondAdmin = await query<{ id: number }>(
|
||||
`INSERT INTO admin_users (username, password_hash, role, status, created_at, updated_at)
|
||||
VALUES ($1, 'x', 'support', 'active', NOW(), NOW()) RETURNING id`,
|
||||
[`it_huya_restore_admin2_${suffix}`],
|
||||
)
|
||||
const secondAdminId = Number(secondAdmin.rows[0]?.id || 0)
|
||||
const secondInjection = await createAdminBrowserSession(
|
||||
result.taskId,
|
||||
'https://www.huya.com/',
|
||||
{ userId: secondAdminId, role: 'support', displayName: '另一个客服' } as never,
|
||||
)
|
||||
assert.equal(secondInjection.cookies.length > 0, true)
|
||||
const operator = await query<{ assigned_admin_user_id: number | null }>(
|
||||
'SELECT assigned_admin_user_id FROM semi_auto_tasks WHERE id = $1',
|
||||
[result.taskId],
|
||||
)
|
||||
// 只记录最近操作人,不构成门禁。
|
||||
assert.equal(Number(operator.rows[0]?.assigned_admin_user_id), secondAdminId)
|
||||
const restored = await query<{
|
||||
connector_session_id: string
|
||||
credential_session_restored: number
|
||||
@@ -1202,7 +1222,8 @@ test(
|
||||
|
||||
// 直接下发账号级 CK:没有票据、没有 TTL,权限靠后台登录态 + 领取人 + 审计。
|
||||
assert.equal(injection.platform, 'huya')
|
||||
assert.equal(injection.targetUrl, 'https://www.huya.com/')
|
||||
// 传平台首页等于「没指定落地页」,必须回落到策略默认的兑换入口页。
|
||||
assert.match(injection.targetUrl, /^https:\/\/m-shop\.huya\.com\/points\.html\?/)
|
||||
assert.equal(
|
||||
injection.cookies.find((cookie) => cookie.name === 'udb_cred')?.value,
|
||||
`restored-${suffix}`,
|
||||
|
||||
Reference in New Issue
Block a user