jdk8 Group statistics based on time

  • 1. Group statistics by time
  • 2. The time field is in yyyy-MM-dd HH:mm:ss format
  • 3. Monthly statistics, no increase in the calculation

1. Statistical methods

Time method to month: parse_yyyyMM, statistical data by month
Time method to month: parse_yyyyMMdd, statistical data by day

   /**
     * 折线图统计(按月)
     * <P>
     *     1- 患者统计
     *     2- 出货统计
     * </P>
     * @param ybOrderPageVO
     * @return
     */
    private List<AdminHomeStatisticsVO.Statistics> getStatistics(List<YbOrderPageVO> ybOrderPageVO) {
        if (ybOrderPageVO.size() != 0) {
            Map<String, List<YbOrderPageVO>> groupByMonth = ybOrderPageVO.stream().collect(
                    Collectors.groupingBy(o -> LocalDateTimeUtil.parse_yyyyMM(o.getCreateTime()))
            );
            List<AdminHomeStatisticsVO.Statistics> patientList = new ArrayList<>();
            groupByMonth.forEach((k, v) -> {
                patientList.add(new AdminHomeStatisticsVO.Statistics(k, v.size()));
            });
            return patientList;
        }
        return null;
    }

Insert picture description here

2. parse_yyyyMMdd method (to date)


    /**
     * 年月日时间处理
     * @param time
     * @return
     */
    public static String parse_yyyyMMdd(LocalDateTime time) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        return df.format(time);
    }

3. parse_yyyyMM method (to month)


    /**
     * 年月日时间处理
     * @param time
     * @return
     */
    public static String parse_yyyyMM(LocalDateTime time) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM");
        return df.format(time);
    }

4. Example of a line chart

Insert picture description here

  • Personal open source project (universal background management system) –> https://gitee.com/wslxm/spring-boot-plus2 , you can check it out if you like

  • This is the end of this article. If you find it useful, please like or pay attention to it. We will continue to update more content from time to time... Thank you for watching!

Guess you like

Origin blog.csdn.net/qq_41463655/article/details/108587408