From 48bb075f91c5daf35cff0a16abe1136f132aafb4 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Mon, 28 Sep 2020 15:40:26 +0800
Subject: [PATCH] 不同天气给定不同分数

---
 src/main/java/com/moral/mapper/AQIMapper.java                        |    2 +
 src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java     |   57 +++++++++++++++++++---------
 src/main/java/com/moral/service/impl/ForecastWeatherServiceImpl.java |   23 ++++++++++-
 src/main/java/com/moral/mapper/HistoryMapper.java                    |    1 
 src/main/resources/mapper/AQIMapper.xml                              |    8 ++++
 src/main/resources/mapper/HistoryHourlyMapper.xml                    |    4 +-
 6 files changed, 72 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/moral/mapper/AQIMapper.java b/src/main/java/com/moral/mapper/AQIMapper.java
index 0fba3fa..39572f1 100644
--- a/src/main/java/com/moral/mapper/AQIMapper.java
+++ b/src/main/java/com/moral/mapper/AQIMapper.java
@@ -11,4 +11,6 @@
 
     List<Map<String,Object>> getO3(Map<String,Object> params);
 
+    List<Map<String,Object>> getAqiByHour(Map<String,Object> params);
+
 }
diff --git a/src/main/java/com/moral/mapper/HistoryMapper.java b/src/main/java/com/moral/mapper/HistoryMapper.java
index 94d535e..07beec2 100644
--- a/src/main/java/com/moral/mapper/HistoryMapper.java
+++ b/src/main/java/com/moral/mapper/HistoryMapper.java
@@ -32,4 +32,5 @@
     int deleteHistoryData(String oldTime);
 
     void deletePartition(@Param("p") String p);
+
 }
