我试图在Drools中使用accumulate函数从日期列表(Java 8)中找到最小日期。
这是我的规则:
rule "Print minimum Service Date from Bill Lines"
when
accumulate (
$lineItem : LineLevelData($dateOfService : dateOfService) ,
$epochDay : min($dateOfService.toEpochDay())
)
$minServiceDate : LocalDate() from LocalDate.ofEpochDay($epochDay)
then
System.err.println("Min. Service Date used in rules calculation : " + $minServiceDate);
end
这是我得到的例外:
Unable to Analyse Expression LocalDate.ofEpochDay($epochDay):
[Error: unable to resolve method using strict-mode: java.time.LocalDate.ofEpochDay(java.lang.Comparable)]
[Near : {... LocalDate.ofEpochDay($epochDay) ....}]
^ : [Rule name='Print minimum Service Date from Bill Lines']
显然,我在这里缺少一些基础知识。有人可以帮我解决这个问题吗?
Drools版本:7.5.0
POJO:
public class LineLevelData{
LocalDate dateofService;
}
更新
rule "Print minimum Service Date from Bill Lines"
when
accumulate ( $lineItem : LineLevelData ( $dateOfService : dateOfService ) ,
$epochDay : min($dateOfService.toEpochDay()) )
$epochLong : Number (longValue > 0 ) from $epochDay
$minServiceDate : LocalDate( ) from LocalDate.ofEpochDay($epochLong)
then
System.err.println("Min. Service Date used in rules calculation : " + $minServiceDate);
end
将演员表添加到Long后,epoch将转换为Local date。如果它可以帮助某人寻找这个,那么添加它。
答案 0 :(得分:0)
我想问题是Drools没有保留min
函数返回的类型,而是将其视为Comparable
而不是long
。
有三种方法可以解决这个问题:
LocalDate
cast
Comparable
返回LocalDate
。解决方法:
rule "Print minimum Service Date from Bill Lines"
when
$c: Comparable() from accumulate (
LineLevelData($dateOfService : dateOfService) ,
min($dateOfService)
)
$minServiceDate: LocalDate() from $c
then
System.err.println("Min. Service Date used in rules calculation : " +
$minServiceDate);
end
希望它有所帮助,