305ee5df09
亮灯表: - 四色覆盖矩阵: 绿亮灯/黄临期/红灭灯/灰未分配 - 按客户经理折叠卡片流, 覆盖率进度条, 团队总览统计 - 红灯客户显示连续未拜访月份, 未分配客户专区 - 后端: 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>
71 lines
2.6 KiB
Python
71 lines
2.6 KiB
Python
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.config import settings
|
|
from app.database import engine, Base
|
|
from app.api import router as api_router
|
|
from app.api import auth, users, customers, visits, work_plans, mini_business, key_visits
|
|
from app.api import dashboard, upload, export, import_data, wecom, daily_notes, ai_summary
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Startup: create tables if not exists (for dev convenience)
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
# Add columns that may be missing from older tables
|
|
await conn.run_sync(lambda c: c.exec_driver_sql(
|
|
"ALTER TABLE customers ADD COLUMN IF NOT EXISTS remarks TEXT DEFAULT ''"
|
|
))
|
|
await conn.run_sync(lambda c: c.exec_driver_sql(
|
|
"ALTER TABLE visits ADD COLUMN IF NOT EXISTS visitor_name VARCHAR(50) DEFAULT ''"
|
|
))
|
|
await conn.run_sync(lambda c: c.exec_driver_sql(
|
|
"ALTER TABLE visits ADD COLUMN IF NOT EXISTS visitor_phone VARCHAR(20) DEFAULT ''"
|
|
))
|
|
# edit_log columns for change tracking
|
|
for tbl in ["visits", "daily_notes", "work_plans", "mini_business", "key_visits"]:
|
|
await conn.run_sync(lambda c, t=tbl: c.exec_driver_sql(
|
|
f"ALTER TABLE {t} ADD COLUMN IF NOT EXISTS edit_log JSONB DEFAULT '[]'"
|
|
))
|
|
yield
|
|
# Shutdown
|
|
await engine.dispose()
|
|
|
|
|
|
app = FastAPI(
|
|
title=settings.APP_NAME,
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.CORS_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Mount all routers
|
|
app.include_router(auth.router, prefix="/api")
|
|
app.include_router(users.router, prefix="/api")
|
|
app.include_router(customers.router, prefix="/api")
|
|
app.include_router(visits.router, prefix="/api")
|
|
app.include_router(work_plans.router, prefix="/api")
|
|
app.include_router(mini_business.router, prefix="/api")
|
|
app.include_router(key_visits.router, prefix="/api")
|
|
app.include_router(dashboard.router, prefix="/api")
|
|
app.include_router(upload.router, prefix="/api")
|
|
app.include_router(export.router, prefix="/api")
|
|
app.include_router(import_data.router, prefix="/api")
|
|
app.include_router(wecom.router, prefix="/api")
|
|
app.include_router(daily_notes.router, prefix="/api")
|
|
app.include_router(ai_summary.router, prefix="/api")
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {"status": "ok", "app": settings.APP_NAME}
|