专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

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:

113006_1307167542JRzE.png

注意:

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

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

46_1.png

文章永久链接:https://tech.souyunku.com/20875

未经允许不得转载:搜云库技术团队 » Java Drools5.1 规则流基础【示例】(中)

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们