|
|
|
package model
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
type Workflow struct {
|
|
|
|
BaseModel
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Status int `json:"status"` // 1-启用 2-禁用
|
|
|
|
Nodes []WorkflowNode `json:"nodes" gorm:"foreignKey:WorkflowID"` // 添加外键定义
|
|
|
|
}
|
|
|
|
|
|
|
|
type WorkflowNode struct {
|
|
|
|
BaseModel
|
|
|
|
WorkflowID uint `json:"workflow_id" gorm:"index"` // 添加索引
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"` // start, end, task, approval等
|
|
|
|
Handler string `json:"handler"` // 处理函数
|
|
|
|
NextNodes string `json:"next_nodes"` // 逗号分隔的下个节点ID
|
|
|
|
Position int `json:"position"`
|
|
|
|
// 可选:添加回Workflow的引用
|
|
|
|
Workflow Workflow `json:"-" gorm:"foreignKey:WorkflowID"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type WorkflowInstance struct {
|
|
|
|
BaseModel
|
|
|
|
WorkflowID uint `json:"workflow_id"`
|
|
|
|
Status string `json:"status"` // running, completed, canceled
|
|
|
|
CurrentNodeID uint `json:"current_node_id"`
|
|
|
|
Data string `json:"data" gorm:"type:text"` // JSON格式的业务数据
|
|
|
|
Tasks []WorkflowTask `json:"tasks" gorm:"foreignKey:InstanceID"` // 添加外键定义
|
|
|
|
}
|
|
|
|
|
|
|
|
type WorkflowTask struct {
|
|
|
|
BaseModel
|
|
|
|
InstanceID uint `json:"instance_id" gorm:"index"` // 添加索引
|
|
|
|
NodeID uint `json:"node_id"`
|
|
|
|
Status string `json:"status"` // pending, processing, completed, canceled
|
|
|
|
Result string `json:"result" gorm:"type:text"` // JSON格式的处理结果
|
|
|
|
Handler string `json:"handler"`
|
|
|
|
Assignee uint `json:"assignee"` // 处理人
|
|
|
|
StartTime time.Time `json:"start_time"`
|
|
|
|
EndTime time.Time `json:"end_time"`
|
|
|
|
// 可选:添加回WorkflowInstance的引用
|
|
|
|
Instance WorkflowInstance `json:"-" gorm:"foreignKey:InstanceID"`
|
|
|
|
}
|