Java Drools-动态日期比较与当前日期操作
我有一个java类,它有personcreationdate字段Java Drools-动态日期比较与当前日期操作,java,drools,Java,Drools,我有一个java类,它有personcreationdate字段 public class PersonPer public Date getCreationDate() { return creationDate == null ? null : new Date(creationDate.getTime()); } public void setCreationDate(Date creationDate) { this.creationDate = creatio
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());
}
我需要比较这个creationdate应该小于,从Drools中的当前日期减少X个月(我想传递X个月的值,比如3个月,从配置文件/java文件)。i、 e.当前日期-2018年6月10日,X个月(3个月)-2018年4月10日,创建日期应在2018年4月10日之前
但它不起作用
1) 如何将动态值(从java)传递到“drools中的函数”
JAVA(现在使用Junit)->
DRL-->
声明事实
...
repMonth:repMonth
..
结束
每月申报
月份:整数
结束
函数日期workWithDates(int m)
{
..
返回NewDate,从CurrentDate中减去mm;
}
规则“日期检查”
什么时候
RepMonth(m:month)`/正如@Esteban所说,您必须将RepMonth对象添加到会话中。在java代码中执行此操作
int RepresentativeAppointmentMonth=3
RepMonth repMonth = new RepMonth(RepresentativeAppointmentMonth);
session.insert(personPer);
session.insert(repMonth);
session.insert(RepresentativeAppointmentMonth);
您从未在会话中插入RepMonth
对象。这就是为什么添加该模式会阻止规则被激活的原因。@estebanaliveri谢谢。成功了。我有一个后续问题。目前,我正在与Junit合作启动规则,drool文件位于src/test/。。。它被触发了。有没有办法确定从实际的JavaSRC文件中触发drl文件规则的位置?谢谢。我将repMonth添加到会话中,它成功了!
declare Facts
...
repMonth:RepMonth
..
end
declare RepMonth
month: int
end
function Date workWithDates(int m)
{
..
return NewDateWithMmonthsubtractedFromCurrentDate;
}
rule "Date check"
when
RepMonth(m : month)` //<- But if I add this line, the next line doesn't trigger, if I comment this line, it works, with static value of Months(hardcoding 3 months-> which I dont want.
PersonPer(CreationDate > workWithDates(m))
then
System.out.println("Rep");
end
int RepresentativeAppointmentMonth=3
RepMonth repMonth = new RepMonth(RepresentativeAppointmentMonth);
session.insert(personPer);
session.insert(repMonth);
session.insert(RepresentativeAppointmentMonth);