使用stream过滤每天,每周,每月数据

        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;

  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值