[英]How to set the default value if no conditions apply in drools decision table?
I am working with drools 7.69.0,我正在使用流口水 7.69.0,
My purpose is to convert the below condition into a decision table at firstly,我的目的是首先将以下条件转换为决策表,
Stream.of(usecase1, usecase2, usecase3, usecase4).collect(Collectors.toSet()).contains(statusRequest.getUseCase())
|| (usecase6 == statusRequest.getUseCase() && aspect == statusRequest.getAspect())
|| (usecase5 != statusRequest.getUseCase() && statusRequest.isCorrection())
So how to apply default action if none of the conditions are applied?那么如果没有应用任何条件,如何应用默认操作呢?
There are two ways to do a "default" value:有两种方法可以设置“默认”值:
In a decision table, #1 is easiest if you have Sequential set to TRUE in the Rule Set area.在决策表中,如果您在 Rule Set 区域中将 Sequential 设置为 TRUE,则 #1 是最简单的。 Default your "default case" rule in the first row, so it fires first.
在第一行默认您的“默认情况”规则,因此它首先触发。 Give it no conditions, so it always triggers.
不给它任何条件,所以它总是触发。
It would look something like this:它看起来像这样:
The second is also possible, but for it to work you need to be able key off of something that all of the other "real" rules will cause to no longer be valid.第二个也是可能的,但要让它工作,你需要能够关闭所有其他“真实”规则将导致不再有效的东西。
In your case, all of your "real" rules are setting a value on the 'status' field of the model.在您的情况下,您所有的“真实”规则都在模型的“状态”字段上设置一个值。 Therefore, it stands to reason that if there is no value set on that field, we can set our default value.
因此,按理说,如果该字段上没有设置值,我们可以设置我们的默认值。
This will require two things:这将需要两件事:
modify
so that the results are visible to the conditional checksmodify
,以便条件检查可以看到结果 The cool thing about this version is that it doesn't rely on rule order, so you don't need to set the Sequential property, and it also simply doesn't matter when the rule fires.这个版本很酷的一点是它不依赖于规则顺序,所以你不需要设置 Sequential 属性,而且规则何时触发也无关紧要。 If the rule fires first, cool: the "real" rules will simply overwrite the value.
如果规则首先触发,很酷:“真正的”规则将简单地覆盖该值。 If it fires last, also cool;
如果它最后着火,也很酷; that means that none of the other rules fired.
这意味着没有触发其他规则。 Somewhere in the middle?
中间的某个地方? Still fine!
还是不错的! Since none of the other rules care about the value of status, it doesn't matter when the rule fires as long as it fires only when the status is null.
由于其他规则都不关心状态的值,因此规则何时触发并不重要,只要它仅在状态为空时触发即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.