效果与 Drools 类似

* 视频：[《Solon Flow vs Drools - 业务规则应用对比》](https://www.bilibili.com/video/BV1FfNjz1EzQ/)

### 1、图配置示例


```yaml
# demo.yml
id: "r1"
title: "评分规则"
layout:
  - { type: "start"}
  - { when: "order.getAmount() >= 100", task: "order.setScore(0);"}
  - { when: "order.getAmount() > 100 && order.getAmount() <= 500", task: "order.setScore(100);"}
  - { when: "order.getAmount() > 500 && order.getAmount() <= 1000", task: "order.setScore(500);"}
  - { type: "end"}
```

规则模式运行时，可以使用简化模式：

* id 不配置时，会自动生成，并按顺序自动建立连接关系
* when 条件，表示当前执行任务的运行条件

### 2、流程图应用示例

集成模式

```java
@Component
public class DemoCom {
    @Inject 
    FlowEngine flowEngine;
    
    //评分
    public int score(Order order) {
        //执行
        flowEngine.eval("r1", FlowContext.of().put("order", order));
        
        //获取评分结果
        return order.getScore();
    }
}
```

原生 Java 模式

```java
public class DemoCom {
    FlowEngine flowEngine = FlowEngine.newInstance();
    
    public DemoCom() {
        //加载配置
        engine.load("classpath:flow/*.yml");
    }
    
    //评分
    public int score(Order order) {
        //执行
        flowEngine.eval("r1", FlowContext.of().put("order", order));
        
        //获取评分结果
        return order.getScore();
    }
}
```