34 lines
1.6 KiB
Python
34 lines
1.6 KiB
Python
from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime, ForeignKey, JSON
|
|
from sqlalchemy.sql import func
|
|
from app.core.database import Base
|
|
|
|
|
|
class ElectricityPricing(Base):
|
|
"""电价配置"""
|
|
__tablename__ = "electricity_pricing"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
name = Column(String(200), nullable=False)
|
|
energy_type = Column(String(50), default="electricity") # electricity, heat, water, gas
|
|
pricing_type = Column(String(20), nullable=False) # flat, tou, tiered
|
|
effective_from = Column(DateTime(timezone=True))
|
|
effective_to = Column(DateTime(timezone=True))
|
|
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 PricingPeriod(Base):
|
|
"""分时电价时段"""
|
|
__tablename__ = "pricing_periods"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
pricing_id = Column(Integer, ForeignKey("electricity_pricing.id"), nullable=False)
|
|
period_name = Column(String(50), nullable=False) # peak, valley, flat, shoulder, sharp
|
|
start_time = Column(String(10), nullable=False) # HH:MM format
|
|
end_time = Column(String(10), nullable=False) # HH:MM format
|
|
price_per_unit = Column(Float, nullable=False) # yuan per kWh
|
|
applicable_months = Column(JSON) # [1,2,3,...12] or null for all months
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|