drools - 具有多个条件的数组列表访问

drools - arraylist access wth multiple condition

我有一个对象 A,其中包含对象 B 的列表。

Class A{
    List<B> bList;
}

Class B{
    String code;//Values QT1,QT2.....QT5
    Boolean answer;
}

B就像一个问卷对象。 A hold all questionares,总会有5个问题(将来可能会增加)QT1到QT5,答案为真、假或空。 当任何 QTx 答案为空或 QT1、QT2 为真时,我需要触发逻辑。我已经实施如下但它不工作。这有什么问题吗?

rule "validateQuestions"
ruleflow-group "validate"
dialect "mvel"
when
    $a : A(bList.empty == false)
    B(code == "QT1",answer == true) from $a.bList
    B(code == "QT2",answer == true) from $a.bList
    B(code == "QT3",answer == null) from $a.bList
    B(code == "QT4",answer == null) from $a.bList
    B(code == "QT5",answer == null) from $a.bList
then
    //("Logic Here")

总会有 5 个 QTx,这可以是答案的任意组合,真假或空值。

rule "validateQuestions"
when
    $a: A()
    B( code in ("QT1", "QT2") && answer == true ||
       code in ("QT3", "QT4", "QT5") && answer == null ) from $a.bList
then

您不需要测试 List.empty。

请务必阅读有关规则的 when 部分中 "pattern" 语义的文档 - 我不会重复所有内容(绑定事实、隐含连词...)这里。此外,请查看有关约束运算符(&&、||、in、not in、...)的文档。