package com.moral.service.impl;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import com.moral.entity.charts.TimeUnits;
|
import com.moral.mapper.AlarmMapper;
|
import com.moral.service.AlarmService;
|
import com.moral.service.HistoryMinutelyService;
|
|
@Service
|
@SuppressWarnings({"rawtypes"})
|
public class AlarmServiceImpl implements AlarmService {
|
|
@Resource
|
private AlarmMapper alarmMapper;
|
|
@Resource
|
private HistoryMinutelyService historyMinutelyService;
|
@Override
|
public List<Map> countByTimes(Date start, Date end, TimeUnits timeUnits) throws ParseException {
|
String format = null;
|
if (timeUnits != null) {
|
switch (timeUnits) {
|
case MONTH:
|
format = "%Y-%m";
|
break;
|
case DAY:
|
format = "%Y-%m-%d";
|
break;
|
default:
|
break;
|
}
|
}
|
if (start == null) {
|
Calendar cal = Calendar.getInstance();
|
String s = cal.get(Calendar.YEAR) + "";
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
|
start = sdf.parse(s);
|
}
|
|
if (end == null) {
|
end = new Date();
|
}
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMM");
|
|
String[] starts = sdf.format(start).split("-");
|
String[] ends = sdf.format(end).split("-");
|
Date startTime = sdf1.parse(starts[0] + "" + starts[1]);
|
Date endTime = sdf1.parse(ends[0] + "" + ends[1]);
|
|
Calendar cal = Calendar.getInstance();
|
cal.setTime(startTime);
|
|
List<String> list = new ArrayList<>();
|
for (long d = cal.getTimeInMillis(); d <= endTime.getTime(); cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1), d = cal.getTimeInMillis()) {
|
list.add(sdf1.format(d));
|
}
|
return alarmMapper.countByTimes(start, end, format, list);
|
|
}
|
|
}
|