ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:35.29KB ,
资源ID:12668026      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/12668026.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(drools Decision Table决策表.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

drools Decision Table决策表.docx

1、drools Decision Table决策表Drools决策表的使用1简单了解 这几天在研究drools, drools到底是怎么与决策表交互的呢,报这个疑问开始了寻找之路。何时使用决策表如果规则能够被表达为模板+数据的格式,那你应该考虑使用决策表。决策表中的每一行就是对应模板的一行数据,将产生一个规则。运行决策表Drools引擎所部署的系统中执行决策表。首先,决策表转换成的Drools规则语言(DRL),然后执行规则引擎需求。这意味着它是可能的业务规则的变更,无需停止和启动,或重新部署任何软件。2创建java类公共java类:Caluculation.java执行java类及规则文件(d

2、rl文件):CalculationDrl.java和calculation.drl执行java类及决策表(xml文件):CalculationXls.java和calculation.xls(运行决策表方法一)执行java类及决策表(xml文件)生成规则,将得到的规则放入规则文件中(drl文件中):GenerationRules.java、calculation.xls、calculations.drl、CalculationDrlXls(运行决策表方法二)2.1.1Caluculation.javapackage com.flagleader.bean;public class Calcul

3、ation private double wage;/当月工资 private double actualwage;/当月税后工资 private double wagemore;/全月应纳税所得额 private double cess;/税率 private double preminus;/速算扣除数 private double wageminus;/当月工资扣减数 /* * 当月工资 * return */ public double getWage() return wage; public void setWage(double wage) this.wage = wage; /

4、* * 当月税后工资 * return */ public double getActualwage() return actualwage; public void setActualwage(double actualwage) this.actualwage = actualwage; /* * 全月应纳税所得额 * return */ public double getWagemore() return wagemore; public void setWagemore(double wagemore) this.wagemore = wagemore; /* * 税率 * retur

5、n */ public double getCess() return cess; public void setCess(double cess) this.cess = cess; /* * 速算扣除数 * return */ public double getPreminus() return preminus; public void setPreminus(double preminus) this.preminus = preminus; /* * 当月工资扣减数 * return */ public double getWageminus() return wageminus;

6、public void setWageminus(double wageminus) this.wageminus = wageminus; public Calculation() public Calculation(double wage) super(); this.wage = wage; public Calculation(double wage,double wagemore) super(); this.wage = wage; this.wagemore=wagemore; Override public String toString() return 当月工资=+wag

7、e+n当月税后工资=+actualwage+n全月应纳税所得额=+wagemore+ n税率=+cess+n速算扣除数=+preminus+n当月工资扣减数=+wageminus; 2.1.2calculation.drlpackage com.flagleader.beanglobal Calculation cal;no-loop truerule 全月应纳税额salience 3 when $cal : Calculation(wage0) then #System.out.println(-全月应纳税额-); cal.setWagemore(cal.getWage()-3500); u

8、pdate(cal);endrule 设置税率salience 2 when eval(true) then #System.out.println(-设置税率-); if ( cal.getWagemore()1500 & cal.getWagemore()4500 & cal.getWagemore()9000 & cal.getWagemore()35000 & cal.getWagemore()55000 & cal.getWagemore()80000 ) cal.setCess(0.45); cal.setPreminus(13505); insert(cal);endrule 税

9、后工资salience 1 when eval(true) then #System.out.println(-税后工资-); cal.setWageminus(cal.getWagemore()*cal.getCess()-cal.getPreminus(); cal.setActualwage(cal.getWage()-cal.getWageminus(); insert(cal);end2.1.3CalculationDrl.javapackage com.flagleader.bean;import org.apache.log4j.Logger;import org.drools.

10、KnowledgeBase;import org.drools.builder.KnowledgeBuilder;import org.drools.builder.KnowledgeBuilderFactory;import org.drools.builder.ResourceType;import org.drools.io.ResourceFactory;import org.drools.runtime.StatefulKnowledgeSession;SuppressWarnings(restriction)public class CalculationDrl static Lo

11、gger logger = Logger.getLogger(CalculationDrl.class); public static void main(String args) logger.info(开始); KnowledgeBuilder kBuilder=KnowledgeBuilderFactory.newKnowledgeBuilder();/规则生成器:将编写好的规则进行编译 kBuilder.add(ResourceFactory.newClassPathResource(calculation.drl, CalculationDrl.class), ResourceTyp

12、e.DRL);/添加规则到规则生成其中进行编译 KnowledgeBase kBase=kBuilder.newKnowledgeBase();/收集应用当中的知识定义知识库对象 kBase.addKnowledgePackages(kBuilder.getKnowledgePackages();/添加规则包 StatefulKnowledgeSession session=kBase.newStatefulKnowledgeSession();/与规则的交互通道 Calculation cal=new Calculation(10000);/输入当月工资 session.setGlobal(

13、cal, cal); session.insert(cal);/将对象添加到交互通道中 session.fireAllRules();/执行规则 session.dispose();/释放资源 System.out.println(cal.toString(); logger.info(结束); 2.1.4calculation.xls2.1.5CalculationXls.javapackage com.flagleader.bean;import org.apache.log4j.Logger;import org.drools.KnowledgeBase;import org.drool

14、s.builder.DecisionTableConfiguration;import org.drools.builder.DecisionTableInputType;import org.drools.builder.KnowledgeBuilder;import org.drools.builder.KnowledgeBuilderFactory;import org.drools.builder.ResourceType;import org.drools.io.ResourceFactory;import org.drools.runtime.StatefulKnowledgeSe

15、ssion;SuppressWarnings(restriction)public class CalculationXls static Logger logger = Logger.getLogger(CalculationDrl.class); public static void main(String args) logger.info(开始); DecisionTableConfiguration dtc=KnowledgeBuilderFactory.newDecisionTableConfiguration(); dtc.setInputType(DecisionTableIn

16、putType.XLS); KnowledgeBuilder builder=KnowledgeBuilderFactory.newKnowledgeBuilder(); builder.add(ResourceFactory.newClassPathResource(com/flagleader/bean/calculation.xls, CalculationXls.class),ResourceType.DTABLE,dtc); KnowledgeBase base=builder.newKnowledgeBase(); base.addKnowledgePackages(base.ge

17、tKnowledgePackages(); StatefulKnowledgeSession session=base.newStatefulKnowledgeSession(); Calculation cal=new Calculation(10000,6500.0); session.insert(cal); session.fireAllRules(); session.dispose();/释放资源 logger.info(结束); 2.1.6GenerationRules.javapackage com.flagleader.bean;import java.io.*;import

18、 org.drools.decisiontable.InputType;import org.drools.decisiontable.SpreadsheetCompiler;import org.junit.Test;public class GenerationRules Test public void compile() throws FileNotFoundException File file = new File( E:qzxx_workspacecalculationsrcmainjavacomflagleaderbeancalculation.xls); InputStrea

19、m is = new FileInputStream(file); SpreadsheetCompiler converter = new SpreadsheetCompiler(); String drl = pile(is, InputType.XLS); System.out.println(nn + drl); 2.1.7calculations.drlpackage com.flagleader.bean /generated from Decision Tableimport com.flagleader.bean.Calculation;import java.lang.Obje

20、ct;function double getCes(double cess) /System.out.println(cess=+cess); return cess; function double getPre(double preminus) /System.out.println(preminus=+preminus); return preminus; global Calculation cal;rule 全月应纳税额no-loop truesalience 65526 when $cal : Calculation(wage0) then System.out.println(-

21、全月应纳税额-); cal.setWagemore(cal.getWage()-3500); update(cal);end/ rule values at D11, header at D6rule test_11 salience 65525 when Calculation(wagemore0,wagemore1500,wagemore4500,wagemore9000,wagemore35000,wagemore55000,wagemore80000,wagemore=100000) then cal.setCess(getCes(0.45); cal.setPreminus(getP

22、re(13505.00); insert(cal);endrule 税后工资salience 65518 when eval(true) then System.out.println(-税后工资-+cal.getCess(); cal.setWageminus(cal.getWagemore()*cal.getCess()-cal.getPreminus(); cal.setActualwage(cal.getWage()-cal.getWageminus(); insert(cal);end2.1.8CalculationDrlXls.javapackage com.flagleader.

23、bean;import org.apache.log4j.Logger;import org.drools.KnowledgeBase;import org.drools.builder.KnowledgeBuilder;import org.drools.builder.KnowledgeBuilderFactory;import org.drools.builder.ResourceType;import org.drools.io.ResourceFactory;import org.drools.runtime.StatefulKnowledgeSession;SuppressWarn

24、ings(restriction)public class CalculationDrlXls static Logger logger = Logger.getLogger(CalculationDrlXls.class); public static void main(String args) logger.info(开始); KnowledgeBuilder kBuilder=KnowledgeBuilderFactory.newKnowledgeBuilder();/规则生成器:将编写好的规则进行编译 kBuilder.add(ResourceFactory.newClassPathResource(calculations.drl, CalculationDrlXls.class), ResourceType.DRL);/添加规

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1