System Management: - System Settings page with 8 configurable parameters (admin only) - Audit Log page with filterable table (user, action, resource, date range) - Audit logging wired into auth, devices, users, alarms, reports API handlers - SystemSetting model + migration (002) Device Detail: - Dedicated /devices/:id page with 4 tabs (realtime, historical trends, alarm history, device info) - ECharts historical charts with granularity/time range selectors - Device name clickable in Devices and Monitoring tables → navigates to detail Email & Scheduling: - Email service with SMTP support (STARTTLS/SSL/plain) - Alarm email notification with professional HTML template - Report scheduler using APScheduler for cron-based auto-generation - Scheduled report task seeded (daily at 8am) UI Enhancements: - Dark mode toggle (persisted to localStorage, Ant Design darkAlgorithm) - Data comparison view in Analysis page (dual date range, side-by-side metrics) - i18n framework (i18next) with zh/en translations for menu and common UI - Language switcher in header (中文/English) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
import logging
|
|
from contextlib import asynccontextmanager
|
|
from typing import Optional
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.api.router import api_router
|
|
from app.api.v1.websocket import start_broadcast_task, stop_broadcast_task
|
|
from app.core.config import get_settings
|
|
from app.services.simulator import DataSimulator
|
|
from app.services.report_scheduler import start_scheduler, stop_scheduler
|
|
from app.collectors.manager import CollectorManager
|
|
|
|
settings = get_settings()
|
|
simulator = DataSimulator()
|
|
collector_manager: Optional[CollectorManager] = None
|
|
|
|
logger = logging.getLogger("app")
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
global collector_manager
|
|
if settings.USE_SIMULATOR:
|
|
logger.info("Starting in SIMULATOR mode")
|
|
await simulator.start()
|
|
else:
|
|
logger.info("Starting in COLLECTOR mode (real IoT devices)")
|
|
collector_manager = CollectorManager()
|
|
await collector_manager.start()
|
|
start_broadcast_task()
|
|
await start_scheduler()
|
|
yield
|
|
await stop_scheduler()
|
|
stop_broadcast_task()
|
|
if settings.USE_SIMULATOR:
|
|
await simulator.stop()
|
|
else:
|
|
if collector_manager:
|
|
await collector_manager.stop()
|
|
collector_manager = None
|
|
|
|
|
|
app = FastAPI(
|
|
title="天普零碳园区智慧能源管理平台",
|
|
description="Tianpu Zero-Carbon Park Smart Energy Management System",
|
|
version="1.0.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:3000", "http://localhost:5173", "http://127.0.0.1:3000", "http://127.0.0.1:5173"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(api_router)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health():
|
|
return {"status": "ok", "app": settings.APP_NAME}
|