package edbmonitor import ( "eta/eta_api/utils" "fmt" "time" "github.com/beego/beego/v2/client/orm" ) type EdbMonitorMessage struct { EdbMonitorMessageId int `orm:"column(edb_monitor_message_id);pk"` EdbInfoId int `description:"指标id"` EdbInfoType int `description:"指标类型: 0-普通指标;1-预测指标"` EdbUniqueCode string `description:"指标唯一标识"` EdbClassifyId int `description:"指标id"` AdminId int `description:"用户id"` IsRead int `description:"是否已读: 0-未读;1-已读"` Message string `description:"消息内容"` MonitorTriggerTime time.Time `description:"预警触发时间"` CreateTime time.Time `description:"创建时间"` } func (m *EdbMonitorMessage) Insert() (insertId int64, err error) { o := orm.NewOrmUsingDB("data") insertId, err = o.Insert(m) return } func (m *EdbMonitorMessage) Update(cols []string) (err error) { o := orm.NewOrmUsingDB("data") _, err = o.Update(m, cols...) return } func BatchModifyEdbMonitorMessageIsRead(ids []int, adminId int) (err error) { if len(ids) == 0 { return } o := orm.NewOrmUsingDB("data") 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)) + `)` _, err = o.Raw(sql, adminId, ids).Exec() return } func (m *EdbMonitorMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { o := orm.NewOrmUsingDB("data") sql := fmt.Sprintf(`SELECT COUNT(1) FROM edb_monitor_message WHERE 1=1 %s`, condition) err = o.Raw(sql, pars).QueryRow(&count) return } func GetEdbMonitorMessageById(id int) (item *EdbMonitorMessage, err error) { o := orm.NewOrmUsingDB("data") sql := "SELECT * FROM edb_monitor_message WHERE edb_monitor_message_id =?" err = o.Raw(sql, id).QueryRow(&item) return } func GetEdbMonitorMessageByAdminId(adminId int) (items []*EdbMonitorMessage, err error) { o := orm.NewOrmUsingDB("data") sql := "SELECT * FROM edb_monitor_message WHERE admin_id =? AND is_read = 0 ORDER BY create_time DESC" _, err = o.Raw(sql, adminId).QueryRows(&items) return } func GetEdbMonitorMessageCountByAdminId(adminId int) (count int, err error) { o := orm.NewOrmUsingDB("data") sql := "SELECT COUNT(*) FROM edb_monitor_message WHERE admin_id =? ORDER BY is_read ASC, create_time DESC" err = o.Raw(sql, adminId).QueryRow(&count) return } func GetEdbMonitorMessagePageByAdminId(adminId, startSize, pageSize int) (items []*EdbMonitorMessage, err error) { o := orm.NewOrmUsingDB("data") sql := "SELECT * FROM edb_monitor_message WHERE admin_id =? ORDER BY is_read ASC, create_time DESC LIMIT?,?" _, err = o.Raw(sql, adminId, startSize, pageSize).QueryRows(&items) return }