当前位置:网站首页>Drools basic grammar
Drools basic grammar
2022-07-26 18:07:00 【Belief_ two hundred and seventy-three million nine hundred and 】
One 、 introduce Jar package , To configure POM file
Two 、 More detailed syntax
3、 ... and 、 Introduction to expression syntax
The simplest rule to complete , Grammar should also include these
rule "name"
when
......
then
......
end
Case study 1
rule "withdraw 11"
agenda-group "trade.withdraw"
enabled true
salience 11
when
$routeResult: RouteResult()
$request: WithdrawRouteRuleRequest()
$payer: RouteRuleRequestAccount(accountType == "AAA" && fundPlSettleModel == "BBB") from $ request.getPayer()
then
logger.info("{} Match to rule , Return scenario code {}",$request.getIdempotenceNo(),"trade.withdraw.1001");
$routeResult.setResult(true);
$routeResult.setBusinessScenariosCode("trade.withdraw.1001");
end
rule “withdraw 11” rule Indicates that this is a rule , Rule name withdraw 11
1、salience
Used to set the priority of rule execution ,salience The value of the property is a number , The higher the number, the higher the execution priority , And its value can be a negative number . By default , Regular ssalience The default value is 0, So if we don't set the rules manually salience attribute , Then its execution order is random ( But it is generally in the loading order .)
2、enabled
enabled Properties are relatively simple , It is used to define whether a rule is available . The value of this attribute is a Boolean value , The default value of this attribute is true, Indicates that the rule is available , If you add a rule manually enabled attribute , And set it enabled The property value is false, Then the engine will not execute the rule
3、agenda-group
The engine is invoking these settings agenda-group Attribute rules need to be displayed to specify a Agenda Group obtain Focus( The focus of ), For example, the following code
//getSession obtain KieSession I wrote it myself .
KieSession ks = getSession();
// Set up agenda-group Of auto-focus Make it execute
ks.getAgenda().getAgendaGroup("group1").setFocus();
notes : Filter the rule name , Only execute the rules under a rule name
kSession.fireAllRules(new RuleNameEqualsAgendaFilter("man"))
//【man】 It's the name of the rule , That is to say rule "man"
Case study 2
rule "withdraw 11"
agenda-group "trade.withdraw"
enabled true
salience 11
when
$routeResult: RouteResult() // Judge that there must be RouteResult Type object
$request: WithdrawRouteRuleRequest() // Judge that there must be WithdrawRouteRuleRequest type
//$request.getPayer() Represents the variable defined above $request Object has a variable payer
//payer The object must be RouteRuleRequestAccount type ,payer Properties in objects accountType
$payer: RouteRuleRequestAccount(accountType == "A" && fundPlSettleModel == "B")
from $request.getPayer()
then
logger.info("{} Match to rule , Return scenario code {}",$request.getIdempotenceNo(),"trade.withdraw.1001");
$routeResult.setResult(true);
$routeResult.setBusinessScenariosCode("trade.withdraw.1001");
end
1、from
from The role of : Specify the left side as its source , As the variable to be used in the expression on the right . Here is an example ,from Usage of .
RouteRuleRequest routeRuleRequest = new RouteRuleRequest ();
kieSession.insert(routeRuleRequest );
// Go to kieSession There is a routeRuleRequest Object of type , Or set the object to the working memory .
## Judge whether it includes TransferRouteRuleRequest Object of type , If there is an assignment to $request This variable .
$request: RouteRuleRequest ()
$receiver: RouteRuleRequestAccount(accountType == 1) from $request.getReceiver()
The above code means , from $request Take one of them 【 Attribute variables receiver】, Then assign a value to the left expression , That is, assign values to the following code
$receiver: RouteRuleRequestAccount(accountType == 1)
On the left, judge this variable receiver Whether it is RouteRuleRequestAccount type , And the attributes inside accountType Is it equal to 1, Then give this result to $receiver This variable .
Case study 3
$request: TransferRouteRuleRequest()
$modeType: TransferRouteRuleRequest(modeType == 2)
$platform: TransferRouteRuleRequest(isSamePlatform == 1)
TransferRouteRuleRequest Bracket judgment data , Can write many lines , The default is and Splicing
Four 、 operation List
kieSession.insert(list); // Set the set to the working memory
## Rule handling : Print out all List The elements in the collection
rule "hello_0"
when
$li:List(size > 0) ## Get all in working memory in turn List Assemble to $li
$m:Animal(name == "cat") from $li ## obtain List in name = "cat" Of Animal object , There may be more than one , There may be only one .
then
## Print the current List Medium message
## Be careful , It will be executed many times , The number of executions is all List Total number of collection elements ( Note that it is not current List The total number of collections )
## Because the rules filter out a completely consistent one from the working memory conditions The data of , Will be in agenda Insert a combination of rule and matching data , Again by agenda Responsible for enforcing the rules .
System.out.println("id:"+$m.getId()+",name:"+$m.getName());
end
边栏推荐
- [metauniverse OMI theory] analyze Web3 risk challenges and build Web3 ecological security
- AI zhetianchuan ml integrated learning
- AI遮天传 ML-无监督学习
- Vector CANape - How to Send Receive CAN Message in CANape
- Diagram of seven connection modes of MySQL
- AI遮天传 DL-回归与分类
- kaggle猫狗数据集开源——用于经典CNN分类实战
- drools-基础语法
- Come on developer! Not only for the 200000 bonus, try the best "building blocks" for a brainstorming!
- 8.1 Diffie-Hellman密钥交换
猜你喜欢

2022年的PMP考试大纲是什么?

【云原生】 iVX 低代码开发 引入腾讯地图并在线预览

Kindergarten system based on SSM

2、 Topic communication principle, code implementation

Heavy! The 2022 China open source development blue book was officially released

AI zhetianchuan DL regression and classification

跟我学 UML 系统建模

LeetCode50天刷题计划(Day 5—— 最长回文子串 10.50-13:00)

如何组装一个注册中心?

Come on developer! Not only for the 200000 bonus, try the best "building blocks" for a brainstorming!
随机推荐
【云原生】 iVX 低代码开发 引入腾讯地图并在线预览
JS recursive Fibonacci sequence deep cloning
3、 Topic communication: create your own information format
SSH based online mall
[training day3] section
如何组装一个注册中心?
Sign up now | oar hacker marathon phase III midsummer debut, waiting for you to challenge
【集训Day3】Reconstruction of roads
常用api
AI sky covering DL multilayer perceptron
2、 Topic communication principle, code implementation
[training Day2] torchbearer
长征证券开户安全吗?
【集训Day1】Spy dispatch
How to become a better data scientist by learning to ask questions
URL跳转漏洞
Analysis of interface testing
Vector CANape - How to Send Receive CAN Message in CANape
Quartz trigger rule
Three ways of de duplication in SQL