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
|
}
|