Solon v3.4.2

示例1:控制组合参考

</> markdown

以下示例采用脚本任务风格

1、if 控制示意

节点(活动节点)任务内控制

id: "c1"
layout: 
  - task: |
    if (order.getAmount() >= 100) {
      order.setScore(0);
    }

使用节点(活动节点)任务条件

id: "c1"
layout: 
  - { when: "order.getAmount() >= 100", task: "order.setScore(0);"}

使用排它网关

id: "c1"
layout: 
  - {type: "exclusive", link: [{when: "order.getAmount() >= 100", nextId: "do"}]}
  - {id: "do", task: "order.setScore(0);"}

2、for / while / iterator 控制示意

节点(活动节点)任务内控制

id: "c1"
layout: 
  - task: |
    for(int i=0; i<10; i++) {
      System.out.println(i); //打印
    }
id: c1
layout:
  - task: |
      import java.util.stream.Stream;

      Stream.of(1,2,3).parallel().forEach(i -> {
          context.runTask(node, "#demo2"); //运行任务描述(#子链)
      });

使用排它网关 + 计数器(while)

# like: do-while
id: c1
layout:
  - type: start
  - id: do
    task: |
      System.out.println(context.incrGet("demo"));
  - type: "exclusive"
    link:
      - nextId: do
        condition: 'context.incrAdd("demo") < 10'
# like: while-do
id: c1
layout:
  - type: start
  - id: while
    type: "exclusive"
    link:
      - nextId: do
        condition: 'context.incrAdd("demo") < 10'
  - id: do
    task: |
      System.out.println(context.incrGet("demo"));
    link: while

使用排它网关 + 遍历器(iterator)

id: c1
layout:
  - type: start
  - id: while
    type: "exclusive"
    link:
      - nextId: do
        condition: 'list.hasNext()'
  - id: do
    task: 'context.put("item", list.next());'
    title: '准备'
  - task: 'System.out.println(item);'
    link: while
id: c1
layout:
  - type: start
  - task: 'if(list instanceof Collection){context.put("list", list.iterator());}'
    title: '预处理'
  - id: while
    type: "exclusive"
    link:
      - nextId: do
        condition: 'list.hasNext()'
  - id: do
    task: 'context.put("item", list.next());'
    title: '准备'
  - task: 'System.out.println(item);'
    link: while

3、switch 控制示意

节点(活动节点)任务内控制

id: "c1"
layout: 
  - task: |
    switch(type) {
      case 1: ...
      case 2: ...
    }

使用包容网关

id: c1
layout:
  - {type: inclusive, link: [{when: "type == 1", nextId: "do1"}, {when: "type == 2", nextId: "do2"}]}
  - {id: do1, task: ...}
  - {id: do2, task: ...}