videoplayer/dao/video.go

58 lines
1.9 KiB
Go
Raw Normal View History

package dao
2024-05-20 17:30:39 +08:00
import (
"gorm.io/gorm"
"time"
)
type Video struct {
2024-05-20 17:30:39 +08:00
gorm.Model
CameraID int `gorm:"column:camera_id"`
VideoPath string `gorm:"column:video_path"`
VideoName string `gorm:"column:video_name"`
AuthId int `gorm:"column:auth_id"`
Human int `gorm:"column:human"`
IsDelete int `gorm:"column:isdelete"`
CreateTime string `gorm:"column:create_time"`
EndTime string `gorm:"column:end_time"`
DeleteTime string `gorm:"column:delete_time"`
FileSize int `gorm:"column:file_size"`
}
func CreateVideo(videoPath, videoName string, cameraID, authID, human, isDelete int, createTime, endTime string, fileSize int) uint {
video := Video{VideoPath: videoPath, VideoName: videoName, CameraID: cameraID, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, FileSize: fileSize}
2024-05-20 17:30:39 +08:00
res := DB.Debug().Create(&video)
if res.Error != nil {
return 0
}
return video.ID
}
func DeleteVideoByID(id, user int) int {
delete_time := time.Now().Format("2006-01-02 15:04:05")
2024-05-20 17:30:39 +08:00
DB.Debug().Where("id = ? and auth_id = ?", id, user).Delete(&Video{DeleteTime: delete_time, IsDelete: 1})
return id
}
func FindVideoByID(id, auth_id int) Video {
var video Video
DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).Where("isdelete = ?", 0).First(&video)
return video
}
func FindVideoListsByAuthID(auth_id int) []Video {
var videos []Video
DB.Debug().Where("auth_id = ?", auth_id).Where("isdelete = ?", 0).Limit(30).Find(&videos)
return videos
}
func FindVideoListByTime(auth_id int, startTime, endTime string) []Video {
var videos []Video
DB.Debug().Where("auth_id = ?", auth_id).Where("isdelete=0").Where("create_time > ? and create_time < ?", startTime, endTime).Find(&videos)
return videos
}
func DelayVideo(id, auth_id, day int) {
DB.Exec("update video set end_time = date_add(end_time, interval ? day) where id = ? and auth_id = ?", day, id, auth_id)
}