// Copyright 2019 github.com. All rights reserved. // Use of this source code is governed by github.com. package v1 import ( "net/http" "smart-site-management-gateway/errors" param_v1 "smart-site-management-gateway/param/v1" "smart-site-management-gateway/pb" "smart-site-management-gateway/pb/v1" "smart-site-management-gateway/utils" "github.com/gin-gonic/gin" "github.com/jaryhe/gopkgs/logger" "github.com/jaryhe/gopkgs/tasker/httptasker" "github.com/jaryhe/gopkgs/util" "go.uber.org/zap" ) // // @Summary 设备绑定摄像头 // @Description 设备绑定摄像头 // @Tags 摄像头后台设置 // @Accept json // @Produce json // @Param token header string true " " // @Param body body v1.DeviceBindCameraBody false " " // @Success 200 {object} v1.DeviceBindCameraResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/camera/bind_device [put] func (c *Controller) DeviceBindCamera(ctx *gin.Context) { // 解析参数 req := ¶m_v1.DeviceBindCameraRequest{} var loginUid int64 var userName string parseParamTask := func() error { err := util.ShouldBind(ctx, nil, nil, nil, &req.DeviceBindCameraBody) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } loginUid, userName, err = utils.GetJwtIdFromCtx(ctx) return nil } // 业务处理 var pid int64 handleServiceTask := func() error { _, projectId, err := utils.GetSubjectValue(ctx) if err != nil { return err } pid = projectId // 响应数据 resp := param_v1.DeviceBindCameraResponse{} rpcReq := &v1.DeviceBindCameraRequest{ DeviceId:req.DeviceId, ChannelId:req.ChannelId, } _, err = pb.Project.DeviceBindCamera(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Project.DeviceBindCamera"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 err := httptasker.Exec(ctx, parseParamTask, handleServiceTask) s, _ := json.MarshalToString(req) utils.LogWrite("设备绑定摄像头", loginUid, userName, s, err, pid) } // // @Summary 设备解绑摄像头 // @Description 设备解绑摄像头 // @Tags 摄像头后台设置 // @Accept json // @Produce json // @Param token header string true " " // @Param body body v1.DeviceUnbindCameraBody false " " // @Success 200 {object} v1.DeviceUnbindCameraResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/camera/unbind_device [put] func (c *Controller) DeviceUnbindCamera(ctx *gin.Context) { // 解析参数 req := ¶m_v1.DeviceUnbindCameraRequest{} var loginUid int64 var userName string parseParamTask := func() error { err := util.ShouldBind(ctx, nil, nil, nil, &req.DeviceUnbindCameraBody) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } loginUid, userName, err = utils.GetJwtIdFromCtx(ctx) return nil } // 业务处理 var pid int64 handleServiceTask := func() error { _, projectId, err := utils.GetSubjectValue(ctx) if err != nil { return err } pid = projectId // 响应数据 resp := param_v1.DeviceUnbindCameraResponse{} rpcReq := &v1.DeviceUnbindCameraRequest{ DeviceId:req.DeviceId, ChannelId:req.ChannelId, } _, err = pb.Project.DeviceUnbindCamera(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Project.DeviceUnbindCamera"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 err := httptasker.Exec(ctx, parseParamTask, handleServiceTask) s, _ := json.MarshalToString(req) utils.LogWrite("设备解绑摄像头", loginUid, userName, s, err, pid) } // // @Summary 获取实时播放地址 // @Description 获取实时播放地址 // @Tags // @Accept json // @Produce json // @Param token header string true " " // @Param channel_no query string true " " // @Success 200 {object} v1.RealPlayResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/camera/real_play [get] func (c *Controller) RealPlay(ctx *gin.Context) { // 解析参数 req := ¶m_v1.RealPlayRequest{} var loginUid int64 var userName string parseParamTask := func() error { err := util.ShouldBind(ctx, nil, nil, &req.RealPlayQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } loginUid, userName, err = utils.GetJwtIdFromCtx(ctx) return nil } // 业务处理 handleServiceTask := func() error { // 响应数据 resp := param_v1.RealPlayResponse{} rpcReq := &v1.RealPlayRequest{ ChannelNo:req.ChannelNo, } rpcRsp, err := pb.Project.RealPlay(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Project.RealPlay"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary ptz控制 // @Description ptz控制 // @Tags // @Accept json // @Produce json // @Param token header string true " " // @Param channel_no query string true " " // @Param ptz_type query string true " 上:up,下:down,左:left,右:right,左上:leftup,左下:leftdown,右上:rightup,右下:rightdown,镜头近:zoomin,镜头远:zoomout, 焦距远:focusfar,焦距近:focusnear, 设置预置位:setpos,调预置位:callpos,调预置位:delpos,停止:stop" // @Param ptz_param query int true "速度范围为1-255 " // @Success 200 {object} v1.PtzResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/camera/ptz [get] func (c *Controller) Ptz(ctx *gin.Context) { // 解析参数 req := ¶m_v1.PtzRequest{} var loginUid int64 var userName string parseParamTask := func() error { err := util.ShouldBind(ctx, nil, nil, &req.PtzQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } loginUid, userName, err = utils.GetJwtIdFromCtx(ctx) return nil } // 业务处理 handleServiceTask := func() error { // 响应数据 resp := param_v1.PtzResponse{} rpcReq := &v1.PtzRequest{ ChannelNo:req.ChannelNo, Ptzparam:req.PtzParam, Ptztype:req.PtzType, } _, err := pb.Project.Ptz(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Project.Ptz"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 摄像头ping // @Description 摄像头ping // @Tags camera // @Accept json // @Produce json // @Param session_id query string true " " // @Success 200 {object} v1.VedioPingResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/camera/ping [get] func (c *Controller) VedioPing(ctx *gin.Context) { // 解析参数 req := ¶m_v1.VedioPingRequest{} var loginUid int64 var userName string parseParamTask := func() error { err := util.ShouldBind(ctx, nil, nil, &req.VedioPingQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } loginUid, userName, err = utils.GetJwtIdFromCtx(ctx) return nil } // 业务处理 handleServiceTask := func() error { // 响应数据 resp := param_v1.VedioPingResponse{} rpcReq := &v1.VedioPingRequest{ Sessionid:req.SessionId, } rpcResp, err := pb.Project.VedioPing(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Project.VedioPing"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } resp.Data = *rpcResp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // 编辑通道 // @Summary 编辑通道 // @Description 编辑通道 // @Tags 摄像头后台设置 // @Accept json // @Produce json // @Param token header string true " " // @Param body body v1.ChannelUpdateBody true " " // @Success 200 {object} v1.ChannelUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/device/vedio_channel [put] func (c *Controller) ChannelUpdate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.ChannelUpdateRequest{} var loginUid int64 var userName string parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ChannelUpdateBody) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } loginUid, userName, err = utils.GetJwtIdFromCtx(ctx) return nil } // 业务处理 var projectId int64 handleServiceTask := func() error { // 响应数据 resp := param_v1.ChannelUpdateResponse{} rpcReq := &v1.ChannelUpdateRequest{ Id:req.Id, Name:req.Name, } rpcRsp, err := pb.Project.ChannelUpdate(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "ChannelUpdate"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } projectId = rpcRsp.ProjectId ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 err := httptasker.Exec(ctx, parseParamTask, handleServiceTask) s, _ := json.MarshalToString(req) utils.LogWrite("编辑通道", loginUid, userName, s, err, projectId) }