Files
X-Financial/server/src/app/api/v1/endpoints/analytics.py
caoxiaozhu 7989f3a159 feat: 新增风险图谱算法与系统仪表盘及操作反馈体系
后端新增风险图谱算法模块、风险观察与反馈服务、规则 DSL
校验器和可解释性引擎,完善系统仪表盘和财务仪表盘统计,
优化 agent 运行和编排执行链路,清理旧开发文档,前端新增
系统趋势、负载热力图等多种仪表盘图表组件,完善操作反馈
对话框和工作台日期选择器,优化报销创建和审批详情交互,
补充单元测试覆盖。
2026-05-30 15:46:51 +08:00

56 lines
2.0 KiB
Python

from __future__ import annotations
from datetime import date
from typing import Annotated
from fastapi import APIRouter, Depends, Query
from sqlalchemy.orm import Session
from app.api.deps import get_db
from app.schemas.finance_dashboard import FinanceDashboardRead
from app.schemas.system_dashboard import SystemDashboardRead
from app.services.finance_dashboard import FinanceDashboardService
from app.services.system_dashboard import SystemDashboardService
router = APIRouter(prefix="/analytics")
DbSession = Annotated[Session, Depends(get_db)]
@router.get(
"/system-dashboard",
response_model=SystemDashboardRead,
summary="查询系统看板真实指标",
description="基于 Agent 运行、工具调用、用户会话和反馈数据聚合系统看板指标。",
)
def get_system_dashboard(
db: DbSession,
days: Annotated[
int,
Query(ge=1, le=30, description="统计窗口天数。"),
] = 7,
) -> SystemDashboardRead:
return SystemDashboardService(db).build_dashboard(days=days)
@router.get(
"/finance-dashboard",
response_model=FinanceDashboardRead,
summary="查询财务看板真实指标",
description="基于报销单据、风险观察和预算池数据聚合财务看板指标。",
)
def get_finance_dashboard(
db: DbSession,
range_key: Annotated[str, Query(max_length=30, description="顶部时间范围。")] = "近10日",
start_date: Annotated[date | None, Query(description="自定义开始日期。")] = None,
end_date: Annotated[date | None, Query(description="自定义结束日期。")] = None,
trend_range: Annotated[str, Query(max_length=30, description="趋势图时间范围。")] = "近12天",
department_range: Annotated[str, Query(max_length=30, description="部门排行时间范围。")] = "本月",
) -> FinanceDashboardRead:
return FinanceDashboardService(db).build_dashboard(
range_key=range_key,
start_date=start_date,
end_date=end_date,
trend_range=trend_range,
department_range=department_range,
)