Solon v3.5.0

示例1:控制组合参考

</> markdown

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

1、if 控制示意

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

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);"}

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

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

2、iterator / for 控制示意

使用循环网关

id: "c1"
layout: 
  - {type: "iterator", meta: {"$for": "item", "$in": "list"}}
  - task: 'System.out.println(item);'

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

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

3、while 控制示意

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

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

4、switch 控制示意

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

id: "c1"
layout: 
  - {when: 'type == 1', task: ...}
  - {when: 'type == 2', task: ...}

使用排它网关

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

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

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