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:"column:ID;primary_key"`
  12. ProjectId int64 `gorm:"column:ProjectId"`
  13. Sn string `gorm:"column:SN"`
  14. ContinuePeriod int32 `gorm:"column:ContinuePeriod"`
  15. AlarmCount int32 `gorm:"column:AlarmCount"`
  16. SilencePeriod int32 `gorm:"column:SilencePeriod"`
  17. IsOn bool `gorm:"column:IsOn"`
  18. CreatedAt string `gorm:"column:CreatedAt"`
  19. UpdatedAt string `gorm:"column:UpdatedAt"`
  20. }
  21. func (TAlarmRule) TableName() string {
  22. return "AlarmRule"
  23. }
  24. func (p *TAlarmRule) Delete(db *gorm.DB, filter map[string]interface{}) error {
  25. err := db.Table(p.TableName()).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. }