```
feat: 添加生命周期报告和AI规则管理功能 - 在Dockerfile中添加pillow依赖包用于图像处理 - 实现生命周期报告调度任务,支持日报和周报两种类型 - 新增TASK_RUN_LIFECYCLE任务常量和相关配置选项 - 扩展AI Agent服务以支持用户规则,并在分析时应用规则 - 添加AI用户规则创建、更新和查询接口 - 增加项目生命周期和财务需求分析技能 - 扩展现有模型以支持更完整的业务数据字段 - 实现飞书图片上传功能用于报告展示 ```
This commit is contained in:
135
app/modules/business/models/lifecycle.py
Normal file
135
app/modules/business/models/lifecycle.py
Normal file
@@ -0,0 +1,135 @@
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from sqlalchemy import Boolean, Date, DateTime, Integer, Numeric, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.database import Base
|
||||
from app.modules.business.constants import SourceSystem, StatusValue
|
||||
from app.modules.business.models.common import TimestampMixin
|
||||
|
||||
|
||||
class Employee(Base, TimestampMixin):
|
||||
__tablename__ = "employees"
|
||||
|
||||
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(128), index=True)
|
||||
department_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
department_name: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
||||
title: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
employment_status: Mapped[str] = mapped_column(
|
||||
String(32), default=StatusValue.UNKNOWN, index=True
|
||||
)
|
||||
hired_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
ding_user_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
source_system: Mapped[str] = mapped_column(String(64), default=SourceSystem.LEGACY_MYSQL)
|
||||
external_id: Mapped[str] = mapped_column(String(128), index=True)
|
||||
source_created_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
source_updated_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, index=True)
|
||||
last_seen_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, index=True)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True, index=True)
|
||||
|
||||
|
||||
class ProjectMember(Base, TimestampMixin):
|
||||
__tablename__ = "project_members"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
project_code: Mapped[str] = mapped_column(String(64), index=True)
|
||||
employee_code: Mapped[str] = mapped_column(String(64), index=True)
|
||||
role_name: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
||||
is_leader: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
|
||||
is_resident: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
work_mode: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
planned_days: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
workload_percent: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
source_system: Mapped[str] = mapped_column(String(64), default=SourceSystem.LEGACY_MYSQL)
|
||||
external_id: Mapped[str] = mapped_column(String(128), index=True)
|
||||
source_created_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
last_seen_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, index=True)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True, index=True)
|
||||
|
||||
|
||||
class ProjectMilestone(Base, TimestampMixin):
|
||||
__tablename__ = "project_milestones"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
code: Mapped[str] = mapped_column(String(128), unique=True, index=True)
|
||||
project_code: Mapped[str] = mapped_column(String(64), index=True)
|
||||
source_stage_id: Mapped[str] = mapped_column(String(64), index=True)
|
||||
stage_name: Mapped[str] = mapped_column(String(128), index=True)
|
||||
plan_start: Mapped[date | None] = mapped_column(Date, nullable=True)
|
||||
plan_end: Mapped[date | None] = mapped_column(Date, nullable=True, index=True)
|
||||
status: Mapped[str] = mapped_column(String(32), default=StatusValue.UNKNOWN, index=True)
|
||||
is_overdue: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
|
||||
activity_total: Mapped[int] = mapped_column(Integer, default=0)
|
||||
activity_completed: Mapped[int] = mapped_column(Integer, default=0)
|
||||
source_system: Mapped[str] = mapped_column(String(64), default=SourceSystem.LEGACY_MYSQL)
|
||||
external_id: Mapped[str] = mapped_column(String(128), index=True)
|
||||
source_updated_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, index=True)
|
||||
last_seen_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, index=True)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True, index=True)
|
||||
|
||||
|
||||
class ProjectContract(Base, TimestampMixin):
|
||||
__tablename__ = "project_contracts"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
project_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
contract_type_code: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
|
||||
contract_type_label: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
amount: Mapped[Decimal] = mapped_column(Numeric(16, 2), default=0)
|
||||
signed_date: Mapped[date | None] = mapped_column(Date, nullable=True, index=True)
|
||||
start_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
||||
end_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
||||
invoice_type_code: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
data_quality_status: Mapped[str] = mapped_column(String(32), index=True)
|
||||
source_system: Mapped[str] = mapped_column(String(64), default=SourceSystem.LEGACY_MYSQL)
|
||||
external_id: Mapped[str] = mapped_column(String(128), index=True)
|
||||
source_created_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
last_seen_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, index=True)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True, index=True)
|
||||
|
||||
|
||||
class ProjectCashFlow(Base, TimestampMixin):
|
||||
__tablename__ = "project_cash_flows"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
project_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
contract_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
flow_type: Mapped[str] = mapped_column(String(32), index=True)
|
||||
direction: Mapped[str] = mapped_column(String(16), index=True)
|
||||
category_code: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
|
||||
category_label: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
planned_amount: Mapped[Decimal] = mapped_column(Numeric(16, 2), default=0)
|
||||
actual_amount: Mapped[Decimal | None] = mapped_column(Numeric(16, 2), nullable=True)
|
||||
planned_date: Mapped[date | None] = mapped_column(Date, nullable=True, index=True)
|
||||
actual_date: Mapped[date | None] = mapped_column(Date, nullable=True, index=True)
|
||||
payment_status: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
|
||||
invoice_status: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
approval_status: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
|
||||
confirmation_status: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
data_quality_status: Mapped[str] = mapped_column(String(32), index=True)
|
||||
source_system: Mapped[str] = mapped_column(String(64), default=SourceSystem.LEGACY_MYSQL)
|
||||
external_id: Mapped[str] = mapped_column(String(128), index=True)
|
||||
source_created_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
source_updated_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, index=True)
|
||||
last_seen_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, index=True)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True, index=True)
|
||||
|
||||
|
||||
class SourceSyncCursor(Base, TimestampMixin):
|
||||
__tablename__ = "source_sync_cursors"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
dataset: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
status: Mapped[str] = mapped_column(String(32), default=StatusValue.PENDING, index=True)
|
||||
watermark_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
watermark_key: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
last_run_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
last_success_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, index=True)
|
||||
processed_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
Reference in New Issue
Block a user