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"`//结束 } 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,"保存失败") } 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, "删除失败") } 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, "获取失败") }