Highcharts展示一天24个时间段的数据统计

1.前端页面










                
                
                
                
                
                

实时统计




        

实时统计

  • 新增用户(今日)

  • ${addMember}

  • 销售商品(今日)

  • ${numberProduct}

  • 新增画报(今日)

  • ${pictorialAddNumber}

  • 新增动态(今日)

  • ${moodAddNumber}

  • 2.后台代码

    @RequestMapping(value = "getData")
    @ResponseBody
    public Result getData(Integer type,Date newDate){
            Map mapList = Maps.newHashMap();
            //得到查询的时间的数据
            long[] theData = null;
            //得到今天的数据
            long[] todayData = new long[24];
            //得到昨天的数据
            long[] yesterdayData = new long[24];
            //得到7天前的数据
            long[] sevenData = new long[24];
            //得到30天前的数据
            long[] thirtyData = new long[24];
            //查找的时间
            Date startDate = null;
            Date endDate = null;
            //今天的时间
            Date theDateStart = DateUtil.getSomeDayStart(0);
            Date theDateEnd = DateUtil.getSomeDayEnd(0);
            //昨天的时间
            Date oneDateStart = DateUtil.getSomeDayStart(1);
            Date oneDateEnd = DateUtil.getSomeDayEnd(1);
            //7天前的时间
            Date sevenDateStart = DateUtil.getSomeDayStart(7);
            Date sevenDateEnd = DateUtil.getSomeDayEnd(7);
            //30天的时间
            Date thirtyDateStart = DateUtil.getSomeDayStart(30);
            Date thirtyDateEnd = DateUtil.getSomeDayEnd(30);
            if(newDate != null){
                    startDate = DateUtil.getStartTimeOfDay(newDate);
                    endDate = DateUtil.getEndTimeOfDay(newDate);
            }
            try {
                    if(type.equals(1)){
                            //用户新增
                            if(newDate != null){
                                    theData = memberBizService.getSomeDayAddMemberCount(startDate, endDate);
                                    todayData = memberBizService.getSomeDayAddMemberCount(theDateStart, theDateEnd);
                            }else{
                                    todayData = memberBizService.getSomeDayAddMemberCount(theDateStart, theDateEnd);
                                    yesterdayData = memberBizService.getSomeDayAddMemberCount(oneDateStart, oneDateEnd);
                                    sevenData = memberBizService.getSomeDayAddMemberCount(sevenDateStart, sevenDateEnd);
                                    thirtyData = memberBizService.getSomeDayAddMemberCount(thirtyDateStart, thirtyDateEnd);
                            }
                    }else if(type.equals(2)){
                            //销售商品
                            if(newDate != null){
                                    theData = borderService.getSomeDayAddPostCount(startDate, endDate);
                                    todayData = borderService.getSomeDayAddPostCount(theDateStart, theDateEnd);
                            }else{
                                    todayData = borderService.getSomeDayAddPostCount(theDateStart, theDateEnd);
                                    yesterdayData = borderService.getSomeDayAddPostCount(oneDateStart, oneDateEnd);
                                    sevenData = borderService.getSomeDayAddPostCount(sevenDateStart, sevenDateEnd);
                                    thirtyData = borderService.getSomeDayAddPostCount(thirtyDateStart, thirtyDateEnd);
                            }
                    }else if(type.equals(3)){
                            //新增画报
                            if(newDate != null){
                                    theData = postBizService.getSomeDayAddPostCount(startDate, endDate);
                                    todayData = postBizService.getSomeDayAddPostCount(theDateStart, theDateEnd);
                            }else{
                                    todayData = postBizService.getSomeDayAddPostCount(theDateStart, theDateEnd);
                                    yesterdayData = postBizService.getSomeDayAddPostCount(oneDateStart, oneDateEnd);
                                    sevenData = postBizService.getSomeDayAddPostCount(sevenDateStart, sevenDateEnd);
                                    thirtyData = postBizService.getSomeDayAddPostCount(thirtyDateStart, thirtyDateEnd);
                            }
                    }else if(type.equals(4)){
                            //新增动态
                            if(newDate != null){
                                    theData = moodBizService.getSomeDayAddMemberCount(startDate, endDate);
                                    todayData = moodBizService.getSomeDayAddMemberCount(theDateStart, theDateEnd);
                            }else{
                                    todayData = moodBizService.getSomeDayAddMemberCount(theDateStart, theDateEnd);
                                    yesterdayData = moodBizService.getSomeDayAddMemberCount(oneDateStart, oneDateEnd);
                                    sevenData = moodBizService.getSomeDayAddMemberCount(sevenDateStart, sevenDateEnd);
                                    thirtyData = moodBizService.getSomeDayAddMemberCount(thirtyDateStart, thirtyDateEnd);
                            }
                    }
            } catch (BizException e) {
                    e.printStackTrace();
            }
            mapList.put("theDay", theData);
            mapList.put("today", todayData);
            mapList.put("yesterday", yesterdayData);
            mapList.put("sevenDay", sevenData);
            mapList.put("thirtyDay", thirtyData);
            return buildDataResult(mapList);
    }
    3.biz中的方法

    //统计某一天各个时间段新增的人数
    public long [] getSomeDayAddMemberCount(Date startTime, Date endTime) throws BizException{
            long [] count = new long[24];
            List> mapList = memberService.getSomeDayCount(startTime, endTime);
            for (Map map : mapList) {
                    int i = (int) map.get("hh");
                    long value = (long) map.get("cnt");
                    count[i] = value;
            }
            return count;
    }
    4.sql语句

    select HOUR(createTime) as hh, count(*) as cnt from user_member
    where createTime<'2016-06-24 23:06:41' and createTime>'2016-06-24 00:06:41'
    group by hh;
    5.示例图片 Highcharts展示一天24个时间段的数据统计_第1张图片 Highcharts展示一天24个时间段的数据统计_第2张图片

    你可能感兴趣的:(实例)