Version:0.1.0.dev.260205

feat: 🆕 完善course模块功能并优化批量导入接口

- 调整 task-class 模型代码并增加注释,使其更简洁易读 ✍️
- 结构调整:将课程相关接口从 schedule 分类移至独立的 course 分类 🚀
  - 修改接口 URL 从 /schedule 更改为 /course 🔄

fix: 🐛 修复批量导入课程接口重复导入相同课程的 bug
- 通过在数据库添加唯一约束解决此问题 🔐
- 这只是初步修复,后续会在 sv 层增加重复/时间冲突检测逻辑 ⚠️
- 引导用户修改课表与任务块时间冲突的机制待实现 

refactor: 🔨 重构 schedule 表单结构
- 将节次管理策略从字符串存储改为原子化存储(如 1-2 节更改为单独两条记录)
- 为后续冲突检查与智能排课做准备 🧠

perf: 🚀 优化批量导入课程接口性能
- 通过数据暂存内存中减少数据插入 MySQL 的次数 
This commit is contained in:
LoveLosita
2026-02-05 16:51:15 +08:00
parent 1bcbd41bec
commit 132b7095ac
10 changed files with 145 additions and 131 deletions

View File

@@ -3,29 +3,12 @@ package model
type Schedule struct {
ID int `gorm:"primaryKey;autoIncrement" json:"id"`
UserID int `gorm:"column:user_id;index" json:"user_id"`
Type string `gorm:"type:enum('course','task');comment:'course / task'" json:"type"`
RelID int `gorm:"column:rel_id;comment:'关联 course_id 或 task_item_id'" json:"rel_id"`
CanBeEmbedded bool `gorm:"column:can_be_embedded;comment:'是否允许嵌入水课'" json:"can_be_embedded"`
EmbeddedTaskID *uint `gorm:"column:embedded_task_id;comment:'若为水课嵌入记录任务ID'" json:"embedded_task_id"`
Week int `gorm:"column:week" json:"week"`
DayOfWeek int `gorm:"column:day_of_week" json:"day_of_week"`
Sections string `gorm:"type:varchar(255)" json:"sections"`
Status string `gorm:"type:enum('normal','interrupted');default:'normal'" json:"status"`
}
type UserImportCoursesRequest struct {
Courses []UserCheckCourseRequest `json:"courses"`
}
type UserCheckCourseRequest struct {
CourseName string `json:"course_name"`
Location string `json:"location"`
IsAllowTasks bool `json:"is_allow_tasks"`
Arrangements []struct {
StartWeek int `json:"start_week"`
EndWeek int `json:"end_week"`
DayOfWeek int `json:"day_of_week"`
StartSection int `json:"start_section"`
EndSection int `json:"end_section"`
} `json:"arrangements"`
Type string `gorm:"type:enum('course','task');comment:course / task" json:"type"`
RelID int `gorm:"column:rel_id;comment:关联 course_id 或 task_item_id" json:"rel_id"`
EmbeddedTaskID *int `gorm:"column:embedded_task_id;index;comment:若为水课嵌入记录任务ID" json:"embedded_task_id"`
Week int `gorm:"column:week;uniqueIndex:idx_user_slot_atomic,priority:2;comment:周次 (1-25)" json:"week"`
DayOfWeek int `gorm:"column:day_of_week;uniqueIndex:idx_user_slot_atomic,priority:3;comment:星期 (1-7)" json:"day_of_week"`
Section int `gorm:"column:section;uniqueIndex:idx_user_slot_atomic,priority:4;comment:原子化节次 (1-12)" json:"section"`
Status string `gorm:"type:enum('normal','interrupted');default:normal" json:"status"`
CanBeEmbedded bool `gorm:"column:can_be_embedded;not null;comment:是否允许嵌入任务" json:"can_be_embedded"`
}