From 9303b69ea569bcb5e581147543a3fd58e90d0d25 Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期四, 20 八月 2020 20:05:23 +0800 Subject: [PATCH] add get buckets contrl --- controllers/pollConfig.go | 97 ++++++++++++++++++++++++++++++++++-------------- 1 files changed, 69 insertions(+), 28 deletions(-) diff --git a/controllers/pollConfig.go b/controllers/pollConfig.go index 18a23e2..b676b8f 100644 --- a/controllers/pollConfig.go +++ b/controllers/pollConfig.go @@ -9,64 +9,66 @@ ) type PollConfigController struct { - } type PollConfig struct { - ServerId string `json:"server_id"`//鏈嶅姟鍣╥d - PollPeriod int `json:"poll_period"`//杞鍛ㄦ湡 - Delay int `json:"delay"`//寤舵椂鏃堕棿 - Enable bool `json:"enable"`//鏄惁鍚敤杞 + ServerId string `json:"server_id"` //鏈嶅姟鍣╥d + PollPeriod int32 `json:"poll_period"` //杞鍛ㄦ湡 + Delay int32 `json:"delay"` //寤舵椂鏃堕棿 + Enable bool `json:"enable"` //鏄惁鍚敤杞 } +// @Security ApiKeyAuth // @Summary 淇濆瓨杞鍛ㄦ湡 // @Description 淇濆瓨杞鍛ㄦ湡 // @Produce json // @Tags 杞閰嶇疆 -// @Param period query int true "杞鍛ㄦ湡" +// @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){ +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,"鍙傛暟鏈夎") + 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) + util.ResponseFormat(c, code.Success, data) } else { - util.ResponseFormat(c,code.ComError,"淇濆瓨澶辫触") + util.ResponseFormat(c, code.ComError, "淇濆瓨澶辫触") } } +// @Security ApiKeyAuth // @Summary 淇濆瓨杞寤舵椂 // @Description 淇濆瓨杞寤舵椂 // @Produce json // @Tags 杞閰嶇疆 -// @Param delay query int true "杞寤舵椂鏃堕棿" +// @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){ +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,"鍙傛暟鏈夎") + 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) + util.ResponseFormat(c, code.Success, data) } else { - util.ResponseFormat(c,code.ComError,"淇濆瓨澶辫触") + util.ResponseFormat(c, code.ComError, "淇濆瓨澶辫触") } } +// @Security ApiKeyAuth // @Summary 鑾峰彇鏈満杞閰嶇疆 // @Description 鑾峰彇鏈満杞閰嶇疆 // @Produce json @@ -74,37 +76,76 @@ // @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){ +func (controller PollConfigController) GetPollConfig(c *gin.Context) { var api dbapi.SysSetApi - b, data := api.GetPollConfig() + b, d := api.GetPollConfig() if b { - util.ResponseFormat(c,code.Success,data) - }else{ - util.ResponseFormat(c,code.ComError,"鏌ヨ澶辫触") + 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){ +func (controller PollConfigController) UpdateEnable(c *gin.Context) { var argBody PollEnableVo - if err := c.BindJSON(&argBody);err !=nil { - util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") + 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,"淇敼鎴愬姛") + if api.UpdatePollEnable(argBody.Enable) { + util.ResponseFormat(c, code.Success, "淇敼鎴愬姛") } else { - util.ResponseFormat(c,code.ComError,"淇敼澶辫触") + 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,"鏇存柊澶辫触") } } \ No newline at end of file -- Gitblit v1.8.0