| | |
| | | List<HistoryHourly> hourlies = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate); |
| | | for (HistoryHourly historyHourly : hourlies) { |
| | | Date time = historyHourly.getTime(); |
| | | int hour = DateUtils.getHour(time); |
| | | String dateStr = DateUtils.dateToDateString(time, "yyyy-MM-dd HH"); |
| | | String value = historyHourly.getValue(); |
| | | timeValueMap.put(String.valueOf(hour), value); |
| | | timeValueMap.put(dateStr, value); |
| | | } |
| | | //如果数据不足则需要补足一天24小时的时间。 |
| | | for (int i = 0; i < 24; i++) { |
| | | //构造时间 |
| | | String time = DateUtils.dateToDateString(startDate, "yyyy-MM-dd"); |
| | | if (i < 10) |
| | | time = time + " 0" + i; |
| | | else |
| | | time = time + " " + i; |
| | | if(timeValueMap.get(time)==null) |
| | | timeValueMap.put(time,null); |
| | | } |
| | | } |
| | | //处理月报数据 |
| | |
| | | List<HistoryDaily> dailies = historyDailyService.getHistoryDailyByMacAndTimeSlot(mac, startDate, endDate); |
| | | for (HistoryDaily historyDaily : dailies) { |
| | | Date time = historyDaily.getTime(); |
| | | int day = DateUtils.getDay(time); |
| | | String dateStr = DateUtils.dateToDateString(time, "yyyy-MM-dd"); |
| | | String value = historyDaily.getValue(); |
| | | timeValueMap.put(String.valueOf(day), value); |
| | | timeValueMap.put(String.valueOf(dateStr), value); |
| | | } |
| | | //如果数据不足则需要补足一个月的时间。 |
| | | int days = DateUtils.getMonthDay(startDate); |
| | | for (int i = 1; i <= days; i++) { |
| | | //构造时间 |
| | | String time = DateUtils.dateToDateString(startDate, "yyyy-MM"); |
| | | if (i < 10) |
| | | time = time + "-0" + i; |
| | | else |
| | | time = time + "-" + i; |
| | | if(timeValueMap.get(time)==null) |
| | | timeValueMap.put(time,null); |
| | | } |
| | | } else |
| | | return null; |
| | |
| | | List<SensorComparisonDisplayDTO> dtos = new ArrayList<>(); |
| | | for (String sensor : sensors) { |
| | | SensorComparisonDisplayDTO dto = new SensorComparisonDisplayDTO(); |
| | | Map<String,Double> dtoTimeValueMap = new LinkedHashMap<>(); |
| | | List<Map<String, Object>> dtoTimeValueList = new ArrayList<>(); |
| | | dto.setSensorCode(sensor); |
| | | timeValueMap.forEach((time, valueJson) -> { |
| | | Map<String, Object> listMap = new HashMap<>(); |
| | | //如果对应时间没有数据 |
| | | if (valueJson == null) { |
| | | listMap.put("time", time); |
| | | listMap.put("value", ""); |
| | | dtoTimeValueList.add(listMap); |
| | | return; |
| | | } |
| | | Map<String, Object> valueMap = JSON.parseObject(valueJson, Map.class); |
| | | Object sensorValueObject = valueMap.get(sensor); |
| | | if(sensorValueObject==null) |
| | | //如果数据中没有该因子,则放入null |
| | | if (sensorValueObject == null) { |
| | | listMap.put("time", time); |
| | | listMap.put("value", ""); |
| | | dtoTimeValueList.add(listMap); |
| | | return; |
| | | Double sensorValue = Double.parseDouble(sensorValueObject.toString()); |
| | | //如果是小时数据需要判断标记位 |
| | | if(reportType.equals(Constants.HOURLY_REPORT)){ |
| | | if(!Constants.NORMAL_FLAG.equals(valueMap.get(sensor+"-Flag"))) |
| | | return; |
| | | } |
| | | //如果是小时数据需要判断标记位 |
| | | if (reportType.equals(Constants.DAILY_REPORT)) { |
| | | if (!Constants.NORMAL_FLAG.equals(valueMap.get(sensor + "-Flag"))) { |
| | | listMap.put("time", time); |
| | | listMap.put("value", ""); |
| | | dtoTimeValueList.add(listMap); |
| | | return; |
| | | } |
| | | } |
| | | //取出数据 |
| | | Double sensorValue = Double.parseDouble(sensorValueObject.toString()); |
| | | //封装数据 |
| | | dtoTimeValueMap.put(time,sensorValue); |
| | | dto.setTimeValueMap(dtoTimeValueMap); |
| | | listMap.put("time", time); |
| | | listMap.put("value", sensorValue); |
| | | dtoTimeValueList.add(listMap); |
| | | }); |
| | | dto.setTimeValueList(dtoTimeValueList); |
| | | dtos.add(dto); |
| | | } |
| | | return dtos; |