2024-05-18 17:12:24 +08:00
|
|
|
package dao
|
|
|
|
|
|
2024-05-20 17:30:39 +08:00
|
|
|
import (
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
2024-05-18 17:12:24 +08:00
|
|
|
|
|
|
|
|
type Video struct {
|
2024-05-20 17:30:39 +08:00
|
|
|
gorm.Model
|
2024-05-18 17:12:24 +08:00
|
|
|
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"`
|
2024-05-18 18:16:34 +08:00
|
|
|
IsDelete int `gorm:"column:isdelete"`
|
2024-05-18 17:12:24 +08:00
|
|
|
CreateTime string `gorm:"column:create_time"`
|
|
|
|
|
EndTime string `gorm:"column:end_time"`
|
|
|
|
|
DeleteTime string `gorm:"column:delete_time"`
|
|
|
|
|
FileSize int `gorm:"column:file_size"`
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-21 11:10:21 +08:00
|
|
|
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
|
|
|
|
|
}
|
2024-05-18 17:12:24 +08:00
|
|
|
return video.ID
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 11:02:55 +08:00
|
|
|
func DeleteVideoByID(id, user int) int {
|
2024-05-18 17:12:24 +08:00
|
|
|
delete_time := time.Now().Format("2006-01-02 15:04:05")
|
2024-05-21 14:57:45 +08:00
|
|
|
DB.Debug().Where("id = ? and auth_id = ?", id, user).Updates(&Video{DeleteTime: delete_time, IsDelete: 1})
|
|
|
|
|
DB.Debug().Where("id = ? and auth_id = ?", id, user).Delete(&Video{})
|
2024-05-18 17:12:24 +08:00
|
|
|
return id
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-21 14:57:45 +08:00
|
|
|
func UpdateVideo(videoPath, videoName string, cameraID, videoID, authID, human, isDelete int, createTime, endTime string, fileSize int) bool {
|
|
|
|
|
res := DB.Debug().Model(&Video{}).Where("id = ? and auth_id = ?", videoID, authID).Updates(Video{VideoPath: videoPath, VideoName: videoName, CameraID: cameraID, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, FileSize: fileSize})
|
|
|
|
|
if res.Error != nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-18 17:12:24 +08:00
|
|
|
func FindVideoByID(id, auth_id int) Video {
|
|
|
|
|
var video Video
|
2024-05-18 18:16:34 +08:00
|
|
|
DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).Where("isdelete = ?", 0).First(&video)
|
2024-05-18 17:12:24 +08:00
|
|
|
return video
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func FindVideoListsByAuthID(auth_id int) []Video {
|
|
|
|
|
var videos []Video
|
2024-05-18 18:16:34 +08:00
|
|
|
DB.Debug().Where("auth_id = ?", auth_id).Where("isdelete = ?", 0).Limit(30).Find(&videos)
|
2024-05-18 17:12:24 +08:00
|
|
|
return videos
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func FindVideoListByTime(auth_id int, startTime, endTime string) []Video {
|
|
|
|
|
var videos []Video
|
2024-05-18 18:16:34 +08:00
|
|
|
DB.Debug().Where("auth_id = ?", auth_id).Where("isdelete=0").Where("create_time > ? and create_time < ?", startTime, endTime).Find(&videos)
|
2024-05-18 17:12:24 +08:00
|
|
|
return videos
|
|
|
|
|
}
|
2024-05-20 11:02:55 +08:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|