| | |
| | | LocalDateTime value = time.truncatedTo(ChronoUnit.DAYS); |
| | | List<String> sensorKeys = sensorService.getSensorKeys(); |
| | | List<String> macs = deviceService.getMacs(); |
| | | for (int i = 0; i <= 5; i++) { |
| | | LocalDateTime startTime = value.plusHours(i); |
| | | LocalDateTime endTime = value.plusHours(i + 1); |
| | | Map<String, Object> devices = new HashMap<>(); |
| | | devices.put("sensorKeys", sensorKeys); |
| | | devices.put("start", startTime); |
| | | devices.put("end", endTime); |
| | | devices.put("macs", macs); |
| | | devices.put("yearAndMonth", yearAndMonth); |
| | | try { |
| | | int count = 0; |
| | | try { |
| | | for (int i = 0; i <= 5; i++) { |
| | | LocalDateTime startTime = value.plusHours(i); |
| | | LocalDateTime endTime = value.plusHours(i + 1); |
| | | Map<String, Object> devices = new HashMap<>(); |
| | | devices.put("sensorKeys", sensorKeys); |
| | | devices.put("start", startTime); |
| | | devices.put("end", endTime); |
| | | devices.put("macs", macs); |
| | | devices.put("yearAndMonth", yearAndMonth); |
| | | List<Map<String, Object>> hourlyData = historyMinutelyService.getMinutelySensorData(devices); |
| | | XxlJobLogger.log("historyHourlyData:" + hourlyData.size()); |
| | | count += hourlyData.size(); |
| | | List<Map<String, Object>> hourlyDataList = new ArrayList<>(); |
| | | for (Map<String, Object> deviceData : hourlyData) { |
| | | if (!ObjectUtils.isEmpty(deviceData)) { |
| | |
| | | } |
| | | if (!CollectionUtils.isEmpty(hourlyDataList)) { |
| | | historyHourlyService.insertHistoryHourly(hourlyDataList); |
| | | ReturnT returnT = new ReturnT(200, "插入小时表成功"); |
| | | return returnT; |
| | | } |
| | | } catch (Exception e) { |
| | | XxlJobLogger.log("historyHourlyException:" + e.getMessage()); |
| | | logger.error(e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | XxlJobLogger.log("historyHourlyData:" + count); |
| | | ReturnT returnT = new ReturnT(200, "插入小时表成功"); |
| | | return returnT; |
| | | } catch (Exception e) { |
| | | XxlJobLogger.log("historyHourlyException:" + e.getMessage()); |
| | | logger.error(e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | ReturnT returnT = new ReturnT(500, "插入小时表失败"); |
| | | return returnT; |