From 70a7d1ec98064e1acb3130e56e16c45af52ade6c Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 24 十月 2023 12:03:49 +0800
Subject: [PATCH] 新增数据分析模块完成

---
 src/main/resources/mapper/ds1/DustStatisticsValueMapper.xml |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/main/resources/mapper/ds1/DustStatisticsValueMapper.xml b/src/main/resources/mapper/ds1/DustStatisticsValueMapper.xml
index 40edb30..4726f1b 100644
--- a/src/main/resources/mapper/ds1/DustStatisticsValueMapper.xml
+++ b/src/main/resources/mapper/ds1/DustStatisticsValueMapper.xml
@@ -22,4 +22,42 @@
     -->
     id, mn_code, lst, day_avg, min, max, day_online, day_valid, day_exceeding, type
   </sql>
+
+  <insert id="dailyStatics">
+    insert into  dust_statistics_value(mn_code,lst,day_avg,min,max,day_online,day_valid,day_exceeding,type)
+    select  a.*
+    from  (select
+    mn_code as mn_code,
+    DATE(lst) as lst,
+    ROUND(AVG(dust_value),3)  as day_avg,
+    min(dust_value) as min,
+    max(dust_value) as max,
+    CONCAT(ROUND(COUNT(*)/96*100, 2), '%')  as day_online,
+    CONCAT(ROUND(SUM(CASE WHEN dust_value >0 THEN 1 ELSE 0 END)/96 *100, 2), '%') as day_valid,
+    CONCAT(ROUND(SUM(CASE WHEN dust_value >= 1  THEN 1 ELSE 0 END)/96*100,2),'%') as  day_exceeding,
+    'day' as type
+    from ja_t_dust_site_data_info
+    where  lst between #{beginTime} and #{endTime}
+    GROUP BY mn_code,DATE(lst)
+    ) as a
+  </insert>
+  <insert id="monthlyStatics">
+    insert into  dust_statistics_value(mn_code,lst,day_avg,min,max,day_online,day_valid,day_exceeding,type)
+    select  a.*
+    from  (
+    SELECT
+    mn_code AS mn_code,
+    DATE_FORMAT(lst, '%Y-%m-01') AS month,
+    ROUND(AVG(dust_value), 3) AS month_avg,
+    MIN(dust_value) AS min,
+    MAX(dust_value) AS max,
+    CONCAT(ROUND(COUNT(*) / #{count} * 100, 2), '%') AS month_online,
+    CONCAT(ROUND(SUM(CASE WHEN flag = 'N' OR flag = 'A' THEN 1 ELSE 0 END) / #{count} * 100, 2), '%') AS month_valid,
+    CONCAT(ROUND(SUM(CASE WHEN dust_value >= 1 THEN 1 ELSE 0 END) / #{count} * 100, 2), '%') AS month_exceeding,
+    'month' as type
+    FROM ja_t_dust_site_data_info
+    WHERE lst BETWEEN #{beginTime} and #{endTime}
+    GROUP BY mn_code, DATE_FORMAT(lst, '%Y-%m-01')
+    ) as a
+  </insert>
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.3