feat: 告警分组统计数量接口

This commit is contained in:
TsMask
2025-07-16 14:52:52 +08:00
parent a667691fff
commit 27b5403339
4 changed files with 153 additions and 7 deletions

View File

@@ -192,3 +192,21 @@ func (r Alarm) SelectAlarmSeqLast(neType, neId string) int64 {
}
return alarmSeq
}
// GroupTotal 分组统计
func (r Alarm) GroupTotal(alarmStatus string, group string, limit int) []map[string]any {
tx := db.DB("").Model(&model.Alarm{})
tx = tx.Select("count(*) as total", group)
tx = tx.Where("alarm_status=?", alarmStatus)
tx = tx.Group(group).Order("total DESC")
// 查询数据
var rows []map[string]any = make([]map[string]any, 0)
if limit > 0 {
tx = tx.Limit(limit)
}
if err := tx.Find(&rows).Error; err != nil {
logger.Errorf("query find err => %v", err.Error())
return rows
}
return rows
}