Initial commit: KPI Management System Backend
Features: - FastAPI backend with JWT authentication - MySQL database with SQLAlchemy ORM - KPI workflow: draft → pending → approved → evaluation → completed - Ollama LLM API integration for AI features - Gitea API integration for version control - Complete API endpoints for KPI, dashboard, notifications Tables: KPI_D_* prefix naming convention 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
97
app/main.py
Normal file
97
app/main.py
Normal file
@@ -0,0 +1,97 @@
|
||||
"""
|
||||
KPI 管理系統 - FastAPI 主程式
|
||||
"""
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.database import init_db
|
||||
from app.api import (
|
||||
auth_router,
|
||||
kpi_router,
|
||||
dashboard_router,
|
||||
notifications_router,
|
||||
llm_router,
|
||||
gitea_router,
|
||||
)
|
||||
|
||||
# 建立 FastAPI 應用程式
|
||||
app = FastAPI(
|
||||
title=settings.APP_NAME,
|
||||
description="KPI 管理系統 API - 整合 Ollama LLM 與 Gitea 版本控制",
|
||||
version="1.0.0",
|
||||
docs_url="/docs",
|
||||
redoc_url="/redoc",
|
||||
)
|
||||
|
||||
# CORS 設定
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"], # 生產環境應限制
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
# 全域例外處理
|
||||
@app.exception_handler(Exception)
|
||||
async def global_exception_handler(request: Request, exc: Exception):
|
||||
"""全域例外處理器"""
|
||||
return JSONResponse(
|
||||
status_code=500,
|
||||
content={
|
||||
"error": {
|
||||
"code": "INTERNAL_ERROR",
|
||||
"message": "內部伺服器錯誤",
|
||||
"details": str(exc) if settings.DEBUG else None,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# 註冊路由
|
||||
app.include_router(auth_router)
|
||||
app.include_router(kpi_router)
|
||||
app.include_router(dashboard_router)
|
||||
app.include_router(notifications_router)
|
||||
app.include_router(llm_router)
|
||||
app.include_router(gitea_router)
|
||||
|
||||
|
||||
# 啟動事件
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""應用程式啟動時初始化資料庫"""
|
||||
init_db()
|
||||
|
||||
|
||||
# 健康檢查
|
||||
@app.get("/health")
|
||||
def health_check():
|
||||
"""健康檢查端點"""
|
||||
return {"status": "healthy", "app": settings.APP_NAME}
|
||||
|
||||
|
||||
# 根路徑
|
||||
@app.get("/")
|
||||
def root():
|
||||
"""API 根路徑"""
|
||||
return {
|
||||
"app": settings.APP_NAME,
|
||||
"version": "1.0.0",
|
||||
"docs": "/docs",
|
||||
"features": [
|
||||
"KPI 管理",
|
||||
"員工績效考核",
|
||||
"Ollama LLM 整合",
|
||||
"Gitea 版本控制",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)
|
||||
Reference in New Issue
Block a user