2023-11-02 04:34:46 +08:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"miniapp/api"
|
|
|
|
"miniapp/global"
|
|
|
|
"miniapp/model/app"
|
|
|
|
"miniapp/model/common"
|
2024-01-11 16:03:51 +08:00
|
|
|
"miniapp/model/common/request"
|
2023-11-02 04:34:46 +08:00
|
|
|
r "miniapp/model/common/response"
|
2024-01-11 16:03:51 +08:00
|
|
|
"strconv"
|
2024-05-09 18:06:45 +08:00
|
|
|
"time"
|
2023-11-02 04:34:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type TodosApi struct{}
|
|
|
|
|
|
|
|
func (t TodosApi) GetUserTodos(ctx *gin.Context) {
|
2024-01-11 16:03:51 +08:00
|
|
|
var p request.GetUserNotes
|
|
|
|
if err := ctx.ShouldBind(&p); err != nil {
|
|
|
|
r.FailWithMessage("参数错误:"+err.Error(), ctx)
|
|
|
|
global.GVA_LOG.Error("参数错误", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
2023-11-02 04:34:46 +08:00
|
|
|
|
|
|
|
var ue app.User
|
|
|
|
if api.GetUser(ctx, &ue, false, true); ctx.IsAborted() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-11 16:03:51 +08:00
|
|
|
p.UserId = strconv.Itoa(int(ue.ID))
|
|
|
|
list, err := todosService.GetUserTodos(&p)
|
2023-11-02 04:34:46 +08:00
|
|
|
if err != nil {
|
|
|
|
r.FailWithMessage("获取Todo列表失败:"+err.Error(), ctx)
|
|
|
|
global.GVA_LOG.Error("获取Todo列表失败", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
r.OkWithData(list, ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateTodo 更新Todo
|
|
|
|
func (t TodosApi) UpdateTodo(ctx *gin.Context) {
|
|
|
|
var todo common.UserTodo
|
|
|
|
if err := ctx.ShouldBind(&todo); err != nil {
|
|
|
|
r.FailWithMessage("参数错误:"+err.Error(), ctx)
|
|
|
|
global.GVA_LOG.Error("参数错误", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新
|
|
|
|
err := todosService.UpdateTodoById(&todo)
|
|
|
|
if err != nil {
|
|
|
|
r.FailWithMessage(err.Error(), ctx)
|
|
|
|
global.GVA_LOG.Error("更新失败", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r.Ok(ctx)
|
|
|
|
}
|
2024-04-26 13:23:20 +08:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2024-05-09 18:06:45 +08:00
|
|
|
todos := make([]common.UserTodo, 0)
|
|
|
|
hour := time.Now().Hour()
|
|
|
|
for i := range list {
|
|
|
|
//将remind_time截取前两位 转为int
|
|
|
|
rt, _ := strconv.Atoi(list[i].RemindTime[:2])
|
|
|
|
rt2 := 24
|
|
|
|
|
|
|
|
if i+1 == len(list) {
|
|
|
|
rt2, _ = strconv.Atoi(list[len(list)-1].RemindTime[:2])
|
|
|
|
} else {
|
|
|
|
rt2, _ = strconv.Atoi(list[i+1].RemindTime[:2])
|
|
|
|
}
|
|
|
|
if hour >= rt && hour <= rt2 {
|
|
|
|
todos = append(todos, list[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//删除todos第一个元素
|
|
|
|
if len(todos) > 0 {
|
|
|
|
todos = todos[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
r.OkWithData(todos, ctx)
|
2024-04-26 13:23:20 +08:00
|
|
|
}
|