feat: 客户亮灯表 + AI 周报摘要 — v0.2
亮灯表: - 四色覆盖矩阵: 绿亮灯/黄临期/红灭灯/灰未分配 - 按客户经理折叠卡片流, 覆盖率进度条, 团队总览统计 - 红灯客户显示连续未拜访月份, 未分配客户专区 - 后端: light_board.py service + GET /api/dashboard/light-board - 前端: LightBoard.vue + 路由 /light-board + 汇总侧边栏 AI 周报摘要: - 接入 OpenAI 兼容大模型, 注入拜访数据+亮灯表覆盖数据 - 四段式结构化输出: 概况/需求/覆盖分析/建议 - 一键生成+Markdown渲染+复制纯文本 - 支局长/分管领导专用, 支持配置内部模型 - 后端: ai_summary.py service + POST /api/ai/summary - 前端: WeeklyReport 集成按钮+结果面板 - 新增配置: AI_API_URL / AI_API_KEY / AI_MODEL Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""AI summary endpoints — LLM-powered weekly report narrative."""
|
||||
|
||||
import uuid
|
||||
from datetime import date
|
||||
from typing import Optional
|
||||
from fastapi import APIRouter, Depends, Query, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.database import get_db
|
||||
from app.middleware.auth import get_current_user
|
||||
from app.services.ai_summary import generate_summary
|
||||
|
||||
router = APIRouter(prefix="/ai", tags=["AI Summary"])
|
||||
|
||||
|
||||
@router.post("/summary")
|
||||
async def ai_summary(
|
||||
reference_date: Optional[str] = Query(None),
|
||||
period: str = Query("week", regex="^(week|month)$"),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Generate AI-powered weekly report summary. Director/leader only."""
|
||||
role = current_user["role"]
|
||||
if role not in ("director", "leader"):
|
||||
raise HTTPException(status_code=403, detail="仅限支局长和分管领导使用")
|
||||
|
||||
try:
|
||||
ref = date.fromisoformat(reference_date) if reference_date else None
|
||||
summary = await generate_summary(
|
||||
db=db,
|
||||
user_id=uuid.UUID(current_user["user_id"]),
|
||||
role=role,
|
||||
reference_date=ref,
|
||||
period=period,
|
||||
)
|
||||
return {"summary": summary, "period": period, "reference_date": str(ref or date.today())}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"AI 摘要生成失败:{str(e)}")
|
||||
Reference in New Issue
Block a user