forked from wangziqi/gongxue-base
feat: add platform usage worker
This commit is contained in:
@@ -884,11 +884,23 @@ export async function platformOverviewRoute(ctx: RequestContext) {
|
||||
),
|
||||
queryOne<{ students: string; questions: string; storageGb: string }>(
|
||||
`
|
||||
with latest_usage as (
|
||||
select tenant_id, metric_key, metric_value,
|
||||
row_number() over (
|
||||
partition by tenant_id, metric_key
|
||||
order by case when metadata->>'source' = 'platform_usage_worker' then 0 else 1 end,
|
||||
period_end desc,
|
||||
created_at desc
|
||||
) as rn
|
||||
from public.tenant_usage_records
|
||||
where period_end >= current_date - interval '31 days'
|
||||
and metric_key in ('students', 'questions', 'storage_gb')
|
||||
)
|
||||
select coalesce(sum(metric_value) filter (where metric_key = 'students'), 0)::text as students,
|
||||
coalesce(sum(metric_value) filter (where metric_key = 'questions'), 0)::text as questions,
|
||||
coalesce(sum(metric_value) filter (where metric_key = 'storage_gb'), 0)::text as "storageGb"
|
||||
from public.tenant_usage_records
|
||||
where period_end >= current_date - interval '31 days'
|
||||
from latest_usage
|
||||
where rn = 1
|
||||
`,
|
||||
),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user