approveflow/app/provider/flow_instance/model/instance_path_config.go

69 lines
1.9 KiB
Go
Raw Normal View History

2024-11-15 16:53:35 +08:00
package model
import (
"approveflow/app/base"
"approveflow/app/provider/flow_definition"
2024-11-19 17:03:12 +08:00
"encoding/json"
2024-11-15 16:53:35 +08:00
)
// InstancePathConfig 动态路径配置表结构
type InstancePathConfig struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"` // 主键ID
NodeID int64 `gorm:"type:bigint;index;not null" json:"node_id"`
FromNodeKey string `gorm:"type:varchar(50);index;not null" json:"from_node_key"`
ToNodeKey string ` gorm:"type:varchar(50);index;not null" json:"to_node_key"`
IsParallel bool `gorm:"not null;default:false" json:"is_parallel"` // 是否并行
IsDynamic bool `gorm:"not null;default:false" json:"is_dynamic"` // 是否为动态步骤
Priority int `gorm:"not null;default:0" json:"priority"` // 路径优先级
flow_definition.ApprovalConditionCommon
base.Model
}
2024-11-19 17:03:12 +08:00
func (d *InstancePathConfig) MarshalBinary() ([]byte, error) {
return json.Marshal(d)
}
func (d *InstancePathConfig) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, d)
}
func (d *InstancePathConfig) GetKey() string {
2024-11-15 16:53:35 +08:00
return d.Key
}
2024-11-19 17:03:12 +08:00
func (d *InstancePathConfig) GetNodeID() int64 {
2024-11-15 16:53:35 +08:00
return d.NodeID
}
2024-11-19 17:03:12 +08:00
func (d *InstancePathConfig) GetFromNodeKey() string {
2024-11-15 16:53:35 +08:00
return d.FromNodeKey
}
2024-11-19 17:03:12 +08:00
func (d *InstancePathConfig) GetToNodeKey() string {
2024-11-15 16:53:35 +08:00
return d.ToNodeKey
}
// NewDynamicPathConfig 创建动态路径
func NewDynamicPathConfig(instanceID, nodeId int64, FromStepKey, ToStepKey string, isParallel bool) *InstancePathConfig {
pathConfig := &InstancePathConfig{
NodeID: nodeId,
FromNodeKey: FromStepKey,
ToNodeKey: ToStepKey,
IsParallel: isParallel,
Priority: 0,
}
return pathConfig
}
// IsConditionMet 判断路径条件是否满足
2024-11-19 17:03:12 +08:00
func (d *InstancePathConfig) IsConditionMet(data map[string]interface{}) (bool, error) {
if d.ConditionExpression == "" {
2024-11-15 16:53:35 +08:00
return true, nil // 无条件,默认满足
}
2024-11-19 17:03:12 +08:00
result, err := d.EvaluateCondition(data)
2024-11-15 16:53:35 +08:00
if err != nil {
return false, err
}
return result, nil
}