feat: complete SOP execution workflow
This commit is contained in:
@@ -13,6 +13,7 @@ type answerNodeConfig struct {
|
||||
FieldKey string `json:"field_key"`
|
||||
FieldKeys []string `json:"field_keys"`
|
||||
Required bool `json:"required"`
|
||||
Options []string `json:"options"`
|
||||
}
|
||||
|
||||
func validateNodeAnswers(node model.SOPNode, fields []model.ScenarioField, answers map[string]interface{}) error {
|
||||
@@ -68,10 +69,22 @@ func validateNodeAnswers(node model.SOPNode, fields []model.ScenarioField, answe
|
||||
if err := validateFieldValue(field, value); err != nil {
|
||||
return err
|
||||
}
|
||||
if node.Type == "choice" && !stringAllowed(config.Options, fmt.Sprint(value)) {
|
||||
return fmt.Errorf("%s的选项不正确", field.FieldName)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func stringAllowed(options []string, selected string) bool {
|
||||
for _, option := range options {
|
||||
if option == selected {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func validateFieldValue(field model.ScenarioField, value interface{}) error {
|
||||
switch field.FieldType {
|
||||
case "text", "textarea":
|
||||
|
||||
Reference in New Issue
Block a user