This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user