feat(training-plans): 添加训练项目管理功能

- 新增训练项目模型、DTO和服务,支持创建、更新、删除和批量操作训练项目
- 在控制器中实现训练项目的相关API,包括添加、批量添加、获取、更新、删除和标记完成状态
- 提供训练项目的完成统计功能,支持获取训练计划下所有项目的完成情况
- 更新训练计划模块以集成训练项目管理功能
This commit is contained in:
richarjiang
2025-08-15 09:44:42 +08:00
parent 2c04325152
commit 8edc27b0ad
7 changed files with 1429 additions and 5 deletions

View File

@@ -0,0 +1,74 @@
import { Column, DataType, ForeignKey, Model, PrimaryKey, Table, BelongsTo } from 'sequelize-typescript';
import { TrainingPlan } from './training-plan.model';
export type ScheduleItemType = 'exercise' | 'rest' | 'note';
@Table({
tableName: 't_schedule_exercises',
underscored: true,
})
export class ScheduleExercise extends Model {
@PrimaryKey
@Column({
type: DataType.UUID,
defaultValue: DataType.UUIDV4,
})
declare id: string;
@ForeignKey(() => TrainingPlan)
@Column({ type: DataType.STRING, allowNull: false })
declare trainingPlanId: string;
@BelongsTo(() => TrainingPlan)
declare trainingPlan: TrainingPlan;
@Column({ type: DataType.STRING, allowNull: false })
declare userId: string;
@Column({ type: DataType.STRING, allowNull: false, comment: '项目标识key' })
declare key: string;
@Column({ type: DataType.STRING, allowNull: false, comment: '项目名称' })
declare name: string;
@Column({ type: DataType.STRING, allowNull: true, comment: '项目分类' })
declare category: string;
@Column({ type: DataType.INTEGER, allowNull: true, comment: '组数' })
declare sets: number;
@Column({ type: DataType.INTEGER, allowNull: true, comment: '重复次数' })
declare reps: number;
@Column({ type: DataType.INTEGER, allowNull: true, comment: '持续时长(秒)' })
declare durationSec: number;
@Column({ type: DataType.INTEGER, allowNull: true, comment: '休息时长(秒)' })
declare restSec: number;
@Column({ type: DataType.TEXT, allowNull: true, comment: '备注' })
declare note: string;
@Column({
type: DataType.ENUM('exercise', 'rest', 'note'),
allowNull: false,
defaultValue: 'exercise',
comment: '项目类型'
})
declare itemType: ScheduleItemType;
@Column({ type: DataType.BOOLEAN, defaultValue: false, comment: '是否已完成' })
declare completed: boolean;
@Column({ type: DataType.INTEGER, allowNull: false, comment: '排序顺序' })
declare sortOrder: number;
@Column({ type: DataType.DATE, defaultValue: DataType.NOW })
declare createdAt: Date;
@Column({ type: DataType.DATE, defaultValue: DataType.NOW })
declare updatedAt: Date;
@Column({ type: DataType.BOOLEAN, defaultValue: false, comment: '是否已删除' })
declare deleted: boolean;
}