feat(ai_agent): 新增openclaw_hermes混合AI适配器 新增OpenClawHermesAdapter适配器,结合Hermes记忆功能和OpenClaw执行能力, 实现AI问答流程中的记忆召回、执行操作和记忆存储的完整闭环。 同时更新NoopAdapter提示信息,添加新的模型提供商选项。 feat(business): 新增考勤、工作报告和风险事件业务模型 新增AttendanceRecord、WorkReport、RiskEvent和LegacySyncRun四个业务模型, 扩展业务领域注册表,支持考勤管理、工作报告生成和风险事件跟踪等核心业务功能。 feat(reports): 实现考勤汇总和工作日报周报生成功能 新增attendance_summary方法用于统计每日考勤情况, 新增generate_work_report方法用于生成日/周经营报告, 包含任务完成情况、待处理事项和风险指标等综合信息。 feat(risk): 扩展风险管理API端点和供应商风险检测 新增供应商风险查询端点和风险事件管理端点, 提供风险事件列表查询和自动生成功能, 增强供应商风险评估能力。 feat(feishu): 添加考勤查询命令和风险摘要增强 集成考勤汇总查询功能到飞书命令系统, 在风险摘要中添加供应商风险和开放风险事件统计, 丰富日常经营管理信息展示。 refactor(service): 优化业务服务数据验证和类型转换 重构_model_payload函数实现数据验证和类型转换, 添加列值类型强制转换逻辑,提高API数据处理的准确性和安全性。 build(deps): 添加postgresql数据库驱动依赖 在Dockerfile中添加psycopg[binary]==3.2.3依赖包, 支持PostgreSQL数据库连接和操作。 chore(config): 更新.gitignore文件排除备份和迁移目录 在.gitignore中添加AGENTS.md.bak-*和migration/目录排除规则, 避免备份文件和本地迁移工作区被提交到版本控制系统。 ```
235 lines
13 KiB
Python
235 lines
13 KiB
Python
from datetime import date, datetime
|
|
from decimal import Decimal
|
|
|
|
from sqlalchemy import JSON, Date, DateTime, Integer, Numeric, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class TimestampMixin:
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
|
|
)
|
|
|
|
|
|
class Project(Base, TimestampMixin):
|
|
__tablename__ = "projects"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(255), index=True)
|
|
owner: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
status: Mapped[str] = mapped_column(String(64), default="立项", index=True)
|
|
priority: Mapped[str] = mapped_column(String(32), default="P2")
|
|
progress_percent: Mapped[int] = mapped_column(Integer, default=0)
|
|
risk_level: Mapped[str] = mapped_column(String(32), default="low", index=True)
|
|
budget_amount: Mapped[Decimal] = mapped_column(Numeric(14, 2), default=0)
|
|
actual_amount: Mapped[Decimal] = mapped_column(Numeric(14, 2), default=0)
|
|
start_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
|
due_date: Mapped[date | None] = mapped_column(Date, nullable=True, index=True)
|
|
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
source_system: Mapped[str] = mapped_column(String(64), default="internal")
|
|
external_id: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
|
|
|
|
class WorkTask(Base, TimestampMixin):
|
|
__tablename__ = "work_tasks"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
title: Mapped[str] = mapped_column(String(255), index=True)
|
|
project_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
|
owner: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
status: Mapped[str] = mapped_column(String(64), default="待办", index=True)
|
|
priority: Mapped[str] = mapped_column(String(32), default="P2")
|
|
due_date: Mapped[date | None] = mapped_column(Date, nullable=True, index=True)
|
|
completed_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
blocker: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
|
|
class Procurement(Base, TimestampMixin):
|
|
__tablename__ = "procurements"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(255), index=True)
|
|
applicant: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
project_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
|
supplier_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
budget_subject: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
expected_amount: Mapped[Decimal] = mapped_column(Numeric(14, 2), default=0)
|
|
actual_amount: Mapped[Decimal] = mapped_column(Numeric(14, 2), default=0)
|
|
approval_status: Mapped[str] = mapped_column(String(64), default="草稿", index=True)
|
|
delivery_status: Mapped[str] = mapped_column(String(64), default="未到货", index=True)
|
|
payment_status: Mapped[str] = mapped_column(String(64), default="未付款", index=True)
|
|
comparison_summary: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
|
|
class Expense(Base, TimestampMixin):
|
|
__tablename__ = "expenses"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
expense_type: Mapped[str] = mapped_column(String(128), index=True)
|
|
amount: Mapped[Decimal] = mapped_column(Numeric(14, 2), default=0)
|
|
applicant: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
department: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
project_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
|
budget_subject: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
payment_account: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
invoice_status: Mapped[str] = mapped_column(String(64), default="未收票")
|
|
approval_status: Mapped[str] = mapped_column(String(64), default="草稿", index=True)
|
|
payment_status: Mapped[str] = mapped_column(String(64), default="未付款", index=True)
|
|
|
|
|
|
class FundAccount(Base, TimestampMixin):
|
|
__tablename__ = "fund_accounts"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(255), index=True)
|
|
account_type: Mapped[str] = mapped_column(String(64), default="bank")
|
|
current_balance: Mapped[Decimal] = mapped_column(Numeric(16, 2), default=0)
|
|
expected_receivable: Mapped[Decimal] = mapped_column(Numeric(16, 2), default=0)
|
|
expected_payable: Mapped[Decimal] = mapped_column(Numeric(16, 2), default=0)
|
|
safety_line: Mapped[Decimal] = mapped_column(Numeric(16, 2), default=0)
|
|
risk_level: Mapped[str] = mapped_column(String(32), default="low", index=True)
|
|
note: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
|
|
class Policy(Base, TimestampMixin):
|
|
__tablename__ = "policies"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
title: Mapped[str] = mapped_column(String(255), index=True)
|
|
policy_type: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
owner_department: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
version: Mapped[str] = mapped_column(String(32), default="v1.0")
|
|
status: Mapped[str] = mapped_column(String(64), default="草案", index=True)
|
|
effective_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
|
feishu_doc_url: Mapped[str | None] = mapped_column(String(1024), nullable=True)
|
|
summary: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
|
|
class Standard(Base, TimestampMixin):
|
|
__tablename__ = "standards"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
title: Mapped[str] = mapped_column(String(255), index=True)
|
|
standard_type: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
applies_to: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
status: Mapped[str] = mapped_column(String(64), default="有效", index=True)
|
|
check_items: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
remediation: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
policy_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
|
|
|
|
|
class PerformanceMetric(Base, TimestampMixin):
|
|
__tablename__ = "performance_metrics"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(255), index=True)
|
|
applies_to_role: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
formula: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
weight: Mapped[Decimal] = mapped_column(Numeric(5, 2), default=0)
|
|
data_source: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
auto_score: Mapped[Decimal] = mapped_column(Numeric(8, 2), default=0)
|
|
confirmed_score: Mapped[Decimal | None] = mapped_column(Numeric(8, 2), nullable=True)
|
|
status: Mapped[str] = mapped_column(String(64), default="草稿", index=True)
|
|
|
|
|
|
class Supplier(Base, TimestampMixin):
|
|
__tablename__ = "suppliers"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(255), index=True)
|
|
category: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
contact: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
quality_score: Mapped[Decimal] = mapped_column(Numeric(5, 2), default=0)
|
|
delivery_score: Mapped[Decimal] = mapped_column(Numeric(5, 2), default=0)
|
|
price_score: Mapped[Decimal] = mapped_column(Numeric(5, 2), default=0)
|
|
risk_level: Mapped[str] = mapped_column(String(32), default="low", index=True)
|
|
blacklist_status: Mapped[str] = mapped_column(String(32), default="normal", index=True)
|
|
|
|
|
|
class AttendanceRecord(Base, TimestampMixin):
|
|
__tablename__ = "attendance_records"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
employee_name: Mapped[str] = mapped_column(String(128), index=True)
|
|
employee_id: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
department: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
project_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
|
work_date: Mapped[date] = mapped_column(Date, index=True)
|
|
check_in_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
check_out_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
status: Mapped[str] = mapped_column(String(64), default="正常", index=True)
|
|
location: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
source_system: Mapped[str] = mapped_column(String(64), default="internal")
|
|
external_id: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
note: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
|
|
class WorkReport(Base, TimestampMixin):
|
|
__tablename__ = "work_reports"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
report_type: Mapped[str] = mapped_column(String(32), index=True)
|
|
title: Mapped[str] = mapped_column(String(255), index=True)
|
|
reporter: Mapped[str] = mapped_column(String(128), default="system", index=True)
|
|
department: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
project_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
|
period_start: Mapped[date] = mapped_column(Date, index=True)
|
|
period_end: Mapped[date] = mapped_column(Date, index=True)
|
|
content: Mapped[str] = mapped_column(Text)
|
|
metrics: Mapped[dict | None] = mapped_column(JSON, nullable=True)
|
|
risk_summary: Mapped[dict | None] = mapped_column(JSON, nullable=True)
|
|
status: Mapped[str] = mapped_column(String(64), default="已生成", index=True)
|
|
source_system: Mapped[str] = mapped_column(String(64), default="internal")
|
|
|
|
|
|
class RiskEvent(Base, TimestampMixin):
|
|
__tablename__ = "risk_events"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
title: Mapped[str] = mapped_column(String(255), index=True)
|
|
risk_type: Mapped[str] = mapped_column(String(64), index=True)
|
|
risk_level: Mapped[str] = mapped_column(String(32), default="medium", index=True)
|
|
status: Mapped[str] = mapped_column(String(32), default="open", index=True)
|
|
source_domain: Mapped[str] = mapped_column(String(128), index=True)
|
|
source_record_id: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
project_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
|
owner: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
detected_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
|
|
due_date: Mapped[date | None] = mapped_column(Date, nullable=True, index=True)
|
|
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
mitigation: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
evidence: Mapped[dict | None] = mapped_column(JSON, nullable=True)
|
|
|
|
|
|
class LegacySyncRun(Base, TimestampMixin):
|
|
__tablename__ = "legacy_sync_runs"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
domain: Mapped[str] = mapped_column(String(128), index=True)
|
|
source_table: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
|
status: Mapped[str] = mapped_column(String(32), default="running", index=True)
|
|
started_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
|
|
finished_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
created_count: Mapped[int] = mapped_column(Integer, default=0)
|
|
updated_count: Mapped[int] = mapped_column(Integer, default=0)
|
|
skipped_count: Mapped[int] = mapped_column(Integer, default=0)
|
|
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
note: Mapped[str | None] = mapped_column(Text, nullable=True)
|