重构(半自动履约): 收敛状态同步并拆分任务服务
This commit is contained in:
@@ -526,6 +526,10 @@ function applyAdminRealtimeEvent(
|
||||
if (event.type === 'order.changed' && event.scopes.includes('admin_douyu_fulfillment')) {
|
||||
void queryClient.invalidateQueries({ queryKey: ['admin-douyu-fulfillment'] })
|
||||
}
|
||||
if (event.type === 'order.changed' && event.scopes.includes('admin_semi_auto_tasks')) {
|
||||
void queryClient.invalidateQueries({ queryKey: ['admin-semi-auto-tasks'] })
|
||||
void queryClient.invalidateQueries({ queryKey: ['admin-semi-auto-task'] })
|
||||
}
|
||||
|
||||
if (event.type === 'admin_notification.changed' && isRecord(event.data)) {
|
||||
queryClient.setQueryData(['admin-notifications'], (current: unknown) => {
|
||||
|
||||
@@ -128,13 +128,11 @@ export default function AdminSemiAutoTasksPage() {
|
||||
const listQuery = useQuery({
|
||||
queryKey: ['admin-semi-auto-tasks', params],
|
||||
queryFn: () => fetchAdminSemiAutoTasks(params),
|
||||
refetchInterval: 3000,
|
||||
})
|
||||
const detailQuery = useQuery({
|
||||
queryKey: ['admin-semi-auto-task', detailTaskId],
|
||||
queryFn: () => fetchAdminSemiAutoTask(Number(detailTaskId)),
|
||||
enabled: Boolean(detailTaskId),
|
||||
refetchInterval: detailTaskId ? 3000 : false,
|
||||
})
|
||||
const list = listQuery.data?.data?.items || []
|
||||
const pagination = listQuery.data?.data?.pagination
|
||||
@@ -479,6 +477,7 @@ export default function AdminSemiAutoTasksPage() {
|
||||
render: (_, task) => (
|
||||
<Space direction="vertical" size={2}>
|
||||
<Tag>{task.displayStatus.label}</Tag>
|
||||
<Text type="secondary">{task.displayStatus.nextAction}</Text>
|
||||
<Text type="secondary">{task.huyaUid ? `UID ${task.huyaUid}` : '未获取 UID'}</Text>
|
||||
<Text type="secondary">
|
||||
{task.platform === 'huya'
|
||||
|
||||
@@ -194,11 +194,25 @@ export default function CustomerFulfillmentPage({
|
||||
) {
|
||||
return
|
||||
}
|
||||
const dedicatedLoginPoll =
|
||||
selectedTask.loginStatus === 'qr_pending' || selectedTask.loginStatus === 'scanned'
|
||||
const dedicatedBindingPoll =
|
||||
selectedTask.platform === 'huya' &&
|
||||
(selectedTask.bindingStatus === 'qr_pending' || selectedTask.bindingStatus === 'scanned')
|
||||
if (dedicatedLoginPoll || dedicatedBindingPoll) return
|
||||
const timer = window.setInterval(() => {
|
||||
void load(true)
|
||||
}, POLL_INTERVAL_MS)
|
||||
}, 10_000)
|
||||
return () => window.clearInterval(timer)
|
||||
}, [load, orderNo, selectedTask?.executionStatus, selectedTask?.id])
|
||||
}, [
|
||||
load,
|
||||
orderNo,
|
||||
selectedTask?.bindingStatus,
|
||||
selectedTask?.executionStatus,
|
||||
selectedTask?.id,
|
||||
selectedTask?.loginStatus,
|
||||
selectedTask?.platform,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedTask) return
|
||||
@@ -725,19 +739,6 @@ export default function CustomerFulfillmentPage({
|
||||
}
|
||||
}
|
||||
|
||||
/** 资料变更后重新打开核对弹窗:只有三项完全一致才让客户直接提交平台绑定。 */
|
||||
function reopenBindingConfirm(
|
||||
nextTask: CustomerSemiAutoTask,
|
||||
nextBinding: CustomerBindingInfo | null | undefined,
|
||||
) {
|
||||
if (nextTask.bindingStatus !== 'role_ready') return false
|
||||
if (!nextBinding?.comparison || nextBinding.rebindUnchanged) return false
|
||||
if (nextBinding.comparison.verdict !== 'match') return false
|
||||
autoOpenedRoleRef.current = `${nextTask.id}:${nextBinding.bindGameRoleId || ''}`
|
||||
setBindingConfirmOpen(true)
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回第二步修改资料:
|
||||
* 立即切回资料表单(步骤条高亮第 2 步、隐藏绑定/换绑结果),同时调后端清空虎牙
|
||||
@@ -802,15 +803,7 @@ export default function CustomerFulfillmentPage({
|
||||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||||
)
|
||||
setProfileEditing(false)
|
||||
let reopened = false
|
||||
try {
|
||||
const bindingResponse = await pollCustomerBinding(orderNo, selectedTask.id)
|
||||
if (bindingResponse.data.binding) setBindingInfo(bindingResponse.data.binding)
|
||||
reopened = reopenBindingConfirm(bindingResponse.data.task, bindingResponse.data.binding)
|
||||
} catch {
|
||||
// 绑定尚未开始时没有 binding,可忽略。
|
||||
}
|
||||
message.success(reopened ? '资料已保存且与平台角色一致,请提交平台绑定' : '资料已保存')
|
||||
message.success('资料已保存,正在重新核对平台角色')
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '保存角色资料失败')
|
||||
} finally {
|
||||
@@ -1460,6 +1453,15 @@ export default function CustomerFulfillmentPage({
|
||||
<span>
|
||||
三项完全一致才能提交平台绑定;请重新扫码换绑,或上一步修改资料。
|
||||
</span>
|
||||
{nextRebindText ? (
|
||||
<span>平台预计下次允许换绑:{nextRebindText}</span>
|
||||
) : null}
|
||||
{Number(bindingInfo?.rebindCooldownDays || 0) > 0 ? (
|
||||
<span>
|
||||
当前仍处于虎牙换绑冷却期,剩余约{' '}
|
||||
{Number(bindingInfo?.rebindCooldownDays || 0)} 天。
|
||||
</span>
|
||||
) : null}
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -3,6 +3,8 @@ export type SemiAutoPlatform = 'huya' | 'weibo'
|
||||
export type SemiAutoDisplayStatus = {
|
||||
key: string
|
||||
label: string
|
||||
owner: 'none' | 'customer' | 'operator' | 'system'
|
||||
nextAction: string
|
||||
}
|
||||
|
||||
export type SemiAutoTask = {
|
||||
|
||||
@@ -21,7 +21,12 @@ export type CustomerSemiAutoTask = {
|
||||
loginStatus: string
|
||||
bindingStatus: string
|
||||
executionStatus: string
|
||||
displayStatus: { key: string; label: string }
|
||||
displayStatus: {
|
||||
key: string
|
||||
label: string
|
||||
owner: 'none' | 'customer' | 'operator' | 'system'
|
||||
nextAction: string
|
||||
}
|
||||
huyaUid: string
|
||||
platformNickname: string
|
||||
bindGameAccount: string
|
||||
|
||||
@@ -29,12 +29,21 @@ test('资料不一致时固定提供重新扫码换绑与上一步修改资料',
|
||||
assert.ok(styles.includes('.customer-binding-role-actions'))
|
||||
})
|
||||
|
||||
test('保存资料后只有三项一致才重新打开核对弹窗', () => {
|
||||
assert.ok(source.includes('function reopenBindingConfirm('))
|
||||
assert.ok(source.includes("if (nextTask.bindingStatus !== 'role_ready') return false"))
|
||||
assert.ok(source.includes("if (nextBinding.comparison.verdict !== 'match') return false"))
|
||||
assert.ok(source.includes('reopened = reopenBindingConfirm('))
|
||||
assert.ok(source.includes('资料已保存且与平台角色一致,请提交平台绑定'))
|
||||
test('保存资料后只由单一自动绑定流程推进,不再并发轮询', () => {
|
||||
assert.ok(!source.includes('function reopenBindingConfirm('))
|
||||
const saveStart = source.indexOf('async function handleSaveProfile()')
|
||||
assert.ok(saveStart > 0)
|
||||
const saveBody = source.slice(saveStart, saveStart + 1800)
|
||||
assert.ok(!saveBody.includes('pollCustomerBinding('))
|
||||
assert.ok(source.includes("message.success('资料已保存,正在重新核对平台角色')"))
|
||||
assert.ok(source.includes("if (selectedTask.bindingStatus !== 'not_started'"))
|
||||
})
|
||||
|
||||
test('登录和绑定专用同步阶段暂停整单轮询', () => {
|
||||
assert.ok(source.includes('const dedicatedLoginPoll ='))
|
||||
assert.ok(source.includes('const dedicatedBindingPoll ='))
|
||||
assert.ok(source.includes('if (dedicatedLoginPoll || dedicatedBindingPoll) return'))
|
||||
assert.ok(source.includes('}, 10_000)'))
|
||||
})
|
||||
|
||||
test('三项一致才出现提交平台绑定,不一致时展示原因', () => {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import test from 'node:test'
|
||||
|
||||
const root = dirname(fileURLToPath(import.meta.url))
|
||||
const adminPage = readFileSync(join(root, '../src/pages/admin/AdminSemiAutoTasksPage.tsx'), 'utf8')
|
||||
const adminLayout = readFileSync(join(root, '../src/layouts/AdminLayout.tsx'), 'utf8')
|
||||
|
||||
test('半自动履约后台由 SSE 刷新,不再定时轮询列表和详情', () => {
|
||||
assert.ok(!adminPage.includes('refetchInterval: 3000'))
|
||||
assert.ok(adminLayout.includes("event.scopes.includes('admin_semi_auto_tasks')"))
|
||||
assert.ok(adminLayout.includes("queryKey: ['admin-semi-auto-tasks']"))
|
||||
assert.ok(adminLayout.includes("queryKey: ['admin-semi-auto-task']"))
|
||||
})
|
||||
|
||||
test('后台状态列展示统一的后端下一步动作', () => {
|
||||
assert.ok(adminPage.includes('task.displayStatus.nextAction'))
|
||||
})
|
||||
Reference in New Issue
Block a user