龚焕茏
2024-07-02 8cc9559b0a1509e655acf8f939318368a1fe95d6
src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java
@@ -32,6 +32,7 @@
import com.ycl.jxkg.rabbitmq.msg.ExamStatusMsg;
import com.ycl.jxkg.rabbitmq.product.Producer;
import com.ycl.jxkg.server.WebsocketServer;
import com.ycl.jxkg.service.ExamPaperScoreService;
import com.ycl.jxkg.service.ExamPaperService;
import com.ycl.jxkg.service.ExamService;
import com.ycl.jxkg.utils.DateTimeUtil;
@@ -70,6 +71,8 @@
    private final WebsocketServer websocketServer;
    private final UserMapper userMapper;
    private final ExamPaperScoreMapper examPaperScoreMapper;
    private final ExamPaperScoreService examPaperScoreService;
    private final Producer producer;
    /**
@@ -505,9 +508,8 @@
            Date now = new Date();
            one.setExamSubmit(JSON.toJSONString(submitData.getTitleList()));
            one.setUpdateTime(now);
            long doTimeL = now.getTime() - one.getCreateTime().getTime();
            Integer doTime = (int) doTimeL;
            one.setDoTime(doTime);
            int doTimeInSeconds = (int) (now.getTime() - one.getCreateTime().getTime()) / 1000;
            one.setDoTime(doTimeInSeconds);
            one.setStatus(status);
            examSubmitTempMapper.updateById(one);
        } else {
@@ -541,7 +543,7 @@
        // 参考但未完成提交人数
        Integer joinButNotFinishedNum = Math.toIntExact(examSubmitTempList.stream().filter(item -> ExamSubmitTempStatusEnum.temp.equals(item.getStatus())).count());
        List<StudentExamInfoVO> studentExamList = classesUserMapper.getClassesUserList(exam.getClassesId());
        List<StudentExamInfoVO> studentExamList = classesUserMapper.getClassesUserList(exam.getId(), exam.getClassesId());
        // 应考人数
        Integer shouldUserNum = studentExamList.size();
@@ -656,7 +658,7 @@
                    if (StringUtils.isEmpty(doQuestionVO.getQuestionAnswer())) {
                        return Result.fail(SystemCode.InnerError.getCode(), "题目id为:" + doQuestionVO.getId() + "的题目缺少答案,请先完善");
                    }
                    trueOrFalse(score,doQuestionVO, navbarVO, doQuestionVO.getQuestionAnswer().equals(doQuestionVO.getAnswer()));
                    score = trueOrFalse(score, doQuestionVO, navbarVO, doQuestionVO.getQuestionAnswer().equals(doQuestionVO.getAnswer()));
                }
                /* 如果是多选 */
                else if (QuestionTypeEnum.MultipleChoice.getCode().equals(questionType)) {
@@ -672,7 +674,7 @@
                    List<String> questionAnswerList = Arrays.asList(questionAnswer.split(","));
                    //学生答案为空,判断为错
                    if (CollectionUtils.isEmpty(answerList)) {
                        trueOrFalse(score,doQuestionVO, navbarVO, false);
                        score = trueOrFalse(score, doQuestionVO, navbarVO, false);
                        num++;
                        navbar.add(navbarVO);
                        continue;
@@ -683,7 +685,7 @@
                    Set<String> set2 = new HashSet<>(questionAnswerList);
                    //答案完全一致,满分
                    if (set1.equals(set2)) {
                        trueOrFalse(score,doQuestionVO, navbarVO, true);
                        score = trueOrFalse(score, doQuestionVO, navbarVO, true);
                        num++;
                        navbar.add(navbarVO);
                        continue;
@@ -693,20 +695,20 @@
                    }
                    //如果多选得分类型为 答错不得分
                    if (Integer.valueOf(DeductTypeEnum.AllCorrect.getCode()).equals(paperMarkVO.getDeductType())) {
                        trueOrFalse(score,doQuestionVO, navbarVO, false);
                        score = trueOrFalse(score, doQuestionVO, navbarVO, false);
                    }
                    //如果多选得分类型为 漏选得固定分值,包含错误选项不得分
                    else if (Integer.valueOf(DeductTypeEnum.PartCorrect.getCode()).equals(paperMarkVO.getDeductType())) {
                        //学生答案移除所有正确答案,如果还有元素说明包含错误选项
                        answerList.removeAll(questionAnswerList);
                        if (!CollectionUtils.isEmpty(answerList)) {
                            trueOrFalse(score,doQuestionVO, navbarVO, false);
                            score = trueOrFalse(score, doQuestionVO, navbarVO, false);
                        } else {
                            navbarVO.setRight(false);
                            doQuestionVO.setRight(false);
                            //漏选得固定分
                            score = score.add(paperMarkVO.getDeductScore());
                            doQuestionVO.setScore(paperMarkVO.getDeductScore());
                            score = score.add(doQuestionVO.getScore());
                        }
                    }
                    //如果多选得分类型为 每对一题得相应分值,包含错误选项不得分
@@ -714,12 +716,13 @@
                        //学生答案移除所有正确答案,如果还有元素说明包含错误选项
                        answerList.removeAll(questionAnswerList);
                        if (!CollectionUtils.isEmpty(answerList)) {
                            trueOrFalse(score,doQuestionVO, navbarVO, false);
                            score = trueOrFalse(score, doQuestionVO, navbarVO, false);
                        } else {
                            navbarVO.setRight(false);
                            doQuestionVO.setRight(false);
                            //漏选得分
                            doQuestionVO.setScore(paperMarkVO.getDeductScore().multiply(new BigDecimal(answerCount)));
                            score = score.add(doQuestionVO.getScore());
                        }
                    }
                }
