sunty
2020-08-20 9303b69ea569bcb5e581147543a3fd58e90d0d25
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package controllers
 
import (
    "basic.com/dbapi.git"
    "github.com/gin-gonic/gin"
    "strconv"
    "webserver/extend/code"
    "webserver/extend/util"
)
 
type PollConfigController struct {
}
 
type PollConfig struct {
    ServerId   string `json:"server_id"`   //服务器id
    PollPeriod int32    `json:"poll_period"` //轮询周期
    Delay      int32    `json:"delay"`       //延时时间
    Enable     bool   `json:"enable"`      //是否启用轮询
}
 
// @Security ApiKeyAuth
// @Summary 保存轮询周期
// @Description 保存轮询周期
// @Produce json
// @Tags 轮询配置
// @Param period formData int true "轮询周期"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/pollConfig/savePollPeriod [post]
func (controller PollConfigController) SavePollPeriod(c *gin.Context) {
    periodStr := c.PostForm("period")
    period, err := strconv.Atoi(periodStr)
    if periodStr == "" || err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.SysSetApi
    b, data := api.SavePollPeriod(period)
    if b {
        util.ResponseFormat(c, code.Success, data)
    } else {
        util.ResponseFormat(c, code.ComError, "保存失败")
    }
}
 
// @Security ApiKeyAuth
// @Summary 保存轮询延时
// @Description 保存轮询延时
// @Produce json
// @Tags 轮询配置
// @Param delay formData int true "轮询延时时间"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/pollConfig/savePollDelay [post]
func (controller PollConfigController) SavePollDelay(c *gin.Context) {
    delayStr := c.PostForm("delay")
    delay, err := strconv.Atoi(delayStr)
    if delayStr == "" || err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.SysSetApi
    b, data := api.SavePollDelay(delay)
    if b {
        util.ResponseFormat(c, code.Success, data)
    } else {
        util.ResponseFormat(c, code.ComError, "保存失败")
    }
}
 
// @Security ApiKeyAuth
// @Summary 获取本机轮询配置
// @Description 获取本机轮询配置
// @Produce json
// @Tags 轮询配置
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/pollConfig/getPollConfig [get]
func (controller PollConfigController) GetPollConfig(c *gin.Context) {
    var api dbapi.SysSetApi
    b, d := api.GetPollConfig()
    if b {
        util.ResponseFormat(c, code.Success, map[string]interface{}{
            "server_id": d.ServerId,
            "poll_period": d.PollPeriod,
            "delay": d.Delay,
            "enable": d.Enable,
            "pollChannelCount": d.PollChannelCount,
        })
    } else {
        util.ResponseFormat(c, code.ComError, "查询失败")
    }
}
 
type PollEnableVo struct {
    Enable bool `json:"enable"`
}
 
// @Security ApiKeyAuth
// @Summary 切换轮询开关
// @Description 切换轮询开关
// @Accept json
// @Produce json
// @Tags 轮询配置
// @Param argBody body controllers.PollEnableVo true "开关参数"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/pollConfig/updateEnable [post]
func (controller PollConfigController) UpdateEnable(c *gin.Context) {
    var argBody PollEnableVo
    if err := c.BindJSON(&argBody); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.SysSetApi
    if api.UpdatePollEnable(argBody.Enable) {
        util.ResponseFormat(c, code.Success, "修改成功")
    } else {
        util.ResponseFormat(c, code.ComError, "修改失败")
    }
}
 
type ChannelCountSet struct {
    PollChannelCount int `json:"pollChannelCount"`
    VideoChannelCount int `json:"videoChannelCount"`
}
 
// @Security ApiKeyAuth
// @Summary 设置轮询算力和本地算力的数量
// @Description 设置轮询算力和本地算力的数量
// @Accept json
// @Produce json
// @Tags 轮询配置
// @Param argBody body controllers.ChannelCountSet true "轮询通道数量以及本地通道数量"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/pollConfig/updateChannelCount [post]
func (controller PollConfigController) UpdateChannelCount(c *gin.Context) {
    var argBody ChannelCountSet
    err := c.BindJSON(&argBody)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.SysSetApi
    if api.UpdateChannelCount(argBody.PollChannelCount, argBody.VideoChannelCount) {
        util.ResponseFormat(c,code.UpdateSuccess,"更新成功")
    } else {
        util.ResponseFormat(c,code.UpdateFail,"更新失败")
    }
}