2025-10-30 11:14:43 +08:00
|
|
|
"""角色数据模型"""
|
2025-12-22 19:53:31 +08:00
|
|
|
from sqlalchemy import Column, String, Text, DateTime, ForeignKey, Boolean, Integer
|
2025-10-30 11:14:43 +08:00
|
|
|
from sqlalchemy.sql import func
|
|
|
|
|
from app.database import Base
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Character(Base):
|
|
|
|
|
"""角色表(包括角色和组织)"""
|
|
|
|
|
__tablename__ = "characters"
|
|
|
|
|
|
|
|
|
|
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
|
|
|
project_id = Column(String(36), ForeignKey("projects.id", ondelete="CASCADE"), nullable=False)
|
|
|
|
|
|
|
|
|
|
# 基本信息
|
|
|
|
|
name = Column(String(100), nullable=False, comment="角色/组织名称")
|
2025-11-10 21:16:55 +08:00
|
|
|
age = Column(String(50), comment="年龄")
|
|
|
|
|
gender = Column(String(50), comment="性别")
|
2025-10-30 11:14:43 +08:00
|
|
|
is_organization = Column(Boolean, default=False, comment="是否为组织")
|
|
|
|
|
|
|
|
|
|
# 角色类型:protagonist(主角)/supporting(配角)/antagonist(反派)
|
|
|
|
|
role_type = Column(String(50), comment="角色类型")
|
|
|
|
|
|
|
|
|
|
# 角色详细信息
|
|
|
|
|
personality = Column(Text, comment="性格特点/组织特性")
|
|
|
|
|
background = Column(Text, comment="背景故事")
|
|
|
|
|
appearance = Column(Text, comment="外貌描述")
|
|
|
|
|
relationships = Column(Text, comment="人物关系(JSON)")
|
|
|
|
|
|
|
|
|
|
# 组织特有字段
|
|
|
|
|
organization_type = Column(String(100), comment="组织类型")
|
|
|
|
|
organization_purpose = Column(String(500), comment="组织目的")
|
|
|
|
|
organization_members = Column(Text, comment="组织成员(JSON)")
|
|
|
|
|
|
2026-02-12 12:38:52 +08:00
|
|
|
# 角色/组织存活状态
|
|
|
|
|
status = Column(String(20), default="active", comment="状态:active/deceased/missing/retired/destroyed")
|
|
|
|
|
status_changed_chapter = Column(Integer, comment="状态变更的章节号")
|
|
|
|
|
|
|
|
|
|
# 心理状态追踪(由章节分析自动更新)
|
|
|
|
|
current_state = Column(Text, comment="角色当前心理状态(由分析自动更新)")
|
|
|
|
|
state_updated_chapter = Column(Integer, comment="心理状态最后更新的章节号")
|
|
|
|
|
|
2025-12-22 19:53:31 +08:00
|
|
|
# 职业相关字段(冗余字段,用于提升查询性能)
|
|
|
|
|
main_career_id = Column(String(36), ForeignKey("careers.id", ondelete="SET NULL"), comment="主职业ID")
|
|
|
|
|
main_career_stage = Column(Integer, comment="主职业当前阶段")
|
|
|
|
|
sub_careers = Column(Text, comment="副职业列表(JSON): [{\"career_id\": \"xxx\", \"stage\": 3}, ...]")
|
|
|
|
|
|
2025-10-30 11:14:43 +08:00
|
|
|
# 其他
|
|
|
|
|
avatar_url = Column(String(500), comment="头像URL")
|
|
|
|
|
traits = Column(Text, comment="特征标签(JSON)")
|
|
|
|
|
|
|
|
|
|
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
|
|
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
entity_type = "组织" if self.is_organization else "角色"
|
|
|
|
|
return f"<Character(id={self.id}, name={self.name}, type={entity_type})>"
|