Drools -Dyanmic Date 比较与当前日期的操作

Drools -Dyanmic Date comparison with manipulation of current date

我有一个 java class,其中包含人员创建日期字段。

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());
}

我需要比较这个创建日期应该小于 Drools 中的当前日期(我想传递 X 个月的值,比如 3 个月,来自配置 file/java 文件)减少 X 个月。即当前日期-2018年6月10日,X月(3个月)-2018年4月10日,创建日期应在2018年4月10日之前。

但它不起作用。

1) 如何将动态值(从 java)传递给 'function in drools'?

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);