五、规则文件及规则流
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,表示当且进当上述规则组均执行完毕后,才执行后面的规则或进程。