From 39191484e5c61aec37b87ed02506552884ac2743 Mon Sep 17 00:00:00 2001 From: Echo <1711788888@qq.com> Date: Fri, 26 Apr 2024 13:23:20 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=BD=93=E6=97=A5=E6=8F=90=E9=86=92=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/app/todos.go | 25 +++++++++++++++++++++++++ model/common/request/notes.go | 2 +- router/app/user.go | 2 +- service/app/todes.go | 10 ++++++++++ task/user.go | 2 +- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/api/v1/app/todos.go b/api/v1/app/todos.go index 1677254..c96e156 100644 --- a/api/v1/app/todos.go +++ b/api/v1/app/todos.go @@ -56,3 +56,28 @@ func (t TodosApi) UpdateTodo(ctx *gin.Context) { } r.Ok(ctx) } + +// GetTodayTodos 获取今日待办 +func (t TodosApi) GetTodayTodos(ctx *gin.Context) { + var p request.GetUserNotes + if err := ctx.ShouldBind(&p); err != nil { + r.FailWithMessage("参数错误:"+err.Error(), ctx) + global.GVA_LOG.Error("参数错误", zap.Error(err)) + return + } + + var ue app.User + if api.GetUser(ctx, &ue, false, true); ctx.IsAborted() { + return + } + + p.UserId = strconv.Itoa(int(ue.ID)) + list, err := todosService.GetTodayTodos(&p) + if err != nil { + r.FailWithMessage("获取Todo列表失败:"+err.Error(), ctx) + global.GVA_LOG.Error("获取Todo列表失败", zap.Error(err)) + return + } + + r.OkWithData(list, ctx) +} diff --git a/model/common/request/notes.go b/model/common/request/notes.go index c3f9fa2..3e243a3 100644 --- a/model/common/request/notes.go +++ b/model/common/request/notes.go @@ -2,7 +2,7 @@ package request type GetUserNotes struct { UserId string `json:"userId" form:"userId" binding:"required"` - IsFinish string `json:"isFinish" form:"isFinish" binding:"required"` + IsFinish string `json:"isFinish" form:"isFinish"` } type TodoTask struct { diff --git a/router/app/user.go b/router/app/user.go index a2c6f61..1fefeff 100644 --- a/router/app/user.go +++ b/router/app/user.go @@ -24,7 +24,7 @@ func (s *LoginRouter) InitUserRouter(Router *gin.RouterGroup) { userRouter.GET("", baseApi.GetUser) userRouter.GET("todo", todoApi.GetUserTodos) userRouter.PUT("todo", todoApi.UpdateTodo) - + userRouter.GET("todo/today", todoApi.GetTodayTodos) userRouter.POST("msg", baseApi.SendMedicineRemind) } diff --git a/service/app/todes.go b/service/app/todes.go index 3b52420..2b03836 100644 --- a/service/app/todes.go +++ b/service/app/todes.go @@ -4,6 +4,7 @@ import ( "miniapp/global" "miniapp/model/common" "miniapp/model/common/request" + "time" ) type TodesService struct{} @@ -18,3 +19,12 @@ func (t TodesService) UpdateTodoById(c *common.UserTodo) error { return global.GVA_DB.Table("t_user_todo").Where("id = ?", c.ID).Update("is_finish", c.IsFinish).Error } + +// GetTodayTodos 获取今日待办 +func (t TodesService) GetTodayTodos(notes *request.GetUserNotes) (list []common.UserTodo, err error) { + // 获取当前时间 + nowTime := time.Now().Format("2006-01-02") + + err = global.GVA_DB.Where("user_id = ? and is_finish = 0 and remind_day = ?", notes.UserId, nowTime).Find(&list).Error + return +} diff --git a/task/user.go b/task/user.go index 9a356ce..d9dd5c2 100644 --- a/task/user.go +++ b/task/user.go @@ -18,7 +18,7 @@ func CheckUserSurgeryDate() { global.GVA_DB.Model(&app.User{}).Find(&users) for _, user := range users { parse, _ := time.Parse("2006-01-02", user.SurgeryTime) - if time.Now().Sub(parse).Hours()/24 == 0 { + if time.Now().Local().Sub(parse.Local()).Hours()/24 <= 1 { global.GVA_DB.Model(&app.User{}).Where("id = ?", user.ID).Updates(app.User{IsSurgery: 1}) } }