noticeRecordDao.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package dao
  2. import (
  3. "fmt"
  4. "gorm.io/gorm"
  5. "iot_manager_service/app/warn/model"
  6. "iot_manager_service/util/common"
  7. )
  8. // NoticeRecord 告警通知记录
  9. type NoticeRecord struct {
  10. gorm.Model
  11. NoticeSetId int `gorm:"comment:告警通知设置ID;" json:"noticeSetId"`
  12. NoticeSet NoticeSet
  13. ArmClassify int `gorm:"comment:告警类型:1运维,2业务;" json:"classify"`
  14. Content string `gorm:"comment:发送内容;" json:"content"`
  15. Status int `gorm:"comment:发送状态;" json:"status"`
  16. SendType int `gorm:"comment:发送方式1短信2邮件" json:"sendType"`
  17. SendTypeName string `gorm:"comment:发送方式" json:"SendTypeName"`
  18. SendValue string `gorm:"comment:手机号或邮件" json:"sendValue"`
  19. SendName string `gorm:"comment:收件人" json:"sendName"`
  20. PlatformAlarmId int
  21. PlatformAlarm PlatformAlarm
  22. }
  23. func (NoticeRecord) TableName() string {
  24. return "warn_notice_record"
  25. }
  26. func (r NoticeRecord) GetList(filter model.RequestNoticeRecordFilter) ([]NoticeRecord, int64, error) {
  27. var list []NoticeRecord
  28. var total int64
  29. db := Db.Debug().Model(&r)
  30. // 告警类型
  31. if filter.ClassifyName != 0 {
  32. db = db.Where(&NoticeRecord{ArmClassify: filter.ClassifyName})
  33. }
  34. //发送状态
  35. if filter.SendValue != 0 {
  36. if filter.SendValue == 2 { //1成功 2为失败
  37. filter.SendValue = 0
  38. }
  39. db = db.Where(&NoticeRecord{Status: filter.SendValue})
  40. }
  41. //发送方式
  42. if filter.SendType != 0 {
  43. db = db.Where(&NoticeRecord{SendType: filter.SendType})
  44. }
  45. //时间范围
  46. if filter.StartTime != "" {
  47. db = db.Where("created_at>=? and created_at<=?", filter.StartTime, filter.EndTime)
  48. }
  49. //发送人
  50. if filter.SendName != "" {
  51. db = db.Where("send_name=?", filter.SendName)
  52. }
  53. db.Count(&total)
  54. db = db.Scopes(common.Paginate(filter.Current, filter.Size)).Preload("NoticeSet")
  55. err := db.Preload("PlatformAlarm").Order("id desc").Find(&list).Error
  56. fmt.Printf("total = %v", total)
  57. return list, total, err
  58. }
  59. func (r NoticeRecord) Create() error {
  60. err := Db.Debug().Create(&r).Error
  61. return err
  62. }