123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- // 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)
- }
|