天,周,月... --- 数据监控

4 篇文章 1 订阅
2 篇文章 0 订阅

摘要: 很多人对这个视图化的数据监控;也有很多的疑问;到底是直接用SQL语句还是前端一些js视图插件呢;我之前也是这么个思路;我发现我写出来的语句它只能查询出有时间段的数据;也就是说数据库里的数据时间段可能不是连续;所以查询出来的也就只能显示数据库中的时间段;那如果一整天没有数据的话;那这个图基本就是一片空白;也就是给使用者错误的感觉;我想着怎么做呢;需要X轴就显示一天的24个小时的时间段或者一周、一个月…的时间段;数据库的数据你给我对号入座就行;没有数据;它也是一个完整的图;让人看了也就知道是没有数据;它的X轴不会依靠数据库的时间来显示;而是写死的时间段;数据对号入座就行。
一、思路:
说着简单;那数据库的数据又怎么让它对号入座呢;或者又怎么写死这个X轴时间段呢等等一系列问题也会随之而来;首先咋们有了这个思路;目标要明确----现在无非就是第一:这个写死的时间段怎么写的;第二数据又是如何知道是这个时间段中的。接下来;说道时间;咋们可以弄个比较牛皮的时间工具类,它怎么牛皮法呢;
如下代码:

import org.apache.commons.lang3.time.DateFormatUtils;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;

/**
 * 时间工具类
 *
 * @author 兄弟连丶狼
 * */
public class DateUtils {
    public static String YYYY = "yyyy";

    public static String YYYY_MM = "yyyy-MM";

    public static String YYYY_MM_DD = "yyyy-MM-dd";

    public static String DD = "dd";

    public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";

    public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

    /**
     * 获取当前Date型日期
     *
     * @return Date() 当前日期
     */
    public static Date getNowDate() {
        return new Date();
    }

    /**
     * 获取当前日期, 默认格式为yyyy-MM-dd
     *
     * @return String
     */
    public static String getDate() {
        return dateTimeNow(YYYY_MM_DD);
    }

    public static final String getTime() {
        return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
    }

    public static final String dateTimeNow() {
        return dateTimeNow(YYYYMMDDHHMMSS);
    }

    public static final String dateTimeNow(final String format) {
        return parseDateToStr(format, new Date());
    }

    public static final String dateTime(final Date date) {
        return parseDateToStr(YYYY_MM_DD, date);
    }

    public static final String parseDateToStr(final String format, final Date date) {
        return new SimpleDateFormat(format).format(date);
    }

