liuxiaolong
2019-11-12 4d0e5b1e9f59ebba7f875c9a39a6ab84c9dde4b6
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
package controllers
 
import (
    "basic.com/dbapi.git"
    "github.com/gin-gonic/gin"
    "webserver/extend/code"
    "webserver/extend/util"
)
 
type CameraPolygonController struct {
 
}
 
type CameraPolygonVo struct {
    CameraId      string `json:"camera_id"`      //摄像机id
    SnapshotUrl   string  `json:"snapshot_url"`   //快照地址
    Line          []PolygonS    `json:"line"`    //画的所有线
    Rect           []PolygonS    `json:"rect"`    //矩形
    Arrow         []PolygonS    `json:"arrow"`     //箭头
    Polygon       []PolygonS    `json:"polygon"`  //多边形
}
 
type PolygonS struct {
    Id string `json:"id"`//形状id
    Name string `json:"name"`//形状名称
    Location []Point `json:"location"`//形状坐标
    DefenceState int `json:"defence_state"`//默认为0,不启用
}
 
//坐标定义
type Point struct {
    X float64 `json:"x"`
    Y float64 `json:"y"`
}
 
// @Security ApiKeyAuth
// @Summary 保存摄像机多边形
// @Description  保存摄像机多边形
// @Accept json
// @Produce json
// @Tags 摄像机多边形
// @Param  cameraPolygon body controllers.CameraPolygonVo 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/polygon/save [post]
func (controller CameraPolygonController) Save(c *gin.Context) {
    paramBody := make(map[string]interface{},0)
    c.BindJSON(&paramBody)
    var api dbapi.CameraApi
    flag, data := api.SaveCameraPolygon(paramBody)
    if flag {
        util.ResponseFormat(c,code.Success,data)
        return
    }
    util.ResponseFormat(c,code.ComError,"保存失败")
}
 
// @Security ApiKeyAuth
// @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/polygon/delete [get]
func (controller CameraPolygonController) Delete(c *gin.Context) {
    id := c.Query("id")
    if id == "" {
        util.ResponseFormat(c,code.RequestParamError,"id不能为空")
        return
    }
 
    var api dbapi.CameraApi
    flag, data := api.DeleteCameraPolygon(id)
    if flag {
        util.ResponseFormat(c,code.Success,data)
        return
    }
    util.ResponseFormat(c,code.ComError,"删除")
}
 
// @Security ApiKeyAuth
// @Summary 查找摄像机区域
// @Description 查找摄像机区域
// @Produce json
// @Tags 摄像机多边形
// @Param  cameraId query string  true "cameraId"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/polygon/findByCameraId [get]
func (controller CameraPolygonController) FindByCameraId(c *gin.Context) {
    cameraId := c.Query("cameraId")
    if cameraId == "" {
        util.ResponseFormat(c,code.RequestParamError,"cameraId不能为空")
        return
    }
    var api dbapi.CameraApi
    flag, data := api.FindPolygonsByCameraId(cameraId)
    if flag {
        util.ResponseFormat(c,code.Success,data)
        return
    }
    util.ResponseFormat(c,code.ComError, data)
}
 
func (controller CameraPolygonController)UpdateDefenceStateByPolygonId(c *gin.Context) {
    polygonId := c.Query("polygonId")//多边形id
    defenceState := c.Query("defence_state")//布撤防状态
    if polygonId=="" || defenceState == ""{
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    var api dbapi.CameraApi
    flag,data := api.UpdateDefenceStateByPolygonId(polygonId, defenceState)
    if flag {
        util.ResponseFormat(c,code.Success,data)
    } else {
        util.ResponseFormat(c,code.ComError,"更新失败")
    }
}
 
func (controller CameraPolygonController)UpdateDefenceStateByCameraId(c *gin.Context) {
    cameraId := c.Query("cameraId")//多边形id
    defenceState := c.Query("defence_state")//布撤防状态
    if cameraId=="" || defenceState == ""{
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    var api dbapi.CameraApi
    flag,data := api.UpdateDefenceStateByCameraId(cameraId,defenceState)
    if flag {
        util.ResponseFormat(c,code.Success,data)
    } else {
        util.ResponseFormat(c,code.ComError,data)
    }
}