liuxiaolong
2019-06-28 5e31a32f6ce2572cb01388150ddb325724ff15b8
Merge branch 'master' of http://192.168.1.14:10010/r/webserver
10个文件已修改
513 ■■■■ 已修改文件
controllers/camera.go 84 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/dictionary.go 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/eventPush.go 115 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/fileController.go 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/pollConfig.go 52 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
middlewares/auth/jwt.go 40 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/dbtablepersons.go 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/dbtables.go 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 84 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/FaceSdkService.go 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/camera.go
@@ -15,25 +15,25 @@
type CameraController struct{}
type CameraVo struct {
    Id        string       `json:"id"`
    Name      string       `json:"name"`
    Type      int          `json:"type" `
    Addr      string       `json:"addr"`
    Areaid    uint         `json:"areaid"`
    Longitude float64      `json:"longitude"`
    Latitude  float64      `json:"latitude"`
    Rtsp      string       `json:"rtsp"`
    Ip        string       `json:"ip"`
    Port      int          `json:"port"`
    Username  string       `json:"username"`
    Password  string       `json:"password"`
    Brand     string       `json:"brand"`
    Reserved  string       `json:"reserved"`
    Id        string  `json:"id"`
    Name      string  `json:"name"`
    Type      int     `json:"type" `
    Addr      string  `json:"addr"`
    Areaid    uint    `json:"areaid"`
    Longitude float64 `json:"longitude"`
    Latitude  float64 `json:"latitude"`
    Rtsp      string  `json:"rtsp"`
    Ip        string  `json:"ip"`
    Port      int     `json:"port"`
    Username  string  `json:"username"`
    Password  string  `json:"password"`
    Brand     string  `json:"brand"`
    Reserved  string  `json:"reserved"`
    IsRunning bool            `json:"is_running"`//是否正在解码
    RunEnable bool            `json:"run_enable"`//控制实时处理或轮询处理的开关
    RunType   int            `json:"run_type"`//处理类型:0:轮询,1:实时
    RunServerId string        `json:"run_server_id"`//当前正在处理的分析服务器id
    IsRunning   bool   `json:"is_running"`    //是否正在解码
    RunEnable   bool   `json:"run_enable"`    //控制实时处理或轮询处理的开关
    RunType     int    `json:"run_type"`      //处理类型:0:轮询,1:实时
    RunServerId string `json:"run_server_id"` //当前正在处理的分析服务器id
}
// @Summary 添加摄像机
@@ -55,7 +55,7 @@
        return
    }
    cam.Id = util.PseudoUuid()
    paramBody :=util.Struct2Map(cam)
    paramBody := util.Struct2Map(cam)
    if api.CameraAdd(paramBody) {
        util.ResponseFormat(c, code.Success, cam)
        return
@@ -82,7 +82,7 @@
        util.ResponseFormat(c, code.RequestParamError, "参数错误")
        return
    }
    paramBody :=util.Struct2Map(cam)
    paramBody := util.Struct2Map(cam)
    if api.CameraAdd(paramBody) {
        util.ResponseFormat(c, code.Success, cam)
        return
@@ -103,11 +103,11 @@
    var api dbapi.CameraApi
    cid := c.Param("cid")
    if api.CameraDelete(cid){
    if api.CameraDelete(cid) {
        util.ResponseFormat(c, code.Success, "删除成功")
        return
    }
    util.ResponseFormat(c, code.ComError,"删除失败")
    util.ResponseFormat(c, code.ComError, "删除失败")
}
// @Summary 显示摄像机
@@ -121,9 +121,9 @@
func (ac CameraController) CameraSel(c *gin.Context) {
    var api dbapi.CameraApi
    cid := c.Param("cid")
    camera,err := api.GetCameraById(cid)
    if err !=nil {
        util.ResponseFormat(c,code.ComError,"查询失败")
    camera, err := api.GetCameraById(cid)
    if err != nil {
        util.ResponseFormat(c, code.ComError, "查询失败")
        return
    }
@@ -210,8 +210,8 @@
    fmt.Println("runType:", runTypeStr)
    fmt.Println("cameraName:", cameraName)
    runType, err := strconv.Atoi(runTypeStr)
    if err !=nil || (runType !=0 && runType !=1) {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
    if err != nil || (runType != 0 && runType != 1) {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.CameraApi
@@ -220,9 +220,9 @@
        dataBytes, _ := json.Marshal(list)
        var cams []CameraVo
        json.Unmarshal(dataBytes, &cams)
        util.ResponseFormat(c,code.Success,cams)
        util.ResponseFormat(c, code.Success, cams)
    } else {
        util.ResponseFormat(c,code.ComError,err)
        util.ResponseFormat(c, code.ComError, err)
    }
}
@@ -235,28 +235,28 @@
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/camera/updateRunEnable [post]
func (cc CameraController) UpdateRunEnable(c *gin.Context){
func (cc CameraController) UpdateRunEnable(c *gin.Context) {
    cameraId := c.PostForm("cameraId")
    enableStr := c.PostForm("runEnable")
    runEnable, err := strconv.ParseBool(enableStr)
    if cameraId == "" || err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
    if cameraId == "" || err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.CameraApi
    b, data := api.UpdateRunEnable(cameraId, runEnable)
    fmt.Println("data:",data)
    fmt.Println("data:", data)
    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, "更新失败")
    }
}
type CameraChangeRunVo struct {
    CameraIds []string `json:"camera_ids"`
    RunType int `json:"run_type"`
    RunType   int      `json:"run_type"`
}
// @Summary 摄像机轮询和实时状态切换
@@ -267,18 +267,18 @@
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/camera/changeRunType [post]
func (cc CameraController) ChangeRunType(c *gin.Context){
func (cc CameraController) ChangeRunType(c *gin.Context) {
    var ccrVo CameraChangeRunVo
    if err := c.BindJSON(&ccrVo);err !=nil{
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
    if err := c.BindJSON(&ccrVo); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    paramBody := util.Struct2Map(ccrVo)
    var api dbapi.CameraApi
    b, data := api.ChangeRunType(paramBody)
    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, "更新失败")
    }
}
}
controllers/dictionary.go
@@ -2,13 +2,12 @@
import (
    "basic.com/dbapi.git"
    "github.com/gin-gonic/gin"
    "webserver/extend/code"
    "webserver/extend/util"
    "github.com/gin-gonic/gin"
)
type DictionaryController struct {
}
// @Summary 根据类型查找字典
@@ -23,9 +22,9 @@
    var api dbapi.DicApi
    flag, data := api.FindByType("")
    if flag {
        util.ResponseFormat(c,code.Success,data)
        util.ResponseFormat(c, code.Success, data)
    } else {
        util.ResponseFormat(c,code.ComError,data)
        util.ResponseFormat(c, code.ComError, data)
    }
}
@@ -40,14 +39,14 @@
func (controller DictionaryController) FindByParentId(c *gin.Context) {
    parentId := c.Query("parentId")
    if parentId == "" {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.DicApi
    flag, data := api.FindByParentId(parentId)
    if flag {
        util.ResponseFormat(c,code.Success,data)
        util.ResponseFormat(c, code.Success, data)
    } else {
        util.ResponseFormat(c,code.ComError,"查询失败")
        util.ResponseFormat(c, code.ComError, "查询失败")
    }
}
}
controllers/eventPush.go
@@ -8,44 +8,43 @@
)
type EventPushController struct {
}
type EventPushVo struct {
    Id string `json:"id"`
    Name string `json:"name"`
    TimeStart string `json:"time_start"`
    TimeEnd string `json:"time_end"`
    IsSatisfyAll bool `json:"is_satisfy_all"`
    RuleText string `json:"rule_text"`
    Enable bool `json:"enable"`
    LinkType string `json:"link_type"`
    LinkDevice string `json:"link_device"`
    Id           string `json:"id"`
    Name         string `json:"name"`
    TimeStart    string `json:"time_start"`
    TimeEnd      string `json:"time_end"`
    IsSatisfyAll bool   `json:"is_satisfy_all"`
    RuleText     string `json:"rule_text"`
    Enable       bool   `json:"enable"`
    LinkType     string `json:"link_type"`
    LinkDevice   string `json:"link_device"`
    IpPorts []EventPushServerPortVo `json:"ip_ports"`
    Urls []EventUrlVo `json:"urls"`
    Rules []EventPushRuleVo `json:"rules"`
    Urls    []EventUrlVo            `json:"urls"`
    Rules   []EventPushRuleVo       `json:"rules"`
}
type EventPushRuleVo struct {
    Id string `json:"id"`
    TopicType string `json:"topic_type"`//参数主题,目前分为五类(摄像机、底库、任务、人员、报警等级)
    TopicArg string `json:"topic_arg"`//主题对应的具体参数
    Operator string `json:"operator"`
    Id           string `json:"id"`
    TopicType    string `json:"topic_type"` //参数主题,目前分为五类(摄像机、底库、任务、人员、报警等级)
    TopicArg     string `json:"topic_arg"`  //主题对应的具体参数
    Operator     string `json:"operator"`
    OperatorType string `json:"operator_type"`
    RuleValue string `json:"rule_value"`
    EventPushId string `json:"event_push_id"`
    RuleValue    string `json:"rule_value"`
    EventPushId  string `json:"event_push_id"`
}
type EventPushServerPortVo struct {
    ServerIp string `json:"server_ip"`
    Port int `json:"port"`
    Enable bool `json:"enable"`
    Port     int    `json:"port"`
    Enable   bool   `json:"enable"`
}
type EventUrlVo struct {
    Url string `json:"url"`
    Enable bool `json:"enable"`
    Url    string `json:"url"`
    Enable bool   `json:"enable"`
}
// @Summary 事件推送保存
@@ -55,19 +54,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/eventPush/save [post]
func (epc EventPushController) Save(c *gin.Context){
func (epc EventPushController) Save(c *gin.Context) {
    var saveBody EventPushVo
    if err := c.BindJSON(&saveBody);err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
    if err := c.BindJSON(&saveBody); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.EventPushApi
    paramBody := util.Struct2Map(saveBody)
    flag, data := api.Save(paramBody)
    if flag {
        util.ResponseFormat(c,code.Success,data)
        util.ResponseFormat(c, code.Success, data)
    } else {
        util.ResponseFormat(c,code.ComError,data)
        util.ResponseFormat(c, code.ComError, data)
    }
}
@@ -80,19 +79,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/eventPush/findByEventTopic [get]
func (epc EventPushController) FindByEventTopic(c *gin.Context){
func (epc EventPushController) FindByEventTopic(c *gin.Context) {
    topic := c.Query("topic")
    childType := c.Query("type")
    if topic == ""{
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
    if topic == "" {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.EventPushApi
    flag, data := api.FindByEventTopic(topic, childType)
    if flag {
        util.ResponseFormat(c,code.Success,data)
        util.ResponseFormat(c, code.Success, data)
    } else {
        util.ResponseFormat(c,code.ComError,data)
        util.ResponseFormat(c, code.ComError, data)
    }
}
@@ -104,14 +103,14 @@
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/eventPush/findAll [get]
func (controller EventPushController) FindAll(c *gin.Context){
func (controller EventPushController) FindAll(c *gin.Context) {
    name := c.Query("name")
    var api dbapi.EventPushApi
    flag,data := api.FindAll(name)
    flag, data := api.FindAll(name)
    if flag {
        util.ResponseFormat(c,code.Success,data)
    } else{
        util.ResponseFormat(c,code.ComError,"")
        util.ResponseFormat(c, code.Success, data)
    } else {
        util.ResponseFormat(c, code.ComError, "")
    }
}
@@ -123,24 +122,24 @@
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/eventPush/getById [get]
func (controller EventPushController) GetById(c *gin.Context){
func (controller EventPushController) GetById(c *gin.Context) {
    id := c.Query("id")
    if id == ""{
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
    if id == "" {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.EventPushApi
    flag,data := api.GetById(id)
    flag, data := api.GetById(id)
    if flag {
        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 ChangeStatusVo struct {
    Id string `json:"id"`
    Enable bool `json:"enable"`
    Id     string `json:"id"`
    Enable bool   `json:"enable"`
}
// @Summary 改变enable状态
@@ -151,19 +150,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/eventPush/changeStatus [post]
func (controller EventPushController) ChangeStatus(c *gin.Context){
func (controller EventPushController) ChangeStatus(c *gin.Context) {
    var statusBody ChangeStatusVo
    err := c.BindJSON(&statusBody)
    if err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.EventPushApi
    flag, data := api.ChangeStatus(statusBody.Id, statusBody.Enable)
    if flag{
        util.ResponseFormat(c,code.Success,data)
    if flag {
        util.ResponseFormat(c, code.Success, data)
    } else {
        util.ResponseFormat(c,code.ComError,data)
        util.ResponseFormat(c, code.ComError, data)
    }
}
@@ -176,17 +175,17 @@
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/eventPush/delete [post]
func (controller EventPushController) Delete(c *gin.Context){
func (controller EventPushController) Delete(c *gin.Context) {
    id := c.PostForm("id")
    if id ==""{
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
    if id == "" {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.EventPushApi
    flag, data := api.Delete(id)
    if flag{
        util.ResponseFormat(c,code.Success,data)
    if flag {
        util.ResponseFormat(c, code.Success, data)
    } else {
        util.ResponseFormat(c,code.ComError,data)
        util.ResponseFormat(c, code.ComError, data)
    }
}
controllers/fileController.go
@@ -17,6 +17,7 @@
    "webserver/extend/util"
    "webserver/models"
    "webserver/service"
)
type FileController struct {
@@ -86,12 +87,13 @@
        util.ResponseFormat(c, code.Success, field)
    }
}
// @Description 人员照片上传并获取特征值
// @Router /data/api-v/dbperson/fileUploadTest [POST]
func (controller FileController) UploadPersonTest(c *gin.Context){
func (controller FileController) UploadPersonTest(c *gin.Context) {
    file, header, err := c.Request.FormFile("file") //image这个是uplaodify参数定义中的   'fileObjName':'image'
    if err != nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    //文件的名称
@@ -152,6 +154,7 @@
            feat := features[0]["feature"].([]byte)   // linux
        if len(feat) != 2560 {                                // linux
            return field,nil,errors.New("NotFeatureFindError")
        }    */                     // linux
        //将上传的图片交人脸检测和人脸提取,获得特征
@@ -164,12 +167,15 @@
            }
        }
        dbperson := new(models.Dbtablepersons)
        dbperson.FaceUrl = picIp+field       //  图片路经
        dbperson.TableId = tableId  //
        dbperson.PersonName = filename // 图片名
        dbperson.FaceFeature = picIp + field //  图片路经
        dbperson.TableId = tableId           //
        dbperson.PersonName = filename       // 图片名
        // 演示base64编码
        dbperson.Feature = faceBase64 // 特征值base64 码
        dbperson.FaceFeature = faceBase64 // 特征值base64 码
        result := addDbPerson(dbperson)
        return field, result, nil
    } else {
@@ -192,7 +198,6 @@
}
/**上传方法**/
// @Summary 批量添加底库人员
// @Description  依据图片批量添加底库人员
@@ -299,7 +304,7 @@
    //features := gorun.GetSimpleFaceDetect(picIp + "/" + field) // 特征值  只在linux 下
    //feat := []byte("hello world")           // windows 测试放开
    result := make(map[string]interface{}, 0)
    result["uploadImage"] = picIp+field
    result["uploadImage"] = picIp + field
    smUrl := make([]string, 0)
    //for _, feature := range features {         // linux
    // 获取图片
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, "修改失败")
    }
}
}
middlewares/auth/jwt.go
@@ -13,14 +13,14 @@
type jwtAuthManager struct {
    secret string
    expire time.Duration
    alg string
    alg    string
}
func NewJwtAuthDriver() *jwtAuthManager{
func NewJwtAuthDriver() *jwtAuthManager {
    return &jwtAuthManager{
        secret:TokenKey,
        expire:time.Hour*8,
        alg:"HS256",
        secret: TokenKey,
        expire: time.Hour * 8,
        alg:    "HS256",
    }
}
@@ -34,41 +34,41 @@
    if len(t) < 2 {
        return false
    }
    var keyFunc = func(token *jwtLib.Token) (interface{},error) {
    var keyFunc = func(token *jwtLib.Token) (interface{}, error) {
        b := []byte(jwtAuth.secret)
        return b,nil
        return b, nil
    }
    authJwtToken, err:= request.ParseFromRequest(c.Request,request.OAuth2Extractor,keyFunc)
    if err !=nil {
    authJwtToken, err := request.ParseFromRequest(c.Request, request.OAuth2Extractor, keyFunc)
    if err != nil {
        return false
    }
    c.Set("User",map[string]interface{}{
        "token":authJwtToken,
    c.Set("User", map[string]interface{}{
        "token": authJwtToken,
    })
    return authJwtToken.Valid
}
func (jwtAuth *jwtAuthManager) User(c *gin.Context) interface{}{
func (jwtAuth *jwtAuthManager) User(c *gin.Context) interface{} {
    var jwtToken *jwtLib.Token
    if jwtUser, exist := c.Get("User");!exist{
        tokenStr :=strings.Replace(c.Request.Header.Get("Authorization"),"Bearer ","",-1)
        if tokenStr == ""{
    if jwtUser, exist := c.Get("User"); !exist {
        tokenStr := strings.Replace(c.Request.Header.Get("Authorization"), "Bearer ", "", -1)
        if tokenStr == "" {
            return map[interface{}]interface{}{}
        }
        var err error
        jwtToken,err = jwtLib.Parse(tokenStr, func(token *jwtLib.Token) (interface{}, error) {
            b :=[]byte(jwtAuth.secret)
            return b,nil
        jwtToken, err = jwtLib.Parse(tokenStr, func(token *jwtLib.Token) (interface{}, error) {
            b := []byte(jwtAuth.secret)
            return b, nil
        })
        if err !=nil {
        if err != nil {
            return nil
        }
    } else {
        jwtToken = jwtUser.(map[string]interface{})["token"].(*jwtLib.Token)
    }
    if claims,ok :=jwtToken.Claims.(jwtLib.MapClaims);ok && jwtToken.Valid{
    if claims, ok := jwtToken.Claims.(jwtLib.MapClaims); ok && jwtToken.Valid {
        var user map[string]interface{}
        if err := json.Unmarshal([]byte(claims["user"].(string)), &user); err != nil {
            return nil
models/dbtablepersons.go
@@ -1,15 +1,14 @@
package models
type Dbtablepersons   struct {
type Dbtablepersons struct {
    BaseEntity
    TableId string `json:"tableId,omitempty" example:"库表id"`
    Feature string  `json:"feature,omitempty" example:"人脸特征值"`
    FaceUrl string `json:"faceUrl,omitempty" example:"图片路径"`
    PersonName string `json:"personName,omitempty" example:"人员姓名"`
    Age string `json:"age,omitempty"  example:"年龄"`
    Sex string  `json:"sex,omitempty" example:"性别 男 女"`
    Idcard string `json:"idcard,omitempty" example:"身份证"`
    PhoneNum string `json:"phoneNum,omitempty" example:"手机号码"`
    TableId      string `json:"tableId,omitempty" example:"库表id"`
    FaceFeature  string `json:"faceFeature,omitempty" example:"人脸特征值"`
    PersonPicUrl string `json:"personPicUrl,omitempty" example:"图片路径"`
    PersonName   string `json:"personName,omitempty" example:"人员姓名"`
    Age          string `json:"age,omitempty"  example:"年龄"`
    Sex          string `json:"sex,omitempty" example:"性别 男 女"`
    IdCard       string `json:"idCard,omitempty" example:"身份证"`
    PhoneNum     string `json:"phoneNum,omitempty" example:"手机号码"`
    MonitorLevel string `json:"monitorLevel,omitempty" example:"等级"`
}
models/dbtables.go
@@ -2,15 +2,14 @@
type Dbtables struct {
    BaseEntity
    TableName string  `json:"tableName,omitempty" example:"底库123"`//表名
    TableDesc string  `json:"tableDesc,omitempty" example:"底库描述"`//描述
    TableType string  `json:"tableType,omitempty" example:"person,car"`//人员表"person
    BwType string   `json:"bwType,omitempty" example:"黑名单:1,白名单:0"`  //黑名单:1,白名单:0
    StartTime string  `json:"startTime,omitempty" example:"2019-01-12 12:14:56"` //有效期开始时间
    EndTime string    `json:"endTime,omitempty" example:"2019-10-12 12:14:56"` //有效期结束时间
    UploadFlag string `json:"uploadFlag,omitempty" example:"上传标志"` //
    CmpThreshold string `json:"cmpThreshold,omitempty" example:"45"`// //人脸比对阈值
    SyncType string  `json:"syncType,omitempty" example:"1:同步库,2:本地库"` //是否是同步库(1:同步库,2:本地库)
    Indeviceid string `json:"indeviceid,omitempty" example:"本地库所属的分析设备id,如果是同步库就不需要记录"`// 分析设备id(本地库所属的分析设备id,如果是同步库就不需要记录)
    TableName string `json:"tableName,omitempty" example:"底库123"`               //表名
    TableDesc string `json:"tableDesc,omitempty" example:"底库描述"`                //描述
    TableType string `json:"tableType,omitempty" example:"person,car"`          //人员表"person
    BwType    string `json:"bwType,omitempty" example:"黑名单:1,白名单:0"`            //黑名单:1,白名单:0
    StartTime string `json:"startTime,omitempty" example:"2019-01-12 12:14:56"` //有效期开始时间
    EndTime   string `json:"endTime,omitempty" example:"2019-10-12 12:14:56"`   //有效期结束时间
    //UploadFlag string `json:"uploadFlag,omitempty" example:"上传标志"` //
    //CmpThreshold string `json:"cmpThreshold,omitempty" example:"45"`// //人脸比对阈值
    IsSync        string `json:"isSync,omitempty" example:"1:同步库,2:本地库"`                      //是否是同步库(1:同步库,2:本地库)
    AnalyServerId string `json:"analyServerId,omitempty" example:"本地库所属的分析设备id,如果是同步库就不需要记录"` // 分析设备id(本地库所属的分析设备id,如果是同步库就不需要记录)
}
router/router.go
@@ -30,19 +30,19 @@
    esSearchController := new(controllers.EsSearchController)
    realTimeController := new(controllers.RealTimeController)
    cameraTimeRuleController := new(controllers.CameraTimeruleController)
    polygonController :=new (controllers.CameraPolygonController)
    cameraTaskController :=new(controllers.CameraTaskController)
    cameraTaskArgsController :=new(controllers.CameraTaskArgsController)
    dicController :=new(controllers.DictionaryController)
    userController :=new(controllers.UserController)
    eventPushController :=new(controllers.EventPushController)
    pollConfigController :=new(controllers.PollConfigController)
    polygonController := new(controllers.CameraPolygonController)
    cameraTaskController := new(controllers.CameraTaskController)
    cameraTaskArgsController := new(controllers.CameraTaskArgsController)
    dicController := new(controllers.DictionaryController)
    userController := new(controllers.UserController)
    eventPushController := new(controllers.EventPushController)
    pollConfigController := new(controllers.PollConfigController)
    fileController := new(controllers.FileController)
    urlPrefix := "/data/api-v" // wp 添加 路径 前缀
    userApi :=r.Group(urlPrefix+"/user")
    userApi := r.Group(urlPrefix + "/user")
    {
        userApi.POST("/login",userController.Login)
        userApi.POST("/login", userController.Login)
    }
    //区域管理
@@ -68,33 +68,33 @@
        camera.GET("/delTask/:cameraId/:taskId", cameraController.CameraDelTask)
        camera.POST("/saveTask", cameraController.CameraTaskSave)
        camera.GET("/getRulesByCameraAndTask",cameraTaskArgsController.FindByCameraAndTask)
        camera.GET("/getCamerasByRunType",cameraController.GetCamerasByRunType)
        camera.POST("/updateRunEnable",cameraController.UpdateRunEnable)
        camera.POST("/changeRunType",cameraController.ChangeRunType)
        camera.GET("/getRulesByCameraAndTask", cameraTaskArgsController.FindByCameraAndTask)
        camera.GET("/getCamerasByRunType", cameraController.GetCamerasByRunType)
        camera.POST("/updateRunEnable", cameraController.UpdateRunEnable)
        camera.POST("/changeRunType", cameraController.ChangeRunType)
    }
    cameraTaskArgsApi :=r.Group(urlPrefix + "/cameraTaskArgs")
    cameraTaskArgsApi := r.Group(urlPrefix + "/cameraTaskArgs")
    {
        cameraTaskArgsApi.GET("/deleteByGroup",cameraTaskArgsController.DeleteByGroup)
        cameraTaskArgsApi.POST("/getLinkRulesByCameraIds",cameraTaskArgsController.GetLinkRulesByCameraIds)
        cameraTaskArgsApi.POST("/saveLinkRulesByGroup",cameraTaskArgsController.SaveLinkRulesByGroup)
        cameraTaskArgsApi.GET("/deleteByGroup", cameraTaskArgsController.DeleteByGroup)
        cameraTaskArgsApi.POST("/getLinkRulesByCameraIds", cameraTaskArgsController.GetLinkRulesByCameraIds)
        cameraTaskArgsApi.POST("/saveLinkRulesByGroup", cameraTaskArgsController.SaveLinkRulesByGroup)
    }
    cameraTaskApi := r.Group(urlPrefix + "/cameraTask")
    {
        cameraTaskApi.POST("/saveIsDataTrans",cameraTaskController.SaveIsDataTrans)
        cameraTaskApi.POST("/saveAlarmLevelByGroup",cameraTaskController.SaveAlarmLevelByGroup)
        cameraTaskApi.POST("/updateCameraTaskStatus",cameraTaskController.UpdateCameraTaskStatus)
        cameraTaskApi.POST("/saveIsDataTrans", cameraTaskController.SaveIsDataTrans)
        cameraTaskApi.POST("/saveAlarmLevelByGroup", cameraTaskController.SaveAlarmLevelByGroup)
        cameraTaskApi.POST("/updateCameraTaskStatus", cameraTaskController.UpdateCameraTaskStatus)
    }
    polygon := r.Group(urlPrefix+"/polygon")
    polygon := r.Group(urlPrefix + "/polygon")
    {
        polygon.POST("/save", polygonController.Save)
        polygon.GET("/findByCameraId", polygonController.FindByCameraId)
        //polygon.GET("/delete", polygonController.Delete)
        polygon.GET("/updateDefenceStateByPolygonId",polygonController.UpdateDefenceStateByPolygonId)
        polygon.GET("/updateDefenceStateByCameraId",polygonController.UpdateDefenceStateByCameraId)
        polygon.GET("/updateDefenceStateByPolygonId", polygonController.UpdateDefenceStateByPolygonId)
        polygon.GET("/updateDefenceStateByCameraId", polygonController.UpdateDefenceStateByCameraId)
    }
    // 任务管理
@@ -143,7 +143,7 @@
        vdbperson.POST("/deleteMoreDbPerson", dbPersonCont.DeleteMoreDbPerson)
        vdbperson.PUT("/addDbPerson", dbPersonCont.AddDbPerson)
        vdbperson.POST("/fileUploadTest",fileController.UploadPersonTest)
        vdbperson.POST("/fileUploadTest", fileController.UploadPersonTest)
    }
    // 系统设置 操作
@@ -164,8 +164,8 @@
    {
        sdkApi.POST("/saveSdk", sdkController.Save)
        sdkApi.GET("/findAllSdk", sdkController.FindAllSdk)
        sdkApi.GET("/findByTaskId",sdkController.FindByTaskId)
        sdkApi.GET("/getById",sdkController.GetById)
        sdkApi.GET("/findByTaskId", sdkController.FindByTaskId)
        sdkApi.GET("/getById", sdkController.GetById)
    }
    cameraTimeApi := r.Group(urlPrefix + "/cameraTimerule")
@@ -174,33 +174,33 @@
        cameraTimeApi.GET("/delete", cameraTimeRuleController.Delete)
        cameraTimeApi.GET("/findAll", cameraTimeRuleController.FindAll)
    }
    dicApi :=r.Group(urlPrefix+"/dictionary")
    dicApi := r.Group(urlPrefix + "/dictionary")
    {
        dicApi.GET("/findByType",dicController.FindByType)
        dicApi.GET("/findByParentId",dicController.FindByParentId)
        dicApi.GET("/findByType", dicController.FindByType)
        dicApi.GET("/findByParentId", dicController.FindByParentId)
    }
    eventPushApi :=r.Group(urlPrefix+"/eventPush")
    eventPushApi := r.Group(urlPrefix + "/eventPush")
    {
        eventPushApi.POST("/save",eventPushController.Save)
        eventPushApi.GET("/findByEventTopic",eventPushController.FindByEventTopic)
        eventPushApi.GET("/findAll",eventPushController.FindAll)
        eventPushApi.GET("/getById",eventPushController.GetById)
        eventPushApi.POST("/changeStatus",eventPushController.ChangeStatus)
        eventPushApi.POST("/delete",eventPushController.Delete)
        eventPushApi.POST("/save", eventPushController.Save)
        eventPushApi.GET("/findByEventTopic", eventPushController.FindByEventTopic)
        eventPushApi.GET("/findAll", eventPushController.FindAll)
        eventPushApi.GET("/getById", eventPushController.GetById)
        eventPushApi.POST("/changeStatus", eventPushController.ChangeStatus)
        eventPushApi.POST("/delete", eventPushController.Delete)
    }
    pollCApi :=r.Group(urlPrefix+"/pollConfig")
    pollCApi := r.Group(urlPrefix + "/pollConfig")
    {
        pollCApi.POST("/savePollPeriod",pollConfigController.SavePollPeriod)
        pollCApi.POST("/savePollDelay",pollConfigController.SavePollDelay)
        pollCApi.GET("/getPollConfig",pollConfigController.GetPollConfig)
        pollCApi.POST("/updateEnable",pollConfigController.UpdateEnable)
        pollCApi.POST("/savePollPeriod", pollConfigController.SavePollPeriod)
        pollCApi.POST("/savePollDelay", pollConfigController.SavePollDelay)
        pollCApi.GET("/getPollConfig", pollConfigController.GetPollConfig)
        pollCApi.POST("/updateEnable", pollConfigController.UpdateEnable)
    }
    // 文件 上传
    r.Static("static", "./static") // 静态文件
    //外部访问swagger.json
    r.StaticFile("/swagger.json", "./docs/swagger.json")
    fileController := new(controllers.FileController)
    vdbperson.POST("/fileupload", fileController.Fileupload)
    vdbperson.POST("/moreFileUpload", fileController.MoreFileUpload)
    r.POST(urlPrefix+"/es/ImageUploadReturnPics", fileController.ImageUploadReturnPics)
service/FaceSdkService.go
@@ -21,13 +21,13 @@
}
const (
    Ipc_Push_Ext = "_2.ipc"
    Ipc_Pull_Ext = "_1.ipc"
    Ipc_Url_Pre = "ipc:///tmp///"
    Ipc_Push_Ext       = "_2.ipc"
    Ipc_Pull_Ext       = "_1.ipc"
    Ipc_Url_Pre        = "ipc:///tmp///"
    Virtual_FaceTaskId = "92496BDF-2BFA-98F2-62E8-96DD9866ABD2"
    Virtual_FaceSdkId = "virtual-faceextract-sdk-pull"
    Url_Service_PUSH = Ipc_Url_Pre + Virtual_FaceSdkId + Ipc_Push_Ext
    Url_Service_PULL = Ipc_Url_Pre + Virtual_FaceSdkId + Ipc_Pull_Ext
    Virtual_FaceSdkId  = "virtual-faceextract-sdk-pull"
    Url_Service_PUSH   = Ipc_Url_Pre + Virtual_FaceSdkId + Ipc_Push_Ext
    Url_Service_PULL   = Ipc_Url_Pre + Virtual_FaceSdkId + Ipc_Pull_Ext
)
func NewFaceSdkService(file multipart.File) FaceSdkService{
@@ -89,18 +89,18 @@
}
func ImgCompress(i *protomsg.Image) ([]byte,error){
    if b, err := proto.Marshal(i);err !=nil{
    if b, err := proto.Marshal(i); err != nil {
        fmt.Println("protoImage marshal err")
        return nil,err
    } else {
        bc := make([]byte,len(b))
        bc := make([]byte, len(b))
        ht := make([]int, 64<<10)
        n,err := lz4.CompressBlock(b, bc, ht)
        if err !=nil {
        n, err := lz4.CompressBlock(b, bc, ht)
        if err != nil {
            fmt.Println(err)
            return nil,err
        }
        if n >= len(b){
        if n >= len(b) {
            fmt.Println("image is not compressible")
            return nil,errors.New("compressed len is 0")
        }
@@ -160,13 +160,13 @@
    //gocv.IMWrite("xxx.jpg", wrMat)
    i = protomsg.Image{
        Width: width,
        Height: height,
        Width:     width,
        Height:    height,
        Timestamp: formatTimeStr,
        Data: data,
        Id: timeUnix,
        Data:      data,
        Id:        timeUnix,
    }
    i.Cid = uuid.NewV4().String()//数据唯一id
    i.Cid = uuid.NewV4().String() //数据唯一id
    fmt.Println("gocv read img completed")
    return i
}
@@ -177,11 +177,12 @@
var resultMap map[string][]*protomsg.ResultFaceExtCom
func InitService(){
func InitService() {
    fmt.Println("service init!")
    imgPushChan = make(chan []byte)
    resultMap = make(map[string][]*protomsg.ResultFaceExtCom,0)
    client_push = deliver.NewClient(deliver.PushPull, Url_Service_PUSH)
    client_pull = deliver.NewClient(deliver.PushPull, Url_Service_PULL)
    defer func() {
@@ -193,14 +194,14 @@
    go thRecv()
}
func thSend(){
func thSend() {
    for {
        select {
        case d := <- imgPushChan:
        case d := <-imgPushChan:
            fmt.Println("imgPushChan in")
            err := client_push.Send(d)
            if err !=nil {
                fmt.Println("img Send err:",err)
            if err != nil {
                fmt.Println("img Send err:", err)
            }
        default:
            //fmt.Println("no img in")
@@ -208,19 +209,20 @@
    }
}
func thRecv(){
func thRecv() {
    for {
        resultBytes, err := client_pull.Recv()
        if err !=nil{
            fmt.Println("pull err:",err)
        if err != nil {
            fmt.Println("pull err:", err)
            continue
        }
        rMsg := protomsg.SdkMessage{}
        if err := proto.Unmarshal(resultBytes, &rMsg);err ==nil{
            fmt.Println("received MSG:",rMsg.Cid)
        if err := proto.Unmarshal(resultBytes, &rMsg); err == nil {
            fmt.Println("received MSG:", rMsg.Cid)
            perId := rMsg.Cid //数据id
            if rMsg.Tasklab !=nil && rMsg.Tasklab.Taskid == Virtual_FaceTaskId {
            if rMsg.Tasklab != nil && rMsg.Tasklab.Taskid == Virtual_FaceTaskId {
                sdkInfos := rMsg.Tasklab.Sdkinfos
                fmt.Println("Len(sdkInfos)=",len(sdkInfos))
                for _,swt :=range sdkInfos{
                    if swt.Sdktype =="FaceDetect"{
@@ -257,8 +259,8 @@
                }
            }
        } else {
            fmt.Println("recv msg Err:",err)
            fmt.Println("recv msg Err:", err)
        }
    }
}
}