sunty
2020-08-20 9303b69ea569bcb5e581147543a3fd58e90d0d25
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
package controllers
 
import (
    "basic.com/dbapi.git"
    "webserver/extend/code"
    "webserver/extend/util"
    "fmt"
    "github.com/gin-gonic/gin"
)
 
 
type CameraTimeruleController struct {
 
}
 
type CameraTimeruleVo struct {
    Id string `json:"id"`
    Name string `json:"name"`
    TimeRule []DayCtlVo `json:"time_rule"`
}
 
type DayCtlVo struct {
    Day       int `json:"day"`
    TimeRange []TimeRangeVo `json:"time_range"`
}
 
//TimeRange 每天的时间段
type TimeRangeVo struct {
    Start string `json:"start"`//开始
    End   string `json:"end"`//结束
}
 
// @Security ApiKeyAuth
// @Summary 时间规则保存
// @Description 时间规则保存
// @Accept json
// @Produce json
// @Tags CameraTimerule
// @Param  cameraTimerule body controllers.CameraTimeruleVo  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/cameraTimerule/save [post]
func (controller CameraTimeruleController) Save(c *gin.Context) {
    var vo CameraTimeruleVo
    err := c.BindJSON(&vo)
    if err !=nil {
        fmt.Println(err)
        util.ResponseFormat(c,code.RequestParamError,"规则参数有误")
        return
    }
    paramBody := make(map[string]interface{})
    paramBody["id"] = vo.Id
    paramBody["name"] = vo.Name
    paramBody["time_rule"] = vo.TimeRule
 
    var api dbapi.CameraApi
    flag, data := api.SaveCameraTimerule(paramBody)
    if flag {
        util.ResponseFormat(c,code.Success,data)
        return
    }
 
    util.ResponseFormat(c,code.ComError,"保存失败")
}
 
// @Security ApiKeyAuth
// @Summary 删除时间规则
// @Description 删除时间规则
// @Produce json
// @Tags CameraTimerule
// @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/cameraTimerule/delete [get]
func (controller CameraTimeruleController) Delete(c *gin.Context) {
    id := c.Query("id")
    if id == "" {
        util.ResponseFormat(c,code.RequestParamError,"id不能为空")
        return
    }
    var api dbapi.CameraApi
    if api.DeleteCameraTimerule(id){
        util.ResponseFormat(c,code.Success,"删除成功")
        return
    }
    util.ResponseFormat(c, code.ComError, "删除失败")
}
 
// @Security ApiKeyAuth
// @Summary 查找所有时间规则
// @Description 查找所有时间规则
// @Accept json
// @Produce json
// @Tags CameraTimerule
// @Success 200 {string} json "{"code":200, success:true, msg:"请求处理成功", data:"成功信息"}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:"错误信息内容"}"
// @Router /data/api-v/cameraTimerule/findAll [get]
func (controller CameraTimeruleController) FindAll(c *gin.Context) {
    var api dbapi.CameraApi
    result, data := api.FindAllTimeRules()
    if result {
        util.ResponseFormat(c,code.Success,data)
        return
    }
 
    util.ResponseFormat(c,code.ComError, "获取失败")
 
}