Drools @Watch 无法在代码中使用 accumulate
Drools @Watch not working with accumulate in code
我正在使用 Drools 7.6,出于某种原因,当只有未监视的 属性 发生变化时,@watch 不会阻止规则重新激活自身或其他规则。这会导致无限循环。
有人能找出我做错了什么吗?
规则:
package com.model
import com.model.*;
import java.util.List;
rule "10% for 15 High-range Items"
when
$o: Order($lines: orderLines) @watch(!discount)
Number(intValue >= 15) from accumulate(
OrderLine($item: item, $q: quantity) from $lines and
Item(category == Item.Category.HIGH_RANGE) from $item,
sum($q)
)
then
modify($o) {increaseDiscount(0.10)}
end
使用的模型来自 Mastering JBoss Drools 一书。增加折扣的方法已经用@Modifes注解了。顺序 class:
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
private Long orderId;
private Date date;
private Customer customer;
private List<OrderLine> orderLines = new ArrayList<>();
private Discount discount;
public Order() {
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public List<OrderLine> getOrderLines() {
return orderLines;
}
public void setItems(List<OrderLine> orderLines) {
this.orderLines = orderLines;
}
public double getTotal() {
return this.getOrderLines().stream()
.mapToDouble(item -> item.getItem().getSalePrice() * item.getQuantity())
.sum();
}
public int getTotalItems() {
return this.getOrderLines().stream()
.mapToInt(item -> item.getQuantity())
.sum();
}
@Modifies({"discount"})
public void increaseDiscount(double increase) {
if (discount == null) {
discount = new Discount(0.0);
}
discount.setPercentage(discount.getPercentage() + increase);
}
public Discount getDiscount() {
return discount;
}
public double getDiscountPercentage() {
return discount.getPercentage();
}
public void setDiscount(Discount discount) {
this.discount = discount;
}
}
'from' 不是反应性的,因此它无法对任何修改做出反应。
我在这里 https://issues.jboss.org/browse/DROOLS-2427 报告了这个问题,并且已经在 Drools master 分支上推送了修复。感谢您报告此事。
我正在使用 Drools 7.6,出于某种原因,当只有未监视的 属性 发生变化时,@watch 不会阻止规则重新激活自身或其他规则。这会导致无限循环。
有人能找出我做错了什么吗?
规则:
package com.model
import com.model.*;
import java.util.List;
rule "10% for 15 High-range Items"
when
$o: Order($lines: orderLines) @watch(!discount)
Number(intValue >= 15) from accumulate(
OrderLine($item: item, $q: quantity) from $lines and
Item(category == Item.Category.HIGH_RANGE) from $item,
sum($q)
)
then
modify($o) {increaseDiscount(0.10)}
end
使用的模型来自 Mastering JBoss Drools 一书。增加折扣的方法已经用@Modifes注解了。顺序 class:
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
private Long orderId;
private Date date;
private Customer customer;
private List<OrderLine> orderLines = new ArrayList<>();
private Discount discount;
public Order() {
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public List<OrderLine> getOrderLines() {
return orderLines;
}
public void setItems(List<OrderLine> orderLines) {
this.orderLines = orderLines;
}
public double getTotal() {
return this.getOrderLines().stream()
.mapToDouble(item -> item.getItem().getSalePrice() * item.getQuantity())
.sum();
}
public int getTotalItems() {
return this.getOrderLines().stream()
.mapToInt(item -> item.getQuantity())
.sum();
}
@Modifies({"discount"})
public void increaseDiscount(double increase) {
if (discount == null) {
discount = new Discount(0.0);
}
discount.setPercentage(discount.getPercentage() + increase);
}
public Discount getDiscount() {
return discount;
}
public double getDiscountPercentage() {
return discount.getPercentage();
}
public void setDiscount(Discount discount) {
this.discount = discount;
}
}
'from' 不是反应性的,因此它无法对任何修改做出反应。
我在这里 https://issues.jboss.org/browse/DROOLS-2427 报告了这个问题,并且已经在 Drools master 分支上推送了修复。感谢您报告此事。