如何从drl Drools中的累积返回列表?

时间:2018-08-02 12:26:50

标签: java drools rule-engine drools-kie-server

这是我的规则

false

我该如何退货

  

finalDuplicateSet

从累加代替计数,我也不想在我的java类中使用任何全局变量或静态变量。可以做到吗?还是需要采取其他方法?

1 个答案:

答案 0 :(得分:0)

希望此代码帮助您获得所需的内容:

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