alarm.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. "time"
  7. "github.com/jaryhe/gopkgs/logger"
  8. "github.com/jinzhu/gorm"
  9. "go.uber.org/zap"
  10. )
  11. type TAlarm struct {
  12. Id int64 `gorm:"primary_key"`
  13. ProjectId int64 `gorm:"column:project_id"`
  14. Sn string `gorm:"column:sn"`
  15. AlarmCode string `gorm:"column:alarm_code"`
  16. AlarmReason string `gorm:"column:alarm_reason"`
  17. IsHandle bool `gorm:"column:is_handle"`
  18. Time time.Time `gorm:"column:time"`
  19. CreatedAt string `gorm:"column:created_at"`
  20. UpdatedAt string `json:"updated_at"`
  21. }
  22. func (TAlarm) TableName() string {
  23. return "t_alarm"
  24. }
  25. func (p *TAlarm) Delete(db *gorm.DB, filter map[string]interface{}) error {
  26. err := db.Where(filter).Delete(p).Error
  27. if err != nil {
  28. fields, _ := json.Marshal(filter)
  29. logger.Error("mysql",
  30. zap.String("sql", "delete from t_alarm"),
  31. zap.String("fields", string(fields)),
  32. zap.String("error", err.Error()))
  33. return err
  34. }
  35. return nil
  36. }