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/resources/mapper/HangzhouAqiMapper.xml |  114 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 101 insertions(+), 13 deletions(-)

diff --git a/src/main/resources/mapper/HangzhouAqiMapper.xml b/src/main/resources/mapper/HangzhouAqiMapper.xml
index 26e4898..f8c7053 100644
--- a/src/main/resources/mapper/HangzhouAqiMapper.xml
+++ b/src/main/resources/mapper/HangzhouAqiMapper.xml
@@ -53,18 +53,106 @@
     </select>
 
     <select id="getAreaAvgDataByAreaCode" resultType="java.util.Map">
-    SELECT
-    DATE_FORMAT(time, #{typeFormat}) time,
-    round(AVG(case when aqi_json->'$.${sensors}' is null then aqi_json->'$.${sensors1}' else aqi_json->'$.${sensors}' end),4)  as '${sensors2}'
-    FROM
-    hangzhou_aqi ha
-    WHERE
-    ha.time >= #{start}
-    AND ha.time <![CDATA[<]]> #{end}
-    AND ha.city_code = #{areaCode}
-    GROUP BY
-    DATE_FORMAT(time, #{typeFormat})
-    ORDER BY
-    time
+        SELECT
+        DATE_FORMAT(time, #{typeFormat}) time,
+        round(AVG(case when aqi_json->'$.${sensors}' is null then aqi_json->'$.${sensors1}' else aqi_json->'$.${sensors}' end),4)  as '${sensors2}'
+        FROM
+        hangzhou_aqi ha
+        WHERE
+        ha.time >= #{start}
+        AND ha.time <![CDATA[<]]> #{end}
+        AND ha.city_code = #{areaCode}
+        GROUP BY
+        DATE_FORMAT(time, #{typeFormat})
+        ORDER BY
+        time
+    </select>
+
+    <select id="getAqiDataByAreaCode" resultType="java.util.Map">
+        SELECT
+        DATE_FORMAT(time, #{typeFormat}) time,
+        ifnull(aqi_json->'$.${sensor1}',aqi_json->'$.${sensor2}') as '${sensor2}'
+        FROM
+        hangzhou_aqi
+        WHERE
+        time >= #{start}
+        AND time <![CDATA[<]]> #{end}
+        AND city_code = #{cityCode}
+        ORDER BY
+        time
   </select>
+
+    <select id="getHistoryO3" resultType="java.util.Map">
+        SELECT
+        DATE_FORMAT(time, #{typeFormat}) time,
+        value->'$.${sensor2}' as '${sensor2}'
+        FROM
+        history_aqi_${timeUnits}
+        WHERE
+        time >= #{start}
+        AND time <![CDATA[<]]> #{end}
+        AND city_code = #{cityCode}
+        ORDER BY
+        time
+  </select>
+
+    <select id="getAqi" resultType="java.util.Map">
+        select
+        DATE_FORMAT(time, #{typeFormat}) time,
+        aqi_json json
+        FROM
+        hangzhou_aqi
+        WHERE
+        time >= #{start}
+        AND time <![CDATA[<]]> #{end}
+        AND city_code = #{cityCode}
+        ORDER BY
+        time
+    </select>
+
+    <select id="getHistoryAqi" resultType="java.util.Map">
+        select
+        DATE_FORMAT(time, #{typeFormat}) time,
+        value json
+        FROM
+        history_aqi_${timeUnits}
+        WHERE
+        time >= #{start}
+        AND time <![CDATA[<]]> #{end}
+        AND city_code = #{cityCode}
+        ORDER BY
+        time
+    </select>
+
+    <select id="getAvgO3EightHours" resultType="java.util.Map">
+        select
+        cast(AVG(case when aqi_json->'$.O3C' is null then aqi_json->'$.O3' else aqi_json->'$.O3C' end) as UNSIGNED  integer) 'O3_8H'
+        FROM
+        hangzhou_aqi
+        WHERE
+        time >= #{start}
+        AND time <![CDATA[<]]> #{end}
+        AND city_code = #{cityCode}
+    </select>
+
+    <select id="getHistoryO3EightHours" resultType="java.util.Map">
+        select
+        value->'$.O3_8h' 'O3_8H'
+        FROM
+        history_aqi_${timeUnits}
+        WHERE
+        time = #{time}
+        and city_code=#{cityCode}
+    </select>
+
+    <select id="getSumO3" resultType="java.util.Map">
+        select
+        SUM(case when aqi_json->'$.O3C' is null then aqi_json->'$.O3' else aqi_json->'$.O3C' end) 'O3Sum'
+        FROM
+        hangzhou_aqi
+        WHERE
+        time >= #{start}
+        AND time <![CDATA[<]]> #{end}
+        AND city_code = #{cityCode}
+    </select>
 </mapper>

--
Gitblit v1.8.0