实现忽略告警和取消忽略告警接口及功能
This commit is contained in:
@@ -40,6 +40,9 @@ type AlarmRepository interface {
|
||||
// DeleteActiveAlarmTx 在指定事务中根据主键 ID 删除一个活跃告警
|
||||
DeleteActiveAlarmTx(ctx context.Context, tx *gorm.DB, id uint) error
|
||||
|
||||
// UpdateIgnoreStatus 更新指定告警的忽略状态
|
||||
UpdateIgnoreStatus(ctx context.Context, id uint, isIgnored bool, ignoredUntil *time.Time) error
|
||||
|
||||
// ListActiveAlarms 支持分页和过滤的活跃告警列表查询。
|
||||
// 返回活跃告警列表、总记录数和错误。
|
||||
ListActiveAlarms(ctx context.Context, opts ActiveAlarmListOptions, page, pageSize int) ([]models.ActiveAlarm, int64, error)
|
||||
@@ -80,7 +83,7 @@ func (r *gormAlarmRepository) CreateActiveAlarm(ctx context.Context, alarm *mode
|
||||
return r.db.WithContext(repoCtx).Create(alarm).Error
|
||||
}
|
||||
|
||||
// IsAlarmActive 检查具有相同来源和告警代码的告警当前是否处于活跃状态
|
||||
// IsAlarmActiveInUse 检查具有相同来源和告警代码的告警当前是否处于活跃表中
|
||||
func (r *gormAlarmRepository) IsAlarmActiveInUse(ctx context.Context, sourceType models.AlarmSourceType, sourceID uint, alarmCode models.AlarmCode) (bool, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "IsAlarmActiveInUse")
|
||||
var count int64
|
||||
@@ -116,6 +119,30 @@ func (r *gormAlarmRepository) DeleteActiveAlarmTx(ctx context.Context, tx *gorm.
|
||||
return tx.WithContext(repoCtx).Unscoped().Delete(&models.ActiveAlarm{}, id).Error
|
||||
}
|
||||
|
||||
// UpdateIgnoreStatus 更新指定告警的忽略状态
|
||||
func (r *gormAlarmRepository) UpdateIgnoreStatus(ctx context.Context, id uint, isIgnored bool, ignoredUntil *time.Time) error {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "UpdateIgnoreStatus")
|
||||
updates := map[string]interface{}{
|
||||
"is_ignored": isIgnored,
|
||||
"ignored_until": ignoredUntil,
|
||||
}
|
||||
|
||||
result := r.db.WithContext(repoCtx).
|
||||
Model(&models.ActiveAlarm{}).
|
||||
Where("id = ?", id).
|
||||
Updates(updates)
|
||||
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
if result.RowsAffected == 0 {
|
||||
return gorm.ErrRecordNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListActiveAlarms 实现了分页和过滤查询活跃告警记录的功能
|
||||
func (r *gormAlarmRepository) ListActiveAlarms(ctx context.Context, opts ActiveAlarmListOptions, page, pageSize int) ([]models.ActiveAlarm, int64, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "ListActiveAlarms")
|
||||
|
||||
Reference in New Issue
Block a user