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;
使用stream过滤每天,每周,每月数据
最新推荐文章于 2024-02-21 16:10:20 发布