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:
+22
-1
@@ -24,6 +24,7 @@ CREATE TABLE `fa_smoke_log` (
|
||||
CREATE TABLE IF NOT EXISTS `fa_smoke_ai_advice` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`uid` int(11) NOT NULL COMMENT '用户ID',
|
||||
`type` varchar(30) NOT NULL DEFAULT 'daily_advice' COMMENT '用途类型(daily_advice/next_smoke_time/...)',
|
||||
`advice_date` date NOT NULL COMMENT '建议针对的日期(通常=昨天)',
|
||||
`prompt_version` varchar(30) NOT NULL DEFAULT 'v1' COMMENT '提示词版本',
|
||||
`provider` varchar(30) DEFAULT NULL COMMENT 'AI 提供方(可选)',
|
||||
@@ -37,7 +38,7 @@ CREATE TABLE IF NOT EXISTS `fa_smoke_ai_advice` (
|
||||
`updatetime` int(11) DEFAULT NULL COMMENT '修改时间',
|
||||
`deletetime` int(11) DEFAULT NULL COMMENT '删除时间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uniq_smoke_ai_advice` (`uid`,`advice_date`,`prompt_version`),
|
||||
UNIQUE KEY `uniq_smoke_ai_advice` (`uid`,`type`,`advice_date`,`prompt_version`),
|
||||
KEY `idx_smoke_ai_advice_uid_date` (`uid`,`advice_date`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='每日AI戒烟建议';
|
||||
|
||||
@@ -77,3 +78,23 @@ CREATE TABLE IF NOT EXISTS `fa_smoke_user_profile` (
|
||||
UNIQUE KEY `uniq_smoke_profile_uid` (`uid`),
|
||||
KEY `idx_smoke_profile_deleted_at` (`deleted_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='戒烟-用户基础信息';
|
||||
|
||||
-- AI 下次抽烟时间建议(结构化缓存:当天)
|
||||
-- 说明:
|
||||
-- - not_before_at:AI 给出的“不早于”时间;suggested_at:AI 建议的下次抽烟时间(>= not_before_at)
|
||||
-- - time_nodes:建议时间节点(JSON 数组,例如 ["10:30","11:10","14:00"])
|
||||
CREATE TABLE IF NOT EXISTS `fa_smoke_ai_next_smoke` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`uid` int(11) NOT NULL COMMENT '用户ID',
|
||||
`plan_date` date NOT NULL COMMENT '计划日期(当天)',
|
||||
`ai_advice_id` bigint unsigned NOT NULL COMMENT '关联AI建议ID(fa_smoke_ai_advice.id)',
|
||||
`node_type` varchar(20) NOT NULL COMMENT '节点类型(not_before/suggested/node)',
|
||||
`node_at` datetime NOT NULL COMMENT '时间点',
|
||||
`createtime` int(11) DEFAULT NULL COMMENT '创建时间',
|
||||
`updatetime` int(11) DEFAULT NULL COMMENT '修改时间',
|
||||
`deletetime` int(11) DEFAULT NULL COMMENT '删除时间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uniq_smoke_ai_next_node` (`ai_advice_id`,`node_type`,`node_at`),
|
||||
KEY `idx_smoke_ai_next_uid_date` (`uid`,`plan_date`),
|
||||
KEY `idx_smoke_ai_next_advice` (`ai_advice_id`,`node_type`,`node_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='AI下次抽烟时间节点';
|
||||
|
||||
Reference in New Issue
Block a user