Files
group_fqcd_jr/app/model/episode.py
T

42 lines
2.2 KiB
Python
Raw Normal View History

from datetime import datetime
from typing import Any
from sqlalchemy import JSON, DateTime, Integer, String, Text
from sqlalchemy.dialects.mysql import BIGINT, TINYINT
from sqlalchemy.orm import Mapped, mapped_column
from app.model.base import Base
class Episode(Base):
"""会话片段(`episodes`);列与库中实际结构逐列一致。
列名与类型按 `information_schema.COLUMNS` 核对(18 列,无生成列),
同名兄弟模型如 `ConversationMessage.handler_id` 既有用法同样使用
`BIGINT(unsigned=True)`,因此无符号列在此保持一致的映射风格。
唯一键 `episode_uuid`、`content_hash` 由数据库维护:抽取幂等依赖
`content_hash` 唯一键,跨存储稳定标识依赖 `episode_uuid`。
"""
__tablename__ = "episodes"
id: Mapped[int] = mapped_column(BIGINT(unsigned=True), primary_key=True, autoincrement=True)
episode_uuid: Mapped[str | None] = mapped_column(String(36), unique=True)
customer_id: Mapped[int] = mapped_column(BIGINT(unsigned=True), nullable=False)
session_id: Mapped[str] = mapped_column(String(64), nullable=False)
start_message_no: Mapped[int | None] = mapped_column(Integer)
end_message_no: Mapped[int | None] = mapped_column(Integer)
portals_involved: Mapped[list[Any]] = mapped_column(JSON, nullable=False)
summary: Mapped[str] = mapped_column(Text, nullable=False)
extraction_status: Mapped[str] = mapped_column(String(16), nullable=False, default="待提取")
content_hash: Mapped[str | None] = mapped_column(String(64), unique=True)
retry_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
started_at: Mapped[datetime | None] = mapped_column(DateTime)
ended_at: Mapped[datetime | None] = mapped_column(DateTime)
handoff_to_employee_id: Mapped[int | None] = mapped_column(BIGINT(unsigned=True))
start_at: Mapped[datetime | None] = mapped_column(DateTime)
end_at: Mapped[datetime | None] = mapped_column(DateTime)
promoted_to_ltm: Mapped[bool] = mapped_column(
TINYINT(display_width=1), nullable=False, default=False
)
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)