如何在Drools对象的所有加入日期中找到最近的日期?
我的规则是这样的:
declare RecentDate
dates : java.util.Date
end
rule "insert_dates"
when
//reading dates from back end
Employee($date : dateOfJoining, $name : name, salary > 10000)
then
insert(new RecentDate($date))
end
现在我想基于dateOfJoining找到最近的员工。任何帮助表示赞赏。谢谢。
一种方法是,给予员工,确保没有其他更高的日期:
declare RecentDate
dates : java.util.Date
end
rule "insert_dates"
when
//reading dates from back end
Employee( $date : dateOfJoining, $name : name, salary > 10000)
not Employee (dateOfJoining > $date)
then
insert(new RecentDate($date))
end
上面的规则仅适用于在执行Employee
之前在会话中拥有所有fireAllRules()
事实的情况。如果不是这种情况,您可以尝试最初插入带有空日期的RecentDate
,然后将每个Employee
与它进行比较并相应地更新它:
rule "Init RecentDate"
when
not RecentDate()
then
insert new RecentDate(null);
end
rule "update_dates"
when
Employee( $date : dateOfJoining, $name : name, salary > 10000)
$d: RecentDate ( date == null || date < $date)
then
modify ($d){
setDate($date)
}
end
希望能帮助到你,