Files
PandaX/apps/video/api/ys.go
2023-09-14 17:28:52 +08:00

58 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package api
import (
"github.com/PandaXGO/PandaKit/biz"
"github.com/PandaXGO/PandaKit/model"
"github.com/PandaXGO/PandaKit/restfulx"
"pandax/pkg/ys"
)
type YsApi struct {
Ys *ys.Ys
}
func (j *YsApi) GetDeviceList(rc *restfulx.ReqCtx) {
pageNum := restfulx.QueryInt(rc, "pageNum", 1)
pageSize := restfulx.QueryInt(rc, "pageSize", 10)
devices, total, err := j.Ys.GetDeviceList(pageNum, pageSize)
biz.ErrIsNil(err, "设备列表获取失败,可能萤石Token过期请联系管理员。。")
rc.ResData = model.ResultPage{
Total: total,
PageNum: int64(pageNum),
PageSize: int64(pageSize),
Data: devices,
}
}
func (j *YsApi) GetDeviceChannelList(rc *restfulx.ReqCtx) {
deviceSerial := restfulx.PathParam(rc, "deviceSerial")
cameras, err := j.Ys.GetDeviceChannelList(deviceSerial)
biz.ErrIsNilAppendErr(err, "设备通道列表获取失败")
rc.ResData = cameras
}
func (j *YsApi) GetDeviceLiveAddress(rc *restfulx.ReqCtx) {
deviceSerial := restfulx.PathParam(rc, "deviceSerial")
channelNo := restfulx.QueryInt(rc, "channelNo", 1)
live, err := j.Ys.GetDeviceLiveAddress(deviceSerial, channelNo)
biz.ErrIsNilAppendErr(err, "设备直播地址获取失败")
rc.ResData = live
}
func (j *YsApi) StartPtz(rc *restfulx.ReqCtx) {
deviceSerial := restfulx.PathParam(rc, "deviceSerial")
channelNo := restfulx.QueryInt(rc, "channelNo", 1)
direction := restfulx.QueryInt(rc, "direction", 0)
speed := restfulx.QueryInt(rc, "speed", 0)
err := j.Ys.StartPtz(deviceSerial, channelNo, direction, speed)
biz.ErrIsNilAppendErr(err, "操作摄像头失败")
}
func (j *YsApi) StopPtz(rc *restfulx.ReqCtx) {
deviceSerial := restfulx.PathParam(rc, "deviceSerial")
channelNo := restfulx.QueryInt(rc, "channelNo", 1)
direction := restfulx.QueryInt(rc, "direction", 0)
err := j.Ys.StopPtz(deviceSerial, channelNo, direction)
biz.ErrIsNilAppendErr(err, "停止摄像头失败")
}