alarm_rule.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package model
  4. import (
  5. "encoding/json"
  6. "github.com/jaryhe/gopkgs/logger"
  7. "go.uber.org/zap"
  8. "github.com/jinzhu/gorm"
  9. )
  10. type TAlarmRule struct {
  11. Id int64 `gorm:"primary_key"`
  12. ProjectId int64 `gorm:"column:project_id"`
  13. Sn string `gorm:"sn"`
  14. ContinuePeriod int32 `gorm:"column:continue_period"`
  15. AlarmCount int32 `gorm:"column:alarm_count"`
  16. SilencePeriod int32 `gorm:"column:silence_period"`
  17. IsOn bool `gorm:"column:is_on"`
  18. CreatedAt string `gorm:"column:created_at"`
  19. UpdatedAt string `gorm:"column:updated_at"`
  20. }
  21. func (TAlarmRule) TableName() string {
  22. return "t_alarm_rule"
  23. }
  24. func (p *TAlarmRule) Delete(db *gorm.DB, filter map[string]interface{}) error {
  25. err := db.Where(filter).Delete(p).Error
  26. if err != nil {
  27. fields, _ := json.Marshal(filter)
  28. logger.Error("mysql",
  29. zap.String("sql", "delete from t_alarm_rule"),
  30. zap.String("fields", string(fields)),
  31. zap.String("error", err.Error()))
  32. }
  33. return err
  34. }