133 lines
3.6 KiB
Go
133 lines
3.6 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
"videoplayer/dao"
|
|
"videoplayer/proto"
|
|
"videoplayer/worker"
|
|
)
|
|
|
|
func GetVideo(id, auth_id int) dao.Video {
|
|
return dao.FindVideoByID(id, auth_id)
|
|
}
|
|
|
|
func GetWillDelVideoList(id int) []dao.Video {
|
|
return dao.FindWillDelVideoList(id)
|
|
}
|
|
|
|
func GetVideoList(auth_id, id int, start, end, hour string) []dao.Video {
|
|
if id > 0 {
|
|
return []dao.Video{dao.FindVideoByID(id, auth_id)}
|
|
}
|
|
if start == "" {
|
|
return dao.FindVideoListsByAuthID(auth_id)
|
|
} else {
|
|
if hour != "33" {
|
|
ss := strings.Split(start, " ")
|
|
ss1 := strings.Split(ss[1], ":")
|
|
start = ss[0] + " " + hour + ":" + ss1[1] + ":" + ss1[2]
|
|
|
|
es := strings.Split(end, " ")
|
|
es1 := strings.Split(es[1], ":")
|
|
end = es[0] + " " + hour + ":" + es1[1] + ":" + es1[2]
|
|
}
|
|
_, err := time.Parse("2006-01-02 15:04:05", start)
|
|
_, err2 := time.Parse("2006-01-02 15:04:05", end)
|
|
if err != nil || err2 != nil {
|
|
return []dao.Video{}
|
|
}
|
|
return dao.FindVideoListByTime(auth_id, start, end)
|
|
}
|
|
}
|
|
|
|
func DelayVideo(id, auth_id, day int) int {
|
|
return dao.DelayVideo(id, auth_id, day)
|
|
}
|
|
func DelayAllVideo(id, day int) int {
|
|
return dao.DelayAllVideo(id, day)
|
|
}
|
|
|
|
func CreateVideo(videoPath, videoName string, cameraID, authID, human, isDelete int, createTime, endTime, deleteTime string, fileSize int) uint {
|
|
return dao.CreateVideo(videoPath, videoName, cameraID, authID, human, isDelete, createTime, endTime, deleteTime, fileSize)
|
|
}
|
|
|
|
func GetVideoListByPage(auth_id, page, page_size int) []dao.Video {
|
|
if page < 0 {
|
|
page = 0 //默认第一页
|
|
}
|
|
if page_size < 0 || page_size > 100 {
|
|
page_size = 10 //默认每页10条
|
|
}
|
|
return dao.GetVideoListByPage(auth_id, page, page_size)
|
|
}
|
|
|
|
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)
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func QuashVideo(user int, data map[string]interface{}) (int, string) {
|
|
var res int
|
|
var msg string
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
fmt.Println("error:", r)
|
|
}
|
|
}()
|
|
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 {
|
|
res = 0
|
|
msg = "success"
|
|
}
|
|
case "delay":
|
|
if data["option"] == "all" {
|
|
if dao.QuashAllDelay(user, data["delay_day"].(int)) == 0 {
|
|
res = proto.RevokeDelayOperationFailed
|
|
msg = "quash all video delay error"
|
|
} else {
|
|
res = proto.SuccessCode
|
|
msg = "success"
|
|
}
|
|
} else if data["option"] == "one" {
|
|
if dao.QuashOneDelay(int(data["id"].(float64)), user, int(data["delay_day"].(float64))) == 0 {
|
|
res = proto.RevokeDelayOperationFailed
|
|
msg = "quash one video error"
|
|
} else {
|
|
res = proto.SuccessCode
|
|
msg = "success"
|
|
}
|
|
|
|
} else {
|
|
res = proto.RevokeOperationFailed
|
|
msg = "option error,no such delay option"
|
|
}
|
|
default:
|
|
res = proto.RevokeOperationFailed
|
|
msg = "method error,no such method"
|
|
}
|
|
return res, msg
|
|
}
|
|
func UpdateVideo(videoPath, videoName string, cameraID, videoID, authID, human, isDelete int, createTime, endTime string, fileSize int) bool {
|
|
video := GetVideo(videoID, authID)
|
|
if video.ID == 0 {
|
|
return false
|
|
}
|
|
return dao.UpdateVideo(videoPath, videoName, cameraID, videoID, authID, human, isDelete, createTime, endTime, fileSize)
|
|
}
|