    public static final Date dateTime(final String format, final String ts) {
        try {
            return new SimpleDateFormat(format).parse(ts);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 日期路径 即年/月/日 如2018/08/08
     */
    public static final String datePath() {
        Date now = new Date();
        return DateFormatUtils.format(now, "yyyy/MM/dd");
    }

    /**
     * 日期路径 即年/月/日 如20180808
     */
    public static final String dateTime() {
        Date now = new Date();
        return DateFormatUtils.format(now, "yyyyMMdd");
    }

    /**
     *  获取当天起始时间
     * @return
     */
    public static Date getDayStartTime(){
        return convertToDateViaInstant(LocalDateTime.of(LocalDate.now(), LocalTime.MIN));
    }

    /**
     *  获取当天结束时间
     * @return
     */
    public static Date getDayEndTime(){
        return convertToDateViaInstant(LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
    }

    /**
     *  几天之后的开始时间
     * @param days
     * @return
     */
    public static Date getPlusTodayStartTime(long days){
        return convertToDateViaInstant(LocalDateTime.of(LocalDate.now().plusDays(days), LocalTime.MIN));
    }

    /**
     *  几天之前的开始时间
     * @param days
     * @return
     */
    public static Date getMinusTodayStartTime(long days){
        return convertToDateViaInstant(LocalDateTime.of(LocalDate.now().minusDays(days), LocalTime.MIN));
    }

    /**
     *  几天之前的结束时间
     * @param days
     * @return
     */
    public static Date getMinusTodayEndTime(long days){
        return convertToDateViaInstant(LocalDateTime.of(LocalDate.now().minusDays(days), LocalTime.MAX));
    }

    /**
     *  获取当月起始时间
     * @return
     */
    public static Date getDayOfMonthStartTime(){
        LocalDate today = LocalDate.now();
        //本月的第一天
        LocalDateTime firstday = LocalDateTime.of(today.getYear(), today.getMonth().getValue(), 1, 0, 0);
        return convertToDateViaInstant(firstday);
    }


    /**
     *  获取上月月起始时间
     * @return
     */
    public static Date getDayOfLastMonthStartTime(){
        LocalDate today = LocalDate.now();
        today = today.minusMonths(1);
        //本月的第一天
        LocalDateTime firstday = LocalDateTime.of(today.getYear(), today.getMonth().getValue(), 1, 0, 0);
        return convertToDateViaInstant(firstday);
    }

    /**
     *  获取当天的时间段
     * @param hour
     * @param minute
     * @param second
     * @return
     */
    public static Date getTodayTime(int hour, int minute, int second){
        LocalDate today = LocalDate.now();
        LocalDateTime localDateTime = LocalDateTime.of(today.getYear(), today.getMonth().getValue(), today.getDayOfMonth(), hour, minute,second);
        return convertToDateViaInstant(localDateTime);
    }


    /**
     *  获取本周第一天
     * @return
     */
    public static Date getDayOfWeekStartTime() {
        LocalDate localDate = LocalDate.now().with(DayOfWeek.MONDAY);

//        TemporalField fieldISO = WeekFields.of(Locale.CHINA).dayOfWeek();
//        LocalDate localDate = LocalDate.now();
//        localDate.with(fieldISO, 1);
//        System.out.println(localDate);
        return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }

    /**
     *  获取周最后一天
     * @return
     */
//    public static Date getEndDayOfWeek() {
//        LocalDate localDate = LocalDate.now();
//        return getEndDayOfWeek(localDate);
//    }


    public static Date convertToDateViaInstant(LocalDateTime dateToConvert) {
        return Date
                .from(dateToConvert.atZone(ZoneId.systemDefault())
                        .toInstant());
    }


    public static Date getEndDayOfWeek(TemporalAccessor date) {
        TemporalField fieldISO = WeekFields.of(Locale.CHINA).dayOfWeek();
        LocalDate localDate = LocalDate.from(date);
        localDate.with(fieldISO, 7);
        return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1L).minusNanos(1L).toInstant());
    }


    /**
     *  获取某天的开始时间
     * @param localDate
     * @return
     */
    public static Date getStartTimeOfDay(LocalDate localDate) {
        return getStartOfDay(localDate);
    }

    /**
     *  获取某天的开始时间
     * @param localDate
     * @return
     */
    public static Date getEndTimeOfDay(LocalDate localDate){
        return getEndOfDay(localDate);
    }

    public static Date getStartOfDay(TemporalAccessor date) {
        LocalDate localDate = LocalDate.from(date);
        return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }

    public static Date getEndOfDay(TemporalAccessor date) {
        LocalDate localDate = LocalDate.from(date);
        return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1L).minusNanos(1L).toInstant());
    }

    /**
     * 订单是否已经过超过三分钟
     * @param date 需要判断的时间
     * @return
     */
    public static boolean isLongerThanMinute(Date date){
        Calendar cal = Calendar.getInstance();

        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date);
        cal1.add(Calendar.MINUTE, +3);

        return cal1.compareTo(cal) != 1;
    }

    public static void different(){

    }

    // 获取当天的开始时间
    public static Date getDayBegin() {
        Calendar cal = new GregorianCalendar();
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    // 获取当天的结束时间
    public static Date getDayEnd() {
        Calendar cal = new GregorianCalendar();
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        return cal.getTime();
    }

    // 获取昨天的开始时间
    public static Date getBeginDayOfYesterday() {
        Calendar cal = new GregorianCalendar();
        cal.setTime(getDayBegin());
        cal.add(Calendar.DAY_OF_MONTH, -1);
        return cal.getTime();
    }

    // 获取昨天的结束时间
    public static Date getEndDayOfYesterDay() {
        Calendar cal = new GregorianCalendar();
        cal.setTime(getDayEnd());
        cal.add(Calendar.DAY_OF_MONTH, -1);
        return cal.getTime();
    }

    // 获取明天的开始时间
    public static Date getBeginDayOfTomorrow() {
        Calendar cal = new GregorianCalendar();
        cal.setTime(getDayBegin());
        cal.add(Calendar.DAY_OF_MONTH, 1);
        return cal.getTime();
    }

    // 获取明天的结束时间
    public static Date getEndDayOfTomorrow() {
        Calendar cal = new GregorianCalendar();
        cal.setTime(getDayEnd());
        cal.add(Calendar.DAY_OF_MONTH, 1);
        return cal.getTime();
    }

    // 获取本周的开始时间
    @SuppressWarnings("unused")
    public static Date getBeginDayOfWeek() {
        Date date = new Date();
        if (date == null) {
            return null;
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
        if (dayofweek == 1) {
            dayofweek += 7;
        }
        cal.add(Calendar.DATE, 2 - dayofweek);
        return getDayStartTime(cal.getTime());
    }

    // 获取本周的结束时间
    public static Date getEndDayOfWeek() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getBeginDayOfWeek());
        cal.add(Calendar.DAY_OF_WEEK, 6);
        Date weekEndSta = cal.getTime();
        return getDayEndTime(weekEndSta);
    }

    // 获取上周的开始时间
    @SuppressWarnings("unused")
    public static Date getBeginDayOfLastWeek() {
        Date date = new Date();
        if (date == null) {
            return null;
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
        if (dayofweek == 1) {
            dayofweek += 7;
        }
        cal.add(Calendar.DATE, 2 - dayofweek - 7);
        return getDayStartTime(cal.getTime());
    }

    // 获取上周的结束时间
    public static Date getEndDayOfLastWeek() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getBeginDayOfLastWeek());
        cal.add(Calendar.DAY_OF_WEEK, 6);
        Date weekEndSta = cal.getTime();
        return getDayEndTime(weekEndSta);
    }

    // 获取本月的开始时间
    public static Date getBeginDayOfMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth() - 1, 1);
        return getDayStartTime(calendar.getTime());
    }

    // 获取本月的结束时间
    public static Date getEndDayOfMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth() - 1, 1);
        int day = calendar.getActualMaximum(5);
        calendar.set(getNowYear(), getNowMonth() - 1, day);
        return getDayEndTime(calendar.getTime());
    }

    // 获取上月的开始时间
    public static Date getBeginDayOfLastMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth() - 2, 1);
        return getDayStartTime(calendar.getTime());
    }

    // 获取上月的结束时间
    public static Date getEndDayOfLastMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth() - 2, 1);
        int day = calendar.getActualMaximum(5);
        calendar.set(getNowYear(), getNowMonth() - 2, day);
        return getDayEndTime(calendar.getTime());
    }

    // 获取本年的开始时间
    public static Date getBeginDayOfYear() {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, getNowYear());
        cal.set(Calendar.MONTH, Calendar.JANUARY);
        cal.set(Calendar.DATE, 1);
        return getDayStartTime(cal.getTime());
    }

    // 获取本年的结束时间
    public static Date getEndDayOfYear() {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, getNowYear());
        cal.set(Calendar.MONTH, Calendar.DECEMBER);
        cal.set(Calendar.DATE, 31);
        return getDayEndTime(cal.getTime());
    }

    // 获取某个日期的开始时间
    public static Timestamp getDayStartTime(Date d) {
        Calendar calendar = Calendar.getInstance();
        if (null != d)
            calendar.setTime(d);
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return new Timestamp(calendar.getTimeInMillis());
    }

    // 获取某个日期的结束时间
    public static Timestamp getDayEndTime(Date d) {
        Calendar calendar = Calendar.getInstance();
        if (null != d)
            calendar.setTime(d);
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return new Timestamp(calendar.getTimeInMillis());
    }

    // 获取今年是哪一年
    public static Integer getNowYear() {
        Date date = new Date();
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
        gc.setTime(date);
        return Integer.valueOf(gc.get(1));
    }

    // 获取本月是哪一月
    public static int getNowMonth() {
        Date date = new Date();
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
        gc.setTime(date);
        return gc.get(2) + 1;
    }

    // 两个日期相减得到的天数
    public static int getDiffDays(Date beginDate, Date endDate) {
        if (beginDate == null || endDate == null) {
            throw new IllegalArgumentException("getDiffDays param is null!");
        }
        long diff = (endDate.getTime() - beginDate.getTime())
                / (1000 * 60 * 60 * 24);
        int days = new Long(diff).intValue();
        return days;
    }

    // 两个日期相减得到的毫秒数
    public static long dateDiff(Date beginDate, Date endDate) {
        long date1ms = beginDate.getTime();
        long date2ms = endDate.getTime();
        return date2ms - date1ms;
    }

    // 获取两个日期中的最大日期
    public static Date max(Date beginDate, Date endDate) {
        if (beginDate == null) {
            return endDate;
        }
        if (endDate == null) {
            return beginDate;
        }
        if (beginDate.after(endDate)) {
            return beginDate;
        }
        return endDate;
    }

    // 获取两个日期中的最小日期
    public static Date min(Date beginDate, Date endDate) {
        if (beginDate == null) {
            return endDate;
        }
        if (endDate == null) {
            return beginDate;
        }
        if (beginDate.after(endDate)) {
            return endDate;
        }
        return beginDate;
    }

    // 返回某月该季度的第一个月
    public static Date getFirstSeasonDate(Date date) {
        final int[] SEASON = { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4 };
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int sean = SEASON[cal.get(Calendar.MONTH)];
        cal.set(Calendar.MONTH, sean * 3 - 3);
        return cal.getTime();
    }

    // 返回某个日期下几天的日期
    public static Date getNextDay(Date date, int i) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.set(Calendar.DATE, cal.get(Calendar.DATE) + i);
        return cal.getTime();
    }

    // 返回某个日期前几天的日期
    public static Date getFrontDay(Date date, int i) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.set(Calendar.DATE, cal.get(Calendar.DATE) - i);
        return cal.getTime();
    }

    // 获取某年某月到某年某月按天的切片日期集合(间隔天数的集合)
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static List getTimeList(int beginYear, int beginMonth, int endYear,
                                   int endMonth, int k) {
        List list = new ArrayList();
        if (beginYear == endYear) {
            for (int j = beginMonth; j <= endMonth; j++) {
                list.add(getTimeList(beginYear, j, k));
            }
        } else {
            {
                for (int j = beginMonth; j < 12; j++) {
                    list.add(getTimeList(beginYear, j, k));
                }
                for (int i = beginYear + 1; i < endYear; i++) {
                    for (int j = 0; j < 12; j++) {
                        list.add(getTimeList(i, j, k));
                    }
                }
                for (int j = 0; j <= endMonth; j++) {
                    list.add(getTimeList(endYear, j, k));
                }
            }
        }
        return list;
    }

    // 获取某年某月按天切片日期集合(某个月间隔多少天的日期集合)
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static List getTimeList(int beginYear, int beginMonth, int k) {
        List list = new ArrayList();
        Calendar begincal = new GregorianCalendar(beginYear, beginMonth, 1);
        int max = begincal.getActualMaximum(Calendar.DATE);
        for (int i = 1; i < max; i = i + k) {
            list.add(begincal.getTime());
            begincal.add(Calendar.DATE, k);
        }
        begincal = new GregorianCalendar(beginYear, beginMonth, max);
        list.add(begincal.getTime());
        return list;
    }


}

