java - Drools - 动态日期比较与当前日期的操作
问题描述
我有一个具有人员创建日期字段的 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());
}
我需要比较这个创建日期应该小于,从 Drools 中的当前日期减少 X 个月(我想从配置文件/java 文件中传递 X 个月的值,比如 3 个月)。即当前日期 - 2018 年 6 月 10 日,X 个月(3 个月) - 2018 年 4 月 10 日,创建日期应在 2018 年 4 月 10 日之前。
但它不起作用。
1)如何将动态值(来自java)传递给“流口水功能”?
JAVA(现在是Junit)->
`int RepresentativeAppointmentMonth=3
session.insert(personPer);
session.insert(RepresentativeAppointmentMonth);`
深度学习-->
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);
推荐阅读
- php - 获取字符串中两个标签之间的所有内容
- javascript - 组件不随状态更新
- next.js - 如何使用 Groq 显示引用的对象
- r - 将列中的名称更改为每组最常用的名称
- c# - 为 AcCoreConsole 创建一个 COM 接口
- node.js - Web scraper 在本地工作,但在部署到 Heroku 服务器时不能工作
- c++ - Visual Studio 中是否存在影响自定义 DLL 函数创建文件的位置的设置?
- cpu-architecture - 确定 CPU 中寄存器的值
- scala - sbt 依赖 % "编译->编译;测试->测试"
- wordpress - get_post_meta 短代码返回空字段