\ No newline at end of file
diff --git a/src/main/java/com/moral/service/impl/ForecastWeatherServiceImpl.java b/src/main/java/com/moral/service/impl/ForecastWeatherServiceImpl.java
index bbe110c..4e3457b 100644
--- a/src/main/java/com/moral/service/impl/ForecastWeatherServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/ForecastWeatherServiceImpl.java
@@ -198,15 +198,32 @@
                 String condition = "";
                 if ("���".equals(text)) {
                     condition = "100";
+                } else if ("���".equals(text)) {
+                    condition = "90";
                 } else if ("������".equals(text)) {
                     condition = "80";
-                } else if ("���".equals(text)) {
+                } else if ("���".equals(text)) {
+                    condition = "70";
+                } else if ("���".equals(text) || "������".equals(text) || "������".equals(text) || "".equals(text)) {
                     condition = "60";
-                } else if ("���������".equals(text) || "������".equals(text)) {
+                } else if ("������".equals(text)) {
+                    condition = "45";
+                } else if ("���������".equals(text)) {
                     condition = "40";
+                } else if ("������������������".equals(text) || "���������������".equals(text)) {
+                    condition = "30";
                 } else if ("������".equals(text)) {
                     condition = "20";
                 } else if ("���".equals(text)) {
+                    condition = "10";
+                } else if ("������������������".equals(text)) {
+                    condition = "5";
+                } else if ("������������������".equals(text)) {
+                    condition = "4";
+                } else if ("������".equals(text) || "������".equals(text) || "������".equals(text)
+                        || "������".equals(text) || "������".equals(text) || "������".equals(text)
+                        || "���������".equals(text) || "���������������������������".equals(text) || "������".equals(text)
+                ) {
                     condition = "0";
                 } else {
                     condition = "50";
@@ -273,7 +290,7 @@
                 map1.put("times", times);
                 map1.put("time", hour);
                 List<Map<String, Object>> O3List = new ArrayList<>();
-                List<Map<String, Object>> beamList=new ArrayList<>();
+                List<Map<String, Object>> beamList = new ArrayList<>();
                 if (times.size() != 0) {
                     O3List = aqiMapper.getO3(map1);
                     if (O3List.size() == 0) {
diff --git a/src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java b/src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java
index 23dfa16..8dac48c 100644
--- a/src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java
@@ -147,34 +147,55 @@
             map.put("data", nowMap);
         }
 
-        List<Map<String,Object>> resultList=new ArrayList<>();
+        List<Map<String, Object>> resultList = new ArrayList<>();
         for (Map<String, Object> map : hashSet) {
-            Map<String,Object> resultMap=new HashMap<>();
-            resultMap.put("cityCode",map.get("cityCode").toString());
-            resultMap.put("time",now);
+            Map<String, Object> resultMap = new HashMap<>();
+            resultMap.put("cityCode", map.get("cityCode").toString());
+            resultMap.put("time", now);
             Map<String, Object> jsonMap = (Map<String, Object>) map.get("data");
 
             //������km/h->m/s
             Double windSpeed = Double.valueOf(jsonMap.get("windSpeed").toString());
             windSpeed = windSpeed * 1000 / 3600;
-            jsonMap.put("windSpeed",df.format(windSpeed));
+            jsonMap.put("windSpeed", df.format(windSpeed));
             jsonMap.remove("obsTime");
             jsonMap.remove("icon");
             String text = jsonMap.get("text").toString();
-            if(text.equals("���")){
-                jsonMap.put("condition","100");
-            }else if(text.equals("������")){
-                jsonMap.put("condition","80");
-            }else if(text.equals("���")){
-                jsonMap.put("condition","60");
-            }else if(text.equals("���������")||text.equals("������")){
-                jsonMap.put("condition","40");
-            }else if(text.equals("������")){
-                jsonMap.put("condition","20");
-            }else if(text.equals("���")){
-                jsonMap.put("condition","0");
+            String condition;
+            if ("���".equals(text)) {
+                condition = "100";
+            } else if ("���".equals(text)) {
+                condition = "90";
+            } else if ("������".equals(text)) {
+                condition = "80";
+            } else if ("���".equals(text)) {
+                condition = "70";
+            } else if ("���".equals(text) || "������".equals(text) || "������".equals(text) || "".equals(text)) {
+                condition = "60";
+            } else if ("������".equals(text)) {
+                condition = "45";
+            } else if ("���������".equals(text)) {
+                condition = "40";
+            } else if ("������������������".equals(text) || "���������������".equals(text)) {
+                condition = "30";
+            } else if ("������".equals(text)) {
+                condition = "20";
+            } else if ("���".equals(text)) {
+                condition = "10";
+            } else if ("������������������".equals(text)) {
+                condition = "5";
+            } else if ("������������������".equals(text)) {
+                condition = "4";
+            } else if ("������".equals(text) || "������".equals(text) || "������".equals(text)
+                    || "������".equals(text) || "������".equals(text) || "������".equals(text)
+                    || "���������".equals(text) || "���������������������������".equals(text)||"������".equals(text)
+            ) {
+                condition = "0";
+            } else {
+                condition = "50";
             }
-            resultMap.put("json",JSONObject.toJSONString(jsonMap));
+            jsonMap.put("condition",condition);
+            resultMap.put("json", JSONObject.toJSONString(jsonMap));
             resultList.add(resultMap);
         }
         realWeatherMapper.deleteRealWeather(sdf1.format(now));
diff --git a/src/main/resources/mapper/AQIMapper.xml b/src/main/resources/mapper/AQIMapper.xml
index 54d35f5..48c605f 100644
--- a/src/main/resources/mapper/AQIMapper.xml
+++ b/src/main/resources/mapper/AQIMapper.xml
@@ -23,4 +23,12 @@
             #{time}
         </foreach>
     </select>
+
+    <select id="getAqiByHour" resultType="java.util.Map">
+        select DATE_FORMAT(time, '%Y-%m-%d %H:%i:%s') time,
+        value
+        from history_aqi_${timeUnits}
+        where city_code=#{cityCode}
+        and DATE_FORMAT(time, '%Y%H')=#{yearAndHour}
+    </select>
 </mapper>
\ No newline at end of file
diff --git a/src/main/resources/mapper/HistoryHourlyMapper.xml b/src/main/resources/mapper/HistoryHourlyMapper.xml
index cf4fc42..ef5edec 100644
--- a/src/main/resources/mapper/HistoryHourlyMapper.xml
+++ b/src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -68,7 +68,8 @@
         DATE_FORMAT(h.time,#{typeFormat}) time,
         avg(h.json->'$.e12[0]') 'beam'
         FROM history_hourly h
-        WHERE h.mac in
+        WHERE h.json->'$.e12[0]' is not null
+        and h.mac in
         <foreach collection="macs" open="(" separator="," close=")" item="mac">
             #{mac}
         </foreach>
@@ -76,7 +77,6 @@
         <foreach collection="times" open="(" separator="," close=")" item="time">
             #{time}
         </foreach>
-        and h.json->'$.e12[0]' is not null
         group by h.time
     </select>
 

--
Gitblit v1.8.0