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 数据库迁移配置 - 添加初始化示例数据脚本 - 更新项目文档
57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
"""
|
|
企业规则模型
|
|
|
|
用于存储企业自定义的映射规则,实现规则复用
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import ForeignKey, Integer, String, Boolean, DateTime, JSON
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import BaseModel
|
|
|
|
|
|
class RuleType(str, Enum):
|
|
"""规则类型"""
|
|
FIELD_MAPPING = "FIELD_MAPPING" # 字段映射规则
|
|
ACCOUNT_MAPPING = "ACCOUNT_MAPPING" # 科目映射规则
|
|
DEPARTMENT_MAPPING = "DEPARTMENT_MAPPING" # 部门映射规则
|
|
|
|
|
|
class RuleStatus(str, Enum):
|
|
"""规则状态"""
|
|
ACTIVE = "ACTIVE" # 启用
|
|
INACTIVE = "INACTIVE" # 停用
|
|
|
|
|
|
class CompanyRule(BaseModel):
|
|
"""
|
|
企业规则模型
|
|
|
|
存储企业自定义的业务规则,用于自动应用
|
|
"""
|
|
|
|
__tablename__ = "company_rules"
|
|
|
|
company_id: Mapped[int] = mapped_column(Integer, ForeignKey("companies.id"), nullable=False, index=True)
|
|
rule_type: Mapped[str] = mapped_column(String(50), nullable=False, index=True, comment="规则类型")
|
|
match_condition: Mapped[dict] = mapped_column(JSON, nullable=False, comment="匹配条件")
|
|
target_value: Mapped[str] = mapped_column(String(100), nullable=False, comment="目标值")
|
|
priority: Mapped[int] = mapped_column(Integer, nullable=False, default=0, comment="优先级,数字越大优先级越高")
|
|
status: Mapped[str] = mapped_column(String(20), nullable=False, default=RuleStatus.ACTIVE.value, comment="状态")
|
|
description: Mapped[Optional[str]] = mapped_column(String(500), nullable=True, comment="规则描述")
|
|
match_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0, comment="匹配次数")
|
|
last_used_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
|
created_by: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True)
|
|
updated_by: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True)
|
|
|
|
# 关系
|
|
company = relationship("Company", back_populates="rules")
|
|
creator = relationship("User", foreign_keys=[created_by])
|
|
updater = relationship("User", foreign_keys=[updated_by])
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<CompanyRule(type='{self.rule_type}', target='{self.target_value}', priority={self.priority})>" |