已取消工单在列表与详情展示取消原因来源操作人与时间

This commit is contained in:
yml2213
2026-08-22 14:17:20 +08:00
parent 91008c98c4
commit f92dc6a4c9
5 changed files with 109 additions and 14 deletions
@@ -382,6 +382,12 @@ export type WorkOrderRow = {
category_name?: string
worker_username?: string
worker_display_name?: string
/** 取消信息,由工单查询从取消类事件推导,仅已取消工单有值。 */
cancel_reason?: string | null
cancel_event_type?: string | null
cancel_actor_type?: string | null
cancel_actor_id?: string | null
cancelled_at?: string | null
}
export type ProblemWorkOrderResolutionAction =
@@ -12,10 +12,43 @@ export const WORK_ORDER_SELECT = `
COALESCE(share_summary.pending_share_count, 0)::int AS pending_share_count,
wc.name AS category_name,
wu.username AS worker_username,
wu.display_name AS worker_display_name
wu.display_name AS worker_display_name,
cancel_info.cancel_reason,
cancel_info.cancel_event_type,
cancel_info.cancel_actor_type,
cancel_info.cancel_actor_id,
cancel_info.cancelled_at
FROM work_orders wo
LEFT JOIN work_categories wc ON wc.id = wo.category_id
LEFT JOIN worker_users wu ON wu.id = wo.assigned_worker_id
LEFT JOIN LATERAL (
SELECT
ev.event_type AS cancel_event_type,
ev.actor_type AS cancel_actor_type,
ev.actor_id AS cancel_actor_id,
ev.created_at AS cancelled_at,
BTRIM(COALESCE(
NULLIF(BTRIM(COALESCE(ev.payload_json->>'reason', '')), ''),
NULLIF(BTRIM(COALESCE(ev.payload_json->>'note', '')), ''),
CASE ev.event_type
WHEN 'timeout_cancel_release' THEN '任务超时未完成,系统自动取消并退还押金'
WHEN 'timeout_cancel_deduct' THEN '任务超时未完成,系统自动取消并扣除押金'
ELSE ''
END
)) AS cancel_reason
FROM work_order_events ev
WHERE ev.work_order_id = wo.id
AND wo.status = 'cancelled'
AND ev.event_type IN (
'cancelled_by_admin',
'problem_cancel_release',
'problem_cancel_deduct',
'timeout_cancel_release',
'timeout_cancel_deduct'
)
ORDER BY ev.id DESC
LIMIT 1
) cancel_info ON TRUE
LEFT JOIN LATERAL (
SELECT
SUM(wos.quantity) FILTER (WHERE wos.status != 'cancelled') AS active_share_quantity,