Files
video-gen/video-gen-api/app/models/bank_transaction.py
T
2026-08-14 15:59:47 +08:00

56 lines
2.6 KiB
Python

"""银行交易流水模型。"""
from datetime import datetime, timezone
from sqlalchemy import Boolean, DateTime, Index, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class BankTransaction(Base):
__tablename__ = "bank_transactions"
id: Mapped[str] = mapped_column(String(32), primary_key=True)
# 账户信息
account_id: Mapped[str] = mapped_column(String(32), index=True, nullable=False, comment="银行账户ID")
account_no: Mapped[str] = mapped_column(String(64), index=True, nullable=False, comment="银行账号")
# 记录创建时间
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
default=lambda: datetime.now(timezone.utc),
nullable=False,
comment="记录创建时间",
)
# 交易信息
transaction_no: Mapped[str | None] = mapped_column(String(128), unique=True, nullable=True, comment="交易流水号(唯一)")
transaction_time: Mapped[DateTime | None] = mapped_column(DateTime(timezone=True), index=True, nullable=True, comment="交易时间")
transaction_amount: Mapped[str] = mapped_column(String(32), nullable=False, comment="交易金额(字符串保持精度)")
balance_direction: Mapped[str | None] = mapped_column(String(8), nullable=True, comment="借贷方向: DR-借/出金, CR-贷/入金")
balance_after: Mapped[str | None] = mapped_column(String(32), nullable=True, comment="交易后余额")
# 对方信息
counterparty_name: Mapped[str | None] = mapped_column(String(128), nullable=True, comment="对方户名")
counterparty_account: Mapped[str | None] = mapped_column(String(64), nullable=True, comment="对方账号")
counterparty_bank: Mapped[str | None] = mapped_column(String(128), nullable=True, comment="对方开户行")
# 交易摘要
remark: Mapped[str | None] = mapped_column(Text, nullable=True, comment="摘要/备注")
digest_code: Mapped[str | None] = mapped_column(String(64), nullable=True, comment="摘要码")
purpose: Mapped[str | None] = mapped_column(String(256), nullable=True, comment="用途")
# 原始数据
raw_data: Mapped[str | None] = mapped_column(Text, nullable=True, comment="接口返回原始JSON")
# 同步信息
sync_batch: Mapped[str | None] = mapped_column(String(32), index=True, nullable=True, comment="同步批次号")
is_synced: Mapped[bool] = mapped_column(Boolean, default=True, comment="是否同步成功")
__table_args__ = (
Index("ix_bank_transactions_account_time", "account_no", "transaction_time"),
Index("ix_bank_transactions_sync_batch", "sync_batch"),
)