123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- package app
- import (
- "context"
- "fmt"
- "github.com/flipped-aurora/gin-vue-admin/server/global"
- "github.com/gin-gonic/gin"
- "github.com/redis/go-redis/v9"
- "github.com/sirupsen/logrus"
- "go.uber.org/zap"
- "lc-fangdaosha/model/app"
- "lc-fangdaosha/model/common/request"
- "lc-fangdaosha/model/common/response"
- "lc-fangdaosha/service"
- "net/http"
- "strings"
- )
- type CameraApi struct {
- }
- var cameraService = service.ServiceGroupApp.AppServiceGroup.CameraService
- // CreateCamera 创建摄像机
- // @Tags Camera
- // @Summary 创建摄像机
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body app.Camera true "创建摄像机"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
- // @Router /camera/createCamera [post]
- func (cameraApi *CameraApi) CreateCamera(c *gin.Context) {
- var camera app.Camera
- err := c.ShouldBindJSON(&camera)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err := cameraService.CreateCamera(&camera); err != nil {
- global.GVA_LOG.Error("创建失败!", zap.Error(err))
- response.FailWithMessage("创建失败", c)
- } else {
- response.OkWithMessage("创建成功", c)
- }
- }
- // DeleteCamera 删除摄像机
- // @Tags Camera
- // @Summary 删除摄像机
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body app.Camera true "删除摄像机"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
- // @Router /camera/deleteCamera [delete]
- func (cameraApi *CameraApi) DeleteCamera(c *gin.Context) {
- var camera app.Camera
- err := c.ShouldBindJSON(&camera)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err := cameraService.DeleteCamera(camera); err != nil {
- global.GVA_LOG.Error("删除失败!", zap.Error(err))
- response.FailWithMessage("删除失败", c)
- } else {
- response.OkWithMessage("删除成功", c)
- }
- }
- // DeleteCameraByIds 批量删除摄像机
- // @Tags Camera
- // @Summary 批量删除摄像机
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.IdsReq true "批量删除摄像机"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
- // @Router /camera/deleteCameraByIds [delete]
- func (cameraApi *CameraApi) DeleteCameraByIds(c *gin.Context) {
- var IDS request.IdsReq
- err := c.ShouldBindJSON(&IDS)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err := cameraService.DeleteCameraByIds(IDS); err != nil {
- global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
- response.FailWithMessage("批量删除失败", c)
- } else {
- response.OkWithMessage("批量删除成功", c)
- }
- }
- // UpdateCamera 更新摄像机
- // @Tags Camera
- // @Summary 更新摄像机
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body app.Camera true "更新摄像机"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
- // @Router /camera/updateCamera [put]
- func (cameraApi *CameraApi) UpdateCamera(c *gin.Context) {
- var camera app.Camera
- err := c.ShouldBindJSON(&camera)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err := cameraService.UpdateCamera(camera); err != nil {
- global.GVA_LOG.Error("更新失败!", zap.Error(err))
- response.FailWithMessage("更新失败", c)
- } else {
- response.OkWithMessage("更新成功", c)
- }
- }
- // FindCamera 用id查询摄像机
- // @Tags Camera
- // @Summary 用id查询摄像机
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data query app.Camera true "用id查询摄像机"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
- // @Router /camera/findCamera [get]
- func (cameraApi *CameraApi) FindCamera(c *gin.Context) {
- var camera app.Camera
- err := c.ShouldBindQuery(&camera)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if recamera, err := cameraService.GetCamera(camera.ID); err != nil {
- global.GVA_LOG.Error("查询失败!", zap.Error(err))
- response.FailWithMessage("查询失败", c)
- } else {
- response.OkWithData(gin.H{"recamera": recamera}, c)
- }
- }
- // Status 获取摄像机的状态
- func (cameraApi *CameraApi) Status(c *gin.Context) {
- topic := c.GetHeader("topic")
- topics := strings.Split(topic, "/")
- if len(topics) != 2 {
- logrus.Error("前端http header : topic数据不对", zap.String("topic", topic))
- response.FailWithMessage("topic头数据不对", c)
- }
- get, err := global.GVA_REDIS.Get(context.Background(), fmt.Sprintf("lcfns:status:%s:%s", topics[0], topics[1])).Result()
- if err == redis.Nil {
- //-1边缘端不在线
- response.OkWithData(-1, c)
- }
- if err != nil {
- response.FailWithMessage("redis 查询失败", c)
- }
- //摄像头:1在线,0不在线
- response.OkWithData(get, c)
- }
- // RewindText 获取回话数据
- func (cameraApi *CameraApi) RewindText(ctx *gin.Context) {
- streamId := ctx.Query("streamId")
- date := ctx.Query("date")
- operate, err := cameraService.GetRewindText(streamId, date)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- }
- if operate == "" {
- ctx.JSON(http.StatusOK, nil)
- return
- }
- response.OkWithData(operate, ctx)
- }
|