收敛工单活跃统计
This commit is contained in:
@@ -425,6 +425,27 @@ export async function countWorkerActiveOrders(workerId: number | string): Promis
|
||||
return Number(result.rows[0]?.total || 0)
|
||||
}
|
||||
|
||||
export async function countWorkerActiveOrdersWithClient(
|
||||
client: PoolClient,
|
||||
workerId: number,
|
||||
): Promise<number> {
|
||||
const result = await client.query<{ total: number }>(
|
||||
`
|
||||
SELECT (
|
||||
SELECT COUNT(*)::int FROM work_orders
|
||||
WHERE assigned_worker_id = $1 AND status = 'in_progress'
|
||||
) + (
|
||||
SELECT COUNT(*)::int
|
||||
FROM work_order_shares wos
|
||||
INNER JOIN work_orders wo ON wo.id = wos.work_order_id
|
||||
WHERE wos.worker_id = $1 AND wos.status = 'joined' AND wo.status = 'open'
|
||||
) AS total
|
||||
`,
|
||||
[workerId],
|
||||
)
|
||||
return Number(result.rows[0]?.total || 0)
|
||||
}
|
||||
|
||||
export async function countTimeoutEventsByWorkerIds(
|
||||
workerIds: number[],
|
||||
): Promise<Map<number, number>> {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
countTimeoutEventsByWorkerIds,
|
||||
countWorkerCancellationsSince,
|
||||
countWorkerActiveOrders,
|
||||
countWorkerActiveOrdersWithClient,
|
||||
countWorkerTimeoutEvents,
|
||||
getWorkOrderById,
|
||||
getWorkOrderByIdWithClient,
|
||||
@@ -1935,28 +1936,3 @@ export async function getOutstandingDepositAmountWithClient(
|
||||
)
|
||||
return resolveOutstandingDepositAmount(result.rows[0])
|
||||
}
|
||||
|
||||
export async function countWorkerActiveOrdersWithClient(
|
||||
client: PoolClient,
|
||||
workerId: number,
|
||||
): Promise<number> {
|
||||
const result = await client.query<{ total: number }>(
|
||||
`
|
||||
SELECT (
|
||||
SELECT COUNT(*)::int
|
||||
FROM work_orders
|
||||
WHERE assigned_worker_id = $1
|
||||
AND status = 'in_progress'
|
||||
) + (
|
||||
SELECT COUNT(*)::int
|
||||
FROM work_order_shares wos
|
||||
INNER JOIN work_orders wo ON wo.id = wos.work_order_id
|
||||
WHERE wos.worker_id = $1
|
||||
AND wos.status = 'joined'
|
||||
AND wo.status = 'open'
|
||||
) AS total
|
||||
`,
|
||||
[workerId],
|
||||
)
|
||||
return Number(result.rows[0]?.total || 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user