xiangpei
2024-06-26 12aa6d1bbe7b386f81731d797942b6a1ac7e3a2f
src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java
@@ -146,6 +146,12 @@
        if (Objects.isNull(exam.getExamPaperId())) {
            throw new RuntimeException("考试未绑定试卷");
        }
        if (ExamStatusEnum.NOT_START.equals(exam.getStatus())) {
            throw new RuntimeException("考试还未开始");
        }
        if (ExamStatusEnum.FINISHED.equals(exam.getStatus())) {
            throw new RuntimeException("考试已经结束");
        }
        // 查出考试试卷
        ExamPaper examPaper = examPaperMapper.selectById(exam.getExamPaperId());
        if (Objects.isNull(examPaper)) {
@@ -159,7 +165,6 @@
            }
            // 转换
            List<PaperFixQuestionVO> data = this.coverTo(examPaper);
            return Result.ok().data(data);
        } else if (ExamPaperTypeEnum.Random.getCode().equals(examPaper.getPaperType())) {
            // 根据随机试卷的配置,随机生成对应题目
@@ -167,8 +172,13 @@
                throw new RuntimeException("试卷配置异常,请联系老师");
            }
            List<PaperQuestionSettingDTO> paperSettingList = JSON.parseArray(examPaper.getContent(), PaperQuestionSettingDTO.class);
            List<DoQuestionVO> questionList = new ArrayList<>(24);
            // 试卷内容
            List<PaperFixQuestionVO> examData = new ArrayList<>(8);
            for (PaperQuestionSettingDTO paperSetting : paperSettingList) {
                PaperFixQuestionVO paperFixQuestionVO = new PaperFixQuestionVO();
                paperFixQuestionVO.setTitle(paperSetting.getTitle());
                paperFixQuestionVO.setQuestionType(paperSetting.getQuestionType());
                // 拿到课目下某类题型的x道随机题
                List<Question> questions = questionMapper.getRandomQuestion(examPaper.getSubjectId(), paperSetting.getQuestionType(), paperSetting.getNum());
                if (paperSetting.getNum() > questions.size()) {
@@ -188,8 +198,10 @@
                    doQuestionVO.setAudioFile(item.getAudioFile());
                    return doQuestionVO;
                }).collect(Collectors.toList());
                questionList.addAll(childQuestions);
                paperFixQuestionVO.setQuestionList(childQuestions);
                examData.add(paperFixQuestionVO);
            }
            return Result.ok(examData);
        }
        return Result.ok();
    }
@@ -201,6 +213,9 @@
     * @return
     */
    private List<PaperFixQuestionVO> coverTo(ExamPaper examPaper) {
        if (! StringUtils.hasText(examPaper.getContent())) {
            throw new RuntimeException("试卷未配置题目,请联系老师");
        }
        List<PaperFixQuestionDTO> questionWarpList = JSON.parseArray(examPaper.getContent(), PaperFixQuestionDTO.class);
        return questionWarpList.stream().map(item -> {
            PaperFixQuestionVO vo = new PaperFixQuestionVO();
@@ -252,6 +267,12 @@
        return Result.ok().data(vos);
    }
    /**
     * 主动提交试卷
     *
     * @param submitData 试卷做题提交数据
     * @return
     */
    @Override
    public Result examSubmit(ExamSubmitVO submitData) {
        // 校验
@@ -291,6 +312,12 @@
        return Result.ok();
    }
    /**
     * 临时保存试卷
     *
     * @param submitData
     * @return
     */
    @Override
    public Result timingSubmit(ExamSubmitVO submitData) {
        saveTempExam(submitData, ExamSubmitTempStatusEnum.TEMP);
@@ -298,7 +325,7 @@
    }
    /**
     * 保存临时试卷
     * 保存试卷:如果接口是定时保存那么是临时试卷。如果接口是自主提交那么是完成试卷
     *
     * @param submitData  前端传递的试卷数据
     * @param status  试卷的状态