zhangzengfei
2019-10-21 e871758bd82d9a4fbce42e43c9665d869c240dfb
controllers/syssetcont.go
@@ -1,15 +1,16 @@
package controllers
import (
   "basic.com/dbapi.git"
   "github.com/gin-gonic/gin"
   "webserver/extend/code"
   "webserver/extend/config"
   "webserver/extend/sys"
   "webserver/extend/util"
   "basic.com/dbapi.git"
   "github.com/gin-gonic/gin"
)
type SysSetController struct {
}
type LocalConfigVo struct {
@@ -40,6 +41,14 @@
   IsAuth bool `json:"IsAuth" example:"是否开启鉴权:true"`
   Password string `json:"Password" example:"密码"`
   UpdateTime string `json:"UpdateTime"`
}
type SysClockConfigVo struct {
   TimeZone  string `json:"timeZone" example:"时区"`
   NTP       bool   `json:"ntp" example:"NTP校时"`
   NTPServer string `json:"ntpServer" example:"NTP服务器地址"`
   Interval  int    `json:"interval" example:"自动校时间隔"`
   NewTime   string `json:"newTime" example:"手动指定时间"`
}
// @Summary 存储信息查询
@@ -192,7 +201,6 @@
   }
}
// @Summary GB28181设置查询
// @Description GB28181设置信息查询
// @Accept  json
@@ -236,3 +244,93 @@
      util.ResponseFormat(c,code.ComError,"更新失败")
   }
}
// @Summary 获取时间配置
// @Description  系统时间配置信息
// @Accept  json
// @Produce json
// @Tags sysset
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/sysset/clockInfo [GET]
func (sset SysSetController) GetClockinfo(c *gin.Context) {
   resData := make(map[string]interface{}, 0)
   resData["time_zone"], resData["local_time"] = sys.TimeZone()
   resData["ntp"], resData["ntp_server"], resData["interval"] = sys.NTPConfig()
   util.ResponseFormat(c, code.Success, resData)
}
// @Summary 测试同步时间
// @Description 测试同步时间服务器是否可用
// @Accept  json
// @Produce json
// @Tags sysset
// @Param server query string true "时间服务器ip"
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/sysset/ntpTest [GET]
func (sset SysSetController) TestNTPServer(c *gin.Context) {
   ntpServer := c.Query("server")
   if root := sys.CheckRootPermissions(); !root {
      util.ResponseFormat(c, code.ServiceInsideError, "服务器没有修改时间的权限")
      return
   }
   isIP, err := sys.RunNTPDate(ntpServer)
   if !isIP {
      util.ResponseFormat(c, code.RequestParamError, "指定的服务器地址错误")
      return
   }
   if err == nil {
      util.ResponseFormat(c, code.Success, "")
   } else {
      util.ResponseFormat(c, code.TaskStoped, "")
   }
}
// @Summary 设置系统时间
// @Description 校正系统时间
// @Accept  json
// @Produce json
// @Tags sysset
// @Param config body controllers.SysClockConfigVo true "校时信息"
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/sysset/updateClock [POST]
func (sset SysSetController) SetSysClock(c *gin.Context) {
   var args SysClockConfigVo
   err := c.BindJSON(&args)
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "参数有误")
      return
   }
   if root := sys.CheckRootPermissions(); !root {
      util.ResponseFormat(c, code.ServiceInsideError, "服务器没有修改时间的权限")
      return
   }
   if args.TimeZone != "CST" && args.TimeZone != "UTC" {
      if r := sys.SetTimeZone(args.TimeZone); !r {
         util.ResponseFormat(c, code.RequestParamError, "时区参数错误")
         return
      }
   }
   if !args.NTP {
      if r := sys.SetLocalTime(args.NewTime); !r {
         util.ResponseFormat(c, code.RequestParamError, "指定的时间参数错误")
         return
      }
   } else {
      if r := sys.EnableNTPCron(args.NTPServer, args.Interval); !r {
         util.ResponseFormat(c, code.RequestParamError, "指定的服务器地址错误")
         return
      }
   }
   util.ResponseFormat(c, code.UpdateSuccess, "配置成功")
}