Commit 263a7b93 by hzc

修改了返回集合,插入了为零的结果

parent ac9e1ecc
......@@ -46,11 +46,15 @@ public class LoggingEventServiceImpl implements LoggingEventService {
calendar.add(calendar.DATE,-30);
startDateTime = calendar.getTimeInMillis();
}
endDateTime = endDateTime+60*60*24*1000;//加一天
logQuery.setStartTime(startDateTime);
logQuery.setEndTime(endDateTime);
//查出符合条件的数据然后再判断具体天数的数量
List<LogStatistics> logStatisticsList=loggingEventMapper.findVisitCount(logQuery);
return logStatisticsList;
return this.trimResults(logStatisticsList,startDateTime,endDateTime);
}
@Override
......@@ -69,12 +73,17 @@ public class LoggingEventServiceImpl implements LoggingEventService {
Calendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(endDateTime);
calendar.add(calendar.DATE,-30);
startDateTime = calendar.getTimeInMillis();
}
endDateTime = endDateTime+60*60*24*1000;//加一天
logQuery.setStartTime(startDateTime);
logQuery.setEndTime(endDateTime);
List<LogStatistics> LogStatisticsList = loggingEventMapper.findVisitUserCount(logQuery);
return LogStatisticsList;
List<LogStatistics> logStatisticsList = loggingEventMapper.findVisitUserCount(logQuery);
return this.trimResults(logStatisticsList,startDateTime,endDateTime);
}
@Override
......@@ -95,6 +104,37 @@ public class LoggingEventServiceImpl implements LoggingEventService {
return loggingEventMapper.findVisitMsg(logQuery);
}
private List<LogStatistics> trimResults(List<LogStatistics> logStatisticsList,Long startTime,Long endTime){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Map<String,Long> map=new HashMap<>();
for (int i=0;i<logStatisticsList.size();i++){
String dateTimeStr = logStatisticsList.get(i).getDateTime();
map.put(dateTimeStr,logStatisticsList.get(i).getCount());
}
Calendar calendar1 = new GregorianCalendar();
calendar1.setTimeInMillis(startTime);
Calendar calendar2 = new GregorianCalendar();
calendar2.setTimeInMillis(endTime);
List<LogStatistics> values = new ArrayList<>();
while (calendar1.getTimeInMillis()<calendar2.getTimeInMillis()){
String dateStr = simpleDateFormat.format(calendar1.getTime());
LogStatistics logStatistics = new LogStatistics();
logStatistics.setDateTime(dateStr);
Long count = map.get(dateStr);
if(count==null){
logStatistics.setCount(0l);
}else{
logStatistics.setCount(count);
}
values.add(logStatistics);
calendar1.add(calendar1.DATE,1);
}
return values;
}
private Long getDateTime(String dateStr){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Long dateTime=null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment