| | |
| | | return yearTimeDescMap; |
| | | } |
| | | |
| | | /** |
| | | * 按月划分且,不存在默认表,都是分表 |
| | | * @param startTimeDate |
| | | * @param endTimeDate |
| | | * @return |
| | | * @throws ParseException |
| | | */ |
| | | public static Map<String,List<Date>> getQueryTimeForSubTablesByMonthDesc2(Date startTimeDate,Date endTimeDate) throws ParseException { |
| | | //根据筛选的时间段,查询出符合要求的各分表记录数 |
| | | //首先,如果当前时间超过7月,默认表中只有本年度的;如果没超过7月,默认表还存在上一年度的记录 |
| | | Calendar now = Calendar.getInstance(); |
| | | if(endTimeDate.compareTo(now.getTime())>0){ //校验优化最大查询时间 |
| | | endTimeDate = now.getTime(); |
| | | } |
| | | LinkedHashMap<String,List<Date>> yearTimeMap = (LinkedHashMap<String, List<Date>>) DateUtil.getMonthListDesc(startTimeDate, endTimeDate); |
| | | Map<String,List<Date>> yearTimeDescMap = new LinkedHashMap<>(); |
| | | boolean existDefaultYear = false; |
| | | //查询的结束时间 |
| | | //if(DateUtil.YYYY_MM_TABLE.format(endTimeDate).equals(DateUtil.YYYY_MM_TABLE.format(now.getTime()))){ |
| | | if(ThreadLocalUtil.format(endTimeDate,2).equals(ThreadLocalUtil.format(now.getTime(),2))){ |
| | | List<Date> defaultDateList = new LinkedList<>(); |
| | | defaultDateList.add(startTimeDate); |
| | | defaultDateList.add(endTimeDate); |
| | | } |
| | | //调整下顺序,将default调整到首位 |
| | | if(existDefaultYear){ |
| | | List<Date> defaultTimeList = yearTimeMap.get("default"); |
| | | yearTimeDescMap.put("default",defaultTimeList); |
| | | } |
| | | Set<String> yearSet = yearTimeMap.keySet(); |
| | | for (String year : yearSet) { |
| | | if(!year.equals("default")){ |
| | | yearTimeDescMap.put(year,yearTimeMap.get(year)); |
| | | } |
| | | } |
| | | |
| | | return yearTimeDescMap; |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) throws ParseException { |
| | | //Date d1 = YYYY_MM_DD_HH_MM_SS.parse("2023-01-22 14:12:22"); |