后端模块拆分
This commit is contained in:
+15
-26
@@ -19,7 +19,7 @@ print(f"当前工作目录: {os.getcwd()}")
|
||||
|
||||
# 测试导入配置模块
|
||||
try:
|
||||
from config.settings import settings
|
||||
from shared.config.settings import settings
|
||||
print("[OK] 配置模块导入成功")
|
||||
except ImportError as e:
|
||||
print(f"[FAIL] 配置模块导入失败: {e}")
|
||||
@@ -42,11 +42,11 @@ from fastapi.responses import JSONResponse
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
from api.auth_routes import router as auth_router
|
||||
from api.inventory import inventory_router
|
||||
from api.aluminum_price_routes import router as aluminum_price_router
|
||||
from utils.logger import setup_logging, get_logger
|
||||
from database.init_db import init_database
|
||||
from shared.services.auth_routes import router as auth_router
|
||||
from inventory.api import inventory_router
|
||||
from moldinsight.api.aluminum_price_routes import router as aluminum_price_router
|
||||
from shared.utils.logger import setup_logging, get_logger
|
||||
from shared.database.init_db import init_database
|
||||
|
||||
setup_logging()
|
||||
logger = get_logger(__name__)
|
||||
@@ -94,8 +94,8 @@ async def startup_event():
|
||||
|
||||
# 初始化RustFS连接
|
||||
try:
|
||||
from storage.rustfs_storage import rustfs_manager
|
||||
from config.settings import settings
|
||||
from moldinsight.storage.rustfs_storage import rustfs_manager
|
||||
from shared.config.settings import settings
|
||||
|
||||
await rustfs_manager.connect(
|
||||
endpoint=settings.RUSTFS_ENDPOINT,
|
||||
@@ -110,7 +110,7 @@ async def startup_event():
|
||||
|
||||
# 初始化Redis连接
|
||||
try:
|
||||
from services.redis_task_manager import redis_task_manager
|
||||
from shared.services.redis_task_manager import redis_task_manager
|
||||
await redis_task_manager.connect()
|
||||
if redis_task_manager.is_connected:
|
||||
print("[OK] Redis连接成功")
|
||||
@@ -124,7 +124,7 @@ async def startup_event():
|
||||
async def shutdown_event():
|
||||
"""应用关闭时清理资源"""
|
||||
try:
|
||||
from services.redis_task_manager import redis_task_manager
|
||||
from shared.services.redis_task_manager import redis_task_manager
|
||||
await redis_task_manager.disconnect()
|
||||
print("[OK] Redis连接已断开")
|
||||
except Exception as e:
|
||||
@@ -154,27 +154,16 @@ app.include_router(auth_router)
|
||||
app.include_router(inventory_router)
|
||||
app.include_router(aluminum_price_router, prefix="/api")
|
||||
try:
|
||||
from api.v1 import router as moldinsight_router
|
||||
except Exception as e:
|
||||
moldinsight_router = None
|
||||
print(f"[WARN] MoldInsight v1路由未加载: {e}")
|
||||
|
||||
if moldinsight_router is None:
|
||||
try:
|
||||
from api.routes import router as moldinsight_router
|
||||
print("[WARN] 已回退到旧版 MoldInsight 路由")
|
||||
except Exception as fallback_error:
|
||||
moldinsight_router = None
|
||||
print(f"[WARN] MoldInsight旧版路由也未加载: {fallback_error}")
|
||||
|
||||
if moldinsight_router is not None:
|
||||
from moldinsight.api import router as moldinsight_router
|
||||
app.include_router(moldinsight_router, prefix="/api")
|
||||
except Exception as e:
|
||||
print(f"[WARN] MoldInsight 路由未加载: {e}")
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
@app.post("/health")
|
||||
async def health():
|
||||
from database.database import db_manager
|
||||
from shared.database.database import db_manager
|
||||
from sqlalchemy import text
|
||||
db_ok = False
|
||||
db_error = None
|
||||
@@ -246,7 +235,7 @@ async def release():
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
from config.settings import settings
|
||||
from shared.config.settings import settings
|
||||
reload_enabled = os.getenv("UVICORN_RELOAD", "0").lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
print("启动 Gemold 模具制造管理系统 v4.0...")
|
||||
|
||||
Reference in New Issue
Block a user