Enhance smoking tracking features with AI next smoke time suggestions

- Added new API endpoint `GET /api/v1/smoke/next_smoke_time` to provide AI-generated suggestions for the next smoking time based on user data.
- Introduced a new database table `fa_smoke_ai_next_smoke` to store structured AI time node suggestions.
- Updated smoke handler and service to integrate the new AI next smoke time functionality.
- Enhanced documentation to reflect the new API endpoint and its usage, including details on how to generate AI time nodes.
This commit is contained in:
nepiedg
2026-01-20 07:08:52 +00:00
parent dc54c4e934
commit 6cf7eb2294
15 changed files with 1394 additions and 27 deletions
+10 -9
View File
@@ -37,11 +37,11 @@ func (s *SmokeLogService) Create(ctx context.Context, uid int, req CreateSmokeLo
updateTime := now
level := req.Level
if level <= 0 {
if level < 0 {
level = 1
}
num := req.Num
if num <= 0 {
if num < 0 {
num = 1
}
@@ -212,7 +212,8 @@ func (s *SmokeLogService) Dashboard(ctx context.Context, uid int, req SmokeDashb
var last smokemodel.SmokeLog
if err := s.db.WithContext(ctx).
Where("uid = ? AND (deletetime IS NULL OR deletetime = 0)", uid).
Order("COALESCE(smoke_at, smoke_time, FROM_UNIXTIME(createtime)) DESC").
Where("NOT (level = 0 AND num = 0)").
Order("COALESCE(smoke_at, FROM_UNIXTIME(createtime), smoke_time) DESC").
Order("id DESC").
Limit(1).
Take(&last).Error; err != nil {
@@ -260,7 +261,7 @@ func (s *SmokeLogService) ListLatest(ctx context.Context, uid int, limit int) ([
Model(&smokemodel.SmokeLog{}).
Select("id, uid, smoke_time, smoke_at, remark, level, num, createtime, updatetime, deletetime").
Where("uid = ? AND (deletetime IS NULL OR deletetime = 0)", uid).
Order("COALESCE(smoke_at, smoke_time, FROM_UNIXTIME(createtime)) DESC").
Order("COALESCE(smoke_at, FROM_UNIXTIME(createtime), smoke_time) DESC").
Order("id DESC").
Limit(limit).
Find(&items).Error; err != nil {
@@ -274,13 +275,13 @@ func lastEventTime(log smokemodel.SmokeLog) (time.Time, bool) {
if log.SmokeAt != nil {
return log.SmokeAt.In(time.Local), true
}
if log.CreateTime != nil {
return time.Unix(*log.CreateTime, 0).In(time.Local), true
}
if log.SmokeTime != nil {
day := dateOnly(*log.SmokeTime)
return day, true
}
if log.CreateTime != nil {
return time.Unix(*log.CreateTime, 0).In(time.Local), true
}
return time.Time{}, false
}
@@ -321,14 +322,14 @@ func (s *SmokeLogService) Update(ctx context.Context, uid int, id int, req Updat
updates["remark"] = *req.Remark
}
if req.Level != nil {
if *req.Level <= 0 {
if *req.Level < 0 {
updates["level"] = int64(1)
} else {
updates["level"] = *req.Level
}
}
if req.Num != nil {
if *req.Num <= 0 {
if *req.Num < 0 {
updates["num"] = 1
} else {
updates["num"] = *req.Num