待办事项数据库添加时间字段

master
DESKTOP-4RNDQIC\29019 2021-07-17 23:53:21 +08:00
parent 30035b2d45
commit b64e0f9147
5 changed files with 57 additions and 22 deletions

View File

@ -1,10 +1,19 @@
/*
* @Author: your name
* @Date: 2019-04-07 11:19:50
* @LastEditTime: 2021-07-17 22:23:23
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: \background\config\redisConf.go
*/
package config
import (
"background/logs"
"fmt"
"github.com/pkg/errors"
"gopkg.in/redis.v4"
"background/logs"
)
var (

View File

@ -1,3 +1,11 @@
/*
* @Author: your name
* @Date: 2020-10-04 18:06:06
* @LastEditTime: 2021-07-17 22:22:05
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \background\controller\middle\auth.go
*/
package middle
import (
@ -22,23 +30,28 @@ func AuthMiddle(c *gin.Context) {
c.Abort()
return
}
if config.RedisOne().Exists(token).Val() {
users := model.Users{}
userInfo := config.RedisOne().Get(token).Val()
e := json.Unmarshal([]byte(userInfo), &users)
if nil != e {
cli := config.RedisOne()
if cli != nil{
if cli.Exists(token).Val() {
users := model.Users{}
userInfo := config.RedisOne().Get(token).Val()
e := json.Unmarshal([]byte(userInfo), &users)
if nil != e {
c.JSON(200, controller.RespBase{
"auth err", 10, nil,
})
c.Abort()
return
}
} else {
c.JSON(200, controller.RespBase{
"auth err", 10, nil,
"expired or no login", 210, nil,
})
c.Abort()
return
}
} else {
c.JSON(200, controller.RespBase{
"expired or no login", 210, nil,
})
c.Abort()
return
c.Next()
}
c.Next()
}

View File

@ -7,6 +7,7 @@ import (
"fmt"
"log"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
@ -153,6 +154,7 @@ func (this *PlanController) CreateUndo(c *gin.Context) {
resp.Msg = "wrong input"
return
}
req.CreateTime = time.Now().Format("2006-01-02 15:04:05")
e = db.GetOrm().Model(&model.Undo{}).Create(&req).Error
if nil != e {
log.Print(e.Error())
@ -189,8 +191,9 @@ func (this *PlanController) FinishUndo(c *gin.Context) {
id := c.Param("id")
log.Print("finish undo id",id)
e := db.GetOrm().Exec(fmt.Sprintf("update background.`undo` set done = 1 where id = '%s'",id )).Error
log.Print(fmt.Sprintf("update undo set done = 1 where id = %d",1 ))
e := db.GetOrm().Exec(fmt.Sprintf("update undo set done = 1,finish_time='%s' where id = %d",
time.Now().Format("2006-01-02 15:04:05"),1)).Error
log.Print(fmt.Sprintf("update undo set done = 1,finish_time='%s' where id = %d",time.Now().Format("2006-01-02 15:04:05"),1))
if nil != e {
logs.Error(e.Error())
return

View File

@ -229,11 +229,11 @@ func DefaultOption(c *gin.Context) {
func (this *UserController) Login(c *gin.Context) {
defer func() {
if err := recover();err != nil{
log.Printf("panic: v%",err)
}
}()
// defer func() {
// if err := recover();err != nil{
// log.Printf("panic: v%",err)
// }
// }()
type LoginReq struct {
RememberMe int32 `json:"remember_me"`
@ -279,7 +279,14 @@ func (this *UserController) Login(c *gin.Context) {
if req.RememberMe == 1 {
config.RedisOne().Set(utils.ByteSliceToString(socketTokenMd5), string(sessionInfo), time.Second*24*3600)
} else {
config.RedisOne().Set(utils.ByteSliceToString(socketTokenMd5), string(sessionInfo), time.Second*8*3600)
log.Print(utils.ByteSliceToString(socketTokenMd5), string(sessionInfo), time.Second*8*3600)
cli := config.RedisOne()
if nil != cli{
status := cli.Set(utils.ByteSliceToString(socketTokenMd5), string(sessionInfo), time.Second*8*3600)
if status.Err() != nil{
log.Println(status)
}
}
}
//存储session
session := sessions.Get(c)
@ -301,6 +308,7 @@ func (this *UserController) Login(c *gin.Context) {
session.Options(*Options)
session.Save()
resp.Msg = "登录成功"
resp.Status = 0
resp.Data = string(sessionInfo)

View File

@ -31,6 +31,8 @@ type Undo struct {
Type int32 `json:"type" gorm:"column:type" sql:"type"`
Done int `json:"done" gorm:"done" sql:"done"`
DeletedAt *time.Time `json:"deleted_at"`
CreateTime string `json:"create_time"`
FinishTime string `json:"finish_time"`
}
type PlanType struct {