yearning
19 小时以前 e3e6db2d9974588f91ac1567a58fa4846655ce1b
backend/app/routers/scores_router.py
@@ -5,6 +5,7 @@
from app.auth import get_current_user
from app.database import get_db
from app.grader_scope import allowed_subjects_for_user, apply_subject_scope
from app.student_no import ensure_student_no
from app.models import (
    ExamPaperMap,
    ExaminationExamExaminee,
@@ -14,6 +15,7 @@
    User,
)
from app.schemas import ScoreRow, ScoresResponse
from app.system_settings import get_or_create_settings
router = APIRouter(prefix="/api", tags=["scores"])
@@ -43,12 +45,17 @@
    allowed = allowed_subjects_for_user(db, user)
    if subject and allowed is not None and subject not in allowed:
        raise HTTPException(403, detail="无权查看该科目")
    settings = get_or_create_settings(db)
    hide_privacy = user.role == "grader" and not settings.grader_can_see_privacy
    q = (
        select(
            ExaminationExamExaminee,
            ExaminationExaminee,
            ImportBatch.subject_name,
            ExaminationPaperSource.paper_name,
            ExaminationPaperSource.id,
        )
        .join(ExaminationExaminee, ExaminationExaminee.id == ExaminationExamExaminee.examinee_id)
        .join(ImportBatch, ImportBatch.id == ExaminationExamExaminee.import_batch_id)
@@ -58,6 +65,7 @@
            ExaminationPaperSource.id == ExamPaperMap.paper_source_id,
        )
    )
    if not hide_privacy:
    if name:
        q = q.where(ExaminationExaminee.nickname.contains(name))
    if id_card:
@@ -77,8 +85,9 @@
    items = [
        ScoreRow(
            examinee_id=str(ex.examinee_id),
            name=ee.nickname,
            id_card=ee.id_card,
            student_no=ensure_student_no(db, ex),
            name=None if hide_privacy else ee.nickname,
            id_card=None if hide_privacy else ee.id_card,
            subject_name=sn,
            score=ex.score,
            attempt_id=str(ex.id),
@@ -87,6 +96,6 @@
            start_time=ex.start_time,
            end_time=ex.end_time,
        )
        for ex, ee, sn, pn in rows
        for ex, ee, sn, pn, ps_id in rows
    ]
    return ScoresResponse(total=total, page=page, page_size=page_size, items=items)