超时订单按打手统计,抢单大厅标注限时任务

This commit is contained in:
yml2213
2026-08-01 19:18:20 +08:00
parent 23ad60a1ef
commit 3650526863
7 changed files with 87 additions and 3 deletions
@@ -1425,6 +1425,7 @@ export async function settleOverdueWorkOrder(input: {
payloadJson: JSON.stringify({
policy: input.policy,
depositAmount: resolvedDepositAmount,
workerId: workerId > 0 ? workerId : null,
}),
now: input.now,
})
@@ -1449,6 +1450,36 @@ export async function countWorkerActiveOrders(workerId: number | string): Promis
return Number(result.rows[0]?.total || 0)
}
export async function countTimeoutEventsByWorkerIds(workerIds: number[]): Promise<Map<number, number>> {
const counts = new Map<number, number>()
const uniqueIds = [...new Set(workerIds.map((id) => Number(id)).filter((id) => id > 0))]
if (uniqueIds.length === 0) return counts
const result = await query<{ worker_id: string; total: number }>(
`
SELECT payload_json->>'workerId' AS worker_id, COUNT(*)::int AS total
FROM work_order_events
WHERE event_type LIKE 'timeout_%'
AND payload_json->>'workerId' IS NOT NULL
AND payload_json->>'workerId' != ''
AND payload_json->>'workerId' = ANY($1::text[])
GROUP BY payload_json->>'workerId'
`,
[uniqueIds.map(String)],
)
for (const row of result.rows) {
const workerId = Number(row.worker_id)
if (Number.isFinite(workerId) && workerId > 0) {
counts.set(workerId, Number(row.total || 0))
}
}
return counts
}
export async function countWorkerTimeoutEvents(workerId: number | string): Promise<number> {
const counts = await countTimeoutEventsByWorkerIds([Number(workerId)])
return counts.get(Number(workerId)) || 0
}
export async function createWorkOrderEvent(input: {
workOrderId: number
actorType: string