Sfoglia il codice sorgente

修改存在性告警获取表

王辉 3 giorni fa
parent
commit
1b5b7319ff

+ 6 - 1
src/main/java/cn/chinaunicom/omniFlowNetCompute/mapper/DashboardMapper.java

@@ -55,14 +55,19 @@ public interface DashboardMapper {
     // 4.2 查询七日内阈值类每日趋势
     List<DateCountVO> getThresholdDailyTrend();
 
+    // 4.3 查询七日内阈值类每日趋势
+    List<DateCountVO> getExistenceDailyTrend();
+
     // 5.1 查询七日内每个系统存在性告警数量
     List<SystemExistenceWeekVO> getSystemExistenceWeekCounts();
 
-    List<DeliveryRecordDTO> getDeliveryRecordsLast7Days();
+    List<SystemCategoryVO> getDeliveryRecordsLast7Days();
 
     List<SystemCategoryVO> getContentAlarmCountLast7Days();
 
     List<SystemCategoryVO> getThresholdAlarmCountLast7Days();
 
     List<SystemInfo> getAllSystemInfos();
+
+    Long getExistenceAlarmsCount(String month);
 }

+ 18 - 95
src/main/java/cn/chinaunicom/omniFlowNetCompute/service/impl/DashboardServiceImpl.java

