package flow_definition import ( "approveflow/app/base" "encoding/json" ) const ( ActionAutoReject = "ActionAutoReject" ActionReassignApprover = "ReassignApprover" ActionAutoApprove = "ActionAutoApprove" ) // ApprovalRule 审批规则表 type ApprovalRule struct { ID int64 `gorm:"primaryKey;autoIncrement" json:"id"` // 主键ID Name string `gorm:"type:varchar(100);not null" json:"name"` // 规则名称 Action string `gorm:"type:varchar(50)" json:"action"` // 执行动作 Priority int `gorm:"type:int;default:0" json:"priority"` // 优先级 StepID int64 `gorm:"index;not null" json:"step_id"` ConditionExpression string `gorm:"type:text" json:"condition_expression"` // 条件表达式 ApprovalConditionCommon `gorm:"-"` base.Model // 通用字段,包括创建时间、更新时间等 } func (rule *ApprovalRule) MarshalBinary() ([]byte, error) { return json.Marshal(rule) } func (rule *ApprovalRule) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, rule) } func NewAutoApproveRule() *ApprovalRule { return &ApprovalRule{ ApprovalConditionCommon: ApprovalConditionCommon{}, Name: "自动通过", Action: ActionAutoApprove, Priority: 1, } } // IsConditionMet 评估规则是否满足条件 func (rule *ApprovalRule) IsConditionMet(data map[string]interface{}) (bool, error) { // 解析和评估条件表达式 result, err := rule.EvaluateCondition(data) if err != nil { return false, err } return result, nil }