| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | | 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 org.springframework.util.ObjectUtils;
|
| | |
|
| | | import com.moral.entity.charts.TimeUnits;
|
| | | import com.moral.mapper.AlarmMapper;
|
| | | import com.moral.service.AlarmService;
|
| | | import com.moral.service.HistoryMinutelyService;
|
| | |
|
| | | @Service
|
| | | @SuppressWarnings({ "rawtypes", "unchecked" })
|
| | | @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) 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();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map getPieData(Map<String, Object> parameters) {
|
| | | Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
|
| | | try {
|
| | | historyMinutelyService.convertQueryParam(parameters);
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | List<Map<String, Object>> alarmDatas = alarmMapper.getAlarmData(parameters);
|
| | | Object dimension = parameters.get("dimension");
|
| | | if ("monitorPoint".equals(dimension)) {
|
| | | for (Map<String, Object> alarmData : alarmDatas) {
|
| | | String name = alarmData.remove("name").toString();
|
| | | alarmData.remove("sum");
|
| | | for (Map.Entry<String, Object> entry : alarmData.entrySet()) {
|
| | | String key = entry.getKey();
|
| | | Object value = entry.getValue().toString();
|
| | | if (!"0".equals(value)) {
|
| | | List list;
|
| | | Map<String, Object> map = new HashMap<String, Object>();
|
| | | if (ObjectUtils.isEmpty(resultMap.get(key))) {
|
| | | list = new ArrayList();
|
| | | } else {
|
| | | list = (List) resultMap.get(key);
|
| | | }
|
| | | map.put("name", name);
|
| | | map.put("value", value);
|
| | | list.add(map);
|
| | | resultMap.put(key, list);
|
| | | }
|
| | | }
|
| | | }
|
| | | } else {
|
| | | Map<String, Object> alarmData = alarmDatas.get(0);
|
| | | List<String> sensors = (List<String>) parameters.get("sensors");
|
| | | List list = new ArrayList();
|
| | | if (!ObjectUtils.isEmpty(alarmData)) {
|
| | | for (String key : alarmData.keySet()) {
|
| | | for (String sensor : sensors) {
|
| | | String[] split = sensor.split("-");
|
| | | if (key.equals(split[0]) && !"0".equals(alarmData.get(key).toString())) {
|
| | | Map<String, Object> map = new HashMap<String, Object>();
|
| | | if (parameters.containsKey("description")) {
|
| | | map.put("name", split[3]);
|
| | | } else {
|
| | | map.put("name", split[1]);
|
| | | }
|
| | | map.put("value", alarmData.get(key));
|
| | | list.add(map);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | resultMap.put("list", list);
|
| | | }
|
| | | return resultMap;
|
| | | }
|
| | | 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);
|
| | |
|
| | | }
|
| | |
|
| | | }
|