@@ -33,37 +33,20 @@ public class DashboardServiceImpl implements DashboardService {
         Long contentAlarms = dashboardMapper.getContentAlarmCount(month);
         dashboard.setTotalThresholdAlarms(contentAlarms != null ? contentAlarms : 0L);
 
-
         // 4. 阈值类告警
         Long thresholdAlarms = dashboardMapper.getThresholdAlarmCount(month);
         dashboard.setToralContentAlarms(thresholdAlarms != null ? thresholdAlarms : 0L);
 
-
         // 5. 存在性告警 - 系统统计和总量统计
-        List<SystemExistenceStatsDTO> systemExistenceStats = calculateSystemExistenceAlarms(month);
-        Long totalExistenceAlarms = systemExistenceStats.stream()
-                .mapToLong(SystemExistenceStatsDTO::getExistenceAlarms)
-                .sum();
-        dashboard.setExistenceAlarms(totalExistenceAlarms);
-        dashboard.setTotalAlarms(totalAlarms+totalExistenceAlarms);
+        Long existenceAlarms = dashboardMapper.getExistenceAlarmsCount(month);
+        dashboard.setExistenceAlarms(existenceAlarms);
+        dashboard.setTotalAlarms(totalAlarms+existenceAlarms);
         dashboard.setTotalProcessed(untreatedAndProcessedCounts != null ? untreatedAndProcessedCounts.getProcessed() : 0L);
         dashboard.setTotalUntreated(dashboard.getTotalAlarms()-dashboard.getTotalProcessed());
+
         // 6. 系统统计列表
         List<SystemStatsDetailVO> systemStats = dashboardMapper.getSystemStatsDetail(month);
 
-        // 7. 设置每个系统的存在性告警数量
-        Map<String, Long> existenceMap = systemExistenceStats.stream()
-                .collect(Collectors.toMap(
-                        SystemExistenceStatsDTO::getSystemId,
-                        SystemExistenceStatsDTO::getExistenceAlarms
-                ));
-
-        for (SystemStatsDetailVO stat : systemStats) {
-            stat.setExistenceAlarms(existenceMap.getOrDefault(stat.getSystemId(), 0L));
-            stat.setTotalAlarms(stat.getTotalAlarms()+stat.getExistenceAlarms());
-            stat.setUntreatedCount(stat.getTotalAlarms()-stat.getProcessedCount());
-        }
-
         dashboard.setSystemStats(systemStats);
 
         return dashboard;
@@ -217,7 +200,7 @@ public class DashboardServiceImpl implements DashboardService {
         }
         vo.setDates(dates);
 
-        // 2. 获取内容类和阈值类每日数量
+        // 2. 获取内容类和阈值类 存在性每日数量
         List<DateCountVO> contentDaily = dashboardMapper.getContentDailyTrend();
         Map<String, Long> contentMap = contentDaily.stream()
                 .collect(Collectors.toMap(DateCountVO::getDate, DateCountVO::getCount));
@@ -226,22 +209,12 @@ public class DashboardServiceImpl implements DashboardService {
         Map<String, Long> thresholdMap = thresholdDaily.stream()
                 .collect(Collectors.toMap(DateCountVO::getDate, DateCountVO::getCount));
 
-        // 3. 获取所有系统配置的指标
-        List<SystemMetricConfigDTO> allMetrics = dashboardMapper.getAllSystemMetrics();
+        List<DateCountVO> existenceDaily = dashboardMapper.getExistenceDailyTrend();
+        Map<String, Long> existenceDailyMap = existenceDaily.stream()
+                .collect(Collectors.toMap(DateCountVO::getDate, DateCountVO::getCount));
 
-        // 4. 获取7天内所有已送达的报送记录
-        List<DeliveryRecordDTO> deliveryRecords = dashboardMapper.getDeliveryRecordsLast7Days();
 
-        // 5. 按日期-系统-指标分组统计实发次数
-        Map<String, Map<String, Map<String, Long>>> actualSendMap = new HashMap<>();
-        for (DeliveryRecordDTO record : deliveryRecords) {
-            actualSendMap
-                    .computeIfAbsent(record.getDate(), k -> new HashMap<>())
-                    .computeIfAbsent(record.getSystemId(), k -> new HashMap<>())
-                    .merge(record.getMetricType(), 1L, Long::sum);
-        }
-
-        // 6. 计算每天的存在性告警数量
+        // 3. 计算内容类和阈值类 存在性告警数量
         List<Long> contentCounts = new ArrayList<>();
         List<Long> thresholdCounts = new ArrayList<>();
         List<Long> existenceCounts = new ArrayList<>();
@@ -254,29 +227,7 @@ public class DashboardServiceImpl implements DashboardService {
             thresholdCounts.add(contentMap.getOrDefault(date, 0L));
 
             // 存在性 - 每天应发-实发
-            long dailyMissedCount = 0L;
-
-            for (SystemMetricConfigDTO metric : allMetrics) {
-                Integer reportInterval = metric.getReportInterval();
-                if (reportInterval == null || reportInterval <= 0) {
-                    reportInterval = 60;
-                }
-
-                // 当天应发次数
-                long shouldSendCount = (24 * 60) / reportInterval;
-
-                // 当天实际已送达次数
-                long actualSendCount = 0L;
-                if (actualSendMap.containsKey(date)
-                        && actualSendMap.get(date).containsKey(metric.getSystemId())
-                        && actualSendMap.get(date).get(metric.getSystemId()).containsKey(metric.getMetricType())) {
-                    actualSendCount = actualSendMap.get(date).get(metric.getSystemId()).get(metric.getMetricType());
-                }
-
-                dailyMissedCount += Math.max(0, shouldSendCount - actualSendCount);
-            }
-
-            existenceCounts.add(dailyMissedCount);
+            existenceCounts.add(existenceDailyMap.getOrDefault(date, 0L));
         }
 
         vo.setContentCounts(contentCounts);
@@ -313,20 +264,13 @@ public class DashboardServiceImpl implements DashboardService {
                         SystemCategoryVO::getContentCount,
                         (v1, v2) -> v1));
 
-        // 4. 获取所有系统配置的指标(用于存在性计算)
-        List<SystemMetricConfigDTO> allMetrics = dashboardMapper.getAllSystemMetrics();
-        Map<String, List<SystemMetricConfigDTO>> metricsBySystem = allMetrics.stream()
-                .collect(Collectors.groupingBy(SystemMetricConfigDTO::getSystemId));
-
-        // 5. 获取7天内所有已送达的报送记录(存在性实发)
-        List<DeliveryRecordDTO> deliveryRecords = dashboardMapper.getDeliveryRecordsLast7Days();
+        // 4. 获取7天内所有已送达的报送记录(存在性实发)
+        List<SystemCategoryVO> existenceAlarms = dashboardMapper.getDeliveryRecordsLast7Days();
+        Map<String, Long> existenceMap = existenceAlarms.stream()
+                .collect(Collectors.toMap(SystemCategoryVO::getSystemId,
+                        SystemCategoryVO::getContentCount,
+                        (v1, v2) -> v1));
 
-        // 按系统+指标分组统计7天实发次数
-        Map<String, Long> actualSendMap = new HashMap<>();
-        for (DeliveryRecordDTO record : deliveryRecords) {
-            String key = record.getSystemId() + ":" + record.getMetricType();
-            actualSendMap.put(key, actualSendMap.getOrDefault(key, 0L) + 1);
-        }
 
         // 6. 遍历每个系统
         for (SystemInfo system : systems) {
@@ -340,29 +284,8 @@ public class DashboardServiceImpl implements DashboardService {
             // 阈值类数量
             vo.setThresholdCount(thresholdMap.getOrDefault(system.getSystemId(), 0L));
 
-            // 存在性告警数量 = 7天应发总数 - 7天实发总数
-            long existenceCount = 0L;
-            List<SystemMetricConfigDTO> systemMetrics = metricsBySystem.getOrDefault(system.getSystemId(), new ArrayList<>());
-
-            for (SystemMetricConfigDTO metric : systemMetrics) {
-                Integer reportInterval = metric.getReportInterval();
-                if (reportInterval == null || reportInterval <= 0) {
-                    reportInterval = 60; // 默认60分钟
-                }
-
-                // 7天应发总数 = 每天应发次数 × 7天
-                long dailyShouldSend = (24 * 60) / reportInterval;
-                long weekShouldSend = dailyShouldSend * 7;
-
-                // 7天实发总数
-                String key = system.getSystemId() + ":" + metric.getMetricType();
-                long weekActualSend = actualSendMap.getOrDefault(key, 0L);
-
-                // 未发送数量
-                existenceCount += Math.max(0, weekShouldSend - weekActualSend);
-            }
-
-            vo.setExistenceCount(existenceCount);
+            // 存在性
+            vo.setExistenceCount(existenceMap.getOrDefault(system.getSystemId(), 0L));
             result.add(vo);
         }
 

+ 31 - 10
src/main/resources/mapper/omni/DashboardMapper.xml

@@ -80,6 +80,12 @@
           AND DATE_FORMAT(trigger_time, '%Y-%m') = #{month}
     </select>
     
+    <select id="getExistenceAlarmsCount" resultType="java.lang.Long" parameterType="java.lang.String">
+        SELECT COUNT(*)
+        FROM sec_data_undelivered_monitor
+        WHERE  DATE_FORMAT(trigger_time, '%Y-%m') = #{month}
+    </select>
+    
     
     <!-- 4. 阈值类告警(其他4个监控表:权限变更、连接性、异常IP、定时任务) -->
     <select id="getThresholdAlarmCount" resultType="java.lang.Long" parameterType="java.lang.String">
@@ -139,15 +145,15 @@
                
                -- 总告警数
                COALESCE(pm.total, 0) + COALESCE(dbm.total, 0) + COALESCE(cm.total, 0) +
-               COALESCE(ipm.total, 0) + COALESCE(tm.total, 0)         as totalAlarms,
+               COALESCE(ipm.total, 0) + COALESCE(tm.total, 0) + COALESCE(um.total, 0)        as totalAlarms,
                
                -- 已办理数
                COALESCE(pm.processed, 0) + COALESCE(dbm.processed, 0) + COALESCE(cm.processed, 0) +
-               COALESCE(ipm.processed, 0) + COALESCE(tm.processed, 0) as processedCount,
+               COALESCE(ipm.processed, 0) + COALESCE(tm.processed, 0) + COALESCE(um.processed, 0) as processedCount,
                
                -- 未办理数
                COALESCE(pm.untreated, 0) + COALESCE(dbm.untreated, 0) + COALESCE(cm.untreated, 0) +
-               COALESCE(ipm.untreated, 0) + COALESCE(tm.untreated, 0) as untreatedCount,
+               COALESCE(ipm.untreated, 0) + COALESCE(tm.untreated, 0) + COALESCE(um.untreated, 0) as untreatedCount,
                
                -- 内容类告警(数据库监控)
                COALESCE(dbm.total, 0)                                 as thresholdAlarms,
@@ -161,10 +167,17 @@
                COALESCE(dbm.total, 0)                                 as dbCount,
                COALESCE(cm.total, 0)                                  as connectCount,
                COALESCE(ipm.total, 0)                                 as ipCount,
-               COALESCE(tm.total, 0)                                  as taskCount
+               COALESCE(tm.total, 0)                                  as taskCount,
+               COALESCE(um.total, 0)                                  as existenceAlarms
         
         FROM sec_system_info si
-                 
+                 LEFT JOIN (SELECT system_id,
+                                   COUNT(*)                                                    as total,
+                                   SUM(CASE WHEN alarm_status = 'processed' THEN 1 ELSE 0 END) as processed,
+                                   SUM(CASE WHEN alarm_status = 'untreated' THEN 1 ELSE 0 END) as untreated
+                            FROM sec_data_undelivered_monitor
+                            WHERE  DATE_FORMAT(trigger_time, '%Y-%m') = #{month}
+                            GROUP BY system_id) um ON si.system_id = um.system_id
                  LEFT JOIN (SELECT system_id,
                                    COUNT(*)                                                    as total,
                                    SUM(CASE WHEN alert_status = 'processed' THEN 1 ELSE 0 END) as processed,
@@ -419,6 +432,16 @@
         ORDER BY date
     </select>
     
+    <select id="getExistenceDailyTrend" resultType="cn.chinaunicom.omniFlowNetCompute.pojo.DateCountVO">
+        SELECT
+            DATE_FORMAT(trigger_time, '%m-%d') as date,
+            COUNT(*)                           as count
+        FROM sec_data_undelivered_monitor
+        WHERE trigger_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
+        GROUP BY DATE_FORMAT(trigger_time, '%m-%d')
+        ORDER BY date
+    </select>
+    
     <!-- 5.1 查询七日内每个系统存在性告警数量(单独) -->
     <select id="getSystemExistenceWeekCounts" resultType="cn.chinaunicom.omniFlowNetCompute.pojo.SystemExistenceWeekVO">
         SELECT si.system_id                       as systemId,
@@ -436,15 +459,13 @@
     </select>
     
     <!-- 4.4 获取7天内所有已送达的报送记录 -->
-    <select id="getDeliveryRecordsLast7Days" resultType="cn.chinaunicom.omniFlowNetCompute.dto.DeliveryRecordDTO">
+    <select id="getDeliveryRecordsLast7Days" resultType="cn.chinaunicom.omniFlowNetCompute.pojo.SystemCategoryVO">
         SELECT
-            DATE_FORMAT(trigger_time, '%m-%d') as date,
             system_id as systemId,
-            metric_name as metricType,
-            last_report_time as reportTime
+            COUNT(*) as contentCount
         FROM sec_data_undelivered_monitor
         WHERE trigger_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
-          AND delivery_status = 1
+        GROUP BY system_id
     </select>
     
     <!-- 获取所有系统信息 -->