知方号

知方号

报表统计<月数据报表查询>

报表统计

一般图表绘制例如echarts等,返回数据格式都大同小异。重点是利用sql或者java实现数据格式的转型,接下来是关键部分:

1.前提:提供的工具方法——获取某月有多少天

//通过年份和月份确定该月的最后一天 public static int getMaxDay(int year,int month ){ Calendar time=Calendar.getInstance(); time.clear(); time.set(Calendar.YEAR,year); //year 为 int time.set(Calendar.MONTH,month-1); //month 为int return time.getActualMaximum(Calendar.DAY_OF_MONTH); }

2.mapper层sql语句书写

SELECT sum(t.ordercount) ordercount, t.[month] month , t.[day] day from order t where 1=1 and t.year=convert(int, #{year}) and t.month=convert(int, #{month}) GROUP BY t.[month],t.[day] HAVING 1=1 ORDER BY t.[day] asc

3.service层实现,调用sql返回结果,及对其返回结果进行格式转换(重要)

Map resultMap = new HashMap(); //获取到数据库搜索的年份对应某月份的31天订单量 List orderCountList = orderCountManager.getAllOrderCountByYearAndMonth(pd); //确定某个月的天数(如果日期截止只要到有数据的最大日期,那么可以修改sql语句排列方式,例如,日期从大到小排列,那么就是位置在0上的数据是最大天数,很简单实现,此处不列出来了) int days = getMaxDay(Integer.parseInt(pd.get("year").toString()),Integer.parseInt(pd.get("month").toString())); //定义数组,默认都是0 int[] countVIP = new int[days]; //将获取到不同年份不同月份不同日期对应不同的订单量放在数组中 if (orderCountList.size()>0 && orderCountList!=null) { for (int i=0;i0) { if (argYear == currentYear && argMonth == currentMonth) { //获取最后一天日期 PageData lastDay = orderCountList.get(orderCountList.size() - 1); //获取截止天数 maxDays = Integer.parseInt(lastDay.get("day").toString()); } } //定义最大天数数组 int[] count = new int[maxDays]; int[] days = new int[maxDays]; //补全日期到数组中 for(int i=0;i0) { //将获取到不同年份不同月份不同日期对应不同的订单量放在数组中 for (int i=0;i0){ if(argYear==currentYear){ //获取最后一个月份 PageData lastMonth = orderCountList.get(orderCountList.size()-1); //获取截止月份 maxMonths= Integer.parseInt(lastMonth.get("month").toString()); } } //定义返回数据格式,默认都是0 int[] count = new int[maxMonths]; int[] months = new int[maxMonths]; //补全月份到数组中 for(int i=0;i0){ //将获取到不同年份不同月份对应的订单量放在数组中 for (int i=0;i

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。