优化任务状态投影和部署文档
This commit is contained in:
@@ -1,10 +1,26 @@
|
||||
import { query } from '../../db/client.js'
|
||||
import { TASK_STATUS } from '../../domain/task-status.js'
|
||||
import { nowIso } from '../../utils/time.js'
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export async function getAdminDashboardSummary() {
|
||||
const todayPrefix = nowIso().slice(0, 10)
|
||||
const paidPendingClaimStatuses = [
|
||||
TASK_STATUS.PAID,
|
||||
TASK_STATUS.LINK_GENERATED,
|
||||
TASK_STATUS.PENDING_BINDING_PREPARE,
|
||||
TASK_STATUS.WAITING_BINDING,
|
||||
]
|
||||
const claimingStatuses = [
|
||||
TASK_STATUS.CLAIMED,
|
||||
TASK_STATUS.ROLE_CONFIRMED,
|
||||
TASK_STATUS.REDEEMING,
|
||||
]
|
||||
const abnormalStatuses = [
|
||||
TASK_STATUS.RETRY_PENDING,
|
||||
TASK_STATUS.MANUAL_REVIEW,
|
||||
]
|
||||
const result = await query(
|
||||
`
|
||||
SELECT
|
||||
@@ -12,26 +28,32 @@ export async function getAdminDashboardSummary() {
|
||||
(
|
||||
SELECT COUNT(*)::int
|
||||
FROM fulfillment_tasks
|
||||
WHERE task_status IN ('paid', 'link_generated', 'pending_binding_prepare', 'waiting_binding')
|
||||
WHERE task_status = ANY($2::text[])
|
||||
) AS paid_pending_claim,
|
||||
(
|
||||
SELECT COUNT(*)::int
|
||||
FROM fulfillment_tasks
|
||||
WHERE task_status IN ('claimed', 'role_confirmed', 'redeeming')
|
||||
WHERE task_status = ANY($3::text[])
|
||||
) AS claiming_tasks,
|
||||
(
|
||||
SELECT COUNT(*)::int
|
||||
FROM fulfillment_tasks
|
||||
WHERE task_status = 'redeemed'
|
||||
WHERE task_status = $4
|
||||
AND to_char(updated_at AT TIME ZONE 'Asia/Shanghai', 'YYYY-MM-DD') = $1
|
||||
) AS redeemed_today,
|
||||
(
|
||||
SELECT COUNT(*)::int
|
||||
FROM fulfillment_tasks
|
||||
WHERE task_status IN ('retry_pending', 'manual_review')
|
||||
WHERE task_status = ANY($5::text[])
|
||||
) AS abnormal_tasks
|
||||
`,
|
||||
[todayPrefix],
|
||||
[
|
||||
todayPrefix,
|
||||
paidPendingClaimStatuses,
|
||||
claimingStatuses,
|
||||
TASK_STATUS.REDEEMED,
|
||||
abnormalStatuses,
|
||||
],
|
||||
)
|
||||
const summary: JsonObject = result.rows[0] || {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user