This commit is contained in:
2026-03-25 23:59:29 +08:00
parent 7964ce1033
commit 23e5df0364
46 changed files with 4168 additions and 254 deletions
+35 -6
View File
@@ -39,7 +39,6 @@ from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import asyncio
from api.routes import router
from api.auth_routes import router as auth_router
from api.inventory import inventory_router
from utils.logger import setup_logging
@@ -58,7 +57,7 @@ app = FastAPI(
async def startup_event():
"""应用启动时初始化数据库和RustFS"""
# 初始化数据库
success = await init_database()
success = await init_database(keep_connected=True)
if success:
print("[OK] 数据库初始化成功")
else:
@@ -102,18 +101,38 @@ app.mount("/html", StaticFiles(directory=html_output_dir), name="html")
app.include_router(auth_router)
app.include_router(inventory_router)
app.include_router(router, prefix="/api")
try:
from api.routes import router as moldinsight_router
except Exception as e:
moldinsight_router = None
print(f"[WARN] MoldInsight路由未加载: {e}")
if moldinsight_router is not None:
app.include_router(moldinsight_router, prefix="/api")
@app.get("/health")
@app.post("/health")
async def health():
from database.database import db_manager
from sqlalchemy import text
db_ok = False
db_error = None
try:
if not db_manager.is_connected:
await db_manager.connect()
async with db_manager.engine.begin() as conn:
await conn.execute(text("SELECT 1"))
db_ok = True
except Exception as e:
db_ok = False
db_error = str(e)
return {
"status": "healthy",
"service": "gemold",
"version": "4.0.0",
"database_connected": db_manager.is_connected
"database_connected": db_ok,
"database_error": db_error
}
@@ -135,6 +154,12 @@ async def inventory():
return FileResponse(os.path.join(os.getcwd(), "static", "index.html"))
@app.get("/login")
async def login():
from fastapi.responses import FileResponse
return FileResponse(os.path.join(os.getcwd(), "static", "index.html"))
@app.get("/users")
async def users():
from fastapi.responses import FileResponse
@@ -144,9 +169,13 @@ async def users():
if __name__ == "__main__":
import uvicorn
from config.settings import settings
reload_enabled = os.getenv("UVICORN_RELOAD", "0").lower() in {"1", "true", "yes", "on"}
print("启动 Gemold 模具制造管理系统 v4.0...")
print(f"访问 http://localhost:{settings.PORT}")
print(f"Python可执行文件: {sys.executable}")
print(f"进程ID: {os.getpid()}")
print(f"热重载: {reload_enabled}")
print("功能模块:")
print(" - 首页仪表盘")
print(" - 用户管理")
@@ -157,5 +186,5 @@ if __name__ == "__main__":
"main:app",
host=settings.HOST,
port=settings.PORT,
reload=True
)
reload=reload_enabled
)