from typing import Optional from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, DECIMAL from sqlalchemy.sql import func from pydantic import BaseModel, Field from .database import Base # 数据库模型 class StationDB(Base): __tablename__ = "stations" id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String(50), nullable=False) service_text = Column(String(50), nullable=False, server_default="服务时间:8:30~20:30") community_id = Column(Integer, ForeignKey("communities.id"), index=True) create_time = Column(DateTime(timezone=True), server_default=func.now()) update_time = Column(DateTime(timezone=True), onupdate=func.now()) # Pydantic 模型 class StationCreate(BaseModel): name: str = Field(..., max_length=100) community_id: int class StationUpdate(BaseModel): name: Optional[str] = Field(None, max_length=100) community_id: Optional[int] = None class StationInfo(BaseModel): id: int name: str community_id: int community_name: Optional[str] = None service_text: str class Config: from_attributes = True