修复(半自动履约): 收口虎牙确认恢复与任务切换
This commit is contained in:
@@ -471,6 +471,20 @@ export async function applySemiAutoTaskStateSnapshot(
|
||||
BINDING_STATUSES,
|
||||
'绑定状态',
|
||||
)
|
||||
const stateVersionRaw = input.stateVersion ?? input.state_version
|
||||
const stateVersion = Number(stateVersionRaw)
|
||||
if (
|
||||
stateVersionRaw === undefined ||
|
||||
stateVersionRaw === null ||
|
||||
String(stateVersionRaw).trim() === '' ||
|
||||
!Number.isSafeInteger(stateVersion) ||
|
||||
stateVersion <= 0
|
||||
) {
|
||||
throw createHttpError('状态快照版本必须为正整数', {
|
||||
statusCode: 400,
|
||||
errorCode: 'semi_auto_snapshot_state_version_required',
|
||||
})
|
||||
}
|
||||
if (!eventId) {
|
||||
throw createHttpError('状态快照事件编号不能为空', {
|
||||
statusCode: 400,
|
||||
@@ -498,6 +512,9 @@ export async function applySemiAutoTaskStateSnapshot(
|
||||
if (task.execution_status === 'completed' || task.execution_status === 'cancelled') {
|
||||
return { applied: false, terminal: true }
|
||||
}
|
||||
if (stateVersion <= Number(task.connector_state_version || 0)) {
|
||||
return { applied: false, stale: true, stateVersion }
|
||||
}
|
||||
|
||||
const uid = String(input.huyaUid ?? input.huya_uid ?? '').trim()
|
||||
const nickname = String(input.platformNickname ?? input.platform_nickname ?? '').trim()
|
||||
@@ -682,9 +699,10 @@ export async function applySemiAutoTaskStateSnapshot(
|
||||
ELSE authenticated_at
|
||||
END,
|
||||
last_error = CASE WHEN $2 IN ('failed', 'expired') THEN $5 ELSE last_error END,
|
||||
connector_state_version = $6,
|
||||
updated_at = NOW()
|
||||
WHERE id = $1`,
|
||||
[task.id, loginStatus, uid, nickname, message],
|
||||
[task.id, loginStatus, uid, nickname, message, stateVersion],
|
||||
)
|
||||
if (
|
||||
loginStatus !== task.login_status ||
|
||||
@@ -718,6 +736,7 @@ export async function applySemiAutoTaskStateSnapshot(
|
||||
terminal: false,
|
||||
taskId: task.id,
|
||||
orderId: task.order_id,
|
||||
stateVersion,
|
||||
executionStatus: bindingResult.executionStatus,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user