修改延迟删除的数据接收及处理
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) {
|
||||
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获取视频列表请求
|
||||
type gvlReq struct {
|
||||
StartTime string `json:"begin"`
|
||||
EndTime string `json:"end"`
|
||||
IP string `json:"ip"`
|
||||
Token string `json:"token"`
|
||||
StartTime string `json:"begin" form:"begin"`
|
||||
EndTime string `json:"end" form:"end"`
|
||||
IP string `json:"ip" form:"ip"`
|
||||
Token string `json:"token" form:"token"`
|
||||
Hour string `json:"hour" form:"hour"`
|
||||
}
|
||||
|
||||
// video添加视频记录请求
|
||||
|
|
@ -47,10 +48,10 @@ type videoUpdateReq struct {
|
|||
|
||||
// video播放视频请求
|
||||
type videoPReq struct {
|
||||
ID int `json:"id"`
|
||||
Token string `json:"token"`
|
||||
AuthId string `json:"userId"`
|
||||
IP string `json:"ip"`
|
||||
ID int `form:"id"`
|
||||
Token string `form:"token"`
|
||||
AuthId string `form:"userId"`
|
||||
IP string `form:"ip"`
|
||||
}
|
||||
|
||||
type VideoDelReq struct {
|
||||
|
|
@ -59,9 +60,11 @@ type VideoDelReq struct {
|
|||
|
||||
// video延迟视频请求
|
||||
type delayReq struct {
|
||||
ID int `json:"id"`
|
||||
AuthId int `json:"userId"`
|
||||
Day int `json:"day"`
|
||||
ID int `form:"id"`
|
||||
Option string `form:"option"`
|
||||
AuthId int `form:"userId"`
|
||||
IP string `form:"ip"`
|
||||
Day int `form:"delay"`
|
||||
}
|
||||
|
||||
func SetUpVideoGroup(router *gin.Engine) {
|
||||
|
|
@ -99,8 +102,10 @@ func UpdateVideo(c *gin.Context) {
|
|||
|
||||
func GetVideo(c *gin.Context) {
|
||||
var vp_req videoPReq
|
||||
user_id,_:=c.Get("id")
|
||||
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
|
||||
path := video.VideoPath
|
||||
if video.IsDelete == 0 {
|
||||
|
|
@ -157,7 +162,16 @@ func DelayVideo(c *gin.Context) {
|
|||
var delay_req delayReq
|
||||
id, _ := c.Get("id")
|
||||
if err := c.ShouldBind(&delay_req); err == nil {
|
||||
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"})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": 1, "message": "failed"})
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package service
|
|||
import (
|
||||
"time"
|
||||
"videoplayer/dao"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func GetVideo(id, auth_id int) dao.Video {
|
||||
|
|
@ -17,18 +18,29 @@ func GetVideoList(auth_id int, start, end string) []dao.Video {
|
|||
if start == "" {
|
||||
return dao.FindVideoListsByAuthID(auth_id)
|
||||
} else {
|
||||
s, _ := time.Parse("2006-01-02 15:04:05", start)
|
||||
e, _ := time.Parse("2006-01-02 15:04:05", end)
|
||||
if s.After(e) {
|
||||
s, err := time.Parse("2006/1/02 15:04:05", start)
|
||||
if err != nil{
|
||||
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.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) {
|
||||
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 {
|
||||
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