videoplayer/dao/video.go

48 lines
1.6 KiB
Go

package dao
import "time"
type Video struct {
ID int `gorm:"primaryKey column:id"`
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:is_delete"`
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, authID, human, isDelete int, createTime, endTime string, fileSize int) int {
video := Video{VideoPath: videoPath, VideoName: videoName, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, FileSize: fileSize}
DB.Create(&video)
return video.ID
}
func DeleteVideoByID(id int) int {
delete_time := time.Now().Format("2006-01-02 15:04:05")
DB.Updates(&Video{IsDelete: 1, DeleteTime: delete_time}).Where("id = ?", id)
return id
}
func FindVideoByID(id, auth_id int) Video {
var video Video
DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).First(&video)
return video
}
func FindVideoListsByAuthID(auth_id int) []Video {
var videos []Video
DB.Debug().Where("auth_id = ?", auth_id).Where("is_delete=0").Find(&videos).Limit(30)
return videos
}
func FindVideoListByTime(auth_id int, startTime, endTime string) []Video {
var videos []Video
DB.Debug().Where("auth_id = ?", auth_id).Where("is_delete=0").Where("create_time > ? and create_time < ?", startTime, endTime).Find(&videos)
return videos
}