edb_monitor_message.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package edbmonitor
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "time"
  7. )
  8. type EdbMonitorMessage struct {
  9. EdbMonitorMessageId int `orm:"column(edb_monitor_message_id);pk" gorm:"primaryKey"`
  10. EdbInfoId int `description:"指标id"`
  11. EdbInfoType int `description:"指标类型: 0-普通指标;1-预测指标"`
  12. EdbUniqueCode string `description:"指标唯一标识"`
  13. EdbClassifyId int `description:"指标id"`
  14. AdminId int `description:"用户id"`
  15. IsRead int `description:"是否已读: 0-未读;1-已读"`
  16. Message string `description:"消息内容"`
  17. MonitorTriggerTime time.Time `description:"预警触发时间"`
  18. CreateTime time.Time `description:"创建时间"`
  19. }
  20. func (m *EdbMonitorMessage) Insert() (insertId int64, err error) {
  21. o := global.DbMap[utils.DbNameIndex]
  22. err = o.Create(m).Error
  23. if err != nil {
  24. return
  25. }
  26. insertId = int64(m.EdbMonitorMessageId)
  27. return
  28. }
  29. func (m *EdbMonitorMessage) Update(cols []string) (err error) {
  30. o := global.DbMap[utils.DbNameIndex]
  31. err = o.Select(cols).Updates(m).Error
  32. return
  33. }
  34. func BatchModifyEdbMonitorMessageIsRead(ids []int, adminId int) (err error) {
  35. if len(ids) == 0 {
  36. return
  37. }
  38. o := global.DbMap[utils.DbNameIndex]
  39. sql := `UPDATE edb_monitor_message SET is_read =1 WHERE admin_id =? AND is_read = 0 AND edb_monitor_message_id IN (` + utils.GetOrmInReplace(len(ids)) + `)`
  40. err = o.Exec(sql, adminId, ids).Error
  41. return
  42. }
  43. func (m *EdbMonitorMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  44. o := global.DbMap[utils.DbNameIndex]
  45. sql := fmt.Sprintf(`SELECT COUNT(1) FROM edb_monitor_message WHERE 1=1 %s`, condition)
  46. err = o.Raw(sql, pars...).Scan(&count).Error
  47. return
  48. }
  49. func GetEdbMonitorMessageById(id int) (item *EdbMonitorMessage, err error) {
  50. o := global.DbMap[utils.DbNameIndex]
  51. sql := "SELECT * FROM edb_monitor_message WHERE edb_monitor_message_id =?"
  52. err = o.Raw(sql, id).First(&item).Error
  53. return
  54. }
  55. func GetEdbMonitorMessageByAdminId(adminId int) (items []*EdbMonitorMessage, err error) {
  56. o := global.DbMap[utils.DbNameIndex]
  57. sql := "SELECT * FROM edb_monitor_message WHERE admin_id =? AND is_read = 0 ORDER BY create_time DESC"
  58. err = o.Raw(sql, adminId).Find(&items).Error
  59. return
  60. }
  61. func GetEdbMonitorMessageCountByAdminId(adminId int) (count int, err error) {
  62. o := global.DbMap[utils.DbNameIndex]
  63. sql := "SELECT COUNT(*) FROM edb_monitor_message WHERE admin_id =? ORDER BY is_read ASC, create_time DESC"
  64. err = o.Raw(sql, adminId).Scan(&count).Error
  65. return
  66. }
  67. func GetEdbMonitorMessagePageByAdminId(adminId, startSize, pageSize int) (items []*EdbMonitorMessage, err error) {
  68. o := global.DbMap[utils.DbNameIndex]
  69. sql := "SELECT * FROM edb_monitor_message WHERE admin_id =? ORDER BY is_read ASC, create_time DESC LIMIT?,?"
  70. err = o.Raw(sql, adminId, startSize, pageSize).Find(&items).Error
  71. return
  72. }
  73. func GetEdbMonitorMessageUnreadListByAdminIds(adminIds []int) (items []*EdbMonitorMessage, err error) {
  74. o := global.DbMap[utils.DbNameIndex]
  75. sql := "SELECT * FROM edb_monitor_message WHERE is_read = 0 AND admin_id IN (?) ORDER BY create_time DESC, edb_monitor_message_id DESC"
  76. err = o.Raw(sql, adminIds).Find(&items).Error
  77. return
  78. }
  79. func SetEdbMonitorMessageReadByIds(msgIds []int) (err error) {
  80. o := global.DbMap[utils.DbNameIndex]
  81. sql := "UPDATE edb_monitor_message SET is_read = 1 WHERE edb_monitor_message_id IN (?) and is_read=0"
  82. err = o.Exec(sql, msgIds).Error
  83. return
  84. }
  85. func GetEdbMonitorMessageUnreadByAdminId(adminId int) (items []*EdbMonitorMessage, err error) {
  86. o := global.DbMap[utils.DbNameIndex]
  87. sql := "SELECT * FROM edb_monitor_message WHERE admin_id =? AND is_read = 0 ORDER BY create_time DESC, edb_monitor_message_id DESC"
  88. err = o.Raw(sql, adminId).Find(&items).Error
  89. return
  90. }
  91. func SetEdbMonitorMessageReadByAdminId(adminId int, msgIds []int) (err error) {
  92. o := global.DbMap[utils.DbNameIndex]
  93. sql := "UPDATE edb_monitor_message SET is_read = 1 WHERE admin_id =? AND edb_monitor_message_id IN (?) and is_read=0"
  94. err = o.Exec(sql, adminId, msgIds).Error
  95. return
  96. }