添加延迟的成功条数
This commit is contained in:
parent
debd994c17
commit
ec9fbc940b
18
dao/video.go
18
dao/video.go
|
|
@ -71,10 +71,20 @@ func FindVideoListByTime(auth_id int, startTime, endTime string) []Video {
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelayVideo(id, auth_id, day int) {
|
// id 为视频id,auth_id为用户id,day为延长天数,返回修改的行数
|
||||||
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 DelayVideo(id, auth_id, day int) int {
|
||||||
|
res := 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)
|
||||||
|
if res.Error != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int(res.RowsAffected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelayAllVideo(id,day int){
|
// id 为用户id,day为延长天数,返回修改的行数
|
||||||
DB.Debug().Exec("update video set delete_time = date_add(delete_time, interval ? day) where auth_id = ? and isdelete = 0", day, id)
|
func DelayAllVideo(id, day int) int {
|
||||||
|
res := DB.Debug().Exec("update video set delete_time = date_add(delete_time, interval ? day) where auth_id = ? and isdelete = 0", day, id)
|
||||||
|
if res.Error != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int(res.RowsAffected)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,11 +60,11 @@ type VideoDelReq struct {
|
||||||
|
|
||||||
// video延迟视频请求
|
// video延迟视频请求
|
||||||
type delayReq struct {
|
type delayReq struct {
|
||||||
ID int `form:"id"`
|
ID int `form:"id"`
|
||||||
Option string `form:"option"`
|
Option string `form:"option"`
|
||||||
AuthId int `form:"userId"`
|
AuthId int `form:"userId"`
|
||||||
IP string `form:"ip"`
|
IP string `form:"ip"`
|
||||||
Day int `form:"delay"`
|
Day int `form:"delay"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetUpVideoGroup(router *gin.Engine) {
|
func SetUpVideoGroup(router *gin.Engine) {
|
||||||
|
|
@ -102,7 +102,7 @@ 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")
|
user_id, _ := c.Get("id")
|
||||||
if err := c.ShouldBindQuery(&vp_req); err == nil {
|
if err := c.ShouldBindQuery(&vp_req); err == nil {
|
||||||
fmt.Println(vp_req)
|
fmt.Println(vp_req)
|
||||||
video := service.GetVideo(vp_req.ID, int(user_id.(float64)))
|
video := service.GetVideo(vp_req.ID, int(user_id.(float64)))
|
||||||
|
|
@ -161,18 +161,23 @@ func GetVideoList(c *gin.Context) {
|
||||||
func DelayVideo(c *gin.Context) {
|
func DelayVideo(c *gin.Context) {
|
||||||
var delay_req delayReq
|
var delay_req delayReq
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
|
cnt := 0
|
||||||
if err := c.ShouldBind(&delay_req); err == nil {
|
if err := c.ShouldBind(&delay_req); err == nil {
|
||||||
if delay_req.Day > 30 || delay_req.Day<1{
|
if delay_req.Day > 30 || delay_req.Day < 1 {
|
||||||
c.JSON(http.StatusOK, gin.H{"code": 1,"data": "延迟天数过大或过小", "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"code": 1, "data": "延迟天数过大或过小", "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if delay_req.Option =="all"{
|
if delay_req.Option == "all" {
|
||||||
service.DelayAllVideo(int(id.(float64)), delay_req.Day)
|
cnt = service.DelayAllVideo(int(id.(float64)), delay_req.Day)
|
||||||
}
|
}
|
||||||
if delay_req.Option =="one"{
|
if delay_req.Option == "one" {
|
||||||
service.DelayVideo(delay_req.ID, int(id.(float64)), delay_req.Day)
|
cnt = service.DelayVideo(delay_req.ID, int(id.(float64)), delay_req.Day)
|
||||||
|
}
|
||||||
|
if cnt == 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"code": 1, "data": "延迟失败影响数据", "message": "failed,cnt:" + string(cnt)})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"code": 0, "data": "延迟成功,cnt=" + string(cnt), "message": "success cnt:" + string(cnt)})
|
||||||
}
|
}
|
||||||
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"})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
"videoplayer/dao"
|
"videoplayer/dao"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetVideo(id, auth_id int) dao.Video {
|
func GetVideo(id, auth_id int) dao.Video {
|
||||||
|
|
@ -19,14 +19,14 @@ func GetVideoList(auth_id int, start, end string) []dao.Video {
|
||||||
return dao.FindVideoListsByAuthID(auth_id)
|
return dao.FindVideoListsByAuthID(auth_id)
|
||||||
} else {
|
} else {
|
||||||
s, err := time.Parse("2006/1/02 15:04:05", start)
|
s, err := time.Parse("2006/1/02 15:04:05", start)
|
||||||
if err != nil{
|
if err != nil {
|
||||||
s, err =time.Parse("2006/01/02 15:04:05", start)
|
s, err = time.Parse("2006/01/02 15:04:05", start)
|
||||||
}
|
}
|
||||||
e, err2 := time.Parse("2006/1/02 15:04:05", end)
|
e, err2 := time.Parse("2006/1/02 15:04:05", end)
|
||||||
if err2 != nil{
|
if err2 != nil {
|
||||||
e, err2 =time.Parse("2006/01/02 15:04:05", end)
|
e, err2 = time.Parse("2006/01/02 15:04:05", end)
|
||||||
}
|
}
|
||||||
if s.After(e) || err !=nil || err2 != nil {
|
if s.After(e) || err != nil || err2 != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
fmt.Println(err2)
|
fmt.Println(err2)
|
||||||
return []dao.Video{}
|
return []dao.Video{}
|
||||||
|
|
@ -35,11 +35,11 @@ func GetVideoList(auth_id int, start, end string) []dao.Video {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelayVideo(id, auth_id, day int) {
|
func DelayVideo(id, auth_id, day int) int {
|
||||||
dao.DelayVideo(id, auth_id, day)
|
return dao.DelayVideo(id, auth_id, day)
|
||||||
}
|
}
|
||||||
func DelayAllVideo(id,day int){
|
func DelayAllVideo(id, day int) int {
|
||||||
dao.DelayAllVideo(id,day)
|
return 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 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue