| | |
| | | LocalDateTime time = LocalDateTime.now(); |
| | | int year = time.getYear(); |
| | | int month = time.getMonthValue(); |
| | | int day = time.getDayOfMonth(); |
| | | if (day == 1) { |
| | | if (month == 1) { |
| | | month = 12; |
| | | year = year - 1; |
| | | } else { |
| | | month = month - 1; |
| | | } |
| | | } |
| | | String monthStr = month < 10 ? ("0" + month) : month + ""; |
| | | String yearAndMonth = year + monthStr; |
| | | LocalDateTime endTime = time.truncatedTo(ChronoUnit.MINUTES); |
| | |
| | | LocalDateTime time = LocalDateTime.now(); |
| | | int year = time.getYear(); |
| | | int month = time.getMonthValue(); |
| | | int day = time.getDayOfMonth(); |
| | | if (day == 1) { |
| | | if (month == 1) { |
| | | month = 12; |
| | | year = year - 1; |
| | | } else { |
| | | month = month - 1; |
| | | } |
| | | } |
| | | String monthStr = month < 10 ? ("0" + month) : month + ""; |
| | | String yearAndMonth = year + monthStr; |
| | | LocalDateTime endTime = time.truncatedTo(ChronoUnit.HOURS); |
| | |
| | | if (!key.equals("mac") && !key.startsWith("M")) { |
| | | List<Object> date = new ArrayList<>(); |
| | | date.add(deviceData.get(key)); |
| | | date.add(new BigDecimal(deviceData.get("MIN" + key).toString())); |
| | | date.add(new BigDecimal(deviceData.get("MAX" + key).toString())); |
| | | if (deviceData.get("MIN" + key) instanceof String) { |
| | | date.add(new BigDecimal(deviceData.get("MIN" + key).toString())); |
| | | date.add(new BigDecimal(deviceData.get("MAX" + key).toString())); |
| | | } else if (deviceData.get("MIN" + key) instanceof byte[]) { |
| | | date.add(new BigDecimal(new String((byte[]) (deviceData.get("MIN" + key))))); |
| | | date.add(new BigDecimal(new String((byte[]) (deviceData.get("MAX" + key))))); |
| | | } |
| | | jo.put(key, date); |
| | | } |
| | | } |
| | |
| | | if (!key.equals("mac") && !key.startsWith("M")) { |
| | | List<Object> date = new ArrayList<>(); |
| | | date.add(deviceData.get(key)); |
| | | date.add(new BigDecimal(deviceData.get("MIN" + key).toString())); |
| | | date.add(new BigDecimal(deviceData.get("MAX" + key).toString())); |
| | | if (deviceData.get("MIN" + key) instanceof String) { |
| | | date.add(new BigDecimal(deviceData.get("MIN" + key).toString())); |
| | | date.add(new BigDecimal(deviceData.get("MAX" + key).toString())); |
| | | } else if (deviceData.get("MIN" + key) instanceof byte[]) { |
| | | date.add(new BigDecimal(new String((byte[]) (deviceData.get("MIN" + key))))); |
| | | date.add(new BigDecimal(new String((byte[]) (deviceData.get("MAX" + key))))); |
| | | } |
| | | jo.put(key, date); |
| | | } |
| | | } |
| | |
| | | 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 (!key.equals("mac") && !key.startsWith("M")) { |
| | | List<Object> date = new ArrayList<>(); |
| | | date.add(deviceData.get(key)); |
| | | date.add(new BigDecimal(deviceData.get("MIN" + key).toString())); |
| | | date.add(new BigDecimal(deviceData.get("MAX" + key).toString())); |
| | | if (deviceData.get("MIN" + key) instanceof String) { |
| | | date.add(new BigDecimal(deviceData.get("MIN" + key).toString())); |
| | | date.add(new BigDecimal(deviceData.get("MAX" + key).toString())); |
| | | } else if (deviceData.get("MIN" + key) instanceof byte[]) { |
| | | date.add(new BigDecimal(new String((byte[]) (deviceData.get("MIN" + key))))); |
| | | date.add(new BigDecimal(new String((byte[]) (deviceData.get("MAX" + key))))); |
| | | } |
| | | jo.put(key, date); |
| | | } |
| | | } |
| | |
| | | } |
| | | 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; |
| | |
| | | devices.put("start", startTime); |
| | | devices.put("end", endTime); |
| | | try { |
| | | List<Map<String, Object>> minutelyData = deviceService.getSensorDataOnce(devices); |
| | | List<Map<String, Object>> minutelyData = deviceService.getSensorDataByMacOnce(devices); |
| | | XxlJobLogger.log("historyMinutelyData:" + minutelyData.size()); |
| | | List<Map<String, Object>> minutelyDataList = new ArrayList<>(); |
| | | for (Map<String, Object> deviceData : minutelyData) { |