| | |
| | | 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, |
| | |
| | | User, |
| | | ) |
| | | from app.schemas import ScoreRow, ScoresResponse |
| | | from app.system_settings import get_or_create_settings |
| | | |
| | | router = APIRouter(prefix="/api", tags=["scores"]) |
| | | |
| | |
| | | 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) |
| | |
| | | ExaminationPaperSource.id == ExamPaperMap.paper_source_id, |
| | | ) |
| | | ) |
| | | if not hide_privacy: |
| | | if name: |
| | | q = q.where(ExaminationExaminee.nickname.contains(name)) |
| | | if id_card: |
| | |
| | | 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), |
| | |
| | | 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) |