feat: 完善履约路由、订单服务与自动核销
This commit is contained in:
@@ -22,7 +22,10 @@ import {
|
||||
findConflictingCarrier,
|
||||
loadActiveCarrierEvidence,
|
||||
} from '../fulfillment/carrier-evidence-service.js'
|
||||
import type { FulfillmentChannel } from '../fulfillment/channel-types.js'
|
||||
import {
|
||||
isInactiveCarrierTaskStatus,
|
||||
type FulfillmentChannel,
|
||||
} from '../fulfillment/channel-types.js'
|
||||
|
||||
type ClaimTokenLike = {
|
||||
token: string
|
||||
@@ -52,13 +55,15 @@ type DeliveryTaskDeps = {
|
||||
createTaskEvent?: typeof createTaskEvent
|
||||
logInfo?: typeof logInfo
|
||||
logWarn?: typeof logWarn
|
||||
allowInactiveTaskRetry?: boolean
|
||||
}
|
||||
|
||||
export async function syncDeliveryTasksForOrder(
|
||||
order: OrderRow,
|
||||
orderItems: OrderItemRow[],
|
||||
options: { allowInactiveTaskRetry?: boolean } = {},
|
||||
): Promise<TaskRow[]> {
|
||||
return syncDeliveryTasksForOrderWithDeps(order, orderItems)
|
||||
return syncDeliveryTasksForOrderWithDeps(order, orderItems, options)
|
||||
}
|
||||
|
||||
export async function syncDeliveryTasksForOrderWithDeps(
|
||||
@@ -79,6 +84,7 @@ export async function syncDeliveryTasksForOrderWithDeps(
|
||||
createTaskEvent: appendTaskEvent = createTaskEvent,
|
||||
logInfo: writeInfoLog = logInfo,
|
||||
logWarn: writeWarnLog = logWarn,
|
||||
allowInactiveTaskRetry = false,
|
||||
} = deps
|
||||
|
||||
const runtimeDeps: FulfillmentPrepareDeps = {
|
||||
@@ -90,7 +96,12 @@ export async function syncDeliveryTasksForOrderWithDeps(
|
||||
|
||||
const existingTasks = await listTasks(order.id)
|
||||
const tasks: DeliveryTaskRow[] = [...existingTasks]
|
||||
const existingTaskKeys = new Set(existingTasks.map(buildTaskUnitKey))
|
||||
const existingTaskKeys = new Set(
|
||||
(allowInactiveTaskRetry
|
||||
? existingTasks.filter((task) => !isInactiveCarrierTaskStatus(task.task_status))
|
||||
: existingTasks
|
||||
).map(buildTaskUnitKey),
|
||||
)
|
||||
const carrierEvidence = await loadCarrierEvidence(orderItems.map((item) => Number(item.id)))
|
||||
|
||||
writeInfoLog('[delivery-task-service]', '开始核对订单履约任务完整性', {
|
||||
@@ -205,6 +216,9 @@ export async function syncDeliveryTasksForOrderWithDeps(
|
||||
task =
|
||||
concurrentTasks.find(
|
||||
(candidate) =>
|
||||
(allowInactiveTaskRetry
|
||||
? !isInactiveCarrierTaskStatus(candidate.task_status)
|
||||
: true) &&
|
||||
buildTaskUnitKey(candidate) === buildOrderItemUnitKey(item.id, unitIndex),
|
||||
) || null
|
||||
if (!task) {
|
||||
|
||||
Reference in New Issue
Block a user