liuxiaolong
2019-07-04 bcfc7757e02487680d7c5132119d9f396211b1df
controllers/syssetcont.go
@@ -1,16 +1,42 @@
package controllers
import (
   "basic.com/dbapi.git"
   "github.com/gin-gonic/gin"
   "time"
   "webserver/extend/code"
   "webserver/extend/util"
   "webserver/models"
   "github.com/satori/go.uuid"
   "strconv"
)
type SysSetController struct {
}
type LocalConfigVo struct {
   Id string  `json:"id"`
   AlarmIp string `json:"alarm_ip,omitempty" example:"192.168.1.182"`
   AlarmPort int `json:"alarm_port,omitempty" example:"22122"`
   WebPicIp string `json:"web_pic_ip,omitempty" example:""`
   WebPicPort int `json:"web_pic_port,omitempty" example:"22122"`
   EsPicIp string `json:"es_pic_ip,omitempty" example:""`
   EsPicPort  int `json:"es_pic_port,omitempty" example:"22122"`
   CutMaxDuration int `json:"cut_max_duration,omitempty" example:"20"`
   CutMinDuration int `json:"cut_min_duration,omitempty" example:"5"`
   ServerId string `json:"server_id,omitempty" example:"分析设备id"`
   ServerName string `json:"server_name,omitempty" example:"分析设备名称"`
   ServerType int `json:"server_type,omitempty" example:"1"`
   Reserved string `json:"reserved,omitempty" example:"1"`
   RealMax int `json:"real_max"`//实时处理的最大路数
}
type Gb28181ConfigVo struct {
   ID int `json:"ID,omitempty" gorm:"primary_key" `
   ServerIp string `json:"ServerIp,omitempty" example:"SIP服务器IP" gorm:"column:ServerIp"`
   ServerPort int `json:"ServerPort,omitempty" example:"21231" gorm:"column:ServerPort"`
   ServerId string `json:"ServerId,omitempty" example:"SIP服务器Id" gorm:"column:ServerId"`
   UserAuthId string `json:"UserAuthId,omitempty" example:"SIP用户认证ID" gorm:"column:UserAuthId"`
   Password string `json:"Password,omitempty" example:"密码" gorm:"column:Password"`
   UpdateTime time.Time `json:"-" gorm:"column:UpdateTime"`
}
// @Summary 存储信息查询
@@ -22,11 +48,12 @@
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/sysset/alarmServerShow [GET]
func (sset SysSetController) AlarmServerShow(c *gin.Context){
   config := new(models.LocalConfig)
   if err := config.Select(); err != nil {
      util.ResponseFormat(c, code.ServiceInsideError, config)
   var api dbapi.SysSetApi
   b, sysconf := api.GetServerInfo()
   if b{
      util.ResponseFormat(c,code.Success,sysconf)
   } else {
         util.ResponseFormat(c, code.Success, config)
      util.ResponseFormat(c,code.ComError,"查询失败")
   }
}
@@ -35,36 +62,25 @@
// @Accept  json
// @Produce json
// @Tags sysset
// @Param config body models.LocalConfig true "报警和存储信息数据"
// @Param config body controllers.LocalConfigVo true "报警和存储信息数据"
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/sysset/alarmEdit [POST]
func (sset SysSetController) AlarmEdit(c *gin.Context) {
   config := new(models.LocalConfig) // 查询绑定
   reqCon := new(models.LocalConfig) // 前台数据绑定
   c.BindJSON(reqCon)
   if err := config.Select(); err != nil { // 查询是否存在
      util.ResponseFormat(c, code.ServiceInsideError, config)
   } else {
         copyColumnValueForAlarm(reqCon ,config)  // 不印象其他值
         reqCon.ID = config.ID   // 修改必须有 id
         if e := reqCon.Update(); e != nil {
            util.ResponseFormat(c, code.ServiceInsideError, e.Error())
         } else {
            util.ResponseFormat(c, code.Success,reqCon)
         }
   var args LocalConfigVo
   err := c.BindJSON(&args)
   if err !=nil {
      util.ResponseFormat(c,code.RequestParamError,"参数有误")
      return
   }
}
// 本地 配置信息 复制
func copyColumnValueForAlarm(reqCon *models.LocalConfig,config *models.LocalConfig)  {
   reqCon.Dev_id = config.Dev_id
   reqCon.Dev_name = config.Dev_name
   reqCon.Cut_min_duration = config.Cut_min_duration
   reqCon.Cut_max_duration = config.Cut_max_duration
   reqCon.Dev_type = config.Dev_type
   reqCon.Reserved = config.Reserved
   var api dbapi.SysSetApi
   paramBody := util.Struct2Map(args)
   b,data := api.AlarmEdit(paramBody)
   if b {
      util.ResponseFormat(c,code.Success,data)
   }else {
      util.ResponseFormat(c,code.ComError,"保存失败")
   }
}
// @Summary 存储信息修改
@@ -76,15 +92,16 @@
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/sysset/videoLenShow [GET]
func (sset SysSetController) VideoLenShow(c *gin.Context){
   config := new(models.LocalConfig) // 前台数据绑定
   if err := config.Select(); err != nil { // 查询是否存在
      util.ResponseFormat(c, code.ServiceInsideError, config)
   var api dbapi.SysSetApi
   b, sysconf := api.GetServerInfo()
   if b {
      resData := make(map[string]int32, 0)
      resData["max_video_len"] = sysconf.CutMaxDuration
      resData["min_video_len"] = sysconf.CutMinDuration
      // 存在则修改
      util.ResponseFormat(c, code.Success, resData)
   } else {
      resData := make(map[string]int, 0)
         resData["max_video_len"] = config.Cut_max_duration
         resData["min_video_len"] = config.Cut_min_duration
         // 存在则修改
         util.ResponseFormat(c, code.Success, resData)
      util.ResponseFormat(c,code.ComError,"查询失败")
   }
}
@@ -99,25 +116,17 @@
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/sysset/videoLenEdit [POST]
func (sset SysSetController) VideoLenEdit(c *gin.Context) {
   config := new(models.LocalConfig) // 前台数据绑定
   /*min_video_len := c.Query("min_video_len") //查询请求URL后面的参数
   max_video_len := c.PostForm("max_video_len") //从表单中查询参数*/
   //POST和PUT主体参数优先于URL查询字符串值。
   max_video_len := c.Request.FormValue("max_video_len")
   min_video_len := c.Request.FormValue("min_video_len")
   if err := config.Select(); err != nil { // 查询是否存在
      util.ResponseFormat(c, code.ServiceInsideError, config)
   var api dbapi.SysSetApi
   b,data := api.VideoLenEdit(max_video_len,min_video_len)
   if b{
      util.ResponseFormat(c,code.UpdateSuccess,data)
   } else {
         max, _ := strconv.Atoi(max_video_len)  // 数据 string 转 int8
         min, _ := strconv.Atoi(min_video_len)
         config.Cut_max_duration = max
         config.Cut_min_duration = min
         if e := config.Update(); e != nil {
            util.ResponseFormat(c, code.ServiceInsideError, e.Error())
         } else {
            util.ResponseFormat(c, code.Success, config)
         }
      util.ResponseFormat(c,code.ComError,"保存失败")
   }
}
@@ -130,15 +139,16 @@
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/sysset/getDevInfo [GET]
func (sset SysSetController) GetDevInfo(c *gin.Context) {
   config := new(models.LocalConfig) // 前台数据绑定
      resData := make(map[string]string, 0)
   if err := config.Select(); err != nil { // 查询是否存在
         util.ResponseFormat(c, code.ServiceInsideError,err.Error())
   var api dbapi.SysSetApi
   b, sysconf := api.GetServerInfo()
   resData := make(map[string]string, 0)
   if !b { // 查询是否存在
      util.ResponseFormat(c, code.ServiceInsideError,"查询失败")
   }else {
         resData["dev_id"] = config.Dev_id
         resData["dev_name"] = config.Dev_name
         // 存在
         util.ResponseFormat(c, code.Success, resData)
      resData["dev_id"] = sysconf.GetServerId()
      resData["dev_name"] = sysconf.GetServerName()
      // 存在
      util.ResponseFormat(c, code.Success, resData)
   }
}
@@ -153,21 +163,16 @@
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/sysset/saveDevInfo [POST]
func (sset SysSetController) SaveDevInfo(c *gin.Context){
   config := new(models.LocalConfig) // 前台数据绑定
   dev_name := c.Request.FormValue("dev_name")
   if err := config.Select(); err != nil { // 查询是否存在
         util.ResponseFormat(c, code.ServiceInsideError,err.Error())
   } else {  // 存在及修改 不存在 即添加
         config.Dev_name = dev_name
      if config.Dev_id == "" {
         config.Dev_id = uuid.NewV4().String()
      }
         if e := config.Update(); e != nil {
            util.ResponseFormat(c, code.ServiceInsideError, e.Error())
         } else {
            util.ResponseFormat(c, code.Success, config)
         }
   dev_name := c.Request.FormValue("dev_name")
   var api dbapi.SysSetApi
   paramBody :=make(map[string]interface{},0)
   paramBody["serverName"] = dev_name
   b,data := api.SaveServerInfo(paramBody)
   if b { // 查询是否存在
      util.ResponseFormat(c,code.Success,data)
   } else {  // 存在及修改 不存在 即添加
      util.ResponseFormat(c,code.ComError,"保存失败")
   }
}
@@ -179,17 +184,14 @@
// @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/vSSLocalSettingShow [GET]
func (sset SysSetController) VSSLocalSettingShow(c *gin.Context) {
   config := new(models.VSSLocalSettingTbl)
   if err := config.Select(); err != nil {
      util.ResponseFormat(c, code.ServiceInsideError, config)
// @Router /data/api-v/sysset/gb28181ConfigShow [GET]
func (sset SysSetController) Gb28181ConfigShow(c *gin.Context) {
   var api dbapi.SysSetApi
   b, data := api.Gb28181ConfigShow()
   if b {
      util.ResponseFormat(c,code.Success,data)
   } else {
      if config == nil {
         util.ResponseFormat(c, code.DdSelectNotFindError, config)
      } else {
         util.ResponseFormat(c, code.Success, config)
      }
      util.ResponseFormat(c,code.ComError,"查询失败")
   }
}
@@ -198,24 +200,23 @@
// @Accept  json
// @Produce json
// @Tags sysset
// @Param config body models.VSSLocalSettingTbl true "GB28181设置数据"
// @Param config body controllers.Gb28181ConfigVo true "GB28181设置数据"
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/sysset/vSSLocalSettingEdit [POST]
func (sset SysSetController) VSSLocalSettingEdit(c *gin.Context) {
   config := new(models.VSSLocalSettingTbl) // 查询绑定
   reqCon := new(models.VSSLocalSettingTbl) // 前台数据绑定
   c.BindJSON(reqCon)
   if err := config.Select(); err != nil { // 查询是否存在
      util.ResponseFormat(c, code.ServiceInsideError, config)
// @Router /data/api-v/sysset/gb28181ConfigEdit [POST]
func (sset SysSetController) Gb28181ConfigEdit(c *gin.Context) {
   var args LocalConfigVo
   err := c.BindJSON(&args)
   if err !=nil {
      util.ResponseFormat(c,code.RequestParamError,"参数有误")
      return
   }
   var api dbapi.SysSetApi
   paramBody := util.Struct2Map(args)
   b, data := api.Gb28181ConfigEdit(paramBody)
   if b {
      util.ResponseFormat(c,code.UpdateSuccess,data)
   } else {
       { // 存在则修改
         reqCon.ID = config.ID
         if e := reqCon.Update(); e != nil {
            util.ResponseFormat(c, code.ServiceInsideError, e.Error())
         } else {
            util.ResponseFormat(c, code.Success, reqCon)
         }
      }
      util.ResponseFormat(c,code.ComError,"更新失败")
   }
}