liuxiaolong
2019-08-22 f4e8f206a6760bdc31734dfcb1c65916b5b76311
controllers/pollConfig.go
@@ -9,14 +9,13 @@
)
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"`//是否启用轮询
   ServerId   string `json:"server_id"`   //服务器id
   PollPeriod int    `json:"poll_period"` //轮询周期
   Delay      int    `json:"delay"`       //延时时间
   Enable     bool   `json:"enable"`      //是否启用轮询
}
// @Summary 保存轮询周期
@@ -27,19 +26,19 @@
// @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, "保存失败")
   }
}
@@ -51,19 +50,19 @@
// @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, "保存失败")
   }
}
@@ -74,19 +73,20 @@
// @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()
   if b {
      util.ResponseFormat(c,code.Success,data)
   }else{
      util.ResponseFormat(c,code.ComError,"查询失败")
      util.ResponseFormat(c, code.Success, data)
   } else {
      util.ResponseFormat(c, code.ComError, "查询失败")
   }
}
type PollEnableVo struct {
   Enable bool `json:"enable"`
}
// @Summary 切换轮询开关
// @Description 切换轮询开关
// @Produce json
@@ -95,16 +95,16 @@
// @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, "修改失败")
   }
}
}