From e745dd38c5a413eaa000c7c5434621fbcd1800d5 Mon Sep 17 00:00:00 2001
From: 于紫祥_1901 <email@yuzixiang_1910>
Date: Wed, 23 Dec 2020 13:55:07 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/com/moral/service/impl/HistoryServiceImpl.java |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
index 8007e0a..498bcec 100644
--- a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
@@ -406,14 +406,17 @@
         String timeUnits = startTime.substring(0, 10).replace("-", "");
         Map<String, Object> map = historyMapper.getAVGValueByMacAndTimeslot(mac, startTime, endTime, timeUnits);
         Map<String, Object> returnMap = new HashMap<>();
-        if (map.isEmpty()) {
-            returnMap.put("AQI", "N/V");
+        if (ObjectUtils.isEmpty(map) || map.isEmpty()) {
+             returnMap.put("AQI", "N/V");
+             return returnMap;
         } else {
             Map<String, Double> AQIMap = new HashMap<>();
             for (Map.Entry<String, Object> entry : map.entrySet()) {
                 String key = entry.getKey();
-                Double value = Double.parseDouble(entry.getValue().toString());
-                AQIMap.put(key, value);
+                if (entry.getValue() != null) {
+                    Double value = Double.parseDouble(entry.getValue().toString());
+                    AQIMap.put(key, value);
+                }
             }
             returnMap = AQICalculation.hourlyAQI(AQIMap);
         }
@@ -537,8 +540,8 @@
         String startTime = parameters.get("startTime").toString();
         DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDateTime startTimeLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
-        LocalDateTime today = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
-        LocalDateTime startTimeDay = startTimeLocalDateTime.truncatedTo(ChronoUnit.DAYS);
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
+        int format = Integer.parseInt(sdf.format(new Date()));
         int year = startTimeLocalDateTime.getYear();
         int month = startTimeLocalDateTime.getMonthValue();
         String monthStr = month < 10 ? ("0" + month) : month + "";
@@ -550,17 +553,15 @@
         }
         parameters.put("sensorKeys", sensorKeys);
         List<Map<String, Object>> listMap = null;
-        /*if (today.compareTo(startTimeDay) == 0) {
-            listMap = historyMapper.listGetSensorData(parameters);
-        }*/
-        //if (CollectionUtils.isEmpty(listMap)) {
         listMap = historyMapper.getCarSensorData(parameters);
         if (CollectionUtils.isEmpty(listMap)) {
             if (year <= 2019) {
                 listMap = historyMinutelyMapper.getSensorData(parameters);
             } else {
-                parameters.put("yearAndMonth", yearAndMonth);
-                listMap = historyMinutelyMapper.getSensorData2020(parameters);
+                if (Integer.parseInt(yearAndMonth) <= format) {
+                    parameters.put("yearAndMonth", yearAndMonth);
+                    listMap = historyMinutelyMapper.getSensorData2020(parameters);
+                }
             }
         }
         //}

--
Gitblit v1.8.0