noticeRecordDao.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package dao
  2. import (
  3. "gorm.io/gorm"
  4. "iot_manager_service/app/warn/model"
  5. "iot_manager_service/util/common"
  6. )
  7. // NoticeRecord 告警通知记录
  8. type NoticeRecord struct {
  9. gorm.Model
  10. NoticeSetId int `gorm:"comment:告警通知设置ID;" json:"noticeSetId"`
  11. NoticeSet NoticeSet
  12. ArmClassify int `gorm:"comment:告警类型:1运维,2业务;" json:"classify"`
  13. Content string `gorm:"comment:发送内容;" json:"content"`
  14. Status int `gorm:"comment:发送状态;" json:"status"`
  15. SendType int `gorm:"comment:发送方式1短信2邮件" json:"sendType"`
  16. SendTypeName string `gorm:"comment:发送方式" json:"SendTypeName"`
  17. SendValue int `gorm:"comment:手机号或邮件" json:"sendValue"`
  18. SendName string `gorm:"comment:收件人" json:"sendName"`
  19. PlatformAlarmId int
  20. PlatformAlarm PlatformAlarm
  21. }
  22. func (NoticeRecord) TableName() string {
  23. return "warn_notice_record"
  24. }
  25. func (r NoticeRecord) GetList(filter model.RequestNoticeRecordFilter) ([]NoticeRecord, int64, error) {
  26. var list []NoticeRecord
  27. var total int64
  28. db := Db.Debug().Model(&r)
  29. db = db.Scopes(common.Paginate(filter.Current, filter.Size)).Preload("NoticeSet")
  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. err := db.Preload("PlatformAlarm").Find(&list).Error
  54. db.Count(&total)
  55. //fmt.Printf("total = %v", total)
  56. return list, total, err
  57. }