如何返回一个列表从Drools的DRL里面的积累?(How to return a list fro

2019-10-29 08:51发布

这里是我的规则

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

从到位数的积累,我不希望使用任何全局变量或静态变量在我的java类也。 可以这样做或做我需要遵循一些其他的方法呢?

Answer 1:

希望这个代码帮助你得到你想要的:

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


文章来源: How to return a list from inside of accumulate in drl Drools?