完成视频调试,创建
This commit is contained in:
parent
14a0863bdf
commit
6ab89f4369
|
|
@ -8,7 +8,7 @@ import (
|
||||||
var DB *gorm.DB
|
var DB *gorm.DB
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
dsn := "video:dLPmjweadG625DtH@tcp(114.115.206.93:3306)/video?charset=utf8mb4&parseTime=True&loc=Local"
|
dsn := "video_t:SDssrzALGiidPcjE@tcp(127.0.0.1:3306)/video_t?charset=utf8mb4&parseTime=True&loc=Local"
|
||||||
|
|
||||||
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
|
|
@ -14,14 +14,13 @@ type Device struct {
|
||||||
DeviceLocation string `gorm:"column:device_location"`
|
DeviceLocation string `gorm:"column:device_location"`
|
||||||
DeviceIP string `gorm:"column:device_ip"`
|
DeviceIP string `gorm:"column:device_ip"`
|
||||||
DeviceInfo string `gorm:"column:device_info"`
|
DeviceInfo string `gorm:"column:device_info"`
|
||||||
CreatedAt time.Time
|
|
||||||
UpdatedAt time.Time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateDevice(authID int, deviceName, deviceType string, deviceStatus, deviceLocation, deviceIP, deviceInfo string) uint {
|
func CreateDevice(authID int, deviceName, deviceType string, deviceStatus, deviceLocation, deviceIP, deviceInfo string) uint {
|
||||||
device := Device{AuthID: authID, DeviceName: deviceName, DeviceType: deviceType, DeviceStatus: deviceStatus, DeviceLocation: deviceLocation, DeviceIP: deviceIP, DeviceInfo: deviceInfo}
|
device := Device{AuthID: authID, DeviceName: deviceName, DeviceType: deviceType, DeviceStatus: deviceStatus, DeviceLocation: deviceLocation, DeviceIP: deviceIP, DeviceInfo: deviceInfo}
|
||||||
result := DB.Debug().Create(&device)
|
result := DB.Debug().Create(&device)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
|
fmt.Println("CreateDevice failed", result.Error)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return device.ID
|
return device.ID
|
||||||
|
|
|
||||||
|
|
@ -1 +1,5 @@
|
||||||
package dao
|
package dao
|
||||||
|
|
||||||
|
type Logger struct {
|
||||||
|
ID uint `gorm:"primarykey"`
|
||||||
|
}
|
||||||
|
|
|
||||||
16
dao/video.go
16
dao/video.go
|
|
@ -1,9 +1,12 @@
|
||||||
package dao
|
package dao
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type Video struct {
|
type Video struct {
|
||||||
ID int `gorm:"primaryKey column:id"`
|
gorm.Model
|
||||||
CameraID int `gorm:"column:camera_id"`
|
CameraID int `gorm:"column:camera_id"`
|
||||||
VideoPath string `gorm:"column:video_path"`
|
VideoPath string `gorm:"column:video_path"`
|
||||||
VideoName string `gorm:"column:video_name"`
|
VideoName string `gorm:"column:video_name"`
|
||||||
|
|
@ -16,15 +19,18 @@ type Video struct {
|
||||||
FileSize int `gorm:"column:file_size"`
|
FileSize int `gorm:"column:file_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateVideo(videoPath, videoName string, authID, human, isDelete int, createTime, endTime string, fileSize int) int {
|
func CreateVideo(videoPath, videoName string, authID, human, isDelete int, createTime, endTime string, fileSize int) uint {
|
||||||
video := Video{VideoPath: videoPath, VideoName: videoName, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, FileSize: fileSize}
|
video := Video{VideoPath: videoPath, VideoName: videoName, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, FileSize: fileSize}
|
||||||
DB.Create(&video)
|
res := DB.Debug().Create(&video)
|
||||||
|
if res.Error != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
return video.ID
|
return video.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteVideoByID(id, user int) int {
|
func DeleteVideoByID(id, user int) int {
|
||||||
delete_time := time.Now().Format("2006-01-02 15:04:05")
|
delete_time := time.Now().Format("2006-01-02 15:04:05")
|
||||||
DB.Updates(&Video{IsDelete: 1, DeleteTime: delete_time}).Where("id = ? and auth_id = ?", id, user)
|
DB.Debug().Where("id = ? and auth_id = ?", id, user).Delete(&Video{DeleteTime: delete_time, IsDelete: 1})
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,10 @@ type videoPReq struct {
|
||||||
IP string `json:"ip"`
|
IP string `json:"ip"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type VideoDelReq struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
// video延迟视频请求
|
// video延迟视频请求
|
||||||
type delayReq struct {
|
type delayReq struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
|
|
@ -85,8 +89,13 @@ func GetVideo(c *gin.Context) {
|
||||||
}
|
}
|
||||||
func CreateVideo(c *gin.Context) {
|
func CreateVideo(c *gin.Context) {
|
||||||
var video_req videoReq
|
var video_req videoReq
|
||||||
|
user_id, _ := c.Get("id")
|
||||||
if err := c.ShouldBindJSON(&video_req); err == nil {
|
if err := c.ShouldBindJSON(&video_req); err == nil {
|
||||||
id := service.CreateVideo(video_req.VideoPath, video_req.VideoName, video_req.AuthId, video_req.Human, video_req.IsDelete, video_req.CreateTime, video_req.EndTime, video_req.FileSize)
|
id := service.CreateVideo(video_req.VideoPath, video_req.VideoName, int(user_id.(float64)), video_req.Human, video_req.IsDelete, video_req.CreateTime, video_req.EndTime, video_req.FileSize)
|
||||||
|
if id == 0 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "create video failed", "code": 1, "message": "failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{"id": id, "code": 0, "message": "success"})
|
c.JSON(http.StatusOK, gin.H{"id": id, "code": 0, "message": "success"})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "code": 1, "message": "failed"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "code": 1, "message": "failed"})
|
||||||
|
|
@ -116,7 +125,7 @@ func DelayVideo(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteVideo(c *gin.Context) {
|
func DeleteVideo(c *gin.Context) {
|
||||||
var video_req videoPReq
|
var video_req VideoDelReq
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
if err := c.ShouldBindJSON(&video_req); err == nil {
|
if err := c.ShouldBindJSON(&video_req); err == nil {
|
||||||
service.DeleteVideo(video_req.ID, int(id.(float64)))
|
service.DeleteVideo(video_req.ID, int(id.(float64)))
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -20,7 +20,7 @@ func main() {
|
||||||
handler.SetUpVideoGroup(r)
|
handler.SetUpVideoGroup(r)
|
||||||
handler.SetUpUserGroup(r)
|
handler.SetUpUserGroup(r)
|
||||||
handler.SetUpDeviceGroup(r)
|
handler.SetUpDeviceGroup(r)
|
||||||
r.Run(":8082") // listen and serve on 0.0.0.0:8082
|
r.Run(":8083") // listen and serve on 0.0.0.0:8082
|
||||||
defer dao.Close()
|
defer dao.Close()
|
||||||
defer worker.CloseRedis()
|
defer worker.CloseRedis()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,13 @@ func GetVideoList(auth_id int, start, end string) []dao.Video {
|
||||||
}
|
}
|
||||||
return dao.FindVideoListByTime(auth_id, start, end)
|
return dao.FindVideoListByTime(auth_id, start, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelayVideo(id, auth_id, day int) {
|
func DelayVideo(id, auth_id, day int) {
|
||||||
dao.DelayVideo(id, auth_id, day)
|
dao.DelayVideo(id, auth_id, day)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateVideo(videoPath, videoName string, authID, human, isDelete int, createTime, endTime string, fileSize int) int {
|
func CreateVideo(videoPath, videoName string, authID, human, isDelete int, createTime, endTime string, fileSize int) uint {
|
||||||
return dao.CreateVideo(videoPath, videoName, authID, human, isDelete, createTime, endTime, fileSize)
|
return dao.CreateVideo(videoPath, videoName, authID, human, isDelete, createTime, endTime, fileSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ func InitRedis() {
|
||||||
// 连接redis
|
// 连接redis
|
||||||
redisClient = redis.NewClient(&redis.Options{
|
redisClient = redis.NewClient(&redis.Options{
|
||||||
Addr: "127.0.0.1:6379", // Redis 服务器地址
|
Addr: "127.0.0.1:6379", // Redis 服务器地址
|
||||||
Password: "", // 如果 Redis 设置了密码
|
Password: "lj502138", // 如果 Redis 设置了密码
|
||||||
DB: 0, // 使用的数据库编号
|
DB: 2, // 使用的数据库编号
|
||||||
})
|
})
|
||||||
|
|
||||||
// 验证 Redis 客户端是否可以正常工作
|
// 验证 Redis 客户端是否可以正常工作
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue