fix
All checks were successful
Deploy on Master Change / deploy (push) Successful in 53s

This commit is contained in:
2026-07-03 17:59:02 +07:00
parent 0fa4a9aae2
commit 96391b0706
13 changed files with 10448 additions and 100 deletions

View File

@@ -45,6 +45,7 @@ func FindActiveClassAndPeriodForStudent(db *gorm.DB, studentRkID int64) (int64,
var schedules []models.ClassSchedule
if err := db.Where("class_rk_id IN ? AND is_active = ?", classRkIDs, true).Find(&schedules).Error; err != nil || len(schedules) == 0 {
// Không có lớp nào có lịch học → trả về lớp đầu tiên
return classRkIDs[0], 1
}
@@ -52,6 +53,7 @@ func FindActiveClassAndPeriodForStudent(db *gorm.DB, studentRkID int64) (int64,
day := scheduleDayIndex(now)
currMin := now.Hour()*60 + now.Minute()
// Ưu tiên 1: Lớp có ca đang diễn ra ngay lúc này
for _, s := range schedules {
if s.DayOfWeek != day {
continue
@@ -67,6 +69,18 @@ func FindActiveClassAndPeriodForStudent(db *gorm.DB, studentRkID int64) (int64,
}
}
// Ưu tiên 2: Fallback về lớp đầu tiên CÓ lịch học (ưu tiên hơn lớp chỉ có allowed_apps)
// Lấy tập hợp các class có schedules
scheduledClassSet := map[int64]bool{}
for _, s := range schedules {
scheduledClassSet[s.ClassRkID] = true
}
for _, id := range classRkIDs {
if scheduledClassSet[id] {
return id, 1
}
}
return classRkIDs[0], 1
}