39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, JSON, Date, ForeignKey
|
||
from sqlalchemy.sql import func
|
||
from pydantic import BaseModel, Field
|
||
from typing import Optional, Dict, Any
|
||
from datetime import date, datetime
|
||
from .database import Base
|
||
from .community import CommunityDB
|
||
|
||
class SettlementHistoryDB(Base):
|
||
"""结算历史记录表"""
|
||
__tablename__ = "settlement_history"
|
||
|
||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||
settle_date = Column(Date, nullable=False, index=True, comment="结算日期")
|
||
community_id = Column(Integer, ForeignKey("communities.id"), nullable=False, index=True, comment="小区ID")
|
||
community_name = Column(String(100), nullable=False, comment="小区名称")
|
||
settle_details = Column(JSON, nullable=False, comment="结算详情,JSON格式")
|
||
create_time = Column(DateTime(timezone=True), server_default=func.now(), comment="创建时间")
|
||
|
||
class Config:
|
||
orm_mode = True
|
||
|
||
# Pydantic 模型
|
||
class SettlementHistoryCreate(BaseModel):
|
||
settle_date: date
|
||
community_id: int
|
||
community_name: str
|
||
settle_details: Dict[str, Any]
|
||
|
||
class SettlementHistoryInfo(BaseModel):
|
||
id: int
|
||
settle_date: date
|
||
community_id: int
|
||
community_name: str
|
||
settle_details: Dict[str, Any]
|
||
create_time: datetime
|
||
|
||
class Config:
|
||
from_attributes = True |