feat(users): 添加用户每日健康数据记录功能,支持多维度健康指标更新
This commit is contained in:
115
src/users/models/user-daily-health.model.ts
Normal file
115
src/users/models/user-daily-health.model.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
import { Column, DataType, Index, Model, PrimaryKey, Table } from 'sequelize-typescript';
|
||||
|
||||
/**
|
||||
* 用户每日健康记录表
|
||||
* 每日每个用户只会生成一条数据,通过 userId + recordDate 唯一确定
|
||||
*/
|
||||
@Table({
|
||||
tableName: 't_user_daily_health',
|
||||
underscored: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['user_id', 'record_date'],
|
||||
name: 'uk_user_record_date',
|
||||
},
|
||||
{
|
||||
fields: ['user_id'],
|
||||
name: 'idx_user_id',
|
||||
},
|
||||
{
|
||||
fields: ['record_date'],
|
||||
name: 'idx_record_date',
|
||||
},
|
||||
],
|
||||
})
|
||||
export class UserDailyHealth extends Model {
|
||||
@PrimaryKey
|
||||
@Column({
|
||||
type: DataType.BIGINT,
|
||||
autoIncrement: true,
|
||||
})
|
||||
declare id: number;
|
||||
|
||||
@Column({
|
||||
type: DataType.STRING(64),
|
||||
allowNull: false,
|
||||
comment: '用户ID',
|
||||
})
|
||||
declare userId: string;
|
||||
|
||||
@Column({
|
||||
type: DataType.DATEONLY,
|
||||
allowNull: false,
|
||||
comment: '记录日期 (YYYY-MM-DD)',
|
||||
})
|
||||
declare recordDate: string;
|
||||
|
||||
@Column({
|
||||
type: DataType.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '饮水量 (毫升 ml)',
|
||||
})
|
||||
declare waterIntake: number | null;
|
||||
|
||||
@Column({
|
||||
type: DataType.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '锻炼分钟数',
|
||||
})
|
||||
declare exerciseMinutes: number | null;
|
||||
|
||||
@Column({
|
||||
type: DataType.FLOAT,
|
||||
allowNull: true,
|
||||
comment: '消耗卡路里 (千卡 kcal)',
|
||||
})
|
||||
declare caloriesBurned: number | null;
|
||||
|
||||
@Column({
|
||||
type: DataType.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '站立时间 (分钟)',
|
||||
})
|
||||
declare standingMinutes: number | null;
|
||||
|
||||
@Column({
|
||||
type: DataType.FLOAT,
|
||||
allowNull: true,
|
||||
comment: '基础代谢 (千卡 kcal)',
|
||||
})
|
||||
declare basalMetabolism: number | null;
|
||||
|
||||
@Column({
|
||||
type: DataType.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '睡眠分钟数',
|
||||
})
|
||||
declare sleepMinutes: number | null;
|
||||
|
||||
@Column({
|
||||
type: DataType.FLOAT,
|
||||
allowNull: true,
|
||||
comment: '血氧饱和度 (百分比 %)',
|
||||
})
|
||||
declare bloodOxygen: number | null;
|
||||
|
||||
@Column({
|
||||
type: DataType.DECIMAL(5, 1),
|
||||
allowNull: true,
|
||||
comment: '压力 (ms,保留一位小数)',
|
||||
})
|
||||
declare stressLevel: number | null;
|
||||
|
||||
@Column({
|
||||
type: DataType.DATE,
|
||||
defaultValue: DataType.NOW,
|
||||
})
|
||||
declare createdAt: Date;
|
||||
|
||||
@Column({
|
||||
type: DataType.DATE,
|
||||
defaultValue: DataType.NOW,
|
||||
})
|
||||
declare updatedAt: Date;
|
||||
}
|
||||
Reference in New Issue
Block a user