| | |
| | | |
| | | @Resource |
| | | private MonitorPointMapper monitorPointMapper; |
| | | @Resource |
| | | HistoryFiveMinutelyMapper historyFiveMinutelyMapper; |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getFiveMinutesDataByMacsAndTime(Map<String, Object> parameters) { |
| | | ValidateUtil.notNull(parameters,"查询五分钟数据参数为空"); |
| | | return historyFiveMinutelyMapper.getFiveMinutesDataByMacsAndTime(parameters); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getDayAQIByDevice(Map<String, Object> parameters) { |
| | |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getAllDeviceDataToExcel(Map<String, Object> parameters) throws Exception { |
| | | String time = parameters.remove("startTime").toString(); |
| | | String timeb; |
| | | if (parameters.get("endTime") == null) { |
| | | timeb = time; |
| | | } else { |
| | | timeb = parameters.remove("endTime").toString(); |
| | | } |
| | | parameters.put("time", time); |
| | | parameters.put("timeb", timeb); |
| | | Calendar cal = Calendar.getInstance(); |
| | | int length = time.length(); |
| | | String type = ""; |
| | | if (length == 10) { |
| | | type = "day"; |
| | | } else if (length == 7) { |
| | | type = "month"; |
| | | } else if (length == 4) { |
| | | type = "year"; |
| | | } else if (length == 13) { |
| | | type = "hour"; |
| | | } |
| | | parameters.put("type", type); |
| | | String[] endTimes = timeb.split("-"); |
| | | String dateFormat = ""; |
| | | String beginTime = ""; |
| | | String endTime = ""; |
| | | Integer year = Integer.valueOf(endTimes[0]); |
| | | int i = 0; |
| | | if (type.equals("year")) { |
| | | dateFormat = "yyyy-MM"; |
| | | beginTime = time + "-01"; |
| | | timeb = Integer.valueOf(timeb) + 1 + ""; |
| | | endTime = timeb + "-01"; |
| | | i = Calendar.MONTH; |
| | | } else if (type.equals("month")) { |
| | | dateFormat = "yyyy-MM-dd"; |
| | | beginTime = time + "-01"; |
| | | i = Calendar.DAY_OF_MONTH; |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); |
| | | cal.setTime(sdf.parse(timeb)); |
| | | cal.add(Calendar.MONTH, 1); |
| | | timeb = sdf.format(cal.getTime()); |
| | | endTime = timeb + "-01"; |
| | | } else if (type.equals("day")) { |
| | | dateFormat = "yyyy-MM-dd HH"; |
| | | beginTime = time + " 00"; |
| | | i = Calendar.HOUR_OF_DAY; |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | cal.setTime(sdf.parse(timeb)); |
| | | cal.add(Calendar.DAY_OF_MONTH, 1); |
| | | timeb = sdf.format(cal.getTime()); |
| | | endTime = timeb + " 00"; |
| | | } else if (type.equals("hour")) { |
| | | dateFormat = "yyyy-MM-dd HH:mm"; |
| | | beginTime = time + ":00:00"; |
| | | i = Calendar.MINUTE; |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH"); |
| | | cal.setTime(sdf.parse(timeb)); |
| | | cal.add(Calendar.HOUR_OF_DAY, 1); |
| | | timeb = sdf.format(cal.getTime()); |
| | | endTime = timeb + ":00:00"; |
| | | } |
| | | SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); |
| | | cal.setTime(sdf.parse(beginTime)); |
| | | List<String> times = new ArrayList<>(); |
| | | for (long d = cal.getTimeInMillis(); d < sdf.parse(endTime).getTime(); cal.set(i, cal.get(i) + 1), d = cal.getTimeInMillis()) { |
| | | String format = sdf.format(d); |
| | | times.add(format); |
| | | } |
| | | String[] sensorKeys = parameters.get("sensorKey").toString().split(","); |
| | | List<String> keys = Arrays.asList(sensorKeys); |
| | | parameters.put("sensors", keys); |
| | | parameters.put("sensorKeys", keys); |
| | | parameters.put("timeb", timeb); |
| | | int mpId = Integer.valueOf(parameters.get("monitorPoint").toString()); |
| | | String monitorPointName = monitorPointMapper.getMonitorName(mpId); |
| | | List<Map<String, Object>> devices = deviceMapper.getDevicesByMpId(mpId); |
| | | List<Map<String, Object>> resultList = new ArrayList<>(); |
| | | for (Map<String, Object> map : devices) { |
| | | String mac = map.get("mac").toString(); |
| | | parameters.put("mac", mac); |
| | | String name = map.get("name").toString(); |
| | | List<Map<String, Object>> data = getMonitorPointOrDeviceAvgData(parameters); |
| | | for (String sensorKey : keys) { |
| | | Map<String, Object> sensor = sensorMapper.getSensorBySensorKey(sensorKey); |
| | | if (sensor == null) { |
| | | continue; |
| | | } |
| | | String description = sensor.get("description").toString(); |
| | | String unit = sensor.get("unit").toString(); |
| | | Map<String, Object> hashMap = new LinkedHashMap<>(); |
| | | for (String t : times) { |
| | | hashMap.put("monitorPointName", monitorPointName); |
| | | hashMap.put("name", name); |
| | | hashMap.put("sensor", description + "(" + unit + ")"); |
| | | hashMap.put(t, ""); |
| | | } |
| | | if (data.size() != 0) { |
| | | for (Map<String, Object> dataMap : data) { |
| | | String t = dataMap.get("time").toString(); |
| | | if (dataMap.get(sensorKey) != null) { |
| | | String value = dataMap.get(sensorKey).toString(); |
| | | hashMap.put(t, value); |
| | | } |
| | | } |
| | | } |
| | | resultList.add(hashMap); |
| | | } |
| | | } |
| | | return resultList; |
| | | } |
| | | } |