如何检查 Drools 模板中的变量是否为空

How to check if variable empty in Drools Templates

我正在使用 Drools 模板从电子表格生成规则。 我对空单元格有一些问题。 有人知道如何检查单元格或变量是否为空吗? 这是模板:

template header
pid
department
maxAmount
storeId

package X.X.X

declare MaxAmountStore
    amount : Integer    
    storeId : String
end

template "FOO"
rule "MaxAmountStore_@{row.rowNumber}"
        when
            Product(pid == "@{pid}")
            Product(departmentId == "@{department}")
        then
            System.out.println("New MaxAmountStore: @{maxAmount} (store: @{storeId})");
            insert( new MaxAmountStore(@{maxAmount}, "@{storeId}"));
    end
end

是否可以有一个空的storeId?

我认为您需要这个:如果单元格中没有任何内容,您不关心 departmentId 值并且只想触发基于 pid 的规则。

template "FOO"
rule "MaxAmountStore_@{row.rowNumber}"
when
    Product( pid == "@{pid}"&& 
             ("" == "@{department}" || departmentId == "@{department}") )
then
    ...
end