ems-core v1.0.0: Standard EMS platform core
Shared backend + frontend for multi-customer EMS deployments. - 12 enterprise modules: quota, cost, charging, maintenance, analysis, etc. - 120+ API endpoints, 37 database tables - Customer config mechanism (CUSTOMER env var + YAML config) - Collectors: Modbus TCP, MQTT, HTTP API, Sungrow iSolarCloud - Frontend: React 19 + Ant Design + ECharts + Three.js - Infrastructure: Redis cache, rate limiting, aggregation engine Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
38
backend/app/models/quota.py
Normal file
38
backend/app/models/quota.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime, ForeignKey
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class EnergyQuota(Base):
|
||||
"""能源配额管理"""
|
||||
__tablename__ = "energy_quotas"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name = Column(String(200), nullable=False)
|
||||
target_type = Column(String(50), nullable=False) # building, department, device_group
|
||||
target_id = Column(Integer, nullable=False) # FK to device_groups.id
|
||||
energy_type = Column(String(50), nullable=False) # electricity, heat, water, gas
|
||||
period = Column(String(20), nullable=False) # monthly, yearly
|
||||
quota_value = Column(Float, nullable=False) # 目标消耗值
|
||||
unit = Column(String(20), default="kWh")
|
||||
warning_threshold_pct = Column(Float, default=80) # 80%预警
|
||||
alert_threshold_pct = Column(Float, default=95) # 95%告警
|
||||
is_active = Column(Boolean, default=True)
|
||||
created_by = Column(Integer, ForeignKey("users.id"))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
|
||||
class QuotaUsage(Base):
|
||||
"""配额使用记录"""
|
||||
__tablename__ = "quota_usage"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
quota_id = Column(Integer, ForeignKey("energy_quotas.id"), nullable=False)
|
||||
period_start = Column(DateTime(timezone=True), nullable=False)
|
||||
period_end = Column(DateTime(timezone=True), nullable=False)
|
||||
actual_value = Column(Float, default=0)
|
||||
quota_value = Column(Float, nullable=False)
|
||||
usage_rate_pct = Column(Float, default=0)
|
||||
status = Column(String(20), default="normal") # normal, warning, exceeded
|
||||
calculated_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
Reference in New Issue
Block a user