feat(users): 添加身体围度测量功能

新增用户身体围度的完整功能模块,包括数据库迁移、模型定义、API接口和历史记录追踪。
支持胸围、腰围、上臀围、臂围、大腿围、小腿围六项身体围度指标的管理。

- 添加数据库迁移脚本,扩展用户档案表字段
- 创建围度历史记录表用于数据追踪
- 实现围度数据的更新和历史查询API
- 添加数据验证和错误处理机制
This commit is contained in:
richarjiang
2025-09-22 09:49:42 +08:00
parent dc06dfbebd
commit e2fcb1c428
7 changed files with 398 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
-- 身体围度功能数据库迁移脚本
-- 执行日期: 2024年
-- 功能: 为用户档案表新增围度字段,创建围度历史记录表
-- 禁用外键检查(执行时)
SET FOREIGN_KEY_CHECKS = 0;
-- 1. 为用户档案表新增围度字段
ALTER TABLE `t_user_profile`
ADD COLUMN `chest_circumference` FLOAT NULL COMMENT '胸围(厘米)' AFTER `daily_water_goal`,
ADD COLUMN `waist_circumference` FLOAT NULL COMMENT '腰围(厘米)' AFTER `chest_circumference`,
ADD COLUMN `upper_hip_circumference` FLOAT NULL COMMENT '上臀围(厘米)' AFTER `waist_circumference`,
ADD COLUMN `arm_circumference` FLOAT NULL COMMENT '臂围(厘米)' AFTER `upper_hip_circumference`,
ADD COLUMN `thigh_circumference` FLOAT NULL COMMENT '大腿围(厘米)' AFTER `arm_circumference`,
ADD COLUMN `calf_circumference` FLOAT NULL COMMENT '小腿围(厘米)' AFTER `thigh_circumference`;
-- 2. 创建用户身体围度历史记录表
CREATE TABLE `t_user_body_measurement_history` (
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`user_id` VARCHAR(255) NOT NULL COMMENT '用户ID',
`measurement_type` ENUM(
'chest_circumference',
'waist_circumference',
'upper_hip_circumference',
'arm_circumference',
'thigh_circumference',
'calf_circumference'
) NOT NULL COMMENT '围度类型',
`value` FLOAT NOT NULL COMMENT '围度值(厘米)',
`source` ENUM('manual', 'other') NOT NULL DEFAULT 'manual' COMMENT '更新来源',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_measurement_type` (`measurement_type`),
KEY `idx_created_at` (`created_at`),
KEY `idx_user_measurement_time` (`user_id`, `measurement_type`, `created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户身体围度历史记录表';
-- 重新启用外键检查
SET FOREIGN_KEY_CHECKS = 1;
-- 验证表结构
SHOW CREATE TABLE `t_user_profile`;
SHOW CREATE TABLE `t_user_body_measurement_history`;
-- 验证新增字段
SELECT
COLUMN_NAME,
DATA_TYPE,
IS_NULLABLE,
COLUMN_COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 't_user_profile'
AND COLUMN_NAME IN (
'chest_circumference',
'waist_circumference',
'upper_hip_circumference',
'arm_circumference',
'thigh_circumference',
'calf_circumference'
);