获取各种各样的时间方法这里应有尽有;这就是它的厉害之处;更厉害的还在后面;咋们在后台控制器或者实现类中首先拿到这个写死的时间段;怎么拿;好,我也教你怎么实现(这里的话我就单独就拿天做个列子吧):

//用集合装写死的时间段
LinkedList<String> timeLines = Lists.newLinkedList();
		timeLines.add("00:00-1:00");
		timeLines.add("01:00-2:00");
		timeLines.add("2:00-3:00");
		timeLines.add("3:00-4:00");
		timeLines.add("4:00-5:00");
		timeLines.add("5:00-6:00");
		timeLines.add("6:00-7:00");
		timeLines.add("7:00-8:00");
		timeLines.add("8:00-9:00");
		timeLines.add("9:00-10:00");
		timeLines.add("10:00-11:00");
		timeLines.add("11:00-12:00");
		timeLines.add("12:00-13:00");
		timeLines.add("13:00-14:00");
		timeLines.add("14:00-15:00");
		timeLines.add("15:00-16:00");
		timeLines.add("16:00-17:00");
		timeLines.add("17:00-18:00");
		timeLines.add("18:00-19:00");
		timeLines.add("19:00-20:00");
		timeLines.add("20:00-21:00");
		timeLines.add("21:00-22:00");
		timeLines.add("22:00-23:00");
		timeLines.add("23:00-24:00");
