使用軟件包 SDK 創建條件
使用時 Automation 360,您可以使用 SDK 軟件包創建條件。
使用條件
If 和 Loop 是中的分支結構 Automation 360。當條件設置 爲 true 時,它們用於運行一系列操作
。條件與 If 和 Loop 軟件包一起使用。條件接受一組輸入並返回布爾值。
所需的註釋
要產生條件 , 需要下列註記 :
註解 | 使用方式 |
---|---|
BotCommand |
將 BotCommand 註釋與 條件一起使用 爲 命令類型 。這可確保純舊 Java 對象 (POJO) 適用於創建 Automation 360 條件。 |
CommandPkg |
創建軟件包時使用這些值。提供註釋的名稱、標籤和說明。 |
IDX |
註釋所有必需的參數和成員變量,並幫助進行驗證檢查,或者它們可能顯示在輸入的接口中。提供索引 (IDX ) 和類型。 |
包裝 |
註釋界面中顯示的所有參數和成員變量。如果 沒有 IDX 附帶此註釋,則將忽略該註釋 。 |
條件測試 |
測試條件時必須調用的方法。它必須返回布爾值。如果方法接受參數,則使用 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; } }
- 註釋
複選框評註
方法,以指示應將此方法用作比較方法。@ConditionTest public Boolean checkGreater(Double first, Double checkAgainst) { return first > checkAgainst; }
每個 條件必須只有一個測試條件方法。
- 使用
IDX
和包註釋 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; }
屬性類型 number 返回
雙精度值
。