当前位置:网站首页>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
边栏推荐
猜你喜欢

It is said that the salary of Alibaba P7 is really fragrant

8.1 Diffie-Hellman密钥交换
![[Digital IC] understand Axi Lite protocol in simple terms](/img/2b/15b3d831bba6aa772ad83f3ac91d23.png)
[Digital IC] understand Axi Lite protocol in simple terms

【集训Day3】Reconstruction of roads

深度学习实验:Softmax实现手写数字识别

AI zhetianchuan DL regression and classification

URL跳转漏洞

跨站脚本攻击(XSS)

Spark统一内存划分

What is the PMP exam outline in 2022?
随机推荐
SQL判断某列中是否包含中文字符、英文字符、纯数字,数据截取
5、 Parameter server principle, code implementation
LeetCode50天刷题计划(Day 1—— 两数相加 11.00-12.30)
带你熟悉云网络的“电话簿”:DNS
PMP考试详解,新考纲有什么变化?
CentOS installs docker and MySQL and redis environments
《敏捷宣言》四大价值观,十二大原则
兆骑科创海外高层次人才引进平台,创业赛事活动路演
Win10 wireless connection cannot input password characters, and it will be stuck as soon as it is input
The Agile Manifesto has four values and twelve principles
drools-基础语法
Laozi cloud and Fuxin Kunpeng achieved a major breakthrough in 3D ofd 3D format documents for the first time
【集训Day1】 Dwarves line up
中国聚异丁烯市场研究与投资价值报告(2022版)
Sign up now | oar hacker marathon phase III midsummer debut, waiting for you to challenge
8.2 一些代数知识(群、循环群和子群)
【集训Day3】Reconstruction of roads
Vector CANoe Menu Plugin拓展入门
天翼云Web应用防火墙(边缘云版)支持检测和拦截Apache Spark shell命令注入漏洞
Simple uploading and downloading of Web project files