qixiaoning
2025-07-08 84d2ef9760af0a4a4aa933937294400b3caa291d
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
49
50
51
52
53
54
55
56
57
58
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
}