liuxiaolong
2019-06-25 2d33ef788ab96646c72c717e28013100540c8430
eventPush done
4个文件已修改
234 ■■■■■ 已修改文件
controllers/dictionary.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/eventPush.go 191 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
middlewares/auth/jwt.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/dictionary.go
@@ -27,4 +27,27 @@
    } else {
        util.ResponseFormat(c,code.ComError,data)
    }
}
// @Summary 根据父ID查找字典
// @Description  根据父ID查找字典
// @Produce json
// @Tags 字典
// @Param parentId query string false "parentId"
// @Success 200 {string} json "{"code":200, success:true, msg:"请求处理成功", data:"成功信息"}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:"错误信息内容"}"
// @Router /data/api-v/dictionary/findByParentId [get]
func (controller DictionaryController) FindByParentId(c *gin.Context) {
    parentId := c.Query("parentId")
    if parentId == "" {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    var api dbapi.DicApi
    flag, data := api.FindByParentId(parentId)
    if flag {
        util.ResponseFormat(c,code.Success,data)
    } else {
        util.ResponseFormat(c,code.ComError,"查询失败")
    }
}
controllers/eventPush.go
@@ -1 +1,192 @@
package controllers
import (
    "basic.com/dbapi.git"
    "github.com/gin-gonic/gin"
    "webserver/extend/code"
    "webserver/extend/util"
)
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"`
    IpPorts []EventPushServerPortVo `json:"ip_ports"`
    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"`
    OperatorType string `json:"operator_type"`
    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"`
}
type EventUrlVo struct {
    Url string `json:"url"`
    Enable bool `json:"enable"`
}
// @Summary 事件推送保存
// @Description 事件推送保存
// @Tags 事件推送
// @Param SaveArgs body controllers.EventPushVo true "时间推送保存参数"
// @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){
    var saveBody EventPushVo
    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)
    } else {
        util.ResponseFormat(c,code.ComError,data)
    }
}
// @Summary 根据事件推送主题的一级和二级选项获取最后下拉菜单列表
// @Description  根据事件推送主题的一级和二级选项获取最后下拉菜单列表
// @Produce json
// @Tags 事件推送
// @Param topic query string true "一级主题选项,例如:camera(摄像机)"
// @Param type query string true "子选项类型,例如:name(名称)或addr(位置)"
// @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){
    topic := c.Query("topic")
    childType := c.Query("type")
    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)
    } else {
        util.ResponseFormat(c,code.ComError,data)
    }
}
// @Summary 查全部
// @Description  查全部
// @Produce json
// @Tags 事件推送
// @Param name query string false "事件名称"
// @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){
    name := c.Query("name")
    var api dbapi.EventPushApi
    flag,data := api.FindAll(name)
    if flag {
        util.ResponseFormat(c,code.Success,data)
    } else{
        util.ResponseFormat(c,code.ComError,"")
    }
}
// @Summary 事件推送编辑
// @Description  事件推送编辑
// @Produce json
// @Tags 事件推送
// @Param id query string true "id"
// @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){
    id := c.Query("id")
    if id == ""{
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    var api dbapi.EventPushApi
    flag,data := api.GetById(id)
    if flag {
        util.ResponseFormat(c,code.Success, data)
    } else{
        util.ResponseFormat(c,code.ComError,"")
    }
}
type ChangeStatusVo struct {
    Id string `json:"id"`
    Enable bool `json:"enable"`
}
// @Summary 改变enable状态
// @Description  改变enable状态
// @Produce json
// @Tags 事件推送
// @Param statusBody body controllers.ChangeStatusVo true "参数结构"
// @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){
    var statusBody ChangeStatusVo
    err := c.BindJSON(&statusBody)
    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)
    } else {
        util.ResponseFormat(c,code.ComError,data)
    }
}
// @Summary 根据id删除
// @Description  根据id删除
// @Accept x-www-form-urlencoded
// @Produce json
// @Tags 事件推送
// @Param id query string true "id"
// @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){
    id := c.PostForm("id")
    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)
    } else {
        util.ResponseFormat(c,code.ComError,data)
    }
}
middlewares/auth/jwt.go
@@ -2,7 +2,6 @@
import (
    "encoding/json"
    "errors"
    jwtLib "github.com/dgrijalva/jwt-go"
    "github.com/dgrijalva/jwt-go/request"
    "github.com/gin-gonic/gin"
@@ -64,7 +63,7 @@
            return b,nil
        })
        if err !=nil {
            panic(err)
            return nil
        }
    } else {
        jwtToken = jwtUser.(map[string]interface{})["token"].(*jwtLib.Token)
@@ -72,7 +71,7 @@
    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 {
            panic(err)
            return nil
        }
        c.Set("User", map[string]interface{}{
            "token": jwtToken,
@@ -80,7 +79,7 @@
        })
        return user
    } else {
        panic(errors.New("decode jwt user claims fail"))
        return nil
    }
}
router/router.go
@@ -7,6 +7,8 @@
    "github.com/szuecs/gin-glog"
    "time"
    "webserver/controllers"
    _ "webserver/docs"
)
func NewRouter() *gin.Engine {
@@ -32,6 +34,7 @@
    cameraTaskArgsController :=new(controllers.CameraTaskArgsController)
    dicController :=new(controllers.DictionaryController)
    userController :=new(controllers.UserController)
    eventPushController :=new(controllers.EventPushController)
    urlPrefix := "/data/api-v" // wp 添加 路径 前缀
    userApi :=r.Group(urlPrefix+"/user")
@@ -166,6 +169,16 @@
    dicApi :=r.Group(urlPrefix+"/dictionary")
    {
        dicApi.GET("/findByType",dicController.FindByType)
        dicApi.GET("/findByParentId",dicController.FindByParentId)
    }
    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)
    }
    // 文件 上传