From bcfc7757e02487680d7c5132119d9f396211b1df Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期四, 04 七月 2019 20:33:25 +0800 Subject: [PATCH] rm db --- controllers/syssetcont.go | 203 +++++++++++++++++++++++++------------------------- 1 files changed, 102 insertions(+), 101 deletions(-) diff --git a/controllers/syssetcont.go b/controllers/syssetcont.go index 1a08f8e..edeefbd 100644 --- a/controllers/syssetcont.go +++ b/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鏈嶅姟鍣↖P" gorm:"column:ServerIp"` + ServerPort int `json:"ServerPort,omitempty" example:"21231" gorm:"column:ServerPort"` + ServerId string `json:"ServerId,omitempty" example:"SIP鏈嶅姟鍣↖d" 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鍜孭UT涓讳綋鍙傛暟浼樺厛浜嶶RL鏌ヨ瀛楃涓插�笺�� 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,"鏇存柊澶辫触") } } -- Gitblit v1.8.0