| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | |
| | | import com.ycl.jxkg.domain.form.ExamForm; |
| | | import com.ycl.jxkg.domain.form.ForceSubmitForm; |
| | | import com.ycl.jxkg.domain.query.ExamQuery; |
| | | import com.ycl.jxkg.domain.question.QuestionItemObject; |
| | | import com.ycl.jxkg.domain.question.QuestionObject; |
| | | import com.ycl.jxkg.domain.vo.*; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperMarkAnswerVO; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperMarkNavbarVO; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperMarkVO; |
| | | import com.ycl.jxkg.enums.DeductTypeEnum; |
| | | import com.ycl.jxkg.enums.ExamPaperTypeEnum; |
| | |
| | | import com.ycl.jxkg.enums.general.ExamSubmitTempStatusEnum; |
| | | import com.ycl.jxkg.mapper.*; |
| | | 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.PageUtil; |
| | |
| | | private final WebsocketServer websocketServer; |
| | | private final UserMapper userMapper; |
| | | private final ExamPaperScoreMapper examPaperScoreMapper; |
| | | private final ExamPaperScoreDetailMapper examPaperScoreDetailMapper; |
| | | |
| | | private final ExamPaperScoreService examPaperScoreService; |
| | | private static final String ANSWER_SPLIT = ","; |
| | | /** |
| | | * 添加 |
| | | * |
| | |
| | | startExamVO.setId(exam.getId()); |
| | | startExamVO.setSuggestTime(examPaper.getSuggestTime()); |
| | | // 试卷内容 |
| | | List<PaperFixQuestionVO> examData; |
| | | List<PaperFixQuestionVO> examData = new ArrayList<>(); |
| | | // 拿到题目副本数据 |
| | | List<QuestionAnswerCopyVO> questionAnswerCopyVOList = new ArrayList<>(32); |
| | | // 将题目转换为可临时保存的题目结构。固定试卷和随序试卷的题目是直接保存到content字段的 |
| | | if (ExamPaperTypeEnum.Fixed.getCode().equals(examPaper.getPaperType()) |
| | | || ExamPaperTypeEnum.RandomOrder.getCode().equals(examPaper.getPaperType())) { |
| | | if (StringUtils.hasText(examPaper.getContent())) { |
| | | if (!StringUtils.hasText(examPaper.getContent())) { |
| | | throw new RuntimeException("试卷题目为空"); |
| | | } |
| | | // 转换 |
| | |
| | | DoQuestionVO doQuestionVO = new DoQuestionVO(); |
| | | doQuestionVO.setTitle(item.getTitle()); |
| | | doQuestionVO.setQuestionType(item.getQuestionType()); |
| | | //从配置里拿题目分数 |
| | | doQuestionVO.setQuestionScore(paperSetting.getScore()); |
| | | if (StringUtils.hasText(item.getContent())) { |
| | | QuestionObject questionObject = JSON.parseObject(item.getContent(), QuestionObject.class); |
| | | doQuestionVO.setQuestionItemList(questionObject.getQuestionItemObjects()); |
| | |
| | | |
| | | // 题目副本 |
| | | QuestionAnswerCopyVO copy = new QuestionAnswerCopyVO(); |
| | | copy.setId(item.getId()); |
| | | copy.setDifficult(item.getDifficult()); |
| | | copy.setAnalyze(JSON.parseObject(item.getContent(), PaperQuestion.class).getAnalyze()); |
| | | copy.setCorrect(item.getCorrect()); |
| | | //填空的答案在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(item.getCorrect()); |
| | | } |
| | | questionAnswerCopyVOList.add(copy); |
| | | |
| | | return doQuestionVO; |
| | |
| | | paperFixQuestionVO.setQuestionList(childQuestions); |
| | | examData.add(paperFixQuestionVO); |
| | | } |
| | | ExamSubmitTemp examSubmitTemp = new ExamSubmitTemp(); |
| | | examSubmitTemp.setExamId(id); |
| | | examSubmitTemp.setStatus(ExamSubmitTempStatusEnum.temp); |
| | | examSubmitTemp.setExamSubmit(JSON.toJSONString(examData)); |
| | | examSubmitTemp.setCreateTime(new Date()); |
| | | examSubmitTemp.setUserId(webContext.getCurrentUser().getId()); |
| | | examSubmitTemp.setMarkPaperStatus(ExamSubmitTempStatusEnum.temp); |
| | | examSubmitTemp.setQuestionAnswerCopy(JSON.toJSONString(questionAnswerCopyVOList)); |
| | | examSubmitTempMapper.insert(examSubmitTemp); |
| | | |
| | | startExamVO.setTitleList(examData); |
| | | return Result.ok(startExamVO); |
| | | } |
| | | return Result.ok(); |
| | | ExamSubmitTemp examSubmitTemp = new ExamSubmitTemp(); |
| | | examSubmitTemp.setExamId(id); |
| | | examSubmitTemp.setStatus(ExamSubmitTempStatusEnum.temp); |
| | | examSubmitTemp.setExamSubmit(JSON.toJSONString(examData)); |
| | | examSubmitTemp.setCreateTime(new Date()); |
| | | examSubmitTemp.setUserId(webContext.getCurrentUser().getId()); |
| | | examSubmitTemp.setMarkPaperStatus(ExamSubmitTempStatusEnum.temp); |
| | | examSubmitTemp.setQuestionAnswerCopy(JSON.toJSONString(questionAnswerCopyVOList)); |
| | | examSubmitTempMapper.insert(examSubmitTemp); |
| | | startExamVO.setTitleList(examData); |
| | | return Result.ok(startExamVO); |
| | | } |
| | | |
| | | /** |
| | | * 将数据库存储的题目,转为可临时保存的题目结构 |
| | | * |
| | | * @param examPaper 试卷 |
| | | * @param examPaper 试卷 |
| | | * @param questionAnswerCopyVOList 题目副本集合 |
| | | * @return |
| | | */ |
| | |
| | | DoQuestionVO doQuestionVO = new DoQuestionVO(); |
| | | doQuestionVO.setTitle(question.getTitle()); |
| | | doQuestionVO.setQuestionType(item.getQuestionType()); |
| | | |
| | | //增加题目分数 |
| | | doQuestionVO.setQuestionScore(question.getScore()); |
| | | // 填空题需要抹除content(因为是答案) |
| | | if (QuestionTypeEnum.GapFilling.getCode().equals(doQuestionVO.getQuestionType())) { |
| | | question.getItems().stream().forEach(option -> { |
| | |
| | | |
| | | // 题目副本 |
| | | QuestionAnswerCopyVO copy = new QuestionAnswerCopyVO(); |
| | | copy.setId(question.getId()); |
| | | copy.setAnalyze(question.getAnalyze()); |
| | | copy.setCorrect(question.getCorrect()); |
| | | 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; |
| | |
| | | // 阅卷后才往exam_paper_answer保存考试成绩、以及保存到exam_paper_customer_answer |
| | | // 现在只需要保存到一张临时表 |
| | | // 该接口是主动提交,所以状态都设置为完成,以便后续老师阅卷 |
| | | //TODO |
| | | saveTempExam(submitData, ExamSubmitTempStatusEnum.finish); |
| | | |
| | | //TODO:考试状态设定为结束 |
| | | |
| | | return Result.ok(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Result timingSubmit(StartExamVO submitData) { |
| | | //TODO |
| | | saveTempExam(submitData, ExamSubmitTempStatusEnum.temp); |
| | | return Result.ok(); |
| | | } |
| | |
| | | ExamSubmitTemp one = new LambdaQueryChainWrapper<>(examSubmitTempMapper) |
| | | .eq(ExamSubmitTemp::getExamId, submitData.getId()) |
| | | .eq(ExamSubmitTemp::getUserId, webContext.getCurrentUser().getId()) |
| | | .eq(ExamSubmitTemp::getDeleted,0) |
| | | .eq(ExamSubmitTemp::getDeleted, 0) |
| | | .one(); |
| | | |
| | | if (Objects.nonNull(one)) { |
| | | long doTimeL = one.getUpdateTime().getTime() - one.getCreateTime().getTime(); |
| | | Integer doTime = (int) doTimeL; |
| | | //TODO |
| | | if (ExamSubmitTempStatusEnum.finish.equals(one.getStatus())) { |
| | | return; |
| | | } |
| | | one.setDoTime(doTime); |
| | | Date now = new Date(); |
| | | one.setExamSubmit(JSON.toJSONString(submitData.getTitleList())); |
| | | one.setUpdateTime(new Date()); |
| | | one.setUpdateTime(now); |
| | | long doTimeL = now.getTime() - one.getCreateTime().getTime(); |
| | | Integer doTime = (int) doTimeL; |
| | | one.setDoTime(doTime); |
| | | one.setStatus(status); |
| | | examSubmitTempMapper.updateById(one); |
| | | } else { |
| | |
| | | examSubmitTemp.setStatus(status); |
| | | examSubmitTemp.setUserId(webContext.getCurrentUser().getId()); |
| | | examSubmitTemp.setExamSubmit(JSON.toJSONString(submitData.getTitleList())); |
| | | //TODO |
| | | examSubmitTemp.setMarkPaperStatus(ExamSubmitTempStatusEnum.temp); |
| | | examSubmitTempMapper.insert(examSubmitTemp); |
| | | } |
| | |
| | | throw new RuntimeException("考试试卷不存在"); |
| | | } |
| | | List<ExamSubmitTemp> examSubmitTempList = new LambdaQueryChainWrapper<>(examSubmitTempMapper) |
| | | .eq(ExamSubmitTemp::getDeleted,0) |
| | | .eq(ExamSubmitTemp::getExamId, id) |
| | | .list(); |
| | | // 参考人数 |
| | | Integer joinExamNum = examSubmitTempList.size(); |
| | | // 参考但未完成提交人数 |
| | | //TODO |
| | | Integer joinButNotFinishedNum = Math.toIntExact(examSubmitTempList.stream().filter(item -> ExamSubmitTempStatusEnum.temp.equals(item.getStatus())).count()); |
| | | |
| | | List<StudentExamInfoVO> studentExamList = classesUserMapper.getClassesUserList(exam.getClassesId()); |
| | |
| | | if (Objects.isNull(userExam)) { |
| | | throw new RuntimeException("该学员考试记录不存在"); |
| | | } |
| | | ExamVO exam = examMapper.getById(examId); |
| | | //如果已经阅过卷了,查成绩表 |
| | | 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); |
| | | //TODO:补充题目答案、解析 |
| | | List<PaperFixQuestionVO> titleItems = paperMarkVO.getTitleItems(); |
| | | for (PaperFixQuestionVO titleItem : titleItems) { |
| | | for (DoQuestionVO doQuestionVO : titleItem.getQuestionList()) { |
| | | |
| | | } |
| | | } |
| | | List<QuestionAnswerCopyVO> answerList = JSONArray.parseArray(userExam.getQuestionAnswerCopy(), QuestionAnswerCopyVO.class); |
| | | //补充题目答案、解析 |
| | | addAnswer(paperMarkVO, answerList); |
| | | //阅卷,客观题打分 |
| | | Result InnerError = markPaper(paperMarkVO); |
| | | if (InnerError != null) return InnerError; |
| | | |
| | | return Result.ok(paperMarkVO); |
| | | } |
| | | //提交批改 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result submitMarkPaper(ExamPaperMarkVO examPaperMark) { |
| | | Integer userId = webContext.getCurrentUser().getId(); |
| | | //插入exam_paper_answer(成绩表) |
| | | ExamPaperScore examPaperScore = new ExamPaperScore(); |
| | | BeanUtils.copyProperties(examPaperMark,examPaperScore); |
| | | examPaperScore.setUserScore(new BigDecimal(examPaperMark.getScore())); |
| | | examPaperScore.setPaperScore(new BigDecimal(examPaperMark.getTotalScore())); |
| | | examPaperScore.setJudgeUser(userId); |
| | | examPaperScore.setCreateUser(examPaperMark.getUserId()); |
| | | examPaperScore.setAnswerTime(examPaperMark.getSubmitTime()); |
| | | examPaperScore.setPaperContent(JSON.toJSONString(examPaperMark.getTitleItems())); |
| | | long questionCorrect =0; |
| | | long questionCount=0; |
| | | if(!CollectionUtils.isEmpty(examPaperMark.getAnswers())){ |
| | | questionCorrect = examPaperMark.getAnswers().stream().filter(ExamPaperMarkAnswerVO::getRight).count(); |
| | | questionCount = examPaperMark.getAnswers().size(); |
| | | |
| | | //补充题目答案、解析 |
| | | private void addAnswer(ExamPaperMarkVO paperMarkVO, List<QuestionAnswerCopyVO> answerList) { |
| | | List<PaperFixQuestionVO> titleItems = paperMarkVO.getTitleItems(); |
| | | for (PaperFixQuestionVO titleItem : titleItems) { |
| | | for (DoQuestionVO doQuestionVO : titleItem.getQuestionList()) { |
| | | Integer questionId = doQuestionVO.getId(); |
| | | Optional<QuestionAnswerCopyVO> first = answerList.stream().filter(answer -> questionId.equals(answer.getId())).findFirst(); |
| | | if (first.isPresent()) { |
| | | QuestionAnswerCopyVO answerCopyVO = first.get(); |
| | | doQuestionVO.setQuestionAnswer(answerCopyVO.getCorrect()); |
| | | doQuestionVO.setAnalyze(answerCopyVO.getAnalyze()); |
| | | doQuestionVO.setDifficult(answerCopyVO.getDifficult()); |
| | | } |
| | | } |
| | | } |
| | | examPaperScore.setQuestionCorrect(Integer.valueOf(questionCorrect+"")); |
| | | examPaperScore.setQuestionCount(Integer.valueOf(questionCount+"")); |
| | | examPaperScoreMapper.insert(examPaperScore); |
| | | return Result.ok(); |
| | | } |
| | | |
| | | //检查是否阅卷 |
| | | private Result<ExamPaperMarkVO> checkHasJudge(Integer examId, Integer userId, ExamSubmitTemp userExam) { |
| | | if (ExamSubmitTempStatusEnum.finish.equals(userExam.getMarkPaperStatus())) { |
| | | ExamPaperScore examPaperScore = examPaperScoreMapper.getByExamIdUserId(examId, userId); |
| | | ExamPaperMarkVO paperMarkVO = new ExamPaperMarkVO(); |
| | | BeanUtils.copyProperties(examPaperScore, paperMarkVO); |
| | | 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)); |
| | | return Result.ok(paperMarkVO); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | //阅卷 |
| | | private Result markPaper(ExamPaperMarkVO paperMarkVO) { |
| | | List<PaperFixQuestionVO> titleItems = paperMarkVO.getTitleItems(); |
| | | //初始化题目序号 |
| | | Integer num = 1; |
| | | List<ExamPaperMarkAnswerVO> answers = new ArrayList<>(); |
| | | BigDecimal score = BigDecimal.ZERO; |
| | | //前端导航数组 |
| | | List<ExamPaperMarkNavbarVO> navbar = new ArrayList<>(); |
| | | //过滤掉题目为空的题目类型 |
| | | titleItems = titleItems.stream().filter(paperFixQuestionVO -> !CollectionUtils.isEmpty(paperFixQuestionVO.getQuestionList())).collect(Collectors.toList()); |
| | | |
| | | for (PaperFixQuestionVO titleItem : titleItems) { |
| | | for (DoQuestionVO doQuestionVO : titleItem.getQuestionList()) { |
| | | //准备题目序号供前端跳转使用 |
| | | ExamPaperMarkAnswerVO answerVO = new ExamPaperMarkAnswerVO(); |
| | | ExamPaperMarkNavbarVO navbarVO = new ExamPaperMarkNavbarVO(); |
| | | //获取试卷类型 |
| | | Integer questionType = doQuestionVO.getQuestionType(); |
| | | /* 如果是简答、计算、分析,不设置right只设置题目序号 */ |
| | | if (QuestionTypeEnum.ShortAnswer.getCode().equals(questionType) || QuestionTypeEnum.Calculate.getCode().equals(questionType) || QuestionTypeEnum.Analysis.getCode().equals(questionType)) { |
| | | answerVO.setItemOrder(num); |
| | | navbarVO.setItemOrder(num); |
| | | doQuestionVO.setItemOrder(num); |
| | | } |
| | | /* 如果是单选、语音、判断(判断答案是A、B) */ |
| | | else if (QuestionTypeEnum.SingleChoice.getCode().equals(questionType) || QuestionTypeEnum.Audio.getCode().equals(questionType) || QuestionTypeEnum.TrueFalse.getCode().equals(questionType)) { |
| | | answerVO.setItemOrder(num); |
| | | navbarVO.setItemOrder(num); |
| | | doQuestionVO.setItemOrder(num); |
| | | if (StringUtils.isEmpty(doQuestionVO.getQuestionAnswer())) { |
| | | return Result.fail(SystemCode.InnerError.getCode(), doQuestionVO.getTitle() + ",此题目缺少答案,请先完善"); |
| | | return Result.fail(SystemCode.InnerError.getCode(), "题目id为:" + doQuestionVO.getId() + "的题目缺少答案,请先完善"); |
| | | } |
| | | trueOrFalse(doQuestionVO, answerVO, doQuestionVO.getQuestionAnswer().equals(doQuestionVO.getAnswer())); |
| | | trueOrFalse(score,doQuestionVO, navbarVO, doQuestionVO.getQuestionAnswer().equals(doQuestionVO.getAnswer())); |
| | | } |
| | | /* 如果是多选 */ |
| | | else if (QuestionTypeEnum.MultipleChoice.getCode().equals(questionType)) { |
| | | answerVO.setItemOrder(num); |
| | | navbarVO.setItemOrder(num); |
| | | doQuestionVO.setItemOrder(num); |
| | | if (StringUtils.isEmpty(doQuestionVO.getQuestionAnswer())) { |
| | | return Result.fail(SystemCode.InnerError.getCode(), doQuestionVO.getTitle() + ",此题目缺少答案,请先完善"); |
| | | return Result.fail(SystemCode.InnerError.getCode(), "题目id为:" + doQuestionVO.getId() + "的题目缺少答案,请先完善"); |
| | | } |
| | | //学生答案 |
| | | List<String> answerList = doQuestionVO.getAnswerList(); |
| | |
| | | List<String> questionAnswerList = Arrays.asList(questionAnswer.split(",")); |
| | | //学生答案为空,判断为错 |
| | | if (CollectionUtils.isEmpty(answerList)) { |
| | | trueOrFalse(doQuestionVO, answerVO, false); |
| | | trueOrFalse(score,doQuestionVO, navbarVO, false); |
| | | num++; |
| | | navbar.add(navbarVO); |
| | | continue; |
| | | } |
| | | //答案数量,不需要考虑顺序 |
| | |
| | | Set<String> set2 = new HashSet<>(questionAnswerList); |
| | | //答案完全一致,满分 |
| | | if (set1.equals(set2)) { |
| | | trueOrFalse(doQuestionVO, answerVO, true); |
| | | trueOrFalse(score,doQuestionVO, navbarVO, true); |
| | | num++; |
| | | navbar.add(navbarVO); |
| | | continue; |
| | | } |
| | | if (paperMarkVO.getDeductType() == null) { |
| | |
| | | } |
| | | //如果多选得分类型为 答错不得分 |
| | | if (Integer.valueOf(DeductTypeEnum.AllCorrect.getCode()).equals(paperMarkVO.getDeductType())) { |
| | | trueOrFalse(doQuestionVO, answerVO, false); |
| | | trueOrFalse(score,doQuestionVO, navbarVO, false); |
| | | } |
| | | //如果多选得分类型为 漏选得固定分值,包含错误选项不得分 |
| | | else if (Integer.valueOf(DeductTypeEnum.PartCorrect.getCode()).equals(paperMarkVO.getDeductType())) { |
| | | //学生答案移除所有正确答案,如果还有元素说明包含错误选项 |
| | | answerList.removeAll(questionAnswerList); |
| | | if (!CollectionUtils.isEmpty(answerList)) { |
| | | trueOrFalse(doQuestionVO, answerVO, false); |
| | | trueOrFalse(score,doQuestionVO, navbarVO, false); |
| | | } else { |
| | | answerVO.setRight(false); |
| | | navbarVO.setRight(false); |
| | | doQuestionVO.setRight(false); |
| | | //漏选得固定分 |
| | | score = score.add(paperMarkVO.getDeductScore()); |
| | | doQuestionVO.setScore(paperMarkVO.getDeductScore()); |
| | | } |
| | | } |
| | |
| | | //学生答案移除所有正确答案,如果还有元素说明包含错误选项 |
| | | answerList.removeAll(questionAnswerList); |
| | | if (!CollectionUtils.isEmpty(answerList)) { |
| | | trueOrFalse(doQuestionVO, answerVO, false); |
| | | trueOrFalse(score,doQuestionVO, navbarVO, false); |
| | | } else { |
| | | answerVO.setRight(false); |
| | | navbarVO.setRight(false); |
| | | doQuestionVO.setRight(false); |
| | | //漏选得分 |
| | | doQuestionVO.setScore(paperMarkVO.getDeductScore().multiply(new BigDecimal(answerCount))); |
| | |
| | | } |
| | | /* 如果是填空 */ |
| | | else if (QuestionTypeEnum.GapFilling.getCode().equals(questionType)) { |
| | | answerVO.setItemOrder(num); |
| | | navbarVO.setItemOrder(num); |
| | | doQuestionVO.setItemOrder(num); |
| | | if (StringUtils.isEmpty(doQuestionVO.getQuestionAnswer())) { |
| | | return Result.fail(SystemCode.InnerError.getCode(), doQuestionVO.getTitle() + ",此题目缺少答案,请先完善"); |
| | | return Result.fail(SystemCode.InnerError.getCode(), "题目id为:" + doQuestionVO.getId() + "的题目缺少答案,请先完善"); |
| | | } |
| | | //学生答案 |
| | | List<String> answerList = doQuestionVO.getAnswerList(); |
| | |
| | | List<String> questionAnswerList = Arrays.asList(questionAnswer.split(",")); |
| | | //学生答案为空,判断为错 |
| | | if (CollectionUtils.isEmpty(answerList)) { |
| | | trueOrFalse(doQuestionVO, answerVO, false); |
| | | trueOrFalse(score,doQuestionVO, navbarVO, false); |
| | | num++; |
| | | navbar.add(navbarVO); |
| | | continue; |
| | | } |
| | | //总空的数量 |
| | | int questionAnswerCount = questionAnswerList.size(); |
| | | //答案完全一致,满分 |
| | | if (answerList.equals(questionAnswerList)) { |
| | | trueOrFalse(doQuestionVO, answerVO, true); |
| | | trueOrFalse(score,doQuestionVO, navbarVO, true); |
| | | } else { |
| | | answerVO.setRight(false); |
| | | navbarVO.setRight(false); |
| | | doQuestionVO.setRight(false); |
| | | //做对的数量,需要按顺序比较 |
| | | int count = 0; |
| | | for (int i = 0; i < answerList.size(); i++) { |
| | | if(answerList.get(i).equals(questionAnswerList.get(i))){ |
| | | if (answerList.get(i).equals(questionAnswerList.get(i))) { |
| | | count++; |
| | | } |
| | | } |
| | |
| | | BigDecimal questionScore = doQuestionVO.getQuestionScore(); |
| | | //每个空的分数 |
| | | BigDecimal scoreEach = questionScore.divide(new BigDecimal(questionAnswerCount), 1, RoundingMode.DOWN); |
| | | BigDecimal score = scoreEach.multiply(new BigDecimal(count)); |
| | | doQuestionVO.setScore(score); |
| | | //填空得分 |
| | | BigDecimal gapScore = scoreEach.multiply(new BigDecimal(count)); |
| | | doQuestionVO.setScore(gapScore); |
| | | } |
| | | |
| | | } |
| | | num++; |
| | | answers.add(answerVO); |
| | | navbar.add(navbarVO); |
| | | } |
| | | } |
| | | paperMarkVO.setAnswers(answers); |
| | | paperMarkVO.setTitleItems(titleItems); |
| | | paperMarkVO.setNavbar(navbar); |
| | | return null; |
| | | } |
| | | |
| | | //设置全对或全错 |
| | | private void trueOrFalse(DoQuestionVO doQuestionVO, ExamPaperMarkAnswerVO answerVO, Boolean isCorrect) { |
| | | private void trueOrFalse(BigDecimal score,DoQuestionVO doQuestionVO, ExamPaperMarkNavbarVO orderVO, Boolean isCorrect) { |
| | | if (isCorrect) { |
| | | //正确 |
| | | answerVO.setRight(isCorrect); |
| | | orderVO.setRight(isCorrect); |
| | | doQuestionVO.setRight(isCorrect); |
| | | doQuestionVO.setScore(doQuestionVO.getQuestionScore()); |
| | | score = score.add(doQuestionVO.getQuestionScore()); |
| | | } else { |
| | | //错误 |
| | | answerVO.setRight(isCorrect); |
| | | orderVO.setRight(isCorrect); |
| | | doQuestionVO.setRight(isCorrect); |
| | | doQuestionVO.setScore(BigDecimal.ZERO); |
| | | } |
| | |
| | | |
| | | //封装阅卷返回数据 |
| | | 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()); |
| | | //TODO: 试卷总分、(多选得分类型、多选得分分数)需要取ExamSubmitTemp |
| | | paperMarkVO.setExamName(exam.getExamName()); |
| | | paperMarkVO.setPaperType(exam.getExamPaperType()); |
| | | paperMarkVO.setSubmitTime(userExam.getUpdateTime()); |
| | | paperMarkVO.setUserName(student.getRealName()); |
| | | paperMarkVO.setTitleItems(JSON.parseArray(userExam.getExamSubmit(), PaperFixQuestionVO.class)); |
| | | paperMarkVO.setTotalScore("100"); |
| | | paperMarkVO.setDeductType(DeductTypeEnum.AllCorrect.getCode()); |
| | | paperMarkVO.setDeductScore(BigDecimal.ZERO); |
| | | paperMarkVO.setTotalScore(examPaper.getScore() + ""); |
| | | paperMarkVO.setDeductType(examPaper.getDeductType()); |
| | | paperMarkVO.setDeductScore(examPaper.getDeductTypeScore()); |
| | | return paperMarkVO; |
| | | } |
| | | |
| | | //提交批改 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result submitMarkPaper(ExamPaperMarkVO examPaperMark) { |
| | | Integer userId = webContext.getCurrentUser().getId(); |
| | | //插入exam_paper_answer(成绩表) |
| | | ExamPaperScore examPaperScore = new ExamPaperScore(); |
| | | BeanUtils.copyProperties(examPaperMark, examPaperScore); |
| | | examPaperScore.setScore(new BigDecimal(examPaperMark.getScore())); |
| | | 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())); |
| | | long questionCorrect = 0; |
| | | long questionCount = 0; |
| | | if (!CollectionUtils.isEmpty(examPaperMark.getNavbar())) { |
| | | questionCorrect = examPaperMark.getNavbar().stream().filter(ExamPaperMarkNavbarVO::getRight).count(); |
| | | questionCount = examPaperMark.getNavbar().size(); |
| | | } |
| | | examPaperScore.setQuestionCorrect(Integer.valueOf(questionCorrect + "")); |
| | | examPaperScore.setQuestionCount(Integer.valueOf(questionCount + "")); |
| | | //找之前有无批改记录 |
| | | ExamPaperScore score = examPaperScoreMapper.getByExamIdUserId(examPaperMark.getExamId(), examPaperMark.getUserId()); |
| | | if (score != null) { |
| | | examPaperScore.setId(score.getId()); |
| | | examPaperScoreMapper.updateById(examPaperScore); |
| | | } else { |
| | | examPaperScoreMapper.insert(examPaperScore); |
| | | } |
| | | return Result.ok(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Result monitorList(ExamQuery query) { |
| | | IPage<ExamSubmitTempVO> page = PageUtil.getPage(query, ExamSubmitTempVO.class); |