Drools @Watch无法使用代码中的累积

时间:2018-03-26 22:31:38

标签: jboss drools jbpm

我正在使用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注释。订单类:

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;
    }


}

2 个答案:

答案 0 :(得分:1)

我在这里报告了问题https://issues.jboss.org/browse/DROOLS-2427并且已经在Drools master分支上推出了修复程序。谢谢你报告了这个。

答案 1 :(得分:0)

&#39;从&#39;不是反应性的,所以它不能对任何修改变化做出反应。