stream filter
1\多个filter的方法:
/** * 过滤掉查询条件 * */ private List<PerformDTO> filterPerformDTOList(List<PerformDTO> performDTOList,EventQueryParamDTO queryParamDTO) { mzLog.info("查询条件过滤前 performDTOList size:{}", performDTOList.size()); Predicate<PerformDTO> eventNoFilter = performDTO -> StringUtils.isBlank(queryParamDTO.getEventNo()) || StringUtils.equals(performDTO.getPerformCode(), queryParamDTO.getEventNo()); // 段段修改;场次名称关键字搜索 2020/12/16 Predicate<PerformDTO> eventNameFilter = performDTO -> StringUtils.isBlank(queryParamDTO.getEventName()) || performDTO.getPerformName().contains(queryParamDTO.getEventName()); Predicate<PerformDTO> startTimeFilter = performDTO -> queryParamDTO.getShowStartTime() == null || performDTO.getStartTime().after(queryParamDTO.getShowStartTime()); // 段段修改;结束时间搜索 Predicate<PerformDTO> endTimeFilter = performDTO -> queryParamDTO.getShowEndTime() == null || performDTO.getEndTime().before(queryParamDTO.getShowEndTime()); Predicate<PerformDTO> eventIdFilter = performDTO -> CollectionUtils.isEmpty(queryParamDTO.getEventIdList()) || queryParamDTO.getEventIdList().contains(performDTO.getId()); Predicate<PerformDTO> stateFilter = performDTO -> { return stateFilter(queryParamDTO, performDTO); }; Predicate<PerformDTO> alreadySoldFilter = performDTO -> { return alreadySoldfilter(queryParamDTO, performDTO); }; // 过滤 performDTOList = performDTOList.stream() .filter(it -> !it.getCoping()) .filter(eventNoFilter) .filter(eventNameFilter) .filter(startTimeFilter) .filter(endTimeFilter) .filter(eventIdFilter) .filter(stateFilter) .filter(alreadySoldFilter) .collect(Collectors.toList()); mzLog.info("查询条件过滤后 performDTOList size:{}", performDTOList.size()); return performDTOList; }
本文来自博客园,作者:aspirant,转载请注明原文链接:https://www.cnblogs.com/aspirant/p/14911985.html