liuxiaolong
2019-06-26 ca0affbce745df4e071dc256c5f47b2a8165a443
controllers/pollConfig.go
@@ -1 +1,110 @@
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 int `json:"poll_period"`//轮询周期
   Delay int `json:"delay"`//延时时间
   Enable bool `json:"enable"`//是否启用轮询
}
// @Summary 保存轮询周期
// @Description 保存轮询周期
// @Produce json
// @Tags 轮询配置
// @Param period query 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.SavePollDelay(period)
   if b {
      util.ResponseFormat(c,code.Success,data)
   } else {
      util.ResponseFormat(c,code.ComError,"保存失败")
   }
}
// @Summary 保存轮询延时
// @Description 保存轮询延时
// @Produce json
// @Tags 轮询配置
// @Param delay query 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,"保存失败")
   }
}
// @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, data := api.GetPollConfig()
   if b {
      util.ResponseFormat(c,code.Success,data)
   }else{
      util.ResponseFormat(c,code.ComError,"查询失败")
   }
}
type PollEnableVo struct {
   Enable bool `json:"enable"`
}
// @Summary 切换轮询开关
// @Description 切换轮询开关
// @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,"修改失败")
   }
}