修复查询视频时间范围错误

This commit is contained in:
junleea 2024-10-25 18:04:08 +08:00
parent 420d652e6b
commit f17467d451
3 changed files with 6 additions and 24 deletions

View File

@ -15,8 +15,8 @@ import (
// video获取视频列表请求 // video获取视频列表请求
type gvlReq struct { type gvlReq struct {
StartTime string `json:"begin" form:"begin"` StartTime int64 `json:"begin" form:"begin"`
EndTime string `json:"end" form:"end"` EndTime int64 `json:"end" form:"end"`
IP string `json:"ip" form:"ip"` IP string `json:"ip" form:"ip"`
Token string `json:"token" form:"token"` Token string `json:"token" form:"token"`
Hour string `json:"hour" form:"hour"` Hour string `json:"hour" form:"hour"`
@ -157,7 +157,10 @@ func GetVideoList(c *gin.Context) {
gvl_req.Hour = "33" gvl_req.Hour = "33"
id, _ := c.Get("id") id, _ := c.Get("id")
if err := c.ShouldBind(&gvl_req); err == nil { if err := c.ShouldBind(&gvl_req); err == nil {
videos := service.GetVideoList(int(id.(float64)), gvl_req.StartTime, gvl_req.EndTime, gvl_req.Hour) const layout = "2006-01-02 15:04:05"
tm1 := time.Unix(gvl_req.StartTime, 0).Format(layout)
tm2 := time.Unix(gvl_req.EndTime, 0).Format(layout)
videos := service.GetVideoList(int(id.(float64)), tm1, tm2, gvl_req.Hour)
c.JSON(http.StatusOK, gin.H{"data": videos, "code": proto.SuccessCode, "message": "success"}) c.JSON(http.StatusOK, gin.H{"data": videos, "code": proto.SuccessCode, "message": "success"})
} else { } else {
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "message": "failed"}) c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "message": "failed"})

View File

@ -1,7 +1,6 @@
package service package service
import ( import (
"fmt"
"regexp" "regexp"
"videoplayer/dao" "videoplayer/dao"
"videoplayer/proto" "videoplayer/proto"
@ -45,7 +44,6 @@ func GetUserByNameLike(name string) []proto.User {
func UpdateUser(user_id int, req proto.UpdateUserInfoReq) (int, error) { func UpdateUser(user_id int, req proto.UpdateUserInfoReq) (int, error) {
cur_user := dao.FindUserByID2(user_id) cur_user := dao.FindUserByID2(user_id)
fmt.Println("cur_user:", cur_user, "req:", req)
if user_id == req.ID { if user_id == req.ID {
dao.UpdateUserByID2(user_id, req) dao.UpdateUserByID2(user_id, req)
return user_id, nil return user_id, nil

View File

@ -20,25 +20,6 @@ func GetVideoList(auth_id int, start, end, hour string) []dao.Video {
if start == "" { if start == "" {
return dao.FindVideoListsByAuthID(auth_id) return dao.FindVideoListsByAuthID(auth_id)
} else { } else {
//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{}
//}
start = strings.Replace(start, "/", "-", -1)
end = strings.Replace(end, "/", "-", -1)
start = strings.Replace(start, " ", " ", -1)
end = strings.Replace(end, " ", " ", -1)
start = start[0:5] + "0" + start[5:]
end = end[0:5] + "0" + end[5:]
if hour != "33" { if hour != "33" {
ss := strings.Split(start, " ") ss := strings.Split(start, " ")
ss1 := strings.Split(ss[1], ":") ss1 := strings.Split(ss[1], ":")