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:
51
backend/app/models/device.py
Normal file
51
backend/app/models/device.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime, ForeignKey, Text, JSON
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class DeviceType(Base):
|
||||
__tablename__ = "device_types"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
code = Column(String(50), unique=True, nullable=False) # pv_inverter, heat_pump, solar_thermal, battery, meter, sensor
|
||||
name = Column(String(100), nullable=False)
|
||||
icon = Column(String(100))
|
||||
data_fields = Column(JSON) # 该类型设备的数据字段定义
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
class DeviceGroup(Base):
|
||||
__tablename__ = "device_groups"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
parent_id = Column(Integer, ForeignKey("device_groups.id"))
|
||||
location = Column(String(200))
|
||||
description = Column(Text)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
class Device(Base):
|
||||
__tablename__ = "devices"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
code = Column(String(100), unique=True, nullable=False) # 设备编号
|
||||
device_type = Column(String(50), ForeignKey("device_types.code"), nullable=False)
|
||||
group_id = Column(Integer, ForeignKey("device_groups.id"))
|
||||
model = Column(String(100)) # 型号
|
||||
manufacturer = Column(String(100)) # 厂商
|
||||
serial_number = Column(String(100)) # 序列号
|
||||
rated_power = Column(Float) # 额定功率 kW
|
||||
install_date = Column(DateTime(timezone=True))
|
||||
location = Column(String(200))
|
||||
protocol = Column(String(50)) # modbus_tcp, modbus_rtu, opc_ua, mqtt, http_api
|
||||
connection_params = Column(JSON) # 连接参数 (IP, port, slave_id, etc.)
|
||||
collect_interval = Column(Integer, default=15) # 采集间隔(秒)
|
||||
category_id = Column(Integer, ForeignKey("energy_categories.id")) # 分项类别
|
||||
status = Column(String(20), default="offline") # online, offline, alarm, maintenance
|
||||
is_active = Column(Boolean, default=True)
|
||||
metadata_ = Column("metadata", JSON) # 扩展元数据
|
||||
last_data_time = Column(DateTime(timezone=True))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
Reference in New Issue
Block a user