当前位置:网站首页>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
边栏推荐
- Coscon'22 city / school / institution producer solicitation order
- AI sky covering DL multilayer perceptron
- AI遮天传 ML-集成学习
- AI zhetianchuan DL regression and classification
- openssl
- Spark unified memory partition
- AI遮天传 DL-多层感知机
- Detailed explanation of openwrt's feeds.conf.default
- Cross site scripting attack (XSS)
- drools-基础语法
猜你喜欢

AI遮天传 DL-回归与分类
![[training Day1] spy dispatch](/img/cd/34845de1093c777f6ecff35d9452c3.png)
[training Day1] spy dispatch

有一说一,阿里P7的薪资待遇是真的香

Click hijacking attack
![[Oumi reading club] talk about the creator economy in the meta universe: infinite dimension](/img/60/17cb0295f81dc580cc3ff8543ec253.png)
[Oumi reading club] talk about the creator economy in the meta universe: infinite dimension

【集训Day2】cinema ticket

Redisdesktopmanager removes the upgrade prompt
![[training Day2] sculpture](/img/d9/2e2ee8b4d995a29204afba889da635.png)
[training Day2] sculpture

来吧开发者!不只为了 20 万奖金,试试用最好的“积木”来一场头脑风暴吧!

COSCon'22城市/学校/机构出品人征集令
随机推荐
[training Day1] Dwaves line up
Click hijacking attack
The user experience center of Analysys Qianfan bank was established to help upgrade the user experience of the banking industry
Is it safe for me to open the securities account of CITIC and find the channel manager?
What is the PMP exam outline in 2022?
【模板】线段树 1
【集训Day1】 Dwarves line up
深度学习实验:Softmax实现手写数字识别
CentOS installs docker and MySQL and redis environments
Heavy! The 2022 China open source development blue book was officially released
[Day2] cinema ticket
8.1 Diffie-Hellman密钥交换
OpenWrt之feeds.conf.default详解
Diagram of seven connection modes of MySQL
LeetCode50天刷题计划(Day 2—— 无重复字符的最长子串 10.00-12.00)
The chess robot broke the finger of a 7-year-old boy because "the chess player violated safety rules"?
AI遮天传 ML-集成学习
7月30号PMP考试延期后我们应该做什么?
[template] segment tree 1
PMP Exam details, what changes have been made to the new exam outline?