feat: initial commit and ignore qwen files

This commit is contained in:
dxc
2026-04-30 10:06:32 +08:00
commit def4f7d71f
55 changed files with 5252 additions and 0 deletions

67
backend/app/main.py Normal file
View File

@ -0,0 +1,67 @@
"""FastAPI 主入口文件
核心原则:
- 所有写操作仅在 pms_db 中进行
- 绝对禁止对 inventory_db 进行任何写操作
- 库存相关查询仅使用只读连接
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.config import settings
from app.routers import (
deduce_bom_router, # 齐套性推演
bom_targets_router, # BOM 成品搜索
work_order_router, # 工单 CRUD
approval_router, # 缺料审批
approvals_router, # 缺料审批列表
material_router, # 物料查询
preference_router, # 用户偏好
project_stats_router, # 项目统计
work_order_kanban_router, # 工单看板
)
# 自动创建表(仅 pms_db
from app.database import engine_pms, Base
from app.models import PmsProject, PmsWorkOrder, PmsMaterialApproval, PmsUserPreference
from app.models.inventory import MaterialBase
Base.metadata.create_all(bind=engine_pms)
# 创建FastAPI应用实例
app = FastAPI(
title="Production Management System API",
description="生产管理系统后端API",
version="1.0.0",
)
# 配置CORS中间件
app.add_middleware(
CORSMiddleware,
allow_origins=settings.CORS_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# ============================================================
# 路由注册说明:
# 1. FastAPI 按 include_router 顺序注册路由
# 2. 更具体的路径(如 /summary必须在通用路径如 /{id})之前定义
# 3. 同一 prefix 的路由必须集中注册,避免路径匹配混乱
# ============================================================
app.include_router(deduce_bom_router)
app.include_router(bom_targets_router)
app.include_router(work_order_router)
app.include_router(approval_router)
app.include_router(approvals_router)
app.include_router(material_router)
app.include_router(preference_router)
app.include_router(project_stats_router)
app.include_router(work_order_kanban_router)
@app.get("/health")
async def health_check():
"""健康检查接口"""
return {"status": "healthy", "service": "PMS API"}