Pārlūkot izejas kodu

month, year视图增加告警时长

Ping 1 gadu atpakaļ
vecāks
revīzija
2628a0bbbf
2 mainītis faili ar 53 papildinājumiem un 10 dzēšanām
  1. 40 6
      views/v_bi_alm_all_alarm_month.sql
  2. 13 4
      views/v_bi_alm_all_alarm_year.sql

+ 40 - 6
views/v_bi_alm_all_alarm_month.sql

@@ -20,8 +20,34 @@ select
     `m`.`is_active_alarm` AS `is_active_alarm`,
     floor((`m`.`alarm_count` / `m`.`months`)) AS `avg_alarm_count`,
     if((`m`.`alarm_source` = '性能告警'),
-    ((60 / 5) * 24 * days_in_month),
-    ((60 * 2) * 24 * days_in_month)) AS `collection_frequency`
+    (((60 / 5) * 24) * `m`.`days_in_month`),
+    (((60 * 2) * 24) * `m`.`days_in_month`)) AS `collection_frequency`,
+    (case
+        when ((`m`.`occur_time` <= `m`.`thedvalue_b`)
+        and (`m`.`update_time` >= `m`.`thedvalue_e`)) then timestampdiff(MINUTE,
+        str_to_date(`m`.`thedvalue_b`,
+        '%Y%m%d%H%m'),
+        str_to_date(`m`.`thedvalue_e`,
+        '%Y%m%d%H%m'))
+        when ((`m`.`occur_time` > `m`.`thedvalue_b`)
+        and (`m`.`update_time` >= `m`.`thedvalue_e`)) then timestampdiff(MINUTE,
+        str_to_date(`m`.`occur_time`,
+        '%Y%m%d%H%m'),
+        str_to_date(`m`.`thedvalue_e`,
+        '%Y%m%d%H%m'))
+        when ((`m`.`occur_time` <= `m`.`thedvalue_b`)
+        and (`m`.`update_time` < `m`.`thedvalue_e`)) then timestampdiff(MINUTE,
+        str_to_date(`m`.`thedvalue_b`,
+        '%Y%m%d%H%m'),
+        str_to_date(`m`.`update_time`,
+        '%Y%m%d%H%m'))
+        when ((`m`.`occur_time` > `m`.`thedvalue_b`)
+        and (`m`.`update_time` < `m`.`thedvalue_e`)) then timestampdiff(MINUTE,
+        str_to_date(`m`.`occur_time`,
+        '%Y%m%d%H%m'),
+        str_to_date(`m`.`update_time`,
+        '%Y%m%d%H%m'))
+    end) AS `alarm_duration`
 from
     (
     select
@@ -42,8 +68,12 @@ from
         'MONTH' AS `dtype`,
         `dates`.`thedvalue` AS `thedvalue`,
         1 AS `is_active_alarm`,
-        alarm_source,
-        DAYOFMONTH(last_day(DATE_ADD(MAKEDATE(`dates`.`thedvalue`/100, 1), INTERVAL MOD(`dates`.`thedvalue`,100)-1 MONTH))) days_in_month
+        `aa`.`alarm_source` AS `alarm_source`,
+        dayofmonth(last_day((makedate((`dates`.`thedvalue` / 100), 1) + interval ((`dates`.`thedvalue` % 100) - 1) month))) AS `days_in_month`,
+        date_format(str_to_date(concat(`dates`.`thedvalue`, '01'), '%Y%m%d'), '%Y%m%d0000') AS `thedvalue_b`,
+        date_format((str_to_date(concat(`dates`.`thedvalue`, '01'), '%Y%m%d') + interval 1 month), '%Y%m%d%H00') AS `thedvalue_e`,
+        date_format(`aa`.`occur_time`, '%Y%m%d%H%m') AS `occur_time`,
+        date_format(`aa`.`update_time`, '%Y%m%d%H%m') AS `update_time`
     from
         (`t_alm_active_alarm` `aa`
     join (
@@ -72,8 +102,12 @@ union all
         'MONTH' AS `dtype`,
         `dates`.`thedvalue` AS `thedvalue`,
         0 AS `is_active_alarm`,
-        alarm_source,
-        DAYOFMONTH(last_day(DATE_ADD(MAKEDATE(`dates`.`thedvalue`/100, 1), INTERVAL MOD(`dates`.`thedvalue`,100)-1 MONTH))) days_in_month
+        `ha`.`alarm_source` AS `alarm_source`,
+        dayofmonth(last_day((makedate((`dates`.`thedvalue` / 100), 1) + interval ((`dates`.`thedvalue` % 100) - 1) month))) AS `days_in_month`,
+        date_format(str_to_date(concat(`dates`.`thedvalue`, '01'), '%Y%m%d'), '%Y%m%d0000') AS `thedvalue_b`,
+        date_format((str_to_date(concat(`dates`.`thedvalue`, '01'), '%Y%m%d%H%m') + interval 1 month), '%Y%m%d%H00') AS `thedvalue_e`,
+        date_format(`ha`.`occur_time`, '%Y%m%d%H%m') AS `occur_time`,
+        date_format(`ha`.`update_time`, '%Y%m%d%H%m') AS `update_time`
     from
         (`t_alm_history_alarm` `ha`
     join (

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 13 - 4
views/v_bi_alm_all_alarm_year.sql