优化快手 Cloud 主链路状态机
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { getTaskById } from '../../repositories/task-repo.js'
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
import { safeParseJson } from './admin-query-utils.js'
|
||||
import {
|
||||
TASK_STATUS,
|
||||
isTaskFulfillmentCompletedStatus,
|
||||
normalizeTaskStatus,
|
||||
} from '../../domain/task-status.js'
|
||||
import {
|
||||
createAdminViewerContext,
|
||||
getTaskPrimaryClaimTokenId,
|
||||
@@ -173,7 +178,7 @@ export function buildOrderFulfillmentProgress(
|
||||
}
|
||||
|
||||
function buildTaskFulfillmentState(task: TaskRow | null | undefined): TaskFulfillmentState {
|
||||
const normalizedStatus = String(task?.task_status || '').trim()
|
||||
const normalizedStatus = normalizeTaskStatus(task?.task_status)
|
||||
|
||||
if (!normalizedStatus) {
|
||||
return {
|
||||
@@ -182,63 +187,63 @@ function buildTaskFulfillmentState(task: TaskRow | null | undefined): TaskFulfil
|
||||
}
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'pending_payment') {
|
||||
if (normalizedStatus === TASK_STATUS.PENDING_PAYMENT) {
|
||||
return { resourceStatus: 'pending_payment', customerStatus: 'not_started' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'paid') {
|
||||
if (normalizedStatus === TASK_STATUS.PAID) {
|
||||
return { resourceStatus: 'pending_prepare', customerStatus: 'not_started' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'pending_binding_prepare') {
|
||||
if (normalizedStatus === TASK_STATUS.PENDING_BINDING_PREPARE) {
|
||||
return { resourceStatus: 'pending_prepare', customerStatus: 'not_started' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'waiting_binding') {
|
||||
if (normalizedStatus === TASK_STATUS.WAITING_BINDING) {
|
||||
return { resourceStatus: 'resource_ready', customerStatus: 'waiting_customer' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'dispatched_pending_return') {
|
||||
if (normalizedStatus === TASK_STATUS.DISPATCHED_PENDING_RETURN) {
|
||||
return { resourceStatus: 'resource_ready', customerStatus: 'customer_completed' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'completed') {
|
||||
if (normalizedStatus === TASK_STATUS.COMPLETED) {
|
||||
return { resourceStatus: 'resource_ready', customerStatus: 'customer_completed' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'manual_review') {
|
||||
if (normalizedStatus === TASK_STATUS.MANUAL_REVIEW) {
|
||||
return { resourceStatus: 'manual_review', customerStatus: 'customer_exception' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'retry_pending') {
|
||||
if (normalizedStatus === TASK_STATUS.RETRY_PENDING) {
|
||||
return { resourceStatus: 'retry_pending', customerStatus: 'customer_exception' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'closed') {
|
||||
if (normalizedStatus === TASK_STATUS.CLOSED) {
|
||||
return { resourceStatus: 'closed', customerStatus: 'closed' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'expired') {
|
||||
if (normalizedStatus === TASK_STATUS.EXPIRED) {
|
||||
return { resourceStatus: 'expired', customerStatus: 'expired' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'link_generated') {
|
||||
if (normalizedStatus === TASK_STATUS.LINK_GENERATED) {
|
||||
return { resourceStatus: 'resource_ready', customerStatus: 'waiting_customer' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'claimed') {
|
||||
if (normalizedStatus === TASK_STATUS.CLAIMED) {
|
||||
return { resourceStatus: 'resource_ready', customerStatus: 'link_opened' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'role_confirmed') {
|
||||
if (normalizedStatus === TASK_STATUS.ROLE_CONFIRMED) {
|
||||
return { resourceStatus: 'resource_ready', customerStatus: 'customer_confirmed' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'redeeming') {
|
||||
if (normalizedStatus === TASK_STATUS.REDEEMING) {
|
||||
return { resourceStatus: 'resource_ready', customerStatus: 'customer_processing' }
|
||||
}
|
||||
|
||||
if (normalizedStatus === 'redeemed') {
|
||||
if (normalizedStatus === TASK_STATUS.REDEEMED) {
|
||||
return { resourceStatus: 'resource_ready', customerStatus: 'customer_completed' }
|
||||
}
|
||||
|
||||
@@ -254,7 +259,7 @@ function isTaskResourcePrepared(task: TaskRow | null | undefined): boolean {
|
||||
}
|
||||
|
||||
function isTaskFulfillmentCompleted(task: TaskRow | null | undefined): boolean {
|
||||
return ['redeemed', 'completed', 'dispatched_pending_return'].includes(String(task?.task_status || '').trim())
|
||||
return isTaskFulfillmentCompletedStatus(task?.task_status)
|
||||
}
|
||||
|
||||
function normalizeRecord(value: unknown): JsonRecord {
|
||||
|
||||
Reference in New Issue
Block a user