qixiaoning
2025-08-08 ef51da5404827e826e979ad614950a9e0192f4c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package models
 
type EventPush struct {
    Id           string `gorm:"primary_key;column:id" json:"id"`
    Name         string `gorm:"column:name" json:"name"`
    PushType     int    `gorm:"column:push_type" json:"push_type"`
    TimeStart    string `gorm:"column:time_start" json:"time_start"`
    TimeEnd      string `gorm:"column:time_end" json:"time_end"`
    IsSatisfyAll bool   `gorm:"column:is_satisfy_all" json:"is_satisfy_all"`
    RuleText     string `gorm:"column:rule_text" json:"rule_text"`
    Enable       bool   `gorm:"column:enable" json:"enable"`
    LinkType     string `gorm:"column:link_type" json:"link_type"`
    LinkDevice   string `gorm:"column:link_device" json:"link_device"`
    PushSet      string `gorm:"column:push_set" json:"push_set"`
}
 
func (EventPush) TableName() string {
    return "event_push"
}
 
func (ep *EventPush) GetById(id string) (bool, error) {
    result := db.Table("event_push").Where("id=?", id).First(&ep)
    return result.RecordNotFound(), result.Error
}
 
func (ep *EventPush) Exist(name string) (int64, error) {
    result := db.Table(ep.TableName()).Where("name=?", name).First(&ep)
    return result.RowsAffected, result.Error
}
 
func (ep *EventPush) FindAll(name string) (flag bool, list []EventPush) {
    sql := "select * from event_push where 1=1"
    if name != "" {
        sql = sql + " and name like ?"
    }
    if err := db.Raw(sql, "%"+name+"%").Scan(&list).Error; err != nil {
        return false, nil
    }
    return true, list
}
 
func (ep *EventPush) ChangeStatus(id string, enable bool) bool {
    result := db.Exec("update event_push set enable=? where id=?", enable, id)
    if result.Error != nil {
        return false
    }
    return result.RowsAffected > 0
}