evaluateCondition 评估条件
(execution *WorkflowExecution, condition *ConditionDef)
| 819 | |
| 820 | // evaluateCondition 评估条件 |
| 821 | func (e *Engine) evaluateCondition(execution *WorkflowExecution, condition *ConditionDef) (bool, error) { |
| 822 | evaluator := NewExpressionEvaluator(execution.Context.Variables) |
| 823 | |
| 824 | switch condition.Type { |
| 825 | case ConditionTypeAnd: |
| 826 | for _, rule := range condition.Rules { |
| 827 | if result, err := e.evaluateConditionRule(execution, rule, evaluator); err != nil { |
| 828 | return false, err |
| 829 | } else if !result { |
| 830 | return false, nil |
| 831 | } |
| 832 | } |
| 833 | return true, nil |
| 834 | case ConditionTypeOr: |
| 835 | for _, rule := range condition.Rules { |
| 836 | if result, err := e.evaluateConditionRule(execution, rule, evaluator); err != nil { |
| 837 | return false, err |
| 838 | } else if result { |
| 839 | return true, nil |
| 840 | } |
| 841 | } |
| 842 | return false, nil |
| 843 | case ConditionTypeCustom: |
| 844 | return evaluator.EvaluateBool(condition.Custom) |
| 845 | default: |
| 846 | return false, fmt.Errorf("unsupported condition type: %s", condition.Type) |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | // evaluateConditionRule 评估条件规则 |
| 851 | func (e *Engine) evaluateConditionRule(execution *WorkflowExecution, rule ConditionRule, evaluator *ExpressionEvaluator) (bool, error) { |
no test coverage detected