使用软件包 SDK 创建条件
使用 Automation 360 时,您可以使用 SDK 软件包创建条件。
使用条件
If 和 Loop 是 Automation 360 中的分支结构。它们用于在条件设置为 true
时运行一系列操作。条件是与 If 和 Loop 软件包一起使用的。条件需要获取一组输入并返回布尔值。
所需注释
要创建条件,需要以下注释:
注释 | 使用 |
---|---|
BotCommand |
使用 BotCommand 注释,condition 为 commandType 。这确保了普通 Java 对象 (POJO) 适用于创建 Automation 360 条件。 |
CommandPkg |
这些值在创建软件包时使用。提供注释的名称、标签和描述。 |
Idx |
注释所有必需的参数和成员变量,并帮助验证检查,或者它们可能显示在输入的界面中。提供索引 (Idx ) 和类型。 |
Pkg |
注释将在界面中显示的所有参数和成员变量。如果没有 Idx ,将忽略此注释。 |
ConditionTest |
检测条件时必须调用的方法。必须返回布尔值。如果该方法接受参数,则使用 Idx 注释它们。 |
使用案例示例
以下用实例验证给定数字是否大于其他数字。
- 使用业务逻辑创建 POJO 类:
public class IsGreater { public Boolean checkGreater(Double first, Double checkAgainst) { return first > checkAgainst; } }
- 为 POJO 类添加注释,以启用该 Automation 360 条件并创建软件包:
@BotCommand(commandType = Condition) @CommandPkg(label = "Is greater condition", name = "IsGreater", description = "Checks if the given number is greater than the other.", node_label = "{{first}} > {{checkAgainst}} ") public class IsGreater { public Boolean checkGreater(Double first, Double checkAgainst) { return first > checkAgainst; } }
- 注释
checkGreater
法以指示该方法应用作比较方法。@ConditionTest public Boolean checkGreater(Double first, Double checkAgainst) { return first > checkAgainst; }
每个条件都必须有一个测试条件方法。
- 用
Idx
和Pkg
注释checkGreater
方法的参数。添加
@NotEmpty
以确保该值不为空。@ConditionTest public Boolean checkGreater( @Idx(index = "1", type = AttributeType.NUMBER) @Pkg(label = "Number to check") @NotEmpty Double first, @Idx(index = "2", type = AttributeType.NUMBER) @Pkg(label = "Number to compare against") @NotEmpty Double checkAgainst) { return first > checkAgainst; }
属性类型编号将返回
Double
。