liuxiaolong
2020-06-08 2a4041f16c6588921c87df93927e9076c2cc309d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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"`
}
 
// @Security ApiKeyAuth
// @Summary 事件推送保存
// @Description 事件推送保存
// @Accept json
// @Produce json
// @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)
    }
}
 
// @Security ApiKeyAuth
// @Summary 根据事件推送主题的一级和二级选项获取最后下拉菜单列表
// @Description  根据事件推送主题的一级和二级选项获取最后下拉菜单列表
// @Accept x-www-form-urlencoded
// @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)
    }
}
 
// @Security ApiKeyAuth
// @Summary 查全部
// @Description  查全部
// @Accept x-www-form-urlencoded
// @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, "")
    }
}
 
// @Security ApiKeyAuth
// @Summary 事件推送编辑
// @Description  事件推送编辑
// @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/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"`
}
 
// @Security ApiKeyAuth
// @Summary 改变enable状态
// @Description  改变enable状态
// @Accept json
// @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)
    }
}
 
// @Security ApiKeyAuth
// @Summary 根据id删除
// @Description  根据id删除
// @Accept x-www-form-urlencoded
// @Produce json
// @Tags 事件推送
// @Param id formData 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)
    }
}