🎨 新增查询当日提醒接口

This commit is contained in:
loser 2024-04-26 13:23:20 +08:00
parent 8aa2b355d9
commit 39191484e5
5 changed files with 38 additions and 3 deletions

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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
}

View File

@ -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})
}
}