设计规则流如下:
先执行:check,然后执行payment
对应的规则流rmf文件如下: 【使用IDE生成,Drools4.0.7 的可读性,不如Drools 5】
<org.drools.ruleflow.core.impl.RuleFlowProcessImpl id="1">
<nodes id="2">
<entry>
<long>1</long>
<org.drools.ruleflow.core.impl.StartNodeImpl id="3">
<id>1</id>
<name>Start</name>
<incomingConnections id="4"/>
<outgoingConnections id="5">
<org.drools.ruleflow.core.impl.ConnectionImpl id="6">
<type>1</type>
<from class="org.drools.ruleflow.core.impl.StartNodeImpl" reference="3"/>
<to class="org.drools.ruleflow.core.impl.RuleSetNodeImpl" id="7">
<ruleFlowGroup>check</ruleFlowGroup>
<id>3</id>
<name>check</name>
<incomingConnections id="8">
<org.drools.ruleflow.core.impl.ConnectionImpl reference="6"/>
</incomingConnections>
<outgoingConnections id="9">
<org.drools.ruleflow.core.impl.ConnectionImpl id="10">
<type>1</type>
<from class="org.drools.ruleflow.core.impl.RuleSetNodeImpl" reference="7"/>
<to class="org.drools.ruleflow.core.impl.RuleSetNodeImpl" id="11">
<ruleFlowGroup>payment</ruleFlowGroup>
<id>4</id>
<name>payment</name>
<incomingConnections id="12">
<org.drools.ruleflow.core.impl.ConnectionImpl reference="10"/>
</incomingConnections>
<outgoingConnections id="13">
<org.drools.ruleflow.core.impl.ConnectionImpl id="14">
<type>1</type>
<from class="org.drools.ruleflow.core.impl.RuleSetNodeImpl" reference="11"/>
<to class="org.drools.ruleflow.core.impl.EndNodeImpl" id="15">
<id>2</id>
<name>End</name>
<incomingConnections id="16">
<org.drools.ruleflow.core.impl.ConnectionImpl reference="14"/>
</incomingConnections>
<outgoingConnections id="17"/>
</to>
</org.drools.ruleflow.core.impl.ConnectionImpl>
</outgoingConnections>
</to>
</org.drools.ruleflow.core.impl.ConnectionImpl>
</outgoingConnections>
</to>
</org.drools.ruleflow.core.impl.ConnectionImpl>
</outgoingConnections>
</org.drools.ruleflow.core.impl.StartNodeImpl>
</entry>
<entry>
<long>2</long>
<org.drools.ruleflow.core.impl.EndNodeImpl reference="15"/>
</entry>
<entry>
<long>3</long>
<org.drools.ruleflow.core.impl.RuleSetNodeImpl reference="7"/>
</entry>
<entry>
<long>4</long>
<org.drools.ruleflow.core.impl.RuleSetNodeImpl reference="11"/>
</entry>
</nodes>
<variables id="18"/>
<lastNodeId>4</lastNodeId>
<id>myflow</id>
<name>MyFlow</name>
<version>1.0</version>
<type>RuleFlow</type>
<packageName>com.chen.drools</packageName>
</org.drools.ruleflow.core.impl.RuleFlowProcessImpl>
规则文件如下:
清单一:rules.drl
package com.chen.drools
#list any import classes here.
import com.chen.beans.User;
#declare any global variables here
#如果申请人既没房也没车,同时学历为大专及以下,并且月薪少于5000,那么不通过。
rule "No1"
ruleflow-group "check"
when
#conditions
$user: User(hasHouse =="无", hasCar =="无", degree =="大专以下", salary <5000)
then
#actions
$user.setApprove(false);
end
#如果申请人既没房也没车,同时学历为大专或本科,并且月薪少于3000,那么不通过。
rule "No2"
#include attributes such as "salience" here...
ruleflow-group "check"
when
#conditions
$user: User( hasHouse =="无", hasCar =="无", salary <3000,( degree =="大专" || degree =="本科"))
then
#actions
$user.setApprove(false);
end
#如果申请人既没房也没车,同时学历为本科以上,并且月薪少于2000,同时之前没有信用卡的,那么不通过。
rule "No3"
ruleflow-group "check"
when
$user:User( hasHouse =="无", hasCar =="无", degree =="本科以上", salary <2000)
then
$user.setApprove(false);
end
清单二: payment.drl
package com.chen.drools
#list any import classes here.
import com.chen.beans.CardInfo;
import com.chen.beans.User;
//如果申请人有房有车,或者月收入在20000以上,那么发放的信用卡信用额度为15000
rule "R1"
ruleflow-group "payment"
when
$user: User( salary >20000 || (hasCar =="有" && hasHouse =="有") )
$card: CardInfo( )
then
$user.setCardInfo($card);
$card.setValue(15000);
$card.setBankName("中银广州");
$card.setUser($user);
#creatPayment(15000,$user);
#输出测试
end
//如果申请人没房没车,但月收入在10000~20000之间,那么发放的信用卡信用额度为6000
rule "R2"
#include attributes such as "salience" here...
ruleflow-group"payment"
when
#conditions
$user: User( hasHouse =="无" , hasCar =="无" , salary >10000 , salary <20000 )
$card: CardInfo( )
then
#actions
$user.setCardInfo($card);
$card.setValue(6000);
$card.setBankName("中银广州2");
$card.setUser($user);
#creatPayment(6000,$user);
end
//如果申请人没房没车,月收入在10000以下,那么发放的信用额度为3000。
rule "R3"
ruleflow-group"payment"
when
$user : User( hasHouse =="无", hasCar =="无" , salary <10000 )
$card: CardInfo( )
then
$user.setCardInfo($card);
$card.setValue(3000);
$card.setBankName("中银广州3");
$card.setUser($user);
end
//如果申请人有房没车或者是没房但有车,月收入在10000以下,那么发放的信用额度为5000。
rule "R4"
ruleflow-group"payment"
when
$user : User( ( hasHouse =="有" && hasCar =="无") || (hasHouse =="无" && hasCar =="有") && salary <10000 )
$card: CardInfo( )
then
$user.setCardInfo($card);
$card.setValue(5000);
$card.setBankName("中银广州4");
$card.setUser($user);
end
// 如果申请人有房没车或者是没房但有车,月收入在10000~2000之间,那么发放的信用额度为8000。
rule "R5"
ruleflow-group"payment"
when
$user: User( (hasHouse =="有" && hasCar =="无") || (hasHouse =="无" && hasCar =="有") && salary <= 20000 , salary >=10000 )
$card: CardInfo( )
then
$user.setCardInfo($card);
$card.setValue(8000);
$card.setBankName("中银广州5");
$card.setUser($user);
end
- 大小: 8.6 KB
分享到:
相关推荐
1 Drools简介1.1 Drools的作用1.2 使用规则引擎的优势1.3 规则引擎应用场景2 Drools初体验2.1 构建项目2.2 案例描述 2.3 代码实现3 Drools语法介绍3.1 规则文件的组成3.2 规则体语法结构3.3 Pattern模式匹配 ...
NULL 博文链接:https://jacky6024.iteye.com/blog/353307
Drools是Jboss公司旗下一款开源的规则引擎,它完整的实现了Rete 算法;提供了强大的Eclipse Plugin开发支持; 通过使用其中的DSL(Domain Specific Language),可以实现用自然语言方式来描述业务规则,使得业务分析...
4、规则引擎是相对独立的,只关心业务规则,使得业务分析人员也可以参与编辑、维护系统的业务规则 5、减少了硬编码业务规则的成本和风险 6、使用规则引擎提供的规则编辑工具,使复杂的业务规则实现变得的简单 对于...
drools整合apollo实现动态规则引擎,可以在不停服的情况下动态调整规则。无需数据库等存储,自动推送
基于Drools规则引擎开发的一个规则验证样例系统,包含java代码源码、规则源码及所依赖的jar包。
从基础讲起,结合应用场景,由浅到深细化讲解drools规则引擎的的相关知识,并结合具体实例,演示功能的使用和注意事项。后面通过搭建具体的项目并结合springboot框架联合使用Drools的相关知识包括决策表的使用,囊括...
基于Drools的规则引擎实例(完整、可运行eclipse工程)。 Drools 规则引擎
Drools是Jboss公司旗下...最新版本Drools5提供了基于WEB的BRMS——Guvnor,Guvnor提供了规则管理的知识库,通过它可以实现规则的版本控制,及规则的在线修改与编译,使得开发人员和系统管理人员可以在线管理业务规则。
Drools规则引擎是一种嵌套在应用程序中的组件, 是用Java...它实现了将业务规则从程序代码忠分离出来,规则引擎使用特定的语法编写业务规则,规则引擎可以接受数据输入、解释业务规则,并根据业务规则做出相应的决策。
drools规则引擎系统概要设计.pdf
drools规则引擎在促销系统中的应用.pdf
从Drools规则引擎到风控反洗钱系统V0.2.3
使用规则引擎可以通过降低实现复杂业务逻辑的组件的复杂性,降低应用程序的维护和可扩展性成本。这篇更新的文章展示如何使用开源的 Drools 规则引擎让 Java™ 应用程序更适应变化。Drools 项目引入了一个新的本地...
Drools 规则引擎的介绍及应用,全面介绍了Drools的规则集文件语法
Drools规则引擎及教程,需在jdk1.6下运行,不缺jar包
drools规则引擎,了解规则匹配,专家系统的可以学习一下,java的同学也可以学习一下,各大厂也在用哦
描述Drools规则引擎的相关内容,并讲述java环境下如何集成drools工具实现规则的推理
从Drools规则引擎到风控反洗钱系统v0.3.2.pdf ,此版本文档在不断刚更新升级中。