//知道我为什么要用LinkedList集合吗;因为它是以一定的顺序储存数据的;那么也就是说这个时间段储存的顺序就是按照上面代码排序的

根据上面代码我们也就可以推算出周的时间段如何去写:

 		timeLines.add(parseDateToStr(DD, getMinusTodayStartTime(6)) + "日");
        timeLines.add(parseDateToStr(DD, getMinusTodayStartTime(5)) + "日");
        timeLines.add(parseDateToStr(DD, getMinusTodayStartTime(4)) + "日");
        timeLines.add(parseDateToStr(DD, getMinusTodayStartTime(3)) + "日");
        timeLines.add(parseDateToStr(DD, getMinusTodayStartTime(2)) + "日");
        timeLines.add(parseDateToStr(DD, getMinusTodayStartTime(1)) + "日");
        timeLines.add(parseDateToStr(DD, new Date()));

…月、年等等都是类似的去获取。我就不一个一个去写了;没有多大的意义。既然我们得到了写死的时间段;那数据库的数据如何对号入座呢;时间工具类最厉害之处就是这个了:

//这里我演示我从数据取得数据;遍历它;所取得的时间段做分类
List<OrderInfo> orderInfos = getUserOwnOrderInfos(filter, getUserOwnVemIdList(vemInfo));


	//分别装数据
		List<OrderInfo> orders01 = Lists.newArrayList();
        List<OrderInfo> orders12 = Lists.newArrayList();
        List<OrderInfo> orders23 = Lists.newArrayList();
        List<OrderInfo> orders34 = Lists.newArrayList();
        List<OrderInfo> orders45 = Lists.newArrayList();
        List<OrderInfo> orders56 = Lists.newArrayList();
        List<OrderInfo> orders67 = Lists.newArrayList();
        List<OrderInfo> orders78 = Lists.newArrayList();
        List<OrderInfo> orders89 = Lists.newArrayList();
        List<OrderInfo> orders910 = Lists.newArrayList();
        List<OrderInfo> orders1011 = Lists.newArrayList();
        List<OrderInfo> orders1112 = Lists.newArrayList();
        List<OrderInfo> orders1213 = Lists.newArrayList();
        List<OrderInfo> orders1314 = Lists.newArrayList();
        List<OrderInfo> orders1415 = Lists.newArrayList();
        List<OrderInfo> orders1516 = Lists.newArrayList();
        List<OrderInfo> orders1617 = Lists.newArrayList();
        List<OrderInfo> orders1718 = Lists.newArrayList();
        List<OrderInfo> orders1819 = Lists.newArrayList();
        List<OrderInfo> orders1920 = Lists.newArrayList();
        List<OrderInfo> orders2021 = Lists.newArrayList();
        List<OrderInfo> orders2122 = Lists.newArrayList();
        List<OrderInfo> orders2223 = Lists.newArrayList();
        List<OrderInfo> orders2324 = Lists.newArrayList();


        for (OrderInfo orderInfo : orderInfos) {
            Date createdDate = orderInfo.getCreateTime();
            //0-1点 数据
            if (createdDate.after(getDayStartTime()) && createdDate.before(getTodayTime(0, 59, 59))) {
                orders01.add(orderInfo);
            } else if (createdDate.after(getTodayTime(1, 0, 0)) && createdDate.before(getTodayTime(1, 59, 59))) {
            //1-2点 数据
                orders12.add(orderInfo);
            } else if (createdDate.after(getTodayTime(2, 0, 0)) && createdDate.before(getTodayTime(2, 59, 59))) {
             //2-3点 数据
                orders23.add(orderInfo);
            } else if (createdDate.after(getTodayTime(3, 0, 0)) && createdDate.before(getTodayTime(3, 59, 59))) {
             //3-4点 数据
                orders34.add(orderInfo);
            } else if (createdDate.after(getTodayTime(4, 0, 0)) && createdDate.before(getTodayTime(4, 59, 59))) {
             //4-5点 数据
                orders45.add(orderInfo);
            } else if (createdDate.after(getTodayTime(5, 0, 0)) && createdDate.before(getTodayTime(5, 59, 59))) {
             //5-6点 数据
                orders56.add(orderInfo);
            } else if (createdDate.after(getTodayTime(6, 0, 0)) && createdDate.before(getTodayTime(6, 59, 59))) {
             //6-7点 数据
                orders67.add(orderInfo);
            } else if (createdDate.after(getTodayTime(7, 0, 0)) && createdDate.before(getTodayTime(7, 59, 59))) {
             //7-8点 数据
                orders78.add(orderInfo);
            } else if (createdDate.after(getTodayTime(8, 0, 0)) && createdDate.before(getTodayTime(8, 59, 59))) {
             //8-9点 数据
                orders89.add(orderInfo);
            } else if (createdDate.after(getTodayTime(9, 0, 0)) && createdDate.before(getTodayTime(9, 59, 59))) {
             //9-10点 数据
                orders910.add(orderInfo);
            } else if (createdDate.after(getTodayTime(10, 0, 0)) && createdDate.before(getTodayTime(10, 59, 59))) {
            //10-11点 数据
                orders1011.add(orderInfo);
            } else if (createdDate.after(getTodayTime(11, 0, 0)) && createdDate.before(getTodayTime(11, 59, 59))) {
            //11-12点 数据
                orders1112.add(orderInfo);
            } else if (createdDate.after(getTodayTime(12, 0, 0)) && createdDate.before(getTodayTime(12, 59, 59))) {
            //12-13点 数据
                orders1213.add(orderInfo);
            } else if (createdDate.after(getTodayTime(13, 0, 0)) && createdDate.before(getTodayTime(13, 59, 59))) {
            //13-14点 数据
                orders1314.add(orderInfo);
            } else if (createdDate.after(getTodayTime(14, 0, 0)) && createdDate.before(getTodayTime(14, 59, 59))) {
            //14-15点 数据
                orders1415.add(orderInfo);
            } else if (createdDate.after(getTodayTime(15, 0, 0)) && createdDate.before(getTodayTime(15, 59, 59))) {
            //15-16点 数据
                orders1516.add(orderInfo);
            } else if (createdDate.after(getTodayTime(16, 0, 0)) && createdDate.before(getTodayTime(16, 59, 59))) {
            //16-17点 数据
                orders1617.add(orderInfo);
            } else if (createdDate.after(getTodayTime(17, 0, 0)) && createdDate.before(getTodayTime(17, 59, 59))) {
            //17-18点 数据
                orders1718.add(orderInfo);
            } else if (createdDate.after(getTodayTime(18, 0, 0)) && createdDate.before(getTodayTime(18, 59, 59))) {
            //18-19点 数据
                orders1819.add(orderInfo);
            } else if (createdDate.after(getTodayTime(19, 0, 0)) && createdDate.before(getTodayTime(19, 59, 59))) {
            //19-20点 数据
                orders1920.add(orderInfo);
            } else if (createdDate.after(getTodayTime(20, 0, 0)) && createdDate.before(getTodayTime(20, 59, 59))) {
            //20-21点 数据
                orders2021.add(orderInfo);
            } else if (createdDate.after(getTodayTime(21, 0, 0)) && createdDate.before(getTodayTime(21, 59, 59))) {
            //21-22点 数据
                orders2122.add(orderInfo);
            } else if (createdDate.after(getTodayTime(22, 0, 0)) && createdDate.before(getTodayTime(22, 59, 59))) {
            //22-23点 数据
                orders2223.add(orderInfo);
            } else if (createdDate.after(getTodayTime(23, 0, 0)) && createdDate.before(getTodayTime(23, 59, 59))) {
            //23-24点 数据
                orders2324.add(orderInfo);
            }
        }

