This commit is contained in:
2026-06-30 11:51:34 +07:00
parent fd08bee7ab
commit 0abf48ea2d
28 changed files with 3514 additions and 37 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -225,6 +225,24 @@ func GetAllowedAppsHandler(db *gorm.DB) fiber.Handler {
studentIDStr := c.Query("studentId", "0")
studentID, _ := strconv.ParseInt(studentIDStr, 10, 64)
// Phòng thi ưu tiên hơn lịch học
if studentID > 0 {
if examInfo := internalDb.FindActiveExamForStudent(db, studentID); examInfo != nil {
keywords := strings.TrimSpace(examInfo.Room.AllowedApps)
if keywords == "" {
keywords = defaultExamAllowedApps
}
return c.JSON(fiber.Map{
"classRkId": rkID,
"keywords": keywords,
"exit": false,
"examMode": true,
"examRoomId": examInfo.Room.ID,
})
}
}
if studentID > 0 {
resolvedClassID := internalDb.FindActiveClassForStudent(db, studentID)
if resolvedClassID > 0 {

View File

@@ -109,7 +109,7 @@ func GetStudentStatusHandler(db *gorm.DB) fiber.Handler {
monitorLabel = fmt.Sprintf("Đang giám sát — Ca %d", currentPeriod)
}
}
// monitorMode = "exam" — dành cho phòng thi (sẽ bổ sung sau)
// monitorMode = "exam" — xử lý ở nhánh FindActiveExamForStudent phía trên
sessionMap := map[int]models.StudentSession{}
attMap := map[int]models.AttendanceResult{}
@@ -169,6 +169,47 @@ func GetStudentStatusHandler(db *gorm.DB) fiber.Handler {
})
}
// Ưu tiên phòng thi nếu sinh viên đang trong khung giờ thi
if examInfo := internalDb.FindActiveExamForStudent(db, studentID); examInfo != nil {
examKeywords := strings.TrimSpace(examInfo.Room.AllowedApps)
if examKeywords == "" {
examKeywords = defaultExamAllowedApps
}
paperSent := examInfo.Enrollment.PaperSentAt != nil
var subCount int64
_ = db.Model(&models.ExamSubmission{}).Where("exam_room_id = ? AND student_rk_id = ?", examInfo.Room.ID, studentID).Count(&subCount).Error
examPayload := fiber.Map{
"examRoomId": examInfo.Room.ID,
"examName": examInfo.Room.Name,
"startTime": examInfo.Room.StartTime,
"endTime": examInfo.Room.EndTime,
"quizUrl": examInfo.Room.QuizURL,
"paperSent": paperSent,
"submitted": subCount > 0,
}
if paperSent && examInfo.Paper != nil {
examPayload["paperId"] = examInfo.Paper.ID
examPayload["paperTitle"] = examInfo.Paper.Title
}
return c.JSON(fiber.Map{
"sessionDate": today,
"monitorMode": "exam",
"monitorLabel": fmt.Sprintf("Phòng thi: %s", examInfo.Room.Name),
"classRkId": classID,
"className": className,
"classCode": classCode,
"currentPeriod": 0,
"currentCourseName": "",
"currentShiftStart": "",
"currentShiftEnd": "",
"inScheduleNow": false,
"blockerActive": examKeywords != "",
"allowedKeywords": examKeywords,
"shifts": shifts,
"exam": examPayload,
})
}
return c.JSON(fiber.Map{
"sessionDate": today,
"monitorMode": monitorMode,