使用 Automation 360 时,您可以使用 SDK 软件包创建自定义变量。

使用自定义变量

使用 Automation 360 创建自定义变量。 这是一个系统变量,用作其他 机器人 变量,但它是只读的,并且该值被计算而不是被分配。

所需注释

要创建变量,需要以下注释:

注释 使用情况
BotCommand BotCommand 注释与变量 配合使用作为commandType。 这确保了普通 Java 对象 (POJO)适用于创建 Automation 360 变量。
CommandPkg 这些值在创建软件包时使用。 提供注释的名称、标签和描述。
Idx 注释所有必需的参数和成员变量,并帮助验证检查。 或者,它们可能会显示在输入界面中。 提供索引 (Idx) 和类型。
Pkg 注释将在界面中显示的所有参数和成员变量。 如果没有 Idx,将忽略此注释。
VariableExecute 返回变量值必须调用的方法。 此方法不接受任何输入参数。 SessionsGlobalSessionContext 可通过 setter 注入获得。

使用案例示例

以下用例显示了如何返回系统默认区域的当前时间。

  1. 使用业务逻辑创建 POJO 类:
    public class Now { public DateTimeValue now() { Instant instant = Instant.now(); ZonedDateTime now = instant.atZone(ZoneId.systemDefault()); return new DateTimeValue(now); } }
  2. 对 POJO 类进行注释,以为 Automation 360 变量启用它并创建软件包:
    @BotCommand(commandType = BotCommand.CommandType.Variable) @CommandPkg(description =“系统默认时区的当前日期时间”, name = "Now", label = "", variable_return_type = DataType.DATETIME) public class Now { public DateTimeValue now() { Instant instant = Instant.now(); ZonedDateTime now = instant.atZone(ZoneId.systemDefault()); return new DateTimeValue(now); } }
  3. 注释 now 方法,将其表示为执行方法。
    @VariableExecute public DateTimeValue now() { Instant instant = Instant.now(); ZonedDateTime now = instant.atZone(ZoneId.systemDefault()); return new DateTimeValue(now); }

    每个变量必须有一个测试 VariableExecute 方法。