当前位置: 首页 > 知识库问答 >
问题:

Drools@Watch不使用代码中的累加

屠君墨
2023-03-14

我使用的是Drools 7.6,出于某种原因,当只有unwatched属性发生更改时,@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个答案

宣俊豪
2023-03-14

“from”不是被动的,因此它无法对任何修改更改作出反应。

劳仲渊
2023-03-14

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

 类似资料:
  • 我的老师想要一个程序向用户询问一个正整数值,程序应该循环得到从1到输入的数字的所有整数的总和。使用Python进行循环。 这是我为for循环所做的,但当我输入负数时它不会循环,当我输入负数后输入正数时它不会显示答案。 帮忙?

  • 问题内容: 我遇到这种奇怪的行为,但无法解释。这些是基准: 与使用变量分配进行比较,为什么比使用带有临时变量的班轮快27%以上呢? 通过Python文档,垃圾回收在timeit期间被禁用,因此并非如此。这是某种优化吗? 结果也可以在Python 2.x中重现,尽管程度较小。 运行Windows 7,CPython 3.5.1,Intel i7 3.40 GHz,64位OS和Python。似乎我尝试

  • 本文向大家介绍Linux watch命令的使用,包括了Linux watch命令的使用的使用技巧和注意事项,需要的朋友参考一下 1.命令简介 watch 命令以周期性的方式执行给定的命令,并全屏显示执行结果。 watch 是一个非常实用的命令,基本所有的 Linux 发行版都带有。如同名字一样,watch 可以帮助监测一个命令的运行结果,省得我们一遍遍地手动运行。比如 tail 一个 log 文件

  • 示例程序 本书所有示例程序都基于Go编写,代码托管到GitHub。 每章的示例都是可直接运行的Go源文件,例如第一章的Hellow World程序可以通过go run hello_world.go来运行并查看运行结果。 # go run hello_world.go Hello World 接下来介绍使用Docker来运行本书的示例程序。

  • 线程“main”java.lang.UnsatifiedLinkError:查找函数“StartConector”时出错:找不到指定的过程。在com.sun.jna.function.(function.java:179)在com.sun.jna.nativelibrary.getfunction(nativelibrary.java:350)在com.sun.jna.nativelibrary.

  • 常见配置 自动保存: "files.autoSave": "onFocusChange" 参考链接:https://blog.csdn.net/WestLonly/article/details/78048049 在新的窗口中打开文件: "workbench.editor.enablePreview": false, 常见操作 如何查看代码结构 方法一:「Cmd + Shift + O」 方法二