Drools:在多次执行后停止触发规则
我想知道如何阻止一条规则在多次执行后被触发。 比如说,如果您购买了一件物品X(当前价格为10美元),您会给予折扣,但每位客户只能享受2次折扣 因此,我的规则如下:Drools:在多次执行后停止触发规则,drools,Drools,我想知道如何阻止一条规则在多次执行后被触发。 比如说,如果您购买了一件物品X(当前价格为10美元),您会给予折扣,但每位客户只能享受2次折扣 因此,我的规则如下: rule "Fixed Price Promotion Item X" when $o : Order( ) $ol1 : OrderLine( item.code == "X" ) then FixedPrice fixedPrice = new FixedPrice(8.80, $ol1.get
rule "Fixed Price Promotion Item X"
when
$o : Order( )
$ol1 : OrderLine( item.code == "X" )
then
FixedPrice fixedPrice = new FixedPrice(8.80, $ol1.getItem().getPrice().doubleValue(), $ol1.getItem().getBarcode(), 1, "e78fbca5ed014f49806ad667aea80965" , "Happy Mother's day!! This is a fixed price promotion" );
insertLogical (fixedPrice); //here I grant a promotion
最初,我想有另一个规则,在我的条件满足时插入一个事实,这样可以阻止我的晋升规则被解雇
我想要这样的东西:
declare LimitReachedOut
promotionId : String
end
rule "stop Promotion"
when
Number($numOfGrantedProm : intValue) from accumulate (
FixedPrice(promotionId == "123",
$count: quantity),
sum($count)
)
then
if( $numOfGrantedProm == 2 ){ //this cause an issue, even > 1 or >=2 will keep inserting new LimitReachedOut("123") recursively.
insertLogical (new LimitReachedOut("123"));
}
end
rule "Fixed Price Promotion Item X"
when
not( LimitReachedOut( promotionId == "123" ) )
$o : Order( )
$ol1 : OrderLine( item.code == "X" )
then
FixedPrice fixedPrice = new FixedPrice(8.80, $ol1.getItem().getPrice().doubleValue(), $ol1.getItem().getBarcode(), 1, "123" , "Happy Mother's day!! This is a fixed price promotion" );
insertLogical (fixedPrice);
end
还有别的办法吗
我将非常感谢您的评论。我已经找到了一种实现我想要的方法,如果有人想使用它,我将把它发布在这里。 我基本上不是在执行规则的RHS,而是在那里放一个条件子句 首先,我正在使用累积函数计算插入到工作内存中的事实数量(FixedPrice,其id名为ruleId,用于将事实链接到此特定规则)。 其次,RHS if($numOfGrantedProm<2)中的条件意味着我将在条件if(创建和插入fixedPrice事实)中执行块最多两次。 无论如何都会触发规则,但if条件将避免执行代码块
rule "Fixed Price Promotion Item X"
when
$o : Order( )
$ol1 : OrderLine( item.code == "X" )
Number($numOfGrantedProm : intValue) from accumulate (
FixedPrice(ruleId ==
"e78fbca5ed014f49806ad667aea80965",$count:quantity),
sum($count)
)
then
if( $numOfGrantedProm < 2 ){
FixedPrice fixedPrice = new FixedPrice(8.80,
$ol1.getItem().getPrice().doubleValue(),
$ol1.getItem().getBarcode(),
1,
"e78fbca5ed014f49806ad667aea80965" ,
"Happy Mother's day!! This is a fixed price
promotion" );
insertLogical (fixedPrice); //here I grant a promotion enter code here
}
end
规则“固定价格促销项目X”
什么时候
$o:订单()
$ol1:订单行(item.code==“X”)
累积(
固定价格(规则ID==
“e78fbca5ed014f49806ad667aea80965”,美元计数:数量),
总数($计数)
)
然后
如果($numograntedprom<2){
固定价格固定价格=新固定价格(8.80,
$ol1.getItem().getPrice().doubleValue(),
$ol1.getItem().getBarcode(),
1.
“e78fbca5ed014f49806ad667aea80965”,
“母亲节快乐!!这是固定价格
晋升);;
insertLogical(fixedPrice);//在这里我授予一次促销,在这里输入代码
}
结束