1. 程式人生 > 其它 >easy-rules-centraldogma-spring-boot-starter spel 模版格式說明

easy-rules-centraldogma-spring-boot-starter spel 模版格式說明

基於模版格式的程式碼,看著會比較清晰,所以添加了一個新的配置引數template 可以開啟此選項

參考配置

easyrules:
  skipOnFirstAppliedRule: false
  skipOnFirstNonTriggeredRule: false
  priorityThreshold: 1000000
  project: demo
  repo: demo
  contentType: json
  confName: /rules3.json
  template: true
centraldogma:
  hosts:
    - "127.0.0.1:36462"
server:
  port: 9000

rule 配置說明

需要使用#{} 格式,因為easy rules 預設會講facts 物件的內容轉為map,我們可以使用#進行變數引用,以下是參考配置

[
  {
    "rulesId": "demoapp",
    "rulesContent": [
      {
        "name": "demo",
        "description": "mydemo",
        "priority": 1,
        "compositeRuleType": "UnitRuleGroup",
        "composingRules": [
          {
            "name": "first",
            "description": "first rule",
            "condition": "#{#biz.age>100}",
            "priority": 2,
            "actions": [
              "#{@myService.setInfo(#biz)}" //  @ 引用spring bean  # 引用變數
            ]
          }
        ]
      }
    ]
  }
]

參考資料

https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#expressions
https://github.com/rongfengliang/easy-rules-centraldogma-spring-boot-starter