Full-stack energy management system for Tianpu Daxing campus. - Frontend: React 19 + TypeScript + Ant Design + ECharts - Backend: FastAPI + SQLAlchemy + PostgreSQL/TimescaleDB - Features: PV monitoring, heat pump management, carbon tracking, alarms, reports Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
39 lines
1.8 KiB
Python
39 lines
1.8 KiB
Python
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, Text, JSON
|
|
from sqlalchemy.sql import func
|
|
from app.core.database import Base
|
|
|
|
|
|
class ReportTemplate(Base):
|
|
__tablename__ = "report_templates"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
name = Column(String(100), nullable=False)
|
|
report_type = Column(String(50), nullable=False) # daily, weekly, monthly, yearly, custom
|
|
description = Column(Text)
|
|
fields = Column(JSON, nullable=False) # 报表字段配置
|
|
filters = Column(JSON) # 默认筛选条件
|
|
aggregation = Column(String(20), default="sum") # sum, avg, max, min
|
|
time_granularity = Column(String(20), default="hour") # hour, day, month
|
|
format_config = Column(JSON) # 展示格式配置
|
|
is_system = Column(Boolean, default=False) # 系统预置
|
|
created_by = Column(Integer, ForeignKey("users.id"))
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
|
class ReportTask(Base):
|
|
__tablename__ = "report_tasks"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
template_id = Column(Integer, ForeignKey("report_templates.id"), nullable=False)
|
|
name = Column(String(200))
|
|
schedule = Column(String(50)) # cron expression or null for manual
|
|
next_run = Column(DateTime(timezone=True))
|
|
last_run = Column(DateTime(timezone=True))
|
|
recipients = Column(JSON) # 接收人
|
|
export_format = Column(String(20), default="xlsx") # xlsx, csv, pdf
|
|
file_path = Column(String(500)) # 最新生成的文件路径
|
|
status = Column(String(20), default="pending") # pending, running, completed, failed
|
|
is_active = Column(Boolean, default=True)
|
|
created_by = Column(Integer, ForeignKey("users.id"))
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|