关于Drools 规则问题,求助帖!!啊

chocolatedo 2018-10-11 10:14:04
一、这是我定义的规则,当我传入yearlySalary =1000000时,规则 7~2都会执行, 规则项rule "1" 不会执行,但是当我传入yearlySalary =36000时,规则rule "1" 就会执行,我想请教一下,为什么我传入yearlySalary =1000000, 规则项rule "1" 不会执行。

package rules
import com.ratepaying.person.entity.User
dialect "mvel"

rule "7"
no-loop true
lock-on-active true
salience 8
when
$s : User(yearlySalary - 960000.00 > 0)
then
$s.setExpenses($s.getExpenses()+($s.getYearlySalary()-960000.00)*0.45);
System.out.println($s.toString()+" "+($s.getYearlySalary()-960000.00)*0.45+" 7");
$s.setYearlySalary(960000.00);
update($s);
end

rule "6"
no-loop true
lock-on-active true
salience 7
when
$s : User(yearlySalary - 660000.00 > 0)
then
$s.setExpenses($s.getExpenses()+($s.getYearlySalary()-660000.00)*0.35);
System.out.println($s.toString()+" "+($s.getYearlySalary()-660000.00)*0.35+" 6");
$s.setYearlySalary(660000.00);
update($s);
end

rule "5"
no-loop true
lock-on-active true
salience 6
when
$s : User(yearlySalary - 420000.00 > 0)
then
$s.setExpenses($s.getExpenses()+($s.getYearlySalary()-420000.00)*0.30);
System.out.println($s.toString()+" "+($s.getYearlySalary()-420000.00)*0.30+" 5");
$s.setYearlySalary(420000.00);
update($s);
end

rule "4"
no-loop true
lock-on-active true
salience 5
when
$s : User(yearlySalary - 300000.00 > 0)
then
$s.setExpenses($s.getExpenses()+($s.getYearlySalary()-300000.00)*0.25);
System.out.println($s.toString()+" "+($s.getYearlySalary()-300000.00)*0.25+" 4");
$s.setYearlySalary(300000.00);
update($s);
end

rule "3"
no-loop true
lock-on-active true
salience 4
when
$s : User(yearlySalary - 144000.00 > 0)
then
$s.setExpenses($s.getExpenses()+($s.getYearlySalary()-144000.00)*0.20);
System.out.println($s.toString()+" "+($s.getYearlySalary()-144000.00)*0.20+" 3");
$s.setYearlySalary(144000.00);
update($s);
end

rule "2"
no-loop true
lock-on-active true
salience 3
when
$s : User(yearlySalary - 36000.00 > 0)
then
$s.setExpenses($s.getExpenses()+($s.getYearlySalary()-36000.00)*0.10);
System.out.println($s.toString()+" "+($s.getYearlySalary()-36000.00)*0.10+" 2");
$s.setYearlySalary(36000.00);
update($s);
end



rule "1"
no-loop false //当前的规则只要满足条件,可以无限次执行
lock-on-active true //只执行一次
salience 2
when
$s : User(yearlySalary <= 36000.00 && yearlySalary >0 )
then
$s.setExpenses($s.getExpenses()+$s.getYearlySalary()*0.03);
System.out.println($s.toString()+" "+$s.getYearlySalary()*0.03+" 1");
$s.setYearlySalary(0.00);
update($s);
end

二 、controller
package com.ratepaying.person.controller;

import com.ratepaying.person.entity.User;
import com.ratepaying.person.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* Good Good Study Day Day Up !!!
*/
@RestController
@RequestMapping("/ratePaying")
public class RatePayingController {

@Autowired
private PersonService personService;

@RequestMapping("/expenses/{yearlySalary}")
public User getExpenses(@PathVariable("yearlySalary") Double yearlySalary) {

return personService.getExpenses(yearlySalary);
}
}

三、service
package com.ratepaying.person.service.impl;

import com.ratepaying.person.entity.User;
import com.ratepaying.person.service.PersonService;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.stereotype.Service;

/**
* Good Good Study Day Day Up !!!
*/
@Service
public class PersonServiceImpl implements PersonService {
@Override
public User getExpenses(Double yearlySalary) {

KieServices ks = KieServices.Factory.get();
KieContainer kc = ks.getKieClasspathContainer();

KieSession ksession = kc.newKieSession("ratePaying-rules");

User user = new User("小明", yearlySalary, 0.0);

ksession.insert(user);
ksession.fireAllRules(); //执行规则
//ksession.dispose();

return user;
}
}
四、kmodule.xml
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="rule1" packages="rules">
<ksession name="ratePaying-rules"/>
</kbase>
</kmodule>
...全文
228 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoujiuw 2019-01-05
  • 打赏
  • 举报
回复
when $s : User(yearlySalary <= 36000.00 && yearlySalary >0 ) then =========== yearlySalary =1000000不满足rule1的条件,不执行是对的吧
zhoujiuw 2019-01-05
  • 打赏
  • 举报
回复
when $s : User(yearlySalary <= 36000.00 && yearlySalary >0 ) then
chocolatedo 2018-10-12
  • 打赏
  • 举报
回复
这个回答让我猝不及防
老王就是我 2018-10-11
  • 打赏
  • 举报
回复
我觉得你这不是java

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