-
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 數據查詢
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.