| | |
| | | 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 com.moral.service.HistoryMinutelyService;
|
| | |
|
| | | @Service
|
| | | @SuppressWarnings({ "rawtypes" })
|
| | | @SuppressWarnings({"rawtypes"})
|
| | | public class AlarmServiceImpl implements AlarmService {
|
| | |
|
| | | @Resource
|
| | | private AlarmMapper alarmMapper;
|
| | | @Resource
|
| | | private AlarmMapper alarmMapper;
|
| | |
|
| | | @Resource
|
| | | private HistoryMinutelyService historyMinutelyService;
|
| | | @Resource
|
| | | private HistoryMinutelyService historyMinutelyService;
|
| | | @Override
|
| | | public List<Map> countByTimes(Date start, Date end, TimeUnits timeUnits){
|
| | | String format = null;
|
| | | if(timeUnits!=null){
|
| | | switch (timeUnits){
|
| | | case MONTH: format = "%Y-%m";
|
| | | case DAY: format = "%Y-%m-%d";
|
| | | }
|
| | | }
|
| | | 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();
|
| | | cal.setTime(new Date());
|
| | | cal.set(Calendar.DAY_OF_MONTH, 1);
|
| | | cal.set(Calendar.HOUR_OF_DAY,0);
|
| | | cal.set(Calendar.MINUTE,0);
|
| | | cal.set(Calendar.SECOND,0);
|
| | | start = cal.getTime();
|
| | | }
|
| | |
|
| | | return alarmMapper.countByTimes(start, end, format);
|
| | | }
|
| | | if (end == null) {
|
| | | Calendar cal = Calendar.getInstance();
|
| | | cal.setTime(start);
|
| | | int lastDay = cal.getActualMaximum(Calendar.DATE);
|
| | | cal.set(Calendar.DAY_OF_MONTH, lastDay);
|
| | | cal.set(Calendar.HOUR_OF_DAY,23);
|
| | | cal.set(Calendar.MINUTE,59);
|
| | | cal.set(Calendar.SECOND,59);
|
| | | end = cal.getTime();
|
| | | }
|
| | |
|
| | | 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);
|
| | |
|
| | | }
|
| | |
|
| | | }
|