@@ -737,7 +740,7 @@
                    List<String> questionAnswerList = Arrays.asList(questionAnswer.split(","));
                    //学生答案为空,判断为错
                    if (CollectionUtils.isEmpty(answerList)) {
                        trueOrFalse(score,doQuestionVO, navbarVO, false);
                        score = trueOrFalse(score, doQuestionVO, navbarVO, false);
                        num++;
                        navbar.add(navbarVO);
                        continue;
@@ -746,7 +749,7 @@
                    int questionAnswerCount = questionAnswerList.size();
                    //答案完全一致,满分
                    if (answerList.equals(questionAnswerList)) {
                        trueOrFalse(score,doQuestionVO, navbarVO, true);
                        score = trueOrFalse(score, doQuestionVO, navbarVO, true);
                    } else {
                        navbarVO.setRight(false);
                        doQuestionVO.setRight(false);
@@ -764,6 +767,7 @@
                        //填空得分
                        BigDecimal gapScore = scoreEach.multiply(new BigDecimal(count));
                        doQuestionVO.setScore(gapScore);
                        score = score.add(doQuestionVO.getScore());
                    }
                }
@@ -773,11 +777,12 @@
        }
        paperMarkVO.setTitleItems(titleItems);
        paperMarkVO.setNavbar(navbar);
        paperMarkVO.setScore(score + "");
        return null;
    }
    //设置全对或全错
    private void trueOrFalse(BigDecimal score,DoQuestionVO doQuestionVO, ExamPaperMarkNavbarVO orderVO, Boolean isCorrect) {
    private BigDecimal trueOrFalse(BigDecimal score, DoQuestionVO doQuestionVO, ExamPaperMarkNavbarVO orderVO, Boolean isCorrect) {
        if (isCorrect) {
            //正确
            orderVO.setRight(isCorrect);
@@ -790,6 +795,7 @@
            doQuestionVO.setRight(isCorrect);
            doQuestionVO.setScore(BigDecimal.ZERO);
        }
        return score;
    }
    //封装阅卷返回数据
@@ -827,7 +833,7 @@
        long questionCorrect = 0;
        long questionCount = 0;
        if (!CollectionUtils.isEmpty(examPaperMark.getNavbar())) {
            questionCorrect = examPaperMark.getNavbar().stream().filter(ExamPaperMarkNavbarVO::getRight).count();
            questionCorrect = examPaperMark.getNavbar().stream().filter(vo -> vo.getRight()!=null && vo.getRight()).count();
            questionCount = examPaperMark.getNavbar().size();
        }
        examPaperScore.setQuestionCorrect(Integer.valueOf(questionCorrect + ""));