异常 "Unable to resolve ObjectType 'getAmount' "

Exception "Unable to resolve ObjectType 'getAmount' "

在 Drools 中,我创建了一个包含以下内容的 drl 文件:

import com.myorg.model.UserAccount;
import function com.myorg.utils.UserAccountHelper.getAmount;

rule "Classification userC"
when
    $user : UserAccount(_age < 50);
    $amount: getAmount($user, "single");
then
    $user.set_userClassification("userC");    
end

在Java中我有一个静态方法UserAccountHelper.getAmount

public static double getAmount(UserAccount account, String status)
{
   double amount = 0d;
   switch(status)
   {
      case "single":
         if (account.canBeFullyRefunded)
            amount = 1000;
         else
            amount = 100;
      default:
         amount = 0d;
   }
   return amount;
}

我在验证 drl file.Someone 时收到异常“无法解析 ObjectType 'getAmount'” 有帮助吗? 我正在使用 Drools 7.37。

这不是您在 DRL 中调用 class 静态方法的方式。我建议您查看文档以更好地理解语法。

如果你想调用模式中的静态(或实例)方法,你可以这样做:

rule "Classification userC"
when
    $user : UserAccount(
        _age < 50, 
        $amount: getAmount(this, "single")
    )
then
    $user.set_userClassification("userC");    
end