/*查詢某一天時間段的付款金額*/ @Override public R getDayData(Long instituId, String beginDate,String endDate) { List<Map> list=baseMapper.getDayData(instituId,beginDate,endDate); /*補全其餘沒有數據的日期*/ List<String> allDate = new ArrayList(); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date dBegin =sdf.parse(beginDate); Date dEnd = sdf.parse(endDate); allDate.add(sdf.format(dBegin)); Calendar cal=Calendar.getInstance(); cal.setTime(sdf.parse(beginDate)); boolean bContinue = true; while (bContinue){ cal.add(Calendar.DAY_OF_MONTH, 1); if(sdf.parse(endDate).after(cal.getTime())){ allDate.add(sdf.format(cal.getTime())); }else{ break; } } } catch (ParseException e) { e.printStackTrace(); } allDate.add(endDate); //造好的日期集合 List<Map> newTime=new ArrayList<>(); for(String time:allDate) { Map m = new HashMap(); m.put("payTime", time); m.put("payment", 0); newTime.add(m); for(Map map:list){ if(time.equals(map.get("payTime").toString())){ newTime.remove(m); } } } //返回結果 List<Map> newList=new ArrayList<>(); newList.addAll(list); newList.addAll(newTime); //返回集合排序 Collections.sort(newList, new Comparator<Map>() { @Override public int compare(Map o1, Map o2) { String payTime1=o1.get("payTime").toString(); String payTime2=o2.get("payTime").toString(); return payTime1.compareTo(payTime2); } }); return R.ok(newList); }