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

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 package config
import ( import (
"background/logs"
"fmt" "fmt"
"github.com/pkg/errors" "github.com/pkg/errors"
"gopkg.in/redis.v4" "gopkg.in/redis.v4"
"background/logs"
) )
var ( 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 package middle
import ( import (
@ -22,23 +30,28 @@ func AuthMiddle(c *gin.Context) {
c.Abort() c.Abort()
return return
} }
if config.RedisOne().Exists(token).Val() { cli := config.RedisOne()
users := model.Users{}
userInfo := config.RedisOne().Get(token).Val() if cli != nil{
e := json.Unmarshal([]byte(userInfo), &users)
if nil != e { 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{ c.JSON(200, controller.RespBase{
"auth err", 10, nil, "expired or no login", 210, nil,
}) })
c.Abort() c.Abort()
return return
} }
} else { c.Next()
c.JSON(200, controller.RespBase{
"expired or no login", 210, nil,
})
c.Abort()
return
} }
c.Next()
} }

View File

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

View File

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

View File

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