164 lines
7.1 KiB
Python
164 lines
7.1 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
工作流数据模型
|
||
"""
|
||
from sqlalchemy import Column, String, Text, Integer, Boolean, DateTime, Index, JSON
|
||
from sqlalchemy.sql import func
|
||
|
||
from app.base_model import BaseModel
|
||
|
||
|
||
class WorkflowDefinition(BaseModel):
|
||
"""工作流定义"""
|
||
__tablename__ = "workflow_definition"
|
||
|
||
# 所属应用(逻辑外键关联 core_application)
|
||
application_id = Column(String(21), nullable=True, index=True, comment="所属应用ID")
|
||
|
||
name = Column(String(100), nullable=False, comment="流程名称")
|
||
code = Column(String(100), unique=True, nullable=False, comment="流程编码")
|
||
workflow_type = Column(String(20), default="other", comment="流程类型: approval/application/business/hr/finance/admin/other")
|
||
icon = Column(String(100), default="", comment="流程图标")
|
||
icon_bg_color = Column(String(200), default="", comment="图标背景色(支持渐变色)")
|
||
category = Column(String(50), default="", comment="分类")
|
||
description = Column(Text, default="", comment="描述")
|
||
status = Column(String(20), default="draft", comment="状态: draft/published/disabled")
|
||
version = Column(Integer, default=1, comment="版本号")
|
||
|
||
# 关联表单
|
||
form_code = Column(String(100), nullable=False, comment="关联表单编码")
|
||
form_name = Column(String(100), default="", comment="关联表单名称")
|
||
|
||
# 关联文档模板(审批通过后自动生成)
|
||
document_template_codes = Column(JSON, default=list, comment="关联文档模板编码列表")
|
||
|
||
# 流程定义(JSON格式存储节点和连线)
|
||
flow_definition = Column(JSON, default=dict, comment="流程定义")
|
||
|
||
__table_args__ = (
|
||
Index("ix_workflow_definition_code", "code"),
|
||
Index("ix_workflow_definition_status", "status"),
|
||
Index("ix_workflow_definition_form_code", "form_code"),
|
||
Index("ix_workflow_definition_workflow_type", "workflow_type"),
|
||
)
|
||
|
||
|
||
class WorkflowInstance(BaseModel):
|
||
"""工作流实例(流程发起后的实例)"""
|
||
__tablename__ = "workflow_instance"
|
||
|
||
# 关联流程定义(逻辑外键)
|
||
workflow_id = Column(String(36), nullable=False, comment="流程定义ID")
|
||
|
||
# 流程实例信息
|
||
instance_no = Column(String(50), unique=True, nullable=False, comment="流程实例编号")
|
||
title = Column(String(200), nullable=False, comment="流程标题")
|
||
status = Column(String(20), default="pending", comment="状态: pending/approved/rejected/canceled")
|
||
|
||
# 发起人(逻辑外键)
|
||
initiator_id = Column(String(36), nullable=False, comment="发起人ID")
|
||
|
||
# 表单数据
|
||
form_code = Column(String(100), nullable=False, comment="表单编码")
|
||
form_data_id = Column(String(36), nullable=False, comment="表单数据ID")
|
||
|
||
# 当前节点
|
||
current_node_id = Column(String(50), default="", comment="当前节点ID")
|
||
current_node_name = Column(String(100), default="", comment="当前节点名称")
|
||
|
||
# 并行分支状态跟踪
|
||
# 格式: {"parallel_node_id": {"branch_id1": "completed", "branch_id2": "pending"}}
|
||
parallel_branch_status = Column(JSON, default=dict, comment="并行分支状态")
|
||
|
||
# 子流程关联
|
||
is_subflow = Column(Boolean, default=False, comment="是否为子流程")
|
||
parent_instance_id = Column(String(36), nullable=True, comment="父流程实例ID")
|
||
parent_node_id = Column(String(50), default="", comment="父流程等待节点ID")
|
||
subflow_timeout = Column(Integer, nullable=True, comment="子流程超时时间(秒)")
|
||
subflow_timeout_action = Column(String(20), default="", comment="超时操作: skip/reject")
|
||
|
||
# 延时节点状态
|
||
delay_node_id = Column(String(50), default="", comment="延时等待的节点ID")
|
||
delay_until = Column(DateTime, nullable=True, comment="延时到期时间")
|
||
|
||
# 时间记录
|
||
started_at = Column(DateTime, server_default=func.now(), comment="发起时间")
|
||
completed_at = Column(DateTime, nullable=True, comment="完成时间")
|
||
|
||
__table_args__ = (
|
||
Index("ix_workflow_instance_workflow_id", "workflow_id"),
|
||
Index("ix_workflow_instance_initiator_id", "initiator_id"),
|
||
Index("ix_workflow_instance_status", "status"),
|
||
Index("ix_workflow_instance_instance_no", "instance_no"),
|
||
)
|
||
|
||
|
||
class WorkflowTask(BaseModel):
|
||
"""工作流任务(待办任务)"""
|
||
__tablename__ = "workflow_task"
|
||
|
||
# 关联流程实例(逻辑外键)
|
||
instance_id = Column(String(36), nullable=False, comment="流程实例ID")
|
||
|
||
# 任务信息
|
||
node_id = Column(String(50), nullable=False, comment="节点ID")
|
||
node_name = Column(String(100), nullable=False, comment="节点名称")
|
||
task_type = Column(String(20), default="approval", comment="任务类型: approval/handle/copy/revise")
|
||
status = Column(String(20), default="pending", comment="状态: pending/waiting/approved/rejected/returned/transferred/delegated/handled/canceled/read")
|
||
|
||
# 处理人(逻辑外键)
|
||
assignee_id = Column(String(36), nullable=False, comment="处理人ID")
|
||
|
||
# 处理信息
|
||
comment = Column(Text, default="", comment="审批意见")
|
||
signature_file_id = Column(String(36), nullable=True, comment="签名文件ID")
|
||
handled_at = Column(DateTime, nullable=True, comment="处理时间")
|
||
|
||
# 转交信息(逻辑外键)
|
||
transferred_to_id = Column(String(36), nullable=True, comment="转交给用户ID")
|
||
|
||
# 委派信息
|
||
parent_task_id = Column(String(50), default="", comment="父任务ID(委派/加签时记录原任务)")
|
||
|
||
# 加签信息
|
||
sign_type = Column(String(20), default="", comment="加签类型: before/after/parallel/delegate/transfer")
|
||
|
||
# 超时配置
|
||
timeout_at = Column(DateTime, nullable=True, comment="超时时间")
|
||
timeout_action = Column(String(20), default="", comment="超时操作: notify/auto_approve/auto_reject")
|
||
timeout_notified = Column(Boolean, default=False, comment="是否已发送超时通知")
|
||
|
||
__table_args__ = (
|
||
Index("ix_workflow_task_instance_id", "instance_id"),
|
||
Index("ix_workflow_task_assignee_id", "assignee_id"),
|
||
Index("ix_workflow_task_status", "status"),
|
||
Index("ix_workflow_task_assignee_status", "assignee_id", "status"),
|
||
Index("ix_workflow_task_instance_status", "instance_id", "status"),
|
||
)
|
||
|
||
|
||
class WorkflowLog(BaseModel):
|
||
"""工作流操作日志"""
|
||
__tablename__ = "workflow_log"
|
||
|
||
# 关联流程实例(逻辑外键)
|
||
instance_id = Column(String(36), nullable=False, comment="流程实例ID")
|
||
|
||
# 操作信息
|
||
node_id = Column(String(50), default="", comment="节点ID")
|
||
node_name = Column(String(100), default="", comment="节点名称")
|
||
action = Column(String(30), nullable=False, comment="操作类型")
|
||
|
||
# 操作人(逻辑外键)
|
||
operator_id = Column(String(36), nullable=False, comment="操作人ID")
|
||
|
||
# 操作详情
|
||
comment = Column(Text, default="", comment="备注/意见")
|
||
extra_data = Column(JSON, default=dict, comment="额外数据")
|
||
|
||
__table_args__ = (
|
||
Index("ix_workflow_log_instance_id", "instance_id"),
|
||
Index("ix_workflow_log_operator_id", "operator_id"),
|
||
)
|