package models import ( "github.com/pkg/errors" ) type PollConfig struct { ServerId string `gorm:"primary_key;column:server_id" json:"server_id"`//服务器id PollPeriod int32 `gorm:"column:poll_period;default:10" json:"poll_period"`//轮询周期 Delay int32 `gorm:"column:delay;default:10" json:"delay"`//延时时间 Enable bool `gorm:"column:enable;default:1" json:"enable"`//是否启用轮询 PollChannelCount int `gorm:"column:pollChannelCount;default:0" json:"pollChannelCount"` } func (PollConfig) TableName() string { return "poll_config" } func (pc *PollConfig) Save() bool{ result := db.Table("poll_config").Save(&pc) if result.Error !=nil { return false } if result.RowsAffected>0 { return true } return false } func (pc *PollConfig) Update() bool{ result := db.Table("poll_config").Update(&pc) if result.Error !=nil { return false } if result.RowsAffected>0{ return true } return false } func (pc *PollConfig) GetOne() (pcE PollConfig,err error) { result := db.Table("poll_config").First(&pcE) if result.Error!=nil{ return pcE,result.Error } if result.RecordNotFound() { return pcE,errors.New("not found") } return pcE,nil } //更新轮询启用状态 func (pc *PollConfig) UpdateEnable(status bool) bool { if result := db.Exec("update poll_config set enable=?",status);result.Error == nil && result.RowsAffected>0{ return true } return false }