Java Drools5.1 规则流基础【示例】(中)


             五、规则文件及规则流

 

              EduInfoRule.drl: 

复制代码
package myrules;
import sample.Employ;
 
rule"Bachelor"
      ruleflow-group"basic_salary"
when
   emp:Employ(eduInfo =="bachelor");
then
   System.out.println("execrule Bachelor ... ");
   emp.setBasicSalary(1500);
end

rule"Master"
      ruleflow-group"basic_salary"
when
   emp:Employ(eduInfo=="master")
then
   System.out.println("execrule Master ... ");
   emp.setBasicSalary(2500);
end
复制代码
             

Resume.drl

复制代码
package myrules
import sample.Employ;

rule"Technician"
       ruleflow-group"duty_salary"
when
   emp:Employ(resume=="tech")
then
   System.out.println("execrule Technician ... ");
  emp.setDutySalary(2000);
end

rule"Manager"
      ruleflow-group"duty_salary"
when
   emp:Employ(awardPunish=="manager")
then
   System.out.println("execrule manager ... ");
   emp.setDutySalary(4500);
end
复制代码

              

BonusRule.drl               

复制代码
package myrules
import sample.Employ;

rule"Excellent"
      ruleflow-group"bonus_salary"
when
  emp: Employ(annualExam=="excellent")
then
   System.out.println("execrule Excellent ... ");
  emp.setBonus(1000*1.0);
end

rule"Good"
       ruleflow-group"bonus_salary"
when
  emp: Employ(annualExam=="good")
then
   System.out.println("execrule Good ... ");
  emp.setBonus(1000*0.9);
end

rule"Common"
      ruleflow-group"bonus_salary"
when
  emp: Employ(annualExam=="common")
then
   System.out.println("execrule Common ... ");
  emp.setBonus(1000*0.6);
end

rule"failing"
       ruleflow-group"bonus_salary"
when
  emp: Employ(annualExam=="failing")
then
   System.out.println("execrule failing ... ");
  emp.setBonus(1000*0.0);
end
复制代码

 AwardPunish.drl      

复制代码
packagemyrules
importsample.Employ;

rule"Award"
       ruleflow-group"award_punish"
when
   emp:Employ(awardPunish=="award")
then
   System.out.println("execrule Award ... ");
  emp.setPercent(1.10);
end

rule"Punishment"
       ruleflow-group"award_punish"
when
   emp:Employ(awardPunish=="punish")
then
   System.out.println("execrule Punishment ... ");
  emp.setPercent(0.90);
end

rule"None"
      ruleflow-group"award_punish"
when
   emp:Employ(awardPunish=="none")
then
   System.out.println("execrule None ... ");
  emp.setPercent(1.00);
end
复制代码

 

              TotalRule.drl   

复制代码
package myrules
import sample.Employ;

rule"Total"
  ruleflow-group"sum_salary"
when
   emp: Employ()
then
   System.out.println("execrule Total ... ");
   double total =emp.getBasicSalary() + emp.getDutySalary() +
                 emp.getBonus();                               
   emp.setTotalSalary(total*emp.getPercent());
end
复制代码

 

               创建规则流文件simple.rf:

            

      注意:

       [1]Split结点类型为OR,约束选择alwaystrue.表示选择其规则组中所有符合事实的规则进行并发执行;

       [2] Join结点类型为AND,表示当且进当上述规则组均执行完毕后,才执行后面的规则或进程。

 

 


 

 

作者:@琴水玉

转载请注明出处:https://www.cnblogs.com/lovesqcc/archive/2011/01/18/4037862.html

微信扫一扫下面的二维码,关注我的公众号 编程大观园 :)


 
posted @   琴水玉  阅读(664)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示