龚焕茏
2024-07-02 8cc9559b0a1509e655acf8f939318368a1fe95d6
src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java
@@ -30,7 +30,7 @@
import com.ycl.jxkg.enums.general.ExamSubmitTempStatusEnum;
import com.ycl.jxkg.mapper.*;
import com.ycl.jxkg.rabbitmq.msg.ExamStatusMsg;
import com.ycl.jxkg.rabbitmq.product.Product;
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;
@@ -59,6 +59,8 @@
@RequiredArgsConstructor
public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements ExamService {
    private static final String ANSWER_SPLIT = ",";
    private final ExamMapper examMapper;
    private final WebContext webContext;
    private final QuestionMapper questionMapper;
@@ -70,8 +72,8 @@
    private final UserMapper userMapper;
    private final ExamPaperScoreMapper examPaperScoreMapper;
    private final ExamPaperScoreService examPaperScoreService;
    private static final String ANSWER_SPLIT = ",";
    private final Product product;
    private final Producer producer;
    /**
     * 添加
@@ -130,20 +132,20 @@
            ingMsg.setVersion(version);
            ingMsg.setExamId(entity.getId());
            ingMsg.setTargetStatus(ExamStatusEnum.ING);
            product.examMsg(entity.getId(), JSON.toJSONString(ingMsg), DateTimeUtil.getTwoTimeDiffMS(entity.getStartTime(), new Date()));
            producer.examMsg(entity.getId(), JSON.toJSONString(ingMsg), DateTimeUtil.getTwoTimeDiffMS(entity.getStartTime(), new Date()));
            // 结束状态消息
            ExamStatusMsg finishedMsg = new ExamStatusMsg();
            finishedMsg.setVersion(version);
            finishedMsg.setExamId(entity.getId());
            finishedMsg.setTargetStatus(ExamStatusEnum.FINISHED);
            product.examMsg(entity.getId(), JSON.toJSONString(finishedMsg), DateTimeUtil.getTwoTimeDiffMS(entity.getEndTime(), new Date()));
            producer.examMsg(entity.getId(), JSON.toJSONString(finishedMsg), DateTimeUtil.getTwoTimeDiffMS(entity.getEndTime(), new Date()));
        } else if (ExamStatusEnum.ING.equals(entity.getStatus())) { // 当前是进行中状态则只需发送结束消息
            // 结束状态消息
            ExamStatusMsg finishedMsg = new ExamStatusMsg();
            finishedMsg.setVersion(0);
            finishedMsg.setExamId(entity.getId());
            finishedMsg.setTargetStatus(ExamStatusEnum.FINISHED);
            product.examMsg(entity.getId(), JSON.toJSONString(finishedMsg), DateTimeUtil.getTwoTimeDiffMS(entity.getEndTime(), new Date()));
            producer.examMsg(entity.getId(), JSON.toJSONString(finishedMsg), DateTimeUtil.getTwoTimeDiffMS(entity.getEndTime(), new Date()));
        }
    }
@@ -506,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 {
@@ -542,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();
@@ -657,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)) {
@@ -673,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;
@@ -684,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;
@@ -694,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());
                        }
                    }
                    //如果多选得分类型为 每对一题得相应分值,包含错误选项不得分
@@ -715,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());
                        }
                    }
                }
@@ -738,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;
@@ -747,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);
@@ -765,6 +767,7 @@
                        //填空得分
                        BigDecimal gapScore = scoreEach.multiply(new BigDecimal(count));
                        doQuestionVO.setScore(gapScore);
                        score = score.add(doQuestionVO.getScore());
                    }
                }
@@ -774,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);
@@ -791,6 +795,7 @@
            doQuestionVO.setRight(isCorrect);
            doQuestionVO.setScore(BigDecimal.ZERO);
        }
        return score;
    }
    //封装阅卷返回数据
@@ -828,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 + ""));