From e3e6db2d9974588f91ac1567a58fa4846655ce1b Mon Sep 17 00:00:00 2001
From: yearning <10538594+wangweifeng1999@user.noreply.gitee.com>
Date: 星期三, 30 九月 2026 12:54:55 +0800
Subject: [PATCH] 1.判断题优化;2.新增考评员是否能查看考生隐私开关

---
 backend/app/routers/attempts_router.py |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/backend/app/routers/attempts_router.py b/backend/app/routers/attempts_router.py
index c5aad61..a142374 100644
--- a/backend/app/routers/attempts_router.py
+++ b/backend/app/routers/attempts_router.py
@@ -7,6 +7,8 @@
 from app.auth import get_current_user
 from app.database import get_db
 from app.grader_scope import assert_subject_allowed
+from app.student_no import ensure_student_no, find_attempt_by_student_no
+from app.system_settings import get_or_create_settings
 from app.models import (
     ExamPaperMap,
     ExaminationExamExaminee,
@@ -20,6 +22,21 @@
 from app.schemas import AttemptDetail, PartGroup, QuestionDetail
 
 router = APIRouter(prefix="/api", tags=["attempts"])
+
+
+@router.get("/attempts/lookup/{student_no}")
+def lookup_attempt(
+    student_no: str,
+    db: Session = Depends(get_db),
+    user: User = Depends(get_current_user),
+):
+    """鏍规嵁缂栫爜鍙嶆煡绛斿嵎锛岃繑鍥� attempt_id 渚涘墠绔烦杞��"""
+    attempt = find_attempt_by_student_no(db, student_no)
+    if not attempt:
+        raise HTTPException(404, detail="缂栫爜涓嶅瓨鍦�")
+    batch = db.get(ImportBatch, attempt.import_batch_id)
+    assert_subject_allowed(db, user, batch.subject_name if batch else None)
+    return {"attempt_id": str(attempt.id)}
 
 
 @router.get("/attempts/{attempt_id}", response_model=AttemptDetail)
@@ -38,6 +55,10 @@
     examinee = db.get(ExaminationExaminee, attempt.examinee_id)
     batch = db.get(ImportBatch, attempt.import_batch_id)
     assert_subject_allowed(db, user, batch.subject_name if batch else None)
+
+    settings = get_or_create_settings(db)
+    hide_privacy = user.role == "grader" and not settings.grader_can_see_privacy
+
     pmap = db.scalar(
         select(ExamPaperMap).where(ExamPaperMap.exam_id == attempt.exam_id)
     )
@@ -84,10 +105,13 @@
             )
         )
 
+    student_no = ensure_student_no(db, attempt)
+
     return AttemptDetail(
         attempt_id=str(attempt.id),
-        examinee_name=examinee.nickname if examinee else None,
-        id_card=examinee.id_card if examinee else None,
+        student_no=student_no,
+        examinee_name=None if hide_privacy else (examinee.nickname if examinee else None),
+        id_card=None if hide_privacy else (examinee.id_card if examinee else None),
         score=attempt.score,
         paper_total_score=paper.total_score if paper else None,
         paper_name=paper.paper_name if paper else None,

--
Gitblit v1.8.0