收敛工单撤单统计

This commit is contained in:
yml2213
2026-08-21 18:23:42 +08:00
parent 90527344ca
commit 45bd917e3c
2 changed files with 19 additions and 18 deletions
@@ -457,6 +457,24 @@ export async function countWorkerTimeoutEvents(workerId: number | string): Promi
return counts.get(Number(workerId)) || 0
}
export async function countWorkerCancellationsSince(
workerId: number | string,
sinceIso: string,
): Promise<number> {
const result = await query<{ total: number }>(
`
SELECT COUNT(*)::int AS total
FROM work_order_events
WHERE actor_type = 'worker'
AND actor_id = $1
AND event_type = 'cancelled_by_worker'
AND created_at >= $2
`,
[String(workerId), sinceIso],
)
return Number(result.rows[0]?.total || 0)
}
export async function getWorkOrderByIdWithClient(
client: PoolClient,
workOrderId: number | string,
@@ -11,6 +11,7 @@ import {
import { createWorkOrderEventWithClient } from './work-order-event-repo.js'
import {
countTimeoutEventsByWorkerIds,
countWorkerCancellationsSince,
countWorkerActiveOrders,
countWorkerTimeoutEvents,
getWorkOrderById,
@@ -714,24 +715,6 @@ export async function reopenCancelledWorkOrder(input: {
})
}
export async function countWorkerCancellationsSince(
workerId: number | string,
sinceIso: string,
): Promise<number> {
const result = await query<{ total: number }>(
`
SELECT COUNT(*)::int AS total
FROM work_order_events
WHERE actor_type = 'worker'
AND actor_id = $1
AND event_type = 'cancelled_by_worker'
AND created_at >= $2
`,
[String(workerId), sinceIso],
)
return Number(result.rows[0]?.total || 0)
}
export async function acceptWorkOrderAndSettle(input: {
workOrderId: number
unfreezeDays: number