Drools 5 - 日期比较
Drools 5 - Date comparison
我正在尝试将 Java class 函数日期与当前日期进行比较。我需要验证 Java class 日期(CreationDate 函数)应该比当前日期早 [3 个月]。
JAVA -
public class PersonPer
....
public Date getCreationDate() {
return creationDate == null ? null : new Date(creationDate.getTime());
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate == null ? null : new Date(creationDate.getTime());
}
.....
用于测试的 Junit -
PersonPer personPer=new PersonPer();
String personCdate="15/12/1998";
Date personCreationDate = null;
try {
personCreationDate=new SimpleDateFormat("dd/MM/yyy").parse(personCdate);
System.out.println("Junit Test personCreationDate : "+ personCreationDate);
} catch (ParseException e) {
System.err.println("Date parsing exception");
e.printStackTrace();
}
personPer.setCreationDate(personCreationDate);
session.insert(personPer);
DRL -
规则 "Person check"
pp: PersonPer(pCreationDate:CreationDate)
....
when:
...
(
...
Date($now : time) from Calendar.getInstance().getTime()
pp: PersonPer(pCreationDate:CreationDate after[90] $now) <--- This doesn't work
...
Then:
System.out.println("Person date : " + pCreationDate);
drools.addError(...);
END
12:32:55 ERROR Error: [ERR 102] Line 141:5 mismatched input 'pp' in rule "Representative Checks"
12:32:55 ERROR Error: Parser returned a null Package
1) 人员创建日期和当前日期之间的比较不起作用。请指教。
2) 另外,关于如何使 90 天 - 可配置 - 以便它可以通过 business/Configuration 文件传递 - 使用微服务的任何建议。
我通过创建用于日期计算的 drool 文件函数解决了这个问题。将月份值作为参数传递给函数,参数是从 Java 程序传递的事实变量,作为插入到状态(ful)会话中的对象。
我正在尝试将 Java class 函数日期与当前日期进行比较。我需要验证 Java class 日期(CreationDate 函数)应该比当前日期早 [3 个月]。
JAVA -
public class PersonPer
....
public Date getCreationDate() {
return creationDate == null ? null : new Date(creationDate.getTime());
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate == null ? null : new Date(creationDate.getTime());
}
..... 用于测试的 Junit -
PersonPer personPer=new PersonPer();
String personCdate="15/12/1998";
Date personCreationDate = null;
try {
personCreationDate=new SimpleDateFormat("dd/MM/yyy").parse(personCdate);
System.out.println("Junit Test personCreationDate : "+ personCreationDate);
} catch (ParseException e) {
System.err.println("Date parsing exception");
e.printStackTrace();
}
personPer.setCreationDate(personCreationDate);
session.insert(personPer);
DRL - 规则 "Person check"
pp: PersonPer(pCreationDate:CreationDate)
....
when:
...
(
...
Date($now : time) from Calendar.getInstance().getTime()
pp: PersonPer(pCreationDate:CreationDate after[90] $now) <--- This doesn't work
...
Then:
System.out.println("Person date : " + pCreationDate);
drools.addError(...);
END
12:32:55 ERROR Error: [ERR 102] Line 141:5 mismatched input 'pp' in rule "Representative Checks"
12:32:55 ERROR Error: Parser returned a null Package
1) 人员创建日期和当前日期之间的比较不起作用。请指教。 2) 另外,关于如何使 90 天 - 可配置 - 以便它可以通过 business/Configuration 文件传递 - 使用微服务的任何建议。
我通过创建用于日期计算的 drool 文件函数解决了这个问题。将月份值作为参数传递给函数,参数是从 Java 程序传递的事实变量,作为插入到状态(ful)会话中的对象。