Files
aiagent/backend/app/models/company.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

102 lines
4.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
虚拟公司模型 — Company + CompanyProject
公司 = 多个部门(Team) + CEO 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 Company(Base):
"""虚拟公司表"""
__tablename__ = "companies"
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="公司描述")
industry = Column(String(50), nullable=True, comment="行业类型: tech-software/ecommerce-retail/consulting-service/manufacturing/media-marketing")
workspace_id = Column(CHAR(36), ForeignKey("workspaces.id"), nullable=True, comment="所属工作区ID")
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=False, comment="创建者ID")
ceo_agent_id = Column(CHAR(36), ForeignKey("agents.id"), nullable=True, comment="CEO Agent ID")
config = Column(JSON, nullable=True, comment="公司配置(部门结构、协作模式等)")
status = Column(String(20), default="active", comment="状态: active/archived")
created_at = Column(DateTime, default=func.now(), comment="创建时间")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")
__table_args__ = (
Index("idx_company_workspace", "workspace_id"),
Index("idx_company_user_id", "user_id"),
)
departments = relationship("Team", back_populates="company", cascade="all, delete-orphan",
primaryjoin="Company.id==Team.parent_company_id")
user = relationship("User", backref="companies")
ceo_agent = relationship("Agent", foreign_keys=[ceo_agent_id])
def __repr__(self):
return f"<Company(id={self.id}, name={self.name})>"
def to_dict(self, include_departments=False):
result = {
"id": self.id,
"name": self.name,
"description": self.description,
"industry": self.industry,
"workspace_id": self.workspace_id,
"user_id": self.user_id,
"ceo_agent_id": self.ceo_agent_id,
"config": self.config,
"status": self.status,
"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_departments and self.departments:
result["departments"] = [d.to_dict(include_members=True) for d in self.departments]
return result
class CompanyProject(Base):
"""公司级项目表"""
__tablename__ = "company_projects"
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="项目ID")
company_id = Column(CHAR(36), ForeignKey("companies.id"), nullable=False, comment="所属公司ID")
name = Column(String(200), nullable=False, comment="项目名称")
description = Column(Text, comment="项目描述(CEO级目标)")
ceo_plan = Column(JSON, nullable=True, comment="CEO 规划结果(DepartmentPlan[])")
review_scores = Column(JSON, nullable=True, comment="CEO审查打分结果")
round_count = Column(String(10), nullable=True, default="1", comment="执行迭代轮次数")
status = Column(String(30), default="created", comment="状态: created/planning/in_progress/completed/failed")
config = Column(JSON, nullable=True, comment="项目配置(含 is_public 标记)")
created_at = Column(DateTime, default=func.now(), comment="创建时间")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")
completed_at = Column(DateTime, nullable=True, comment="完成时间")
__table_args__ = (
Index("idx_cp_company_id", "company_id"),
)
company = relationship("Company", backref="projects")
def __repr__(self):
return f"<CompanyProject(id={self.id}, name={self.name})>"
def to_dict(self):
return {
"id": self.id,
"company_id": self.company_id,
"name": self.name,
"description": self.description,
"ceo_plan": self.ceo_plan,
"review_scores": self.review_scores,
"round_count": self.round_count,
"status": self.status,
"config": self.config,
"created_at": self.created_at.isoformat() if self.created_at else None,
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
"completed_at": self.completed_at.isoformat() if self.completed_at else None,
}