feat(analytics): 看板v2全平台口径——默认双渠道合计/拆分小字/双线趋势/跳转带query预选

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-07 12:20:18 +08:00
parent 9f2dff08d9
commit 1aadc80d6b
8 changed files with 395 additions and 117 deletions
+9 -2
View File
@@ -18,6 +18,9 @@ router = APIRouter(prefix="/api/analytics", tags=["analytics"])
SessionDep = Annotated[AsyncSession, Depends(get_session)]
ChannelParam = Annotated[Literal["wechat", "whatsapp"], Query()]
# 看板 v2(2026-09-07):overview 默认全平台——"all" 在 router 层翻译成
# metrics 的 channel=None,不把哨兵字符串传进 SQL
AllChannelParam = Annotated[Literal["all", "wechat", "whatsapp"], Query()]
ScopeParam = Annotated[Literal["today", "week", "month"], Query()]
@@ -31,15 +34,19 @@ async def analytics_health(session: SessionDep) -> dict[str, Any]:
@router.get("/overview")
async def analytics_overview(
session: SessionDep,
channel: ChannelParam = "wechat",
channel: AllChannelParam = "all",
scope: ScopeParam = "today",
) -> dict[str, Any]:
"""A1 经营总览:卡片+趋势+异常警示一次返回(单往返)。
channel=all(默认)=全平台口径:卡片合计+by_channel 拆分+trend_by_channel
双渠道趋势序列;单渠道行为不变。
cards 不含 data_as_of——数据截至走 /health(data_as_of 为 ms-epoch int
与 entities[].last_seen 为 ISO 字符串的双格式)。
"""
return await metrics_svc.overview(session, channel=channel, scope=scope)
return await metrics_svc.overview(
session, channel=None if channel == "all" else channel, scope=scope
)
@router.get("/churn")