Files
aiagent/backend/app/models/team.py
renjianbo f2e65a8fbb feat: virtual company module, team projects, PWA dishes app, and startup scripts overhaul
- Add company module (3-tier org, CEO planning, parallel departments)
- Add company orchestrator, knowledge extractor, presets, scheduler
- Add company API endpoints, models, and frontend views
- Add 今天吃啥 PWA app (69 dishes, real images, offline support)
- Add team_projects output directory structure
- Add unified manage.ps1 for service lifecycle
- Add Windows startup guide v1.0
- Add TTS troubleshooting doc
- Update frontend (AgentChat UX overhaul, new views)
- Update backend (voice engine fix, multi-tenant, RBAC)
- Remove deprecated startup scripts and old docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 22:37:56 +08:00

95 lines
4.2 KiB
Python

"""
虚拟团队模型 — Team + TeamMember
用于将多个 Agent 组织为角色化的虚拟软件团队
"""
from sqlalchemy import Column, String, Text, Integer, DateTime, JSON, ForeignKey, Boolean, Index, func
from sqlalchemy.dialects.mysql import CHAR
from sqlalchemy.orm import relationship
from app.core.database import Base
import uuid
class Team(Base):
"""虚拟团队表(兼作虚拟公司的部门)"""
__tablename__ = "teams"
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="团队ID")
name = Column(String(100), nullable=False, comment="团队名称")
description = Column(Text, comment="团队描述")
workspace_id = Column(CHAR(36), ForeignKey("workspaces.id"), nullable=True, comment="所属工作区ID")
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=False, comment="创建者ID")
is_template = Column(Boolean, default=False, comment="是否为预置模板")
config = Column(JSON, nullable=True, comment="团队配置(协作模式等)")
status = Column(String(20), default="active", comment="状态: active/inactive")
# 虚拟公司扩展字段
department_type = Column(String(30), nullable=True, comment="部门类型: executive/product/engineering/marketing/operations/sales/finance/hr")
parent_company_id = Column(CHAR(36), ForeignKey("companies.id"), nullable=True, comment="所属公司ID")
created_at = Column(DateTime, default=func.now(), comment="创建时间")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")
__table_args__ = (
Index("idx_team_workspace", "workspace_id"),
Index("idx_team_user_id", "user_id"),
)
members = relationship("TeamMember", back_populates="team", cascade="all, delete-orphan")
user = relationship("User", backref="teams")
company = relationship("Company", back_populates="departments", foreign_keys=[parent_company_id])
def __repr__(self):
return f"<Team(id={self.id}, name={self.name})>"
def to_dict(self, include_members=False):
result = {
"id": self.id,
"name": self.name,
"description": self.description,
"workspace_id": self.workspace_id,
"user_id": self.user_id,
"is_template": self.is_template,
"config": self.config,
"status": self.status,
"department_type": self.department_type,
"parent_company_id": self.parent_company_id,
"created_at": self.created_at.isoformat() if self.created_at else None,
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
}
if include_members:
result["members"] = [m.to_dict() for m in self.members] if self.members else []
return result
class TeamMember(Base):
"""团队成员表 — Agent 在团队中的角色映射"""
__tablename__ = "team_members"
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="成员ID")
team_id = Column(CHAR(36), ForeignKey("teams.id"), nullable=False, comment="团队ID")
agent_id = Column(CHAR(36), ForeignKey("agents.id"), nullable=False, comment="Agent ID")
role = Column(String(30), nullable=False, comment="角色: pm/developer/qa/designer/devops/custom")
position = Column(Integer, default=0, comment="排序位置")
is_lead = Column(Boolean, default=False, comment="是否为团队Leader")
created_at = Column(DateTime, default=func.now(), comment="创建时间")
__table_args__ = (
Index("idx_tm_team_id", "team_id"),
Index("idx_tm_agent_id", "agent_id"),
)
team = relationship("Team", back_populates="members")
agent = relationship("Agent", backref="team_memberships")
def __repr__(self):
return f"<TeamMember(team={self.team_id}, agent={self.agent_id}, role={self.role})>"
def to_dict(self):
return {
"id": self.id,
"team_id": self.team_id,
"agent_id": self.agent_id,
"role": self.role,
"position": self.position,
"is_lead": self.is_lead,
"created_at": self.created_at.isoformat() if self.created_at else None,
}