## P1 数据库基础 - zqyy_app: 创建 auth/biz schema、FDW 连接 etl_feiqiu - etl_feiqiu: 创建 app schema RLS 视图、商品库存预警表 - 清理 assistant_abolish 残留数据 ## P2 ETL/DWS 扩展 - 新增 DWS 助教订单贡献度表 (dws.assistant_order_contribution) - 新增 assistant_order_contribution_task 任务及 RLS 视图 - member_consumption 增加充值字段、assistant_daily 增加处罚字段 - 更新 ODS/DWD/DWS 任务文档及业务规则文档 - 更新 consistency_checker、flow_runner、task_registry 等核心模块 ## P3 小程序鉴权系统 - 新增 xcx_auth 路由/schema(微信登录 + JWT) - 新增 wechat/role/matching/application 服务层 - zqyy_app 鉴权表迁移 + 角色权限种子数据 - auth/dependencies.py 支持小程序 JWT 鉴权 ## 文档与审计 - 新增 DOCUMENTATION-MAP 文档导航 - 新增 7 份 BD_Manual 数据库变更文档 - 更新 DDL 基线快照(etl_feiqiu 6 schema + zqyy_app auth) - 新增全栈集成审计记录、部署检查清单更新 - 新增 BACKLOG 路线图、FDW→Core 迁移计划 ## Kiro 工程化 - 新增 5 个 Spec(P1/P2/P3/全栈集成/核心业务) - 新增审计自动化脚本(agent_on_stop/build_audit_context/compliance_prescan) - 新增 6 个 Hook(合规检查/会话日志/提交审计等) - 新增 doc-map steering 文件 ## 运维与测试 - 新增 ops 脚本:迁移验证/API 健康检查/ETL 监控/集成报告 - 新增属性测试:test_dws_contribution / test_auth_system - 清理过期 export 报告文件 - 更新 .gitignore 排除规则
75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
"""
|
||
NeoZQYY 后端 API 入口
|
||
|
||
基于 FastAPI 构建,为管理后台和微信小程序提供 RESTful API。
|
||
OpenAPI 文档自动生成于 /docs(Swagger UI)和 /redoc(ReDoc)。
|
||
"""
|
||
|
||
from contextlib import asynccontextmanager
|
||
|
||
from fastapi import FastAPI
|
||
from fastapi.middleware.cors import CORSMiddleware
|
||
|
||
from app import config
|
||
# CHANGE 2026-02-19 | 新增 xcx_test 路由(MVP 验证)+ wx_callback 路由(微信消息推送)
|
||
# CHANGE 2026-02-22 | 新增 member_birthday 路由(助教手动补录会员生日)
|
||
# CHANGE 2026-02-23 | 新增 ops_panel 路由(运维控制面板)
|
||
# CHANGE 2026-02-25 | 新增 xcx_auth 路由(小程序微信登录 + 申请 + 状态查询 + 店铺切换)
|
||
from app.routers import auth, execution, schedules, tasks, env_config, db_viewer, etl_status, xcx_test, wx_callback, member_birthday, ops_panel, xcx_auth
|
||
from app.services.scheduler import scheduler
|
||
from app.services.task_queue import task_queue
|
||
from app.ws.logs import ws_router
|
||
|
||
|
||
@asynccontextmanager
|
||
async def lifespan(app: FastAPI):
|
||
"""应用生命周期:启动时拉起后台服务,关闭时优雅停止。"""
|
||
# 启动
|
||
task_queue.start()
|
||
scheduler.start()
|
||
yield
|
||
# 关闭
|
||
await scheduler.stop()
|
||
await task_queue.stop()
|
||
|
||
|
||
app = FastAPI(
|
||
title="NeoZQYY API",
|
||
description="台球门店运营助手 — 后端 API(管理后台 + 微信小程序)",
|
||
version="0.1.0",
|
||
docs_url="/docs",
|
||
redoc_url="/redoc",
|
||
lifespan=lifespan,
|
||
)
|
||
|
||
# ---- CORS 中间件 ----
|
||
# 允许来源从环境变量 CORS_ORIGINS 读取,缺省允许 Vite 开发服务器 (localhost:5173)
|
||
app.add_middleware(
|
||
CORSMiddleware,
|
||
allow_origins=config.CORS_ORIGINS,
|
||
allow_credentials=True,
|
||
allow_methods=["*"],
|
||
allow_headers=["*"],
|
||
)
|
||
|
||
# ---- 路由注册 ----
|
||
app.include_router(auth.router)
|
||
app.include_router(tasks.router)
|
||
app.include_router(execution.router)
|
||
app.include_router(schedules.router)
|
||
app.include_router(env_config.router)
|
||
app.include_router(db_viewer.router)
|
||
app.include_router(etl_status.router)
|
||
app.include_router(ws_router)
|
||
app.include_router(xcx_test.router)
|
||
app.include_router(wx_callback.router)
|
||
app.include_router(member_birthday.router)
|
||
app.include_router(ops_panel.router)
|
||
app.include_router(xcx_auth.router)
|
||
|
||
|
||
@app.get("/health", tags=["系统"])
|
||
async def health_check():
|
||
"""健康检查端点,用于探活和监控。"""
|
||
return {"status": "ok"}
|