423baff73b
- Docker bridge 网络隔离(8000 端口封死) - Gunicorn 4 Worker 多进程 - Alembic 数据库迁移基线 - 日志轮转 20m×3 - JWT 密钥 + DB 密码 + CORS 收紧 - 3-2-1 备份链路(NAS + R740-B 冷备) - 连接池 pool_pre_ping + pool_recycle=3600
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
销售复盘报告 API
|
|
GET /api/v1/reports/monthly - 获取当月销售复盘报告 (AI 生成)
|
|
"""
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.api.deps import get_current_user
|
|
from app.core.database import get_db
|
|
from app.services.analytics import generate_monthly_report
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
# ---- 响应模型 ----
|
|
|
|
class StageMetric(BaseModel):
|
|
"""单个阶段的统计指标"""
|
|
stage: str
|
|
count: int
|
|
total_amount: float
|
|
|
|
|
|
class MonthlyReportResponse(BaseModel):
|
|
"""月度复盘报告响应"""
|
|
metrics: list[StageMetric]
|
|
report: str
|
|
|
|
|
|
# ---- 路由 ----
|
|
|
|
@router.get(
|
|
"/monthly",
|
|
response_model=MonthlyReportResponse,
|
|
summary="获取当月销售复盘报告",
|
|
tags=["数据报告"],
|
|
)
|
|
async def get_monthly_report(
|
|
db: AsyncSession = Depends(get_db),
|
|
current_user: dict = Depends(get_current_user),
|
|
):
|
|
"""
|
|
生成当月销售复盘报告:
|
|
1. SQL 预聚合统计各阶段的机会数量和金额
|
|
2. 将真实数据注入 Prompt,调用 qwen3:14b 生成分析报告
|
|
3. 同步返回结构化数据 + AI 报告文本
|
|
|
|
注意:此接口为同步等待模式(用户主动触发),
|
|
AI 生成可能需要 10-30 秒,前端应显示加载状态。
|
|
"""
|
|
result = await generate_monthly_report(db)
|
|
return MonthlyReportResponse(**result)
|