Merge branch 'refs/heads/feat-video'

This commit is contained in:
junleea 2024-12-17 18:31:49 +08:00
commit 39cb9bc91f
3 changed files with 27 additions and 8 deletions

View File

@ -57,6 +57,16 @@ func LogicDeleteVideoByID(id, user int) int {
return id
}
// 回滚视频输出-逻辑删除,若文件已删除则不可回滚
func RollbackVideoByID(id, user int) int {
res := DB.Exec("update videos set deleted_at=null where id=? and auth_id=? and isdelete=0", id, user) //isdelete=0说明文件未删除
if res.Error != nil {
fmt.Println("dao RollbackVideoByID:", res.Error)
return 0
}
return id
}
func UpdateVideo(videoPath, videoName string, cameraID, videoID, authID, human, isDelete int, createTime, endTime string, fileSize int) bool {
res := DB.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 {

View File

@ -205,13 +205,9 @@ func DelayVideo(c *gin.Context) {
func DeleteVideo(c *gin.Context) {
var video_req VideoDelReq
id, _ := c.Get("id")
user, _ := c.Get("username")
if err := c.ShouldBind(&video_req); err == nil {
res := service.DeleteVideo(video_req.ID, int(id.(float64)), video_req.Type)
if res != 0 {
data := map[string]interface{}{"id": video_req.ID, "auth_id": int(id.(float64)), "delete_time": time.Now().Format("2006-01-02 15:04:05"), "method": "delete"}
str, _ := json.Marshal(data)
worker.PushRedisList(user.(string)+"-"+strconv.Itoa(int(id.(float64)))+"-option", string(str))
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "msg": "success", "data": "delete video success"})
} else {
c.JSON(http.StatusOK, gin.H{"code": proto.ParameterError, "msg": "failed", "data": "delete video failed"})
@ -223,16 +219,16 @@ func DeleteVideo(c *gin.Context) {
func QuashOption(c *gin.Context) {
id, _ := c.Get("id")
user, _ := c.Get("username")
res := worker.PopRedisList(user.(string) + "-" + strconv.Itoa(int(id.(float64))) + "-option")
id1 := int(id.(float64))
res := worker.PopRedisList("user-" + strconv.Itoa(int(id.(float64))) + "-option")
if res != "" {
var retrievedData map[string]interface{}
err2 := json.Unmarshal([]byte(res), &retrievedData)
if err2 == nil {
code, msg := service.QuashVideo(int(id.(float64)), retrievedData)
code, msg := service.QuashVideo(id1, retrievedData)
c.JSON(http.StatusOK, gin.H{"code": code, "message": msg, "data": msg})
} else {
worker.PushRedisList(user.(string)+"-"+strconv.Itoa(int(id.(float64)))+"-option", res) //未操作成功重新添加到队列
worker.PushRedisList("user-"+strconv.Itoa(int(id.(float64)))+"-option", res) //未操作成功重新添加到队列
c.JSON(http.StatusOK, gin.H{"code": proto.ParameterError, "message": err2, "data": "json解析错误"})
return
}

View File

@ -1,11 +1,14 @@
package service
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"videoplayer/dao"
"videoplayer/proto"
"videoplayer/worker"
)
func GetVideo(id, auth_id int) dao.Video {
@ -64,6 +67,9 @@ func GetVideoListByPage(auth_id, page, page_size int) []dao.Video {
func DeleteVideo(id, user int, tp string) int {
if tp == "del_with_logic" {
data := map[string]interface{}{"id": id, "auth_id": user, "delete_time": time.Now().Format("2006-01-02 15:04:05"), "method": "delete"}
str, _ := json.Marshal(data)
worker.PushRedisList("user-"+strconv.Itoa(user)+"-option", string(str))
return dao.LogicDeleteVideoByID(id, user)
} else if tp == "del_with_real" {
return dao.DeleteVideoByID(id, user)
@ -81,6 +87,13 @@ func QuashVideo(user int, data map[string]interface{}) (int, string) {
}()
switch data["method"] {
case "delete":
video_id := int(data["id"].(float64))
res = dao.RollbackVideoByID(video_id, user)
if res == 0 {
msg = strconv.Itoa(video_id) + " rollback video error"
} else {
msg = "success"
}
case "delay":
if data["option"] == "all" {
if dao.QuashAllDelay(user, data["delay_day"].(int)) == 0 {