[英]Drools -Dyanmic Date comparison with manipulation of current date
我有一個具有人創建日期字段的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());
}
我需要比較一下這個creationdate應該小於,從Drools中的Current Date(我想傳遞X months的值,例如3個月,從配置文件/ java文件傳遞)減少X個月。 即當前日期-2018年6月10日,X月(3個月)-2018年4月10日,創建日期應在2018年4月10日之前。
但這是行不通的。
1)如何將動態值(來自Java)傳遞給“流口水函數”?
JAVA(目前為Junit)->
`int RepresentativeAppointmentMonth=3
session.insert(personPer);
session.insert(RepresentativeAppointmentMonth);`
DRL->
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
2)還有其他建議可以解決嗎? 我嘗試了很多方法,但是缺少一些東西。 我是Drools的新手。
正如@Esteban所說,您必須在會話中添加RepMonth對象。 在您的Java代碼中執行此操作
int RepresentativeAppointmentMonth=3
RepMonth repMonth = new RepMonth(RepresentativeAppointmentMonth);
session.insert(personPer);
session.insert(repMonth);
session.insert(RepresentativeAppointmentMonth);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.