fuliqi
2024-10-17 8546b3d285af4235a0ef615a0c6e89486ae2c806
src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java
@@ -9,6 +9,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.jxkg.base.Result;
import com.ycl.jxkg.base.SystemCode;
import com.ycl.jxkg.constants.ExamScoreConstant;
import com.ycl.jxkg.context.WebContext;
import com.ycl.jxkg.domain.base.AbsVo;
import com.ycl.jxkg.domain.entity.*;
@@ -116,9 +117,8 @@
        entity.setStatus(ExamStatusEnum.getStatusByTime(form.getStartTime(), form.getEndTime(), null));
        // 如果修改成功发送mq消息
        if (baseMapper.updateById(entity) > 0) {
            this.sendMQ(entity, entity.getUpdateVersion() + 1);
            this.sendMQ(entity, entity.getUpdateVersion());
        }
        return Result.ok("修改成功");
    }
@@ -250,6 +250,10 @@
                .eq(ExamSubmitTemp::getUserId, webContext.getCurrentUser().getId())
                .one();
        if (Objects.nonNull(hasJoin)) {
            // 允许提交后继续作答
//            if(ExamSubmitTempStatusEnum.finish.equals(hasJoin.getStatus())){
//                throw new RuntimeException("您已提交试卷,请勿重复作答");
//            }
            StartExamVO startExamVO = new StartExamVO();
            startExamVO.setExamName(exam.getExamName());
            startExamVO.setId(hasJoin.getExamId());
@@ -374,6 +378,24 @@
                doQuestionVO.setQuestionType(item.getQuestionType());
                //增加题目分数
                doQuestionVO.setQuestionScore(question.getScore());
                // 题目副本
                QuestionAnswerCopyVO copy = new QuestionAnswerCopyVO();
                copy.setId(question.getId());
                copy.setAnalyze(question.getAnalyze());
                copy.setDifficult(question.getDifficult());
                //填空的答案在Json里
                if (QuestionTypeEnum.GapFilling.getCode().equals(item.getQuestionType())) {
                    List<String> gapAnswer = new ArrayList<>();
                    for (QuestionItemObject questionItemObject : question.getItems()) {
                        gapAnswer.add(questionItemObject.getContent());
                    }
                    copy.setCorrect(String.join(ANSWER_SPLIT, gapAnswer));
                } else {
                    copy.setCorrect(question.getCorrect());
                }
                questionAnswerCopyVOList.add(copy);
                // 填空题需要抹除content(因为是答案)
                if (QuestionTypeEnum.GapFilling.getCode().equals(doQuestionVO.getQuestionType())) {
                    question.getItems().stream().forEach(option -> {
@@ -384,24 +406,6 @@
                doQuestionVO.setId(question.getId());
                doQuestionVO.setOriginalFile(question.getOriginalFile());
                doQuestionVO.setAudioFile(question.getAudioFile());
                // 题目副本
                QuestionAnswerCopyVO copy = new QuestionAnswerCopyVO();
                copy.setId(question.getId());
                copy.setAnalyze(question.getAnalyze());
                copy.setDifficult(question.getDifficult());
                //填空的答案在Json里
                if (QuestionTypeEnum.GapFilling.getCode().equals(item.getQuestionType())) {
                    List<String> gapAnswer = new ArrayList<>();
                    for (QuestionItemObject questionItemObject : doQuestionVO.getQuestionItemList()) {
                        gapAnswer.add(questionItemObject.getContent());
                    }
                    copy.setCorrect(String.join(ANSWER_SPLIT, gapAnswer));
                } else {
                    copy.setCorrect(question.getCorrect());
                }
                questionAnswerCopyVOList.add(copy);
                return doQuestionVO;
            }).collect(Collectors.toList());
            if (ExamPaperTypeEnum.RandomOrder.getCode().equals(examPaper.getPaperType())) {
@@ -558,14 +562,21 @@
        for (StudentExamInfoVO studentExamInfoVO : studentExamList) {
            Integer userId = studentExamInfoVO.getUserId();
            Optional<ExamSubmitTemp> first = examSubmitTempList.stream().filter(examSubmitTemp -> examSubmitTemp.getUserId().equals(userId)).findFirst();
            if(first.isPresent()){
            if (first.isPresent()) {
                ExamSubmitTemp examSubmitTemp = first.get();
                studentExamInfoVO.setMarkPaperStatus(examSubmitTemp.getMarkPaperStatus());
                studentExamInfoVO.setStatus(examSubmitTemp.getStatus());
                studentExamInfoVO.setDoTime(examSubmitTemp.getDoTime());
            }else {
                studentExamInfoVO.setMarkPaperStatus(ExamSubmitTempStatusEnum.temp);
            } else {
                //不存在考试记录
                studentExamInfoVO.setStatus(ExamSubmitTempStatusEnum.temp);
                //根据Score表判断
                ExamPaperScore paperScore = examPaperScoreMapper.getByExamIdUserId(exam.getId(), userId);
                if(paperScore==null) {
                    studentExamInfoVO.setMarkPaperStatus(ExamSubmitTempStatusEnum.temp);
                }else {
                    studentExamInfoVO.setMarkPaperStatus(ExamSubmitTempStatusEnum.finish);
                }
                studentExamInfoVO.setDoTime(0);
            }
        }
@@ -586,20 +597,22 @@
    @Override
    public Result getMarkPaperInfo(Integer examId, Integer userId) {
        User student = userMapper.getUserById(userId);
        //如果已经阅过卷了,查成绩表
        Result<ExamPaperMarkVO> paperMarkVO1 = checkHasJudge(examId, student);
        if (paperMarkVO1 != null) return paperMarkVO1;
        ExamVO exam = examMapper.getById(examId);
        //学生答题表
        ExamSubmitTemp userExam = new LambdaQueryChainWrapper<>(examSubmitTempMapper)
                .eq(ExamSubmitTemp::getExamId, examId)
                .eq(ExamSubmitTemp::getUserId, userId)
                .one();
        if (Objects.isNull(userExam)) {
            throw new RuntimeException("该学员考试记录不存在");
            //缺考,学生没有做题信息
            ExamPaperMarkVO paperMarkVO = createVO(null, exam, student);
            return Result.ok(paperMarkVO);
        }
        //如果已经阅过卷了,查成绩表
        Result<ExamPaperMarkVO> paperMarkVO1 = checkHasJudge(examId, userId, userExam);
        if (paperMarkVO1 != null) return paperMarkVO1;
        User student = userMapper.getUserById(userId);
        ExamVO exam = examMapper.getById(examId);
        //封装阅卷基本数据
        ExamPaperMarkVO paperMarkVO = createVO(userExam, exam, student);
        List<QuestionAnswerCopyVO> answerList = JSONArray.parseArray(userExam.getQuestionAnswerCopy(), QuestionAnswerCopyVO.class);
@@ -630,16 +643,21 @@
    }
    //检查是否阅卷
    private Result<ExamPaperMarkVO> checkHasJudge(Integer examId, Integer userId, ExamSubmitTemp userExam) {
        if (ExamSubmitTempStatusEnum.finish.equals(userExam.getMarkPaperStatus())) {
            ExamPaperScore examPaperScore = examPaperScoreMapper.getByExamIdUserId(examId, userId);
    private Result<ExamPaperMarkVO> checkHasJudge(Integer examId, User student) {
        ExamPaperScore examPaperScore = examPaperScoreMapper.getByExamIdUserId(examId, student.getId());
        if (examPaperScore != null) {
            ExamPaperMarkVO paperMarkVO = new ExamPaperMarkVO();
            BeanUtils.copyProperties(examPaperScore, paperMarkVO);
            paperMarkVO.setUserName(student.getRealName());
            paperMarkVO.setTotalScore(examPaperScore.getTotalScore() + "");
            paperMarkVO.setScore(examPaperScore.getScore() + "");
            List<PaperFixQuestionVO> paperFixQuestionVOS = JSONArray.parseArray(examPaperScore.getPaperContent(), PaperFixQuestionVO.class);
            paperMarkVO.setTitleItems(paperFixQuestionVOS);
            paperMarkVO.setNavbar(JSONArray.parseArray(examPaperScore.getNavbar(), ExamPaperMarkNavbarVO.class));
            if (!StringUtils.isEmpty(examPaperScore.getPaperContent())) {
                List<PaperFixQuestionVO> paperFixQuestionVOS = JSONArray.parseArray(examPaperScore.getPaperContent(), PaperFixQuestionVO.class);
                paperMarkVO.setTitleItems(paperFixQuestionVOS);
            }
            if (!StringUtils.isEmpty(examPaperScore.getNavbar())) {
                paperMarkVO.setNavbar(JSONArray.parseArray(examPaperScore.getNavbar(), ExamPaperMarkNavbarVO.class));
            }
            return Result.ok(paperMarkVO);
        }
        return null;
@@ -817,16 +835,23 @@
    //封装阅卷返回数据
    private ExamPaperMarkVO createVO(ExamSubmitTemp userExam, ExamVO exam, User student) {
        Integer paperId = exam.getExamPaperId();
        ExamPaper examPaper = examPaperMapper.selectById(paperId);
        ExamPaperMarkVO paperMarkVO = new ExamPaperMarkVO();
        BeanUtils.copyProperties(userExam, paperMarkVO);
        paperMarkVO.setPaperId(exam.getExamPaperId());
        paperMarkVO.setExamName(exam.getExamName());
        paperMarkVO.setPaperType(exam.getExamPaperType());
        paperMarkVO.setSubmitTime(userExam.getUpdateTime());
        if (userExam != null) {
            BeanUtils.copyProperties(userExam, paperMarkVO);
            paperMarkVO.setSubmitTime(userExam.getUpdateTime());
            paperMarkVO.setTitleItems(JSON.parseArray(userExam.getExamSubmit(), PaperFixQuestionVO.class));
        } else {
            //缺考,学生没有做题信息
            paperMarkVO.setExamId(exam.getId());
            paperMarkVO.setUserId(student.getId());
            paperMarkVO.setScore(BigDecimal.ZERO + "");
            paperMarkVO.setDoTime(0);
        }
        paperMarkVO.setUserName(student.getRealName());
        paperMarkVO.setTitleItems(JSON.parseArray(userExam.getExamSubmit(), PaperFixQuestionVO.class));
        paperMarkVO.setExamName(exam.getExamName());
        paperMarkVO.setPaperId(exam.getExamPaperId());
        paperMarkVO.setPaperType(exam.getExamPaperType());
        ExamPaper examPaper = examPaperMapper.selectById(exam.getExamPaperId());
        paperMarkVO.setTotalScore(examPaper.getScore() + "");
        paperMarkVO.setDeductType(examPaper.getDeductType());
        paperMarkVO.setDeductScore(examPaper.getDeductTypeScore());
@@ -845,13 +870,24 @@
        examPaperScore.setTotalScore(new BigDecimal(examPaperMark.getTotalScore()));
        examPaperScore.setJudgeUser(userId);
        examPaperScore.setJudgeTime(new Date());
        examPaperScore.setPaperContent(JSON.toJSONString(examPaperMark.getTitleItems()));
        examPaperScore.setNavbar(JSON.toJSONString(examPaperMark.getNavbar()));
        if (!StringUtils.isEmpty(examPaperMark.getTitleItems())) {
            examPaperScore.setPaperContent(JSON.toJSONString(examPaperMark.getTitleItems()));
        }
        if (!StringUtils.isEmpty(examPaperMark.getNavbar())) {
            examPaperScore.setNavbar(JSON.toJSONString(examPaperMark.getNavbar()));
        }
        long questionCorrect = 0;
        long questionCount = 0;
        if (!CollectionUtils.isEmpty(examPaperMark.getNavbar())) {
            examPaperScore.setStatus(ExamScoreConstant.PRESENT);
            questionCorrect = examPaperMark.getNavbar().stream().filter(vo -> vo.getRight() != null && vo.getRight()).count();
            questionCount = examPaperMark.getNavbar().size();
        } else {
            //缺考查试卷配置
            Integer paperId = examPaperMark.getPaperId();
            ExamPaper examPaper = examPaperMapper.selectById(paperId);
            questionCount = examPaper.getNum();
            examPaperScore.setStatus(ExamScoreConstant.ABSENT);
        }
        examPaperScore.setQuestionCorrect(Integer.valueOf(questionCorrect + ""));
        examPaperScore.setQuestionCount(Integer.valueOf(questionCount + ""));
@@ -867,8 +903,10 @@
                    .eq(ExamSubmitTemp::getExamId, examPaperMark.getExamId())
                    .eq(ExamSubmitTemp::getUserId, examPaperMark.getUserId())
                    .one();
            userExam.setMarkPaperStatus(ExamSubmitTempStatusEnum.finish);
            examSubmitTempMapper.updateById(userExam);
            if (userExam != null) {
                userExam.setMarkPaperStatus(ExamSubmitTempStatusEnum.finish);
                examSubmitTempMapper.updateById(userExam);
            }
        }
        return Result.ok();
    }
@@ -877,32 +915,36 @@
    @Override
    public Result monitorList(ExamQuery query) {
        IPage<ExamSubmitTempVO> page = PageUtil.getPage(query, ExamSubmitTempVO.class);
        return Result.ok((examSubmitTempMapper.monitorList(page, query)));
        IPage<ExamSubmitTempVO> vo = examSubmitTempMapper.monitorList(page, query);
        return Result.ok(vo);
    }
    @Override
    public Result addTime(AddTimeForm form) {
        WebsocketDataVO websocket = new WebsocketDataVO();
        websocket.setCommend(WebsocketCommendEnum.DELAYED.getCommend());
        websocket.setData(form);
        if (! websocketServer.checkUserOnline(form.getUserId())) {
        if (!websocketServer.checkUserOnline(form.getUserId())) {
            throw new RuntimeException("该学员不在线,无法执行该操作");
        }
        WebsocketDataVO websocket = new WebsocketDataVO();
        websocket.setCommend(WebsocketCommendEnum.DELAYED.getCommand());
        BigDecimal sed = BigDecimal.valueOf(60).multiply(form.getAddTimeM());
        form.setAddTimeM(sed);
        websocket.setData(form);
        // 发送websocket消息
        websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(form));
        websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(websocket));
        return Result.ok("操作成功");
    }
    @Override
    public Result forceSubmit(ForceSubmitForm form) {
        WebsocketDataVO websocket = new WebsocketDataVO();
        websocket.setCommend(WebsocketCommendEnum.FORCE_SUBMIT.getCommend());
        websocket.setData(form);
        if (! websocketServer.checkUserOnline(form.getUserId())) {
        if (!websocketServer.checkUserOnline(form.getUserId())) {
            throw new RuntimeException("该学员不在线,无法执行该操作");
        }
        WebsocketDataVO websocket = new WebsocketDataVO();
        websocket.setCommend(WebsocketCommendEnum.FORCE_SUBMIT.getCommand());
        websocket.setData(form);
        // 发送websocket消息
        websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(form));
        websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(websocket));
        return Result.ok("操作成功");
    }
}