如何从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

如何返回设置的

finalDuplicateSet

从accumulate代替count,我不想在我的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

最新更新