修复用户二维码登录redis设置后消失问题,修改logger错误输出,实现视频按日期及小时精度查找。
This commit is contained in:
parent
a8a1826d9c
commit
062fb6f4b6
|
|
@ -3,6 +3,7 @@ package handler
|
|||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt"
|
||||
|
|
@ -44,11 +45,21 @@ func GetScanUUID(c *gin.Context) {
|
|||
c.JSON(200, gin.H{"code": 9, "message": err, "data": "2"})
|
||||
return
|
||||
}
|
||||
data := map[string]interface{}{"status": "0", "address": ReqData.Address, "ip": c.ClientIP()}
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
c.JSON(200, gin.H{"code": 9, "message": err, "data": "2"})
|
||||
return
|
||||
}
|
||||
id := uuid.New()
|
||||
res := worker.SetHash(id.String(), map[string]interface{}{"status": "0", "address": ReqData.Address, "ip": c.ClientIP()})
|
||||
res := worker.SetRedisWithExpire(id.String(), string(jsonData), time.Minute*30)
|
||||
if res {
|
||||
data := worker.GetHashAll(id.String())
|
||||
c.JSON(200, gin.H{"code": 0, "message": data, "data": id.String()})
|
||||
var retrievedData map[string]interface{}
|
||||
if err2 := json.Unmarshal([]byte(worker.GetRedis(id.String())), &retrievedData); err2 != nil {
|
||||
c.JSON(200, gin.H{"code": 9, "message": err2, "data": "2"})
|
||||
return
|
||||
}
|
||||
c.JSON(200, gin.H{"code": 0, "message": retrievedData, "data": id.String()})
|
||||
} else {
|
||||
c.JSON(200, gin.H{"code": 8, "message": "qr code invalid", "data": "1"})
|
||||
}
|
||||
|
|
@ -61,10 +72,20 @@ func SetQRStatus(c *gin.Context) {
|
|||
c.JSON(200, gin.H{"code": 18, "message": "uuid not found in server", "data": "0"})
|
||||
return
|
||||
}
|
||||
res := worker.SetHashWithField(qrsetReq.UUID, "status", "1")
|
||||
var retrievedData map[string]interface{}
|
||||
if err2 := json.Unmarshal([]byte(worker.GetRedis(qrsetReq.UUID)), &retrievedData); err2 != nil {
|
||||
c.JSON(200, gin.H{"code": 9, "message": err2, "data": "2"})
|
||||
return
|
||||
}
|
||||
retrievedData["status"] = "1"
|
||||
jsonData, err2 := json.Marshal(retrievedData)
|
||||
if err2 != nil {
|
||||
c.JSON(200, gin.H{"code": 9, "message": err2, "data": "2"})
|
||||
return
|
||||
}
|
||||
res := worker.SetRedisWithExpire(qrsetReq.UUID, string(jsonData), time.Minute*30)
|
||||
if res {
|
||||
data := worker.GetHashAll(qrsetReq.UUID)
|
||||
c.JSON(200, gin.H{"code": 0, "message": "success", "data": data})
|
||||
c.JSON(200, gin.H{"code": 0, "message": "success", "data": retrievedData})
|
||||
} else {
|
||||
c.JSON(200, gin.H{"code": 8, "message": "qr code invalid", "data": "1"})
|
||||
}
|
||||
|
|
@ -89,7 +110,18 @@ func ConfirmQRLogin(c *gin.Context) {
|
|||
c.JSON(200, gin.H{"code": 18, "message": "uuid not found in server", "data": "0"})
|
||||
return
|
||||
}
|
||||
if worker.SetHashWithField(qrsetReq.UUID, "status", token) {
|
||||
var retrievedData map[string]interface{}
|
||||
if err2 := json.Unmarshal([]byte(worker.GetRedis(qrsetReq.UUID)), &retrievedData); err2 != nil {
|
||||
c.JSON(200, gin.H{"code": 9, "message": err2, "data": "2"})
|
||||
return
|
||||
}
|
||||
retrievedData["status"] = token
|
||||
jsonData, err2 := json.Marshal(retrievedData)
|
||||
if err2 != nil {
|
||||
c.JSON(200, gin.H{"code": 9, "message": err2, "data": "2"})
|
||||
return
|
||||
}
|
||||
if worker.SetRedisWithExpire(qrsetReq.UUID, string(jsonData), time.Minute*10) {
|
||||
c.JSON(200, gin.H{"code": 0, "message": "success", "data": "0"})
|
||||
} else {
|
||||
c.JSON(200, gin.H{"code": 8, "message": "设置Token失败", "data": "8"})
|
||||
|
|
@ -105,13 +137,12 @@ func ConfirmQRLogin(c *gin.Context) {
|
|||
func GetQRStatus(c *gin.Context) {
|
||||
var qrReq QRReq
|
||||
if err := c.ShouldBind(&qrReq); err == nil {
|
||||
end := worker.SetHashWithField(qrReq.UUID, "address", qrReq.Address)
|
||||
end_ := worker.SetHashWithField(qrReq.UUID, "ip", qrReq.IP)
|
||||
if !end || !end_ {
|
||||
c.JSON(200, gin.H{"code": 8, "message": "set redis failed", "data": "8"})
|
||||
var retrievedData map[string]interface{}
|
||||
if err2 := json.Unmarshal([]byte(worker.GetRedis(qrReq.UUID)), &retrievedData); err2 != nil {
|
||||
c.JSON(200, gin.H{"code": 9, "message": err2, "data": "2"})
|
||||
return
|
||||
}
|
||||
str := worker.GetHash(qrReq.UUID, "status")
|
||||
str := retrievedData["status"].(string)
|
||||
switch str {
|
||||
case "":
|
||||
c.JSON(200, gin.H{"code": 18, "message": "uuid not found", "data": "0"}) //空值
|
||||
|
|
|
|||
|
|
@ -150,9 +150,10 @@ func CreateVideo(c *gin.Context) {
|
|||
|
||||
func GetVideoList(c *gin.Context) {
|
||||
var gvl_req gvlReq
|
||||
gvl_req.Hour = "33"
|
||||
id, _ := c.Get("id")
|
||||
if err := c.ShouldBind(&gvl_req); err == nil {
|
||||
videos := service.GetVideoList(int(id.(float64)), gvl_req.StartTime, gvl_req.EndTime)
|
||||
videos := service.GetVideoList(int(id.(float64)), gvl_req.StartTime, gvl_req.EndTime, gvl_req.Hour)
|
||||
c.JSON(http.StatusOK, gin.H{"data": videos, "code": 0, "message": "success"})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": 9, "message": "failed"})
|
||||
|
|
|
|||
6
main.go
6
main.go
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt"
|
||||
"io"
|
||||
|
|
@ -45,10 +44,7 @@ func writeLogger(c *gin.Context) {
|
|||
params = string(bodyBytes)
|
||||
}
|
||||
}
|
||||
res := dao.InsertLogToDB(path, ip, method, params)
|
||||
if res == 0 {
|
||||
fmt.Println("insert log failed")
|
||||
}
|
||||
go dao.InsertLogToDB(path, ip, method, params)
|
||||
}
|
||||
|
||||
func JWTAuthMiddleware() gin.HandlerFunc {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"strings"
|
||||
"videoplayer/dao"
|
||||
)
|
||||
|
||||
|
|
@ -14,23 +13,39 @@ func GetWillDelVideoList(id int) []dao.Video {
|
|||
return dao.FindWillDelVideoList(id)
|
||||
}
|
||||
|
||||
func GetVideoList(auth_id int, start, end string) []dao.Video {
|
||||
func GetVideoList(auth_id int, start, end, hour string) []dao.Video {
|
||||
if start == "" {
|
||||
return dao.FindVideoListsByAuthID(auth_id)
|
||||
} 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{}
|
||||
//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" {
|
||||
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]
|
||||
}
|
||||
|
||||
return dao.FindVideoListByTime(auth_id, start, end)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue