27 lines
1.2 KiB
Python
27 lines
1.2 KiB
Python
|
|
"""会话模型。"""
|
|||
|
|
from sqlalchemy import Column, Integer, String, TIMESTAMP, func, Boolean
|
|||
|
|
from insurance.db.compat import db
|
|||
|
|
|
|||
|
|
|
|||
|
|
class ChatSession(db.Model):
|
|||
|
|
"""会话表。"""
|
|||
|
|
__tablename__ = "insurance_chat_sessions"
|
|||
|
|
|
|||
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|||
|
|
session_id = Column(String(128), unique=True, nullable=False, comment="本地会话 ID")
|
|||
|
|
user_id = Column(String(64), nullable=False, comment="用户 ID")
|
|||
|
|
name = Column(String(256), default="新会话", comment="会话名称")
|
|||
|
|
baodan_conversation_id = Column(String(128), nullable=True, comment="BaoDan 返回的 conversation_id,用于保持上下文")
|
|||
|
|
is_deleted = Column(Boolean, default=False, comment="是否已删除")
|
|||
|
|
created_at = Column(TIMESTAMP, server_default=func.now())
|
|||
|
|
updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
|
|||
|
|
|
|||
|
|
def to_dict(self):
|
|||
|
|
return {
|
|||
|
|
"id": self.session_id,
|
|||
|
|
"name": self.name,
|
|||
|
|
"baodan_conversation_id": self.baodan_conversation_id,
|
|||
|
|
"created_at": str(self.created_at) if self.created_at else None,
|
|||
|
|
"updated_at": str(self.updated_at) if self.updated_at else None,
|
|||
|
|
}
|