Drools'Like'条件 - 是否存在?

时间:2017-10-24 15:23:16

标签: drools

我是drools的新手,并尝试搜索API文档,但找不到有关比较关键字'LIKE'的任何信息。我已成功使用&lt ;,>,< =,> =,==,!=创建规则,但现在我正在尝试使用“LIKE”关键字创建规则。老年人告诉我,它应该像SQL一样像关键字一样工作。以下是我在drl文件中的规则,但是我在规则5495Y中收到错误输入“LIKE”的错误

使用drools 5.6.0

**From DRL File:**
rule "5495Y"
agenda-group "1"
date-effective "04-Sep-2017"
when
JournalEntry : JournalEntry( (ledgerCd=="COMN") && accountNumber LIKE 1234 
&& entryTypeCode == "Y" );
DroolsUtil : DroolsUtil(  );
then
JournalEntry.addConsequence("rejectReason","kk like test");
JournalEntry.addConsequence("sendToLedger","N");
DroolsUtil.reclassEntry(JournalEntry,"NOCHG", "5495Y");
end

**Exact Error I am getting:**
[38583,71]: [ERR 102] Line 38583:71 mismatched input 'LIKE' in rule "5495R"
[38596,71]: [ERR 102] Line 38596:71 mismatched input 'LIKE' in rule "5495Y"
[0,0]: Parser returned a null Package

11:09:17,118 ERROR main ReclassAccountingRuleJob:132 - java.lang.Exception: Know
ledgeBuilder has errors. DRL File parsing error
java.lang.Exception: KnowledgeBuilder has errors. DRL File parsing error

1 个答案:

答案 0 :(得分:0)

对于String类型属性,Drools支持正则表达式匹配(比SQL中的LIKE运算符强大得多):

rule "5495Y"
when
    JournalEntry : JournalEntry(
        ledgerCd == "COMN",
        accountNumber matches ".*1234.*", //accountNumber must be of type String. Otherwise, you will need to convert it first.
        entryTypeCode == "Y" 
    )
    DroolsUtil : DroolsUtil(  )
then
    ...
end

有关matches运算符的详细信息,请参阅文档的this section

希望它有所帮助,