java - 如何从 drl Drools 中的累积内部返回列表?
问题描述
这是我的规则
rule "Multiple bookings via same mobile"
when
(stayDateGroupingIteration : StayDateGroupingDto($stayGroupedBookings : stayGroupedBookings)) and (QueryTypeDto( queryType == "multiple" ))
$travellerCount :Number() from accumulate(BookingSummaryDtoList( $bookingSummaryDtoList : bookingSummaryDtoList) from $stayGroupedBookings,
init( int count=0; List<String> globalList= new ArrayList(); Set<String> duplicateSet=new HashSet();),
action(
for(Object bookingSummary : $bookingSummaryDtoList)
{
if(((BookingSummaryDto)bookingSummary).getTravellerId()!=null)
{
String travellerId=((BookingSummaryDto)bookingSummary).getTravellerId().toString();
Set<String> finalDuplicateSet=MultiBookingFraudServiceImpl.checkDuplicates(travellerId,globalList,duplicateSet);
count=count+1;
}
}
),
result( new Integer(count)))
then
//some action to be taken here
System.out.println($travellerCount);
end
如何退回套装
最终复制集
从累积代替计数,我也不想在我的java类中使用任何全局变量或静态变量。可以这样做还是我需要遵循其他方法?
解决方案
希望这段代码能帮助你得到你想要的:
rule "Multiple bookings via same mobile"
when
(stayDateGroupingIteration : StayDateGroupingDto($stayGroupedBookings : stayGroupedBookings)) and (QueryTypeDto( queryType == "multiple" ))
$duplicateTravellerList :List() from accumulate(BookingSummaryDtoList( $bookingSummaryDtoList : bookingSummaryDtoList) from $stayGroupedBookings,
init( int count=0; List<String> globalList= new ArrayList(); Set<String> duplicateSet=new HashSet(); List<String> finalDuplicateSet=new ArrayList();),
action(
for(Object bookingSummary : $bookingSummaryDtoList)
{
if(((BookingSummaryDto)bookingSummary).getTravellerId()!=null)
{
String travellerId=((BookingSummaryDto)bookingSummary).getTravellerId().toString();
finalDuplicateSet.add(MultiBookingFraudServiceImpl.checkDuplicates(travellerId,globalList,duplicateSet));
count=count+1;
}
}
),
result( new ArrayList(finalDuplicateSet)))
then
//some action to be taken here
System.out.println($duplicateTravellerList);
end
推荐阅读
- php - MySQL 5.5.47 表从 MyISAM 切换到 InnoDB
- ssl - 具有多个证书的简单 ssl 终止。Nginx/haproxy 还是其他?
- reportbuilder - SSRS:堆叠条形图类别轴的自定义颜色
- node.js - 处理 id 令牌过期?
- python-3.x - 仅缺少数字 Weasyprint PDF
- mysql - MariaDB 循环不显示查询结果
- python - SQLite中如何声明日期和年份的数据类型?
- php - 如何将具有相同ID和名称的多个输入类型号相乘
- android - 设备支持随 AndroidX 迁移而变化吗?
- c# - 错误 CS0019:运算符 * 不能应用于“Vector3”和“Vector3”类型的操作数