-
service.java 文件 /** * 查询一段时间内的数据 * @param type 类型 1:天;2:周:3:月 4:年 * @param startDay 开始时间 * @param endDay 结束时间 * @return list */ public List<CountNumberVO> countNumber(int type, String startDay, String endDay) { if (StringUtils.isEmpty(startDay)){ startDay = "2017-11-13"; } if (StringUtils.isEmpty(endDay)){ endDay = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); } List<Map> list; switch(type){ case 1: list= authenticationRepository.countDay(startDay, endDay); break; case 2: list= authenticationRepository.countWeek(startDay, endDay); break; case 3: list= authenticationRepository.countMonth(startDay, endDay); break; default: list= authenticationRepository.countYear(startDay, endDay); break; } System.out.println("================="); List<CountNumberVO> listVo = new ArrayList<>(); list.forEach(item ->{ CountNumberVO vo = new CountNumberVO(); try{ BeanUtils.populate(vo, item); }catch (Exception e){ e.printStackTrace(); } listVo.add(vo); }); return listVo; }
-
Repository.java @Query(value = "SELECT DATE_FORMAT( create_time, '%Y-%m-%d' ) date, COUNT( * ) number FROM register_user where create_time BETWEEN ?1 and ?2 GROUP BY date; ",nativeQuery = true) List<Map> countDay(String startDay, String endDay); @Query(value = "select DATE_FORMAT(create_time,'%Y-%u') date,count(*) number from register_user where create_time BETWEEN ?1 and ?2 group by date",nativeQuery = true) List<Map> countWeek(String startDay, String endDay); @Query(value = "select DATE_FORMAT(create_time,'%Y-%m') date,count(*) number from register_user where create_time BETWEEN ?1 and ?2 group by date;",nativeQuery = true) List<Map> countMonth(String startDay, String endDay); @Query(value = "select date_format(create_time, '%Y') date, count(*) number from register_user where create_time BETWEEN ?1 and ?2 group by date;",nativeQuery = true) List<Map> countYear(String startDay, String endDay);
报表 天、周、月 、年 springboot 数据查询
最新推荐文章于 2024-07-02 09:29:10 发布