liuxiaolong
2019-07-04 bcfc7757e02487680d7c5132119d9f396211b1df
rm db
7个文件已修改
346 ■■■■■ 已修改文件
controllers/syssetcont.go 203 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/db.go 50 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/localconfig.go 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/task.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/vssLocalSettingTbl.go 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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,"更新失败")
    }
}
main.go
@@ -30,7 +30,7 @@
    flag.Lookup("alsologtostderr").Value.Set("true")
    flag.Lookup("log_dir").Value.Set("./log")
    config.Init(*envirment)
    models.Init()
    //models.Init()
    r := router.NewRouter()
    r.Run("0.0.0.0:8000")
models/db.go
@@ -1,33 +1,31 @@
package models
import (
    "github.com/golang/glog"
    "github.com/jinzhu/gorm"
    _ "github.com/jinzhu/gorm/dialects/sqlite"
    "webserver/extend/config"
)
var db *gorm.DB
var err error
//import (
//    "github.com/jinzhu/gorm"
//    _ "github.com/jinzhu/gorm/dialects/sqlite"
//)
//
//var db *gorm.DB
//var err error
// Init creates a connection to mysql database and
// migrates any new models
func Init() {
    // dbname, file path
    db, err = gorm.Open(config.DBconf.Name, config.DBconf.FilePath)
    db.LogMode(true)
    db.Exec("PRAGMA foreign_keys = ON")
    if err != nil {
        glog.Error("db open error ", err)
    }
    db.AutoMigrate(&Area{}, &Camera{}, &LocalConfig{}, &VSSLocalSettingTbl{}, &Task{}, &CameraTask{}, &TaskSdk{}, &Sdk{})
}
//func Init() {
//    // dbname, file path
//    db, err = gorm.Open(config.DBconf.Name, config.DBconf.FilePath)
//    db.LogMode(true)
//    db.Exec("PRAGMA foreign_keys = ON")
//    if err != nil {
//        glog.Error("db open error ", err)
//    }
//    //db.AutoMigrate(&Area{}, &Camera{}, &LocalConfig{}, &VSSLocalSettingTbl{}, &Task{}, &CameraTask{}, &TaskSdk{}, &Sdk{})
//}
//GetDB ...
func GetDB() *gorm.DB {
    return db
}
func CloseDB() {
    db.Close()
}
//func GetDB() *gorm.DB {
//    return db
//}
//
//func CloseDB() {
//    db.Close()
//}
models/localconfig.go
@@ -14,45 +14,4 @@
    Dev_name string `json:"dev_name,omitempty" example:"分析设备名称"`
    Dev_type int `json:"dev_type,omitempty" example:"1"`
    Reserved string `json:"dev_type,omitempty" example:"1"`
}
// 设置User的表名为`profiles`
func (LocalConfig) TableName() string {
    return "local_configs"
}
func (loCon *LocalConfig) FindAreaSliece() (config []LocalConfig, err error) {
    if err := db.Table(loCon.TableName()).Find(&config).Error; err != nil {
        return nil, err
    }
    return config, nil
}
/*func (loCon *LocalConfig) Create() (err error){
    tx := db.Table(loCon.TableName()).Begin()
    if tx.Error != nil {
        return err
    }
    fmt.Println(loCon)
    if err := tx.Create(&loCon).Error; err != nil {
        tx.Rollback()
        return err
    }
    return tx.Commit().Error
}*/
func (loCon *LocalConfig) Select()(err error) {
    if err = db.Table(loCon.TableName()).First(&loCon).Error; err != nil{
        if err.Error() == "record not found"{ loCon = nil; return nil }
        return err
    }
    return nil
}
func (loCon *LocalConfig) Update() error{
    if err := db.Save(&loCon).Error; err != nil {
        return err
    }
    return nil
}
}
models/task.go
@@ -1,8 +1 @@
package models
// 关联查询全部摄像机
//func (camera *Camera) FindAllCamTask() (cams []Camera) {
//    var cameras []Camera
//    db.Preload("CamTask").Find(&cameras) //查询所有device记录   // .Preload("CamTask")
//    return cameras
//}
models/vssLocalSettingTbl.go
@@ -12,39 +12,4 @@
    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"`
}
func (VSSLocalSettingTbl)TableName() string {
    return  "VSSLocalSettingTbl"
}
func (vst *VSSLocalSettingTbl) Select() (err error) {
    if err = db.Table("VSSLocalSettingTbl").First(&vst).Error; err != nil {
        if err.Error() == "record not found"{ vst = nil; return nil }
        return err
    }
    return nil
}
/*func (vst *VSSLocalSettingTbl) Insert() (err error) {
    tx := db.Table("VSSLocalSettingTbl").Begin()
    if tx.Error != nil {
        return err
    }
    fmt.Println(vst)
    if err := tx.Create(&vst).Error; err != nil {
        tx.Rollback()
        return err
    }
    return tx.Commit().Error
}*/
func (vst *VSSLocalSettingTbl) Update() error {  // cid int
    // find record by id
    vst.UpdateTime = time.Now()
    if err := db.Save(&vst).Error; err != nil {
        return err
    }
    return nil
}
}
router/router.go
@@ -167,8 +167,8 @@
        vsset.POST("/videoLenEdit", ssController.VideoLenEdit)
        vsset.GET("/getDevInfo", ssController.GetDevInfo)
        vsset.POST("/saveDevInfo", ssController.SaveDevInfo)
        vsset.GET("/vSSLocalSettingShow", ssController.VSSLocalSettingShow)
        vsset.POST("/vSSLocalSettingEdit", ssController.VSSLocalSettingEdit)
        vsset.GET("/gb28181ConfigShow", ssController.Gb28181ConfigShow)
        vsset.POST("/gb28181ConfigEdit", ssController.Gb28181ConfigEdit)
    }
    //算法库操作