上面我就是利用时间工具类将我从数据库所取得数据进行一个分类;无非就是将数据库的数据以是时间段进行一个简单的分类麻;那么周月年的分类也就如同类似了;但是疑惑又来了;分完了之后呢;这还只是分完;这里我只是教大家按时段去将某个时间段的数据集合在一起;然后做个统计和;如果你是统计数据中某个字段的数值之和;那么这里的集合添加的不是数据了;而是你根据数据算出来的值;既然是统计出集合的总条数;那不是很简单;size()这个方法不就能解决问题嘛;最重要的还是这一步:

//使用LinkedList添加所区分的数据和也就能够对应写死的时间段了。
LinkedList<Integer> orderQuantities = Lists.newLinkedList();
		orderQuantities.add(orders01.size());
        orderQuantities.add(orders12.size());
        orderQuantities.add(orders23.size());
        orderQuantities.add(orders34.size());
        orderQuantities.add(orders45.size());
        orderQuantities.add(orders56.size());
        orderQuantities.add(orders67.size());
        orderQuantities.add(orders78.size());
        orderQuantities.add(orders89.size());
        orderQuantities.add(orders910.size());
        orderQuantities.add(orders1011.size());
        orderQuantities.add(orders1112.size());
        orderQuantities.add(orders1213.size());
        orderQuantities.add(orders1314.size());
        orderQuantities.add(orders1415.size());
        orderQuantities.add(orders1516.size());
        orderQuantities.add(orders1617.size());
        orderQuantities.add(orders1718.size());
        orderQuantities.add(orders1819.size());
        orderQuantities.add(orders1920.size());
        orderQuantities.add(orders2021.size());
        orderQuantities.add(orders2122.size());
        orderQuantities.add(orders2223.size());
        orderQuantities.add(orders2324.size());

怎么返回数据;我也教你,俗话说;帮人帮到底;自己会变帅;可惜的是;我已经够帅了;☹哈哈;好吧;下面这一招希望你能够在往日举一反三:

//将你已的数据和;封装到一个类中就行了;返回该类;在前端也就能拿到数值。
 DailySalesAnalysisVo vo = new DailySalesAnalysisVo();
        vo.setTimeLine(timeLines);
        vo.setOrderQuantities(orderQuantities);

给你们看看呈现图吧;让你从此跪拜在我的门下;喔哈哈…(喜欢我的;记得垫个小赞ღ)
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小面包CC

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值