修改延迟删除的数据接收及处理
This commit is contained in:
parent
710ba85261
commit
debd994c17
|
|
@ -72,5 +72,9 @@ func FindVideoListByTime(auth_id int, startTime, endTime string) []Video {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelayVideo(id, auth_id, day int) {
|
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)
|
DB.Debug().Exec("update video set delete_time = date_add(delete_time, interval ? day) where id = ? and auth_id = ? and isdelete=0", day, id, auth_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DelayAllVideo(id,day int){
|
||||||
|
DB.Debug().Exec("update video set delete_time = date_add(delete_time, interval ? day) where auth_id = ? and isdelete = 0", day, id)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,11 @@ import (
|
||||||
|
|
||||||
// video获取视频列表请求
|
// video获取视频列表请求
|
||||||
type gvlReq struct {
|
type gvlReq struct {
|
||||||
StartTime string `json:"begin"`
|
StartTime string `json:"begin" form:"begin"`
|
||||||
EndTime string `json:"end"`
|
EndTime string `json:"end" form:"end"`
|
||||||
IP string `json:"ip"`
|
IP string `json:"ip" form:"ip"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token" form:"token"`
|
||||||
|
Hour string `json:"hour" form:"hour"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// video添加视频记录请求
|
// video添加视频记录请求
|
||||||
|
|
@ -47,10 +48,10 @@ type videoUpdateReq struct {
|
||||||
|
|
||||||
// video播放视频请求
|
// video播放视频请求
|
||||||
type videoPReq struct {
|
type videoPReq struct {
|
||||||
ID int `json:"id"`
|
ID int `form:"id"`
|
||||||
Token string `json:"token"`
|
Token string `form:"token"`
|
||||||
AuthId string `json:"userId"`
|
AuthId string `form:"userId"`
|
||||||
IP string `json:"ip"`
|
IP string `form:"ip"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VideoDelReq struct {
|
type VideoDelReq struct {
|
||||||
|
|
@ -59,9 +60,11 @@ type VideoDelReq struct {
|
||||||
|
|
||||||
// video延迟视频请求
|
// video延迟视频请求
|
||||||
type delayReq struct {
|
type delayReq struct {
|
||||||
ID int `json:"id"`
|
ID int `form:"id"`
|
||||||
AuthId int `json:"userId"`
|
Option string `form:"option"`
|
||||||
Day int `json:"day"`
|
AuthId int `form:"userId"`
|
||||||
|
IP string `form:"ip"`
|
||||||
|
Day int `form:"delay"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetUpVideoGroup(router *gin.Engine) {
|
func SetUpVideoGroup(router *gin.Engine) {
|
||||||
|
|
@ -99,8 +102,10 @@ func UpdateVideo(c *gin.Context) {
|
||||||
|
|
||||||
func GetVideo(c *gin.Context) {
|
func GetVideo(c *gin.Context) {
|
||||||
var vp_req videoPReq
|
var vp_req videoPReq
|
||||||
|
user_id,_:=c.Get("id")
|
||||||
if err := c.ShouldBindQuery(&vp_req); err == nil {
|
if err := c.ShouldBindQuery(&vp_req); err == nil {
|
||||||
video := service.GetVideo(vp_req.ID, c.GetInt("id"))
|
fmt.Println(vp_req)
|
||||||
|
video := service.GetVideo(vp_req.ID, int(user_id.(float64)))
|
||||||
name := video.VideoName
|
name := video.VideoName
|
||||||
path := video.VideoPath
|
path := video.VideoPath
|
||||||
if video.IsDelete == 0 {
|
if video.IsDelete == 0 {
|
||||||
|
|
@ -157,7 +162,16 @@ func DelayVideo(c *gin.Context) {
|
||||||
var delay_req delayReq
|
var delay_req delayReq
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
if err := c.ShouldBind(&delay_req); err == nil {
|
if err := c.ShouldBind(&delay_req); err == nil {
|
||||||
service.DelayVideo(delay_req.ID, int(id.(float64)), delay_req.Day)
|
if delay_req.Day > 30 || delay_req.Day<1{
|
||||||
|
c.JSON(http.StatusOK, gin.H{"code": 1,"data": "延迟天数过大或过小", "message": "failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if delay_req.Option =="all"{
|
||||||
|
service.DelayAllVideo(int(id.(float64)), delay_req.Day)
|
||||||
|
}
|
||||||
|
if delay_req.Option =="one"{
|
||||||
|
service.DelayVideo(delay_req.ID, int(id.(float64)), delay_req.Day)
|
||||||
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{"code": 0,"data":"延迟成功", "message": "success"})
|
c.JSON(http.StatusOK, gin.H{"code": 0,"data":"延迟成功", "message": "success"})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": 1, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": 1, "message": "failed"})
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package service
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
"videoplayer/dao"
|
"videoplayer/dao"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetVideo(id, auth_id int) dao.Video {
|
func GetVideo(id, auth_id int) dao.Video {
|
||||||
|
|
@ -17,18 +18,29 @@ func GetVideoList(auth_id int, start, end string) []dao.Video {
|
||||||
if start == "" {
|
if start == "" {
|
||||||
return dao.FindVideoListsByAuthID(auth_id)
|
return dao.FindVideoListsByAuthID(auth_id)
|
||||||
} else {
|
} else {
|
||||||
s, _ := time.Parse("2006-01-02 15:04:05", start)
|
s, err := time.Parse("2006/1/02 15:04:05", start)
|
||||||
e, _ := time.Parse("2006-01-02 15:04:05", end)
|
if err != nil{
|
||||||
if s.After(e) {
|
s, err =time.Parse("2006/01/02 15:04:05", start)
|
||||||
|
}
|
||||||
|
e, err2 := time.Parse("2006/1/02 15:04:05", end)
|
||||||
|
if err2 != nil{
|
||||||
|
e, err2 =time.Parse("2006/01/02 15:04:05", end)
|
||||||
|
}
|
||||||
|
if s.After(e) || err !=nil || err2 != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
fmt.Println(err2)
|
||||||
return []dao.Video{}
|
return []dao.Video{}
|
||||||
}
|
}
|
||||||
return dao.FindVideoListByTime(auth_id, start, end)
|
return dao.FindVideoListByTime(auth_id, s.Format("2006-01-02 15:04:05"), e.Format("2006-01-02 15:04:05"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 DelayAllVideo(id,day int){
|
||||||
|
dao.DelayAllVideo(id,day)
|
||||||
|
}
|
||||||
|
|
||||||
func CreateVideo(videoPath, videoName string, cameraID, authID, human, isDelete int, createTime, endTime string, fileSize int) uint {
|
func CreateVideo(videoPath, videoName string, cameraID, authID, human, isDelete int, createTime, endTime string, fileSize int) uint {
|
||||||
return dao.CreateVideo(videoPath, videoName, cameraID, authID, human, isDelete, createTime, endTime, fileSize)
|
return dao.CreateVideo(videoPath, videoName, cameraID, authID, human, isDelete, createTime, endTime, fileSize)
|
||||||
|
|
|
||||||
BIN
videoplayer
BIN
videoplayer
Binary file not shown.
Loading…
Reference in New Issue