edb_monitor_message.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package edbmonitor
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "time"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. type EdbMonitorMessage struct {
  9. EdbMonitorMessageId int `orm:"column(edb_monitor_message_id);pk"`
  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 := orm.NewOrmUsingDB("data")
  22. insertId, err = o.Insert(m)
  23. return
  24. }
  25. func (m *EdbMonitorMessage) Update(cols []string) (err error) {
  26. o := orm.NewOrmUsingDB("data")
  27. _, err = o.Update(m, cols...)
  28. return
  29. }
  30. func BatchModifyEdbMonitorMessageIsRead(ids []int, adminId int) (err error) {
  31. if len(ids) == 0 {
  32. return
  33. }
  34. o := orm.NewOrmUsingDB("data")
  35. 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)) + `)`
  36. _, err = o.Raw(sql, adminId, ids).Exec()
  37. return
  38. }
  39. func (m *EdbMonitorMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  40. o := orm.NewOrmUsingDB("data")
  41. sql := fmt.Sprintf(`SELECT COUNT(1) FROM edb_monitor_message WHERE 1=1 %s`, condition)
  42. err = o.Raw(sql, pars).QueryRow(&count)
  43. return
  44. }
  45. func GetEdbMonitorMessageById(id int) (item *EdbMonitorMessage, err error) {
  46. o := orm.NewOrmUsingDB("data")
  47. sql := "SELECT * FROM edb_monitor_message WHERE edb_monitor_message_id =?"
  48. err = o.Raw(sql, id).QueryRow(&item)
  49. return
  50. }
  51. func GetEdbMonitorMessageByAdminId(adminId int) (items []*EdbMonitorMessage, err error) {
  52. o := orm.NewOrmUsingDB("data")
  53. sql := "SELECT * FROM edb_monitor_message WHERE admin_id =? AND is_read = 0 ORDER BY create_time DESC"
  54. _, err = o.Raw(sql, adminId).QueryRows(&items)
  55. return
  56. }
  57. func GetEdbMonitorMessageCountByAdminId(adminId int) (count int, err error) {
  58. o := orm.NewOrmUsingDB("data")
  59. sql := "SELECT COUNT(*) FROM edb_monitor_message WHERE admin_id =? ORDER BY is_read ASC, create_time DESC"
  60. err = o.Raw(sql, adminId).QueryRow(&count)
  61. return
  62. }
  63. func GetEdbMonitorMessagePageByAdminId(adminId, startSize, pageSize int) (items []*EdbMonitorMessage, err error) {
  64. o := orm.NewOrmUsingDB("data")
  65. sql := "SELECT * FROM edb_monitor_message WHERE admin_id =? ORDER BY is_read ASC, create_time DESC LIMIT?,?"
  66. _, err = o.Raw(sql, adminId, startSize, pageSize).QueryRows(&items)
  67. return
  68. }