This commit is contained in:
2026-07-21 10:08:00 +08:00
parent 76d03e7de1
commit 2a9c2d868c
4 changed files with 39 additions and 30 deletions
+7 -3
View File
@@ -1856,8 +1856,8 @@ async def get_stats(
)
)).scalar() or 0
# ── 每日各模块积分消耗(按日期+模块分组)
daily_credits_rows = (await db.execute(
# ── 每日各模块积分消耗(按日期+模块分组,子查询排序避免 PG GROUP BY 限制
_daily_subq = (
select(
func.to_char(CreditRecord.created_at, 'YYYY-MM-DD').label('date'),
func.coalesce(CreditRecord.source_module, 'other').label('module'),
@@ -1869,7 +1869,11 @@ async def get_stats(
CreditRecord.created_at <= date_end,
)
.group_by(func.to_char(CreditRecord.created_at, 'YYYY-MM-DD'), func.coalesce(CreditRecord.source_module, 'other'))
.order_by(func.to_char(CreditRecord.created_at, 'YYYY-MM-DD'))
.subquery()
)
daily_credits_rows = (await db.execute(
select(_daily_subq.c.date, _daily_subq.c.module, _daily_subq.c.credits)
.order_by(_daily_subq.c.date)
)).all()
daily_credits_by_module = [
DailyCreditOut(date=row.date, module=row.module, credits=float(row.credits or 0))