33b4c734aa
后端: - 新增认证(auth)、任务(tasks)、映射(mappings)、对账(reconciliation)、异常(exceptions)、导出(exports) API - 新增核心模块: database, security, permissions, tenant, exceptions, error_handlers - 新增数据模型: user, company, reconciliation_task, field_mapping, uploaded_file 等 - 新增服务层: ai_recognizer, file_parser, file_storage, mapping, reconciliation 等 - 添加数据库迁移脚本 前端: - 新增登录页面和仪表盘页面 - 新增任务列表、任务详情、字段映射页面 - 新增异常处理页面和规则设置页面 - 新增 API 代理路由 /api/[...path] - 新增 UI 组件库 (button, card, dialog, input, table 等) - 新增 auth 组件 (ProtectedRoute, PermissionGate) - 新增 layout 组件 (Header, Sidebar) - 新增 mapping 组件 (FieldMappingTable, AISuggestionPanel) - 新增 API 客户端和 hooks (useAsync, useToast, usePermission 等) - 新增状态管理 (auth-store, company-store, ui-store) - 集成 Tailwind CSS 和 shadcn/ui 组件库 其他: - 添加 Alembic 数据库迁移配置 - 添加初始化示例数据脚本 - 更新项目文档
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
from enum import Enum
|
|
|
|
from sqlalchemy import Boolean, Integer, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import BaseModel
|
|
|
|
|
|
class CompanyPlan(str, Enum):
|
|
"""企业套餐类型"""
|
|
FREE = "免费版"
|
|
BASIC = "基础版"
|
|
PROFESSIONAL = "专业版"
|
|
ENTERPRISE = "企业版"
|
|
|
|
|
|
class CompanyStatus(str, Enum):
|
|
"""企业状态"""
|
|
ACTIVE = "正常"
|
|
SUSPENDED = "暂停"
|
|
EXPIRED = "已过期"
|
|
DELETED = "已删除"
|
|
|
|
|
|
class Company(BaseModel):
|
|
"""
|
|
企业模型 - 多租户隔离的核心实体
|
|
|
|
Attributes:
|
|
name: 企业名称
|
|
plan: 套餐类型
|
|
data_retention_months: 数据保留月数
|
|
status: 企业状态
|
|
max_users: 最大用户数
|
|
is_trial: 是否试用
|
|
"""
|
|
|
|
__tablename__ = "companies"
|
|
|
|
name: Mapped[str] = mapped_column(String(200), nullable=False, index=True)
|
|
plan: Mapped[str] = mapped_column(
|
|
String(50),
|
|
nullable=False,
|
|
default=CompanyPlan.FREE.value
|
|
)
|
|
data_retention_months: Mapped[int] = mapped_column(Integer, nullable=False, default=12)
|
|
status: Mapped[str] = mapped_column(
|
|
String(20),
|
|
nullable=False,
|
|
default=CompanyStatus.ACTIVE.value,
|
|
index=True,
|
|
)
|
|
max_users: Mapped[int] = mapped_column(Integer, nullable=False, default=5)
|
|
is_trial: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
|
|
|
# 关系
|
|
users = relationship("User", back_populates="company")
|
|
field_mappings = relationship("FieldMapping", back_populates="company")
|
|
rules = relationship("CompanyRule", back_populates="company")
|
|
tasks = relationship("ReconciliationTask", back_populates="company")
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Company(id={self.id}, name='{self.name}', plan='{self.plan}')>" |