feat: 告警分组统计数量接口
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user