Files
wx_service/docs/sql/smoke.sql
T
nepiedg dc54c4e934 Add user profile management for smoking data
- Introduced new API endpoints `GET /api/v1/smoke/profile` and `PUT /api/v1/smoke/profile` for retrieving and updating user smoking profiles.
- Added a new database table `fa_smoke_user_profile` to store user-specific smoking data, including daily smoking habits and motivations.
- Updated the smoke handler and service to integrate user profile data into AI advice generation.
- Enhanced documentation to reflect the new user profile features and their usage.
2026-01-20 02:37:20 +00:00

80 lines
4.5 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 戒烟/抽烟记录主表
-- 注意:该表字段来自旧系统(createtime/updatetime/deletetime 为秒级时间戳)
CREATE TABLE `fa_smoke_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) NOT NULL COMMENT '用户ID',
`smoke_time` date DEFAULT NULL COMMENT '抽烟时间',
`smoke_at` datetime DEFAULT NULL COMMENT '真实抽烟时间(可补录,精确到时分秒;为空则可用 createtime 近似)',
`remark` text COMMENT '抽烟原因',
`createtime` int(11) DEFAULT NULL COMMENT '创建时间',
`updatetime` int(11) DEFAULT NULL COMMENT '修改时间',
`deletetime` int(11) DEFAULT NULL COMMENT '删除时间',
`level` bigint(2) DEFAULT '1' COMMENT '烟瘾程度',
`num` int(2) DEFAULT '1' COMMENT '抽烟数量',
PRIMARY KEY (`id`,`uid`),
KEY `idx_smoke_uid_date` (`uid`,`smoke_time`),
KEY `idx_smoke_uid_at` (`uid`,`smoke_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='抽烟记录';
-- AI 戒烟建议(按天缓存,避免重复调用;通常 date=昨天)
-- 说明:
-- - access gating:会员用户直接可用;非会员需要先完成“看广告解锁”(见 fa_smoke_ai_advice_unlocks
-- - input_snapshot:建议将“昨日总量 + 时间节点列表”作为 JSON 落库,便于追溯与复现
CREATE TABLE IF NOT EXISTS `fa_smoke_ai_advice` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`uid` int(11) NOT NULL COMMENT '用户ID',
`advice_date` date NOT NULL COMMENT '建议针对的日期(通常=昨天)',
`prompt_version` varchar(30) NOT NULL DEFAULT 'v1' COMMENT '提示词版本',
`provider` varchar(30) DEFAULT NULL COMMENT 'AI 提供方(可选)',
`model` varchar(60) DEFAULT NULL COMMENT '模型名(可选)',
`input_snapshot` json NOT NULL COMMENT '当次输入快照(昨日总量+节点)',
`advice` mediumtext NOT NULL COMMENT 'AI 建议内容(文本/Markdown',
`tokens_in` int DEFAULT NULL,
`tokens_out` int DEFAULT NULL,
`cost_cent` int DEFAULT 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_advice` (`uid`,`advice_date`,`prompt_version`),
KEY `idx_smoke_ai_advice_uid_date` (`uid`,`advice_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='每日AI戒烟建议';
-- 每日广告解锁记录(非会员:当天/指定日期解锁后即可生成建议)
CREATE TABLE IF NOT EXISTS `fa_smoke_ai_advice_unlocks` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`uid` int(11) NOT NULL COMMENT '用户ID',
`unlock_date` date NOT NULL COMMENT '解锁的建议日期(通常=昨天)',
`ad_watched_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_unlock` (`uid`,`unlock_date`),
KEY `idx_smoke_ai_unlock_uid_date` (`uid`,`unlock_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='AI戒烟建议-广告解锁';
-- 用户基础信息(首次进入补全,用于基准/AI/看板公式等)
-- 说明:
-- - 使用 GORM 默认 created_at/updated_at/deleted_atdatetime(3)
-- - smoke_motivations/quit_motivations 建议存 JSON 数组(例如 ["压力大","社交"]
CREATE TABLE IF NOT EXISTS `fa_smoke_user_profile` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) NULL DEFAULT NULL,
`updated_at` datetime(3) NULL DEFAULT NULL,
`deleted_at` datetime(3) NULL DEFAULT NULL,
`uid` int NOT NULL COMMENT '用户ID',
`baseline_cigs_per_day` int NOT NULL DEFAULT 0 COMMENT '基础烟量(日均抽烟支数)',
`smoking_years` decimal(6,2) NOT NULL DEFAULT 0.00 COMMENT '烟龄(年)',
`pack_price_cent` int NOT NULL DEFAULT 0 COMMENT '单包价格(分)',
`smoke_motivations` json DEFAULT NULL COMMENT '抽烟动机(JSON数组)',
`quit_motivations` json DEFAULT NULL COMMENT '戒烟动力(JSON数组)',
`wake_up_time` varchar(5) NOT NULL DEFAULT '' COMMENT '起床时间(HH:MM)',
`sleep_time` varchar(5) NOT NULL DEFAULT '' COMMENT '入睡时间(HH:MM)',
`onboarding_completed_at` datetime(3) DEFAULT NULL COMMENT '首次补全完成时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_smoke_profile_uid` (`uid`),
KEY `idx_smoke_profile_deleted_at` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='戒烟-用户基础信息';