繁体   English   中英

Drools:规则编译错误-无法解析为变量

[英]Drools: Rule Compilation error - cannot be resolved to a variable

我在编写流口水的简单规则时遇到了麻烦。 我已经分析了代码,无法找出问题所在。 它可能与条件“或”有关。

rule "Generic AC1" 
    when 
        $product : Product(canonicalId == "Product AC1") from listOfCompatibleProducts 
        or DateRangeValidator($verifyDate : validationDate, ($verifyDate.compareTo(DateUtils.parseDate("1970-01-01 01:00:00.000")) < 1) || ($verifyDate.compareTo(DateUtils.parseDate("4892-10-07 22:52:48.547")) > 0)) 
    then 
        System.out.println("DEBUG: ENGINE has fired Generic AC1"); 
        listOfCompatibleProducts.remove($product); 
end; 

我收到以下错误:

One or more rules are invalid: 
ERROR - Rule Compilation error $product cannot be resolved to a variable

事实是,Drools会将您的or分成两个独立的规则:

rule "Generic AC1 1" 
    when 
        $product : Product(canonicalId == "Product AC1") from listOfCompatibleProducts         
    then 
        System.out.println("DEBUG: ENGINE has fired Generic AC1"); 
        listOfCompatibleProducts.remove($product); 
end

rule "Generic AC1 2" 
    when 
        DateRangeValidator($verifyDate : validationDate, ($verifyDate.compareTo(DateUtils.parseDate("1970-01-01 01:00:00.000")) < 1) || ($verifyDate.compareTo(DateUtils.parseDate("4892-10-07 22:52:48.547")) > 0)) 
    then 
        System.out.println("DEBUG: ENGINE has fired Generic AC1"); 
        listOfCompatibleProducts.remove($product); 
end; 

如您所见,在第二条规则的RHS中,您尝试使用的LHS中未定义的$product变量。

希望能帮助到你,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM