OrderScreenVo orderScreenVo = new OrderScreenVo();
List<PartitionPercentageVo> orderScreenCampVos = new ArrayList<>();
OrderScreenQto orderScreenQto = new OrderScreenQto();
List<OrderInfoScreenDto> allByOrderScreen = orderInfoScreenDtoService.getAllByOrderScreenQto(orderScreenQto);
List<OrderInfoScreenDto> orderInfoScreen = allByOrderScreen.stream().filter(v -> v.getOrderStatus() != OrderInfoEnum.NO_PAY && v.getOrderStatus()!=OrderInfoEnum.ORDER_CLOSE).filter(v -> v.getModelType() == ModelTypeEnum.CAMP).collect(Collectors.toList());
long totalSize = orderInfoScreen.size();
orderScreenVo.setOrderTotal(totalSize);
LocalDate now = LocalDate.now();
List<LocalDate> weekDays = List.of(now.with(DayOfWeek.MONDAY), now.with(DayOfWeek.TUESDAY), now.with(DayOfWeek.WEDNESDAY), now.with(DayOfWeek.THURSDAY), now.with(DayOfWeek.FRIDAY), now.with(DayOfWeek.SATURDAY), now.with(DayOfWeek.SUNDAY));
//今日订单
long nowOrderCount = orderInfoScreen.stream().filter(v -> v.getCreatedAt().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().equals(now)).count();
orderScreenVo.setTodayOrder(nowOrderCount);
//当月新增订单
YearMonth yearMonth = YearMonth.from(now);
long monthCount = orderInfoScreen.stream().filter(v -> YearMonth.from(v.getCreatedAt().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()).equals(yearMonth)).count();
orderScreenVo.setMonthOrder(monthCount);
//营位加商品
long allMonthCount = allByOrderScreen.stream().filter(v -> v.getOrderStatus() != OrderInfoEnum.NO_PAY).filter(v -> YearMonth.from(v.getCreatedAt().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()).equals(yearMonth)).count();
orderScreenVo.setAllMonthOrder(allMonthCount);
//本周订单
long weekCount = orderInfoScreen.stream().filter(v -> weekDays.contains(v.getCreatedAt().toInstant().atZone(ZoneId.systemDefault()).toLocalDate())).count();
orderScreenVo.setWeekOrder(weekCount);
List<PartitionInfoDto> allByPubPartition = partitionInfoDtoRpcAdapter.getAllByPubPartitionQto(new PubPartitionQto());
for (PartitionInfoDto partitionInfoDto : allByPubPartition) {
PartitionPercentageVo partitionPercentageVo = new PartitionPercentageVo();
partitionPercentageVo.setPartitionName(partitionInfoDto.getPartitionName());
List<CampInfoDto> campInfoDtos = campInfoDtoRpcAdapter.getByPartitionId(partitionInfoDto.getId());
long count = campInfoDtos.stream().filter(v -> orderInfoScreen.stream().anyMatch(p -> p.getCampId().equals(v.getId()))).count();
if (totalSize == 0 || count == 0) {
partitionPercentageVo.setPercentage(0 + "%");
} else {
BigDecimal partCount = BigDecimal.valueOf(count);
BigDecimal total = BigDecimal.valueOf(totalSize);
BigDecimal divideValue = partCount.divide(total, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).stripTrailingZeros();
partitionPercentageVo.setPercentage(divideValue + "%");
orderScreenCampVos.add(partitionPercentageVo);
orderScreenVo.setPartitionInfo(orderScreenCampVos);
return orderScreenVo;
List<MkCsQuestionRecordDO> yesterdayCsQuestionRecord = totalCsQuestionRecord.
stream
()
.filter((MkCsQuestionRecordDO a) -> DateUtil.parseDateFormat(a.getGmtModified(), DateUtil.NEW_FORMAT)
数据
准备:
List<Student> studenList = new ArrayList<Student>();
studenList.add(new Student("李小明",true,18,1.76,LocalDate.of(2001,3,23)));
studenList.add(new Student("张小丽",false,18,1.61,LocalDate.of(2001,6,3)));
studenList.add(
Java
8
使用
stream
().filter()
过滤
List(查找符合条件的对象集合)
在
Java
8及以上版本
中
,
使用
stream
().filter()来
过滤
一个List对象,查找符合条件的对象集合。
1.对象类 Teacher
import
java
.time.LocalDate;
import
java
.util.List;
* @author qzz
public class Teacher{
privat
CSDN-Ada助手:
使用stream流对数据进行筛选,求和,对比
CSDN-Ada助手:
AssertUtil使用
CSDN-Ada助手:
钉钉消息提醒java
CSDN-Ada助手:
java实现钉钉免登对接
CSDN-Ada助手: