在 drools 5.x 中执行多个规则

发布于 2024-12-05 19:11:11 字数 999 浏览 0 评论 0原文

我对流口水有点陌生。我的 drl 文件中有 2 条规则,即 DateYYYYMMDD 和 TotalChargesAndTax 。我使用以下语法从我的 main 方法执行 2 条规则。

    Command<?> syntacticValidation = new FireAllRulesCommand(
                    new RuleNameEqualsAgendaFilter("DateYYYYMMDD"));                
            Command<?> semanticValidation = new FireAllRulesCommand(
                new RuleNameEqualsAgendaFilter("TotalChargesAndTax"));

            List<Command> commands = new ArrayList<Command>();
            commands.add(semanticValidation);
            commands.add(syntacticValidation);

            session.execute(CommandFactory
                    .newBatchExecution(commands));

但是,当我运行应用程序时,仅执行 TotalChargesAndTax 规则,而跳过 DateYYYYMMDD 规则。如果我交换 ArayList 中命令对象的位置(如下所示),

    commands.add(syntacticValidation);
    commands.add(semanticValidation);

则执行 DateYYYYMMDD 规则并跳过 TotalChargesAndTax 规则。有没有办法同时执行这两个规则并执行这两个规则的结果?到目前为止,仅执行一个结果,具体取决于数组列表中第一个命令。

I am a bit new to drools. I have 2 rules namely DateYYYYMMDD and TotalChargesAndTax in my drl file. I am using the following syntax to execute the 2 rules from my main method.

    Command<?> syntacticValidation = new FireAllRulesCommand(
                    new RuleNameEqualsAgendaFilter("DateYYYYMMDD"));                
            Command<?> semanticValidation = new FireAllRulesCommand(
                new RuleNameEqualsAgendaFilter("TotalChargesAndTax"));

            List<Command> commands = new ArrayList<Command>();
            commands.add(semanticValidation);
            commands.add(syntacticValidation);

            session.execute(CommandFactory
                    .newBatchExecution(commands));

But when I run my application, only the TotalChargesAndTax rule is executed and the DateYYYYMMDD rule is skipped. If I interchange the position of the command objects in the ArayList as shown below,

    commands.add(syntacticValidation);
    commands.add(semanticValidation);

then the DateYYYYMMDD rule is executed and the TotalChargesAndTax rule is skipped. Is there a way to execute both the rules and execute the consequence of both the rules? As of now, only one consequence is executed depending on which command is first in the array list.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金兰素衣 2024-12-12 19:11:11

当您编写规则时,您无法确定必须触发哪个规则。规则引擎将根据您在知识会话中插入的事实/pojo 选择规则。我建议您不要使用议程过滤器来尝试强制执行规则。如果您插入的对象与规则条件端 (WHEN) 匹配,则将自动执行多个规则。
如果您想分享您的规则,我们可以为您提供帮助。
干杯

When you write rules you cannot say which rule must fire. Rules will be picked by the rule engine based on the facts/pojos that you insert in your knowledge session. I recommend you to not use Agenda filters to try to force rules execution. Multiple rules will be executed automatically if the objects that you insert match with your rules conditional side (WHEN).
If you want to share how your rules looks like we can help you.
Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文