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.
47 lines
1.4 KiB
47 lines
1.4 KiB
package memory
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/pb"
|
|
)
|
|
|
|
// Stats 即时统计
|
|
//
|
|
// ⚠️ 花销**按币种分行**返回,不做汇率换算。把 CNY 和 JPY 加成一个数是错的,
|
|
// 而汇率换算需要实时汇率源与换算时点口径,那是另一个功能。
|
|
//
|
|
// @Summary 记忆统计
|
|
// @Description 按时间范围统计待办完成情况、灵感数、花销(分币种)
|
|
// @Tags Memory
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param data body pb.MemoryStatsReq true "请求数据"
|
|
// @Success 200 {object} comm.HttpResult{data=pb.MemoryStatsResp} "响应数据"
|
|
// @Router /api/home/memory_stats [post]
|
|
func (this *apiComp) Stats(session comm.IUserSession, req *pb.MemoryStatsReq) (resp *pb.MemoryStatsResp, errdata *pb.ErrorData) {
|
|
uid, errdata := requireUID(session)
|
|
if errdata != nil {
|
|
return
|
|
}
|
|
st, err := this.module.computeStats(uid, req.StartDate, req.EndDate)
|
|
if err != nil {
|
|
this.module.Errorf("memory_stats uid:%s err:%v", uid, err)
|
|
errdata = &pb.ErrorData{Code: pb.ErrorCode_DBError, Message: "统计失败"}
|
|
return
|
|
}
|
|
resp = &pb.MemoryStatsResp{
|
|
TodoTotal: st.TodoTotal,
|
|
TodoDone: st.TodoDone,
|
|
TodoUndone: st.TodoUndone,
|
|
IdeaCount: st.IdeaCount,
|
|
AlarmTotal: st.AlarmTotal,
|
|
}
|
|
for _, e := range st.Expenses {
|
|
resp.Expenses = append(resp.Expenses, &pb.MemoryExpenseSum{
|
|
Currency: e.Currency, TotalCents: e.TotalCents, Count: e.Count,
|
|
})
|
|
}
|
|
_ = comm.MemoryCatTodo
|
|
return
|
|
}
|
|
|