chore: initial baseline with P0-safety .gitignore
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
# =============================================================================
|
||||
# 企微IT智能服务台 — 坐席备注模型
|
||||
# =============================================================================
|
||||
# 说明:对应数据库 agent_notes 表,存储坐席对会话的备注
|
||||
# 用途:坐席可以记录处理过程中的关键信息,方便后续跟进
|
||||
# 一个会话可以有多条备注(不同坐席或同一坐席多次记录)
|
||||
# =============================================================================
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, Index, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class AgentNote(Base):
|
||||
"""坐席备注模型 — 对应 agent_notes 表。
|
||||
|
||||
记录坐席在处理会话时添加的备注信息。
|
||||
一个会话可以有多条备注。
|
||||
|
||||
Attributes:
|
||||
id: 备注唯一标识(UUID,数据库自动生成)
|
||||
conversation_id: 所属会话ID(外键,关联 conversations 表)
|
||||
agent_id: 坐席ID
|
||||
content: 备注内容
|
||||
created_at: 创建时间
|
||||
updated_at: 更新时间
|
||||
"""
|
||||
|
||||
# 表名(必须和架构文档 DDL 一致)
|
||||
__tablename__ = "agent_notes"
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# 字段定义
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
# 主键:UUID,Python端生成(兼容PostgreSQL和SQLite)
|
||||
id: Mapped[str] = mapped_column(
|
||||
String(36),
|
||||
primary_key=True,
|
||||
default=lambda: str(uuid.uuid4()),
|
||||
)
|
||||
|
||||
# 所属会话ID(外键,关联 conversations 表)
|
||||
# ON DELETE CASCADE:删除会话时自动删除该会话的所有备注
|
||||
conversation_id: Mapped[str] = mapped_column(
|
||||
String(36),
|
||||
ForeignKey("conversations.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
comment="所属会话ID",
|
||||
)
|
||||
|
||||
# 坐席ID(记录是哪个坐席写的备注)
|
||||
agent_id: Mapped[str] = mapped_column(
|
||||
String(64),
|
||||
nullable=False,
|
||||
comment="坐席ID",
|
||||
)
|
||||
|
||||
# 备注内容(坐席自由输入的文本)
|
||||
content: Mapped[str] = mapped_column(
|
||||
Text,
|
||||
nullable=False,
|
||||
comment="备注内容",
|
||||
)
|
||||
|
||||
# 创建时间
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=False,
|
||||
default=datetime.now,
|
||||
comment="创建时间",
|
||||
)
|
||||
|
||||
# 更新时间
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=False,
|
||||
default=datetime.now,
|
||||
onupdate=datetime.now,
|
||||
comment="更新时间",
|
||||
)
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# 索引定义(和架构文档 DDL 严格一致)
|
||||
# --------------------------------------------------------------------------
|
||||
__table_args__ = (
|
||||
# 按会话ID查询(如获取某会话的所有备注)
|
||||
Index("idx_an_conversation", "conversation_id"),
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""备注对象的字符串表示,方便调试。"""
|
||||
return (
|
||||
f"<AgentNote(id={self.id}, conv={self.conversation_id}, "
|
||||
f"agent={self.agent_id})>"
|
||||
)
|
||||
Reference in New Issue
Block a user