You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.1 KiB
69 lines
2.1 KiB
package memory
|
|
|
|
import (
|
|
"time"
|
|
|
|
"yunyan/comm"
|
|
"yunyan/pb"
|
|
)
|
|
|
|
// Upcoming 未来 N 天待提醒项(客户端排本地通知用)
|
|
//
|
|
// 返回的是**已展开成绝对时刻**的列表:重复项按它自己的时区就地摊开,客户端不必
|
|
// 再实现一遍容易出错的日期逻辑,也不需要理解 repeat_rule。
|
|
//
|
|
// @Summary 待提醒列表
|
|
// @Description 拉取未来 N 天的提醒时刻,重复项已展开成绝对时刻,按时间升序
|
|
// @Tags Memory
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param data body pb.MemoryUpcomingReq true "请求数据"
|
|
// @Success 200 {object} comm.HttpResult{data=pb.MemoryUpcomingResp} "响应数据"
|
|
// @Router /api/home/memory_upcoming [post]
|
|
func (this *apiComp) Upcoming(session comm.IUserSession, req *pb.MemoryUpcomingReq) (resp *pb.MemoryUpcomingResp, errdata *pb.ErrorData) {
|
|
uid, errdata := requireUID(session)
|
|
if errdata != nil {
|
|
return
|
|
}
|
|
days := int(req.Days)
|
|
if days <= 0 {
|
|
days = 7
|
|
}
|
|
if days > maxUpcomingDays {
|
|
days = maxUpcomingDays
|
|
}
|
|
|
|
loc := comm.LoadMemoryLocation(req.Tz)
|
|
now := time.Now().In(loc)
|
|
// 往前多取一年:重复项的锚点日可能远在过去(比如去年设的每周一闹钟),
|
|
// 只按未来窗口筛 happen_date 会把所有重复项漏掉。
|
|
start := comm.FormatMemoryDate(now.AddDate(-1, 0, 0))
|
|
end := comm.FormatMemoryDate(now.AddDate(0, 0, days))
|
|
|
|
items, _, err := this.module.model.listItems(&itemQuery{
|
|
uid: uid,
|
|
startDate: start,
|
|
endDate: end,
|
|
categories: []string{comm.MemoryCatAlarm, comm.MemoryCatTodo},
|
|
states: []int32{int32(pb.MemoryState_MemoryState_Pending)},
|
|
size: maxListSize,
|
|
})
|
|
if err != nil {
|
|
this.module.Errorf("memory_upcoming uid:%s err:%v", uid, err)
|
|
errdata = &pb.ErrorData{Code: pb.ErrorCode_DBError, Message: "查询失败"}
|
|
return
|
|
}
|
|
|
|
slots := expandAll(items, days, req.Tz)
|
|
// 只保留窗口内的
|
|
limit := now.AddDate(0, 0, days).Unix()
|
|
kept := make([]*pb.MemoryRemindSlot, 0, len(slots))
|
|
for _, s := range slots {
|
|
if s.RemindAt <= limit {
|
|
kept = append(kept, s)
|
|
}
|
|
}
|
|
resp = &pb.MemoryUpcomingResp{Slots: kept}
|
|
return
|
|
}
|
|
|