From 526745df87b382366960df1c765b83a84d493019 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期三, 03 七月 2024 16:23:23 +0800 Subject: [PATCH] 随机试卷增加维度 --- src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java | 128 +++++++++++++++++++++++++----------------- 1 files changed, 75 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java b/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java index f89bf62..bd7cc38 100644 --- a/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java +++ b/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; @@ -13,6 +14,7 @@ import com.ycl.jxkg.domain.exam.PaperFixQuestionDTO; import com.ycl.jxkg.domain.exam.PaperQuestion; import com.ycl.jxkg.domain.exam.PaperQuestionSettingDTO; +import com.ycl.jxkg.domain.exam.PaperSettingItem; import com.ycl.jxkg.domain.form.AddTimeForm; import com.ycl.jxkg.domain.form.ExamForm; import com.ycl.jxkg.domain.form.ForceSubmitForm; @@ -32,6 +34,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; @@ -71,7 +74,6 @@ private final UserMapper userMapper; private final ExamPaperScoreMapper examPaperScoreMapper; private final ExamPaperScoreService examPaperScoreService; - private static final String ANSWER_SPLIT = ","; private final Producer producer; @@ -106,7 +108,7 @@ // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); // 鍒ゆ柇鑰冭瘯鐘舵�� - if (! ExamStatusEnum.NOT_START.equals(entity.getStatus())) { + if (!ExamStatusEnum.NOT_START.equals(entity.getStatus())) { throw new RuntimeException("鍙兘淇敼杩樻湭寮�濮嬬殑鑰冭瘯"); } BeanUtils.copyProperties(form, entity); @@ -121,7 +123,7 @@ /** * 鍙戦�乵q娑堟伅 * - * @param entity 鑰冭瘯瀹炰綋绫� + * @param entity 鑰冭瘯瀹炰綋绫� * @param version 涔愯閿佺増鏈� */ public void sendMQ(Exam entity, Integer version) { @@ -282,50 +284,58 @@ 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()) { - throw new RuntimeException("閰嶇疆鐨勯鐩暟涓嶈冻浠ョ敓鎴愯瘯鍗�"); - } - - // 鎷垮埌棰樼洰鍚庣粍瑁呬负鍙复鏃朵繚瀛樼殑棰樼洰缁撴瀯 - List<DoQuestionVO> childQuestions = questions.stream().map(item -> { - 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()); + //涓�涓被鍨嬬殑棰樼洰list + List<DoQuestionVO> childQuestionList = new ArrayList<>(); + List<PaperSettingItem> settingList = paperSetting.getSettingList(); + for (PaperSettingItem settingItem : settingList) { + Integer num = settingItem.getNum(); + Integer difficult = settingItem.getDifficult(); + //闇�瑕侀厤缃殑棰樼洰鏁伴噺涓�0鍒欒烦杩� + if (num == null || num == 0) continue; + List<Question> questions = questionMapper.getRandomQuestion(settingItem.getSubjectId(), paperSetting.getQuestionType(), difficult, settingItem.getNum()); + if (org.springframework.util.CollectionUtils.isEmpty(questions) || settingItem.getNum() > questions.size()) { + throw new RuntimeException("閰嶇疆鐨勯鐩暟涓嶈冻浠ョ敓鎴愯瘯鍗�"); } - doQuestionVO.setId(item.getId()); - doQuestionVO.setOriginalFile(item.getOriginalFile()); - doQuestionVO.setAudioFile(item.getAudioFile()); - - // 棰樼洰鍓湰 - QuestionAnswerCopyVO copy = new QuestionAnswerCopyVO(); - copy.setId(item.getId()); - copy.setDifficult(item.getDifficult()); - copy.setAnalyze(JSON.parseObject(item.getContent(), PaperQuestion.class).getAnalyze()); - //濉┖鐨勭瓟妗堝湪Json閲� - if (QuestionTypeEnum.GapFilling.getCode().equals(item.getQuestionType())) { - List<String> gapAnswer = new ArrayList<>(); - for (QuestionItemObject questionItemObject : doQuestionVO.getQuestionItemList()) { - gapAnswer.add(questionItemObject.getContent()); + // 鎷垮埌棰樼洰鍚庣粍瑁呬负鍙复鏃朵繚瀛樼殑棰樼洰缁撴瀯 + List<DoQuestionVO> childQuestions = questions.stream().map(item -> { + DoQuestionVO doQuestionVO = new DoQuestionVO(); + doQuestionVO.setQuestionType(item.getQuestionType()); + //浠庨厤缃噷鎷块鐩垎鏁� + doQuestionVO.setQuestionScore(settingItem.getScore()); + if (StringUtils.hasText(item.getContent())) { + QuestionObject questionObject = JSON.parseObject(item.getContent(), QuestionObject.class); + doQuestionVO.setQuestionItemList(questionObject.getQuestionItemObjects()); + doQuestionVO.setTitle(questionObject.getTitleContent()); } - copy.setCorrect(String.join(ANSWER_SPLIT, gapAnswer)); - } else { - copy.setCorrect(item.getCorrect()); - } - questionAnswerCopyVOList.add(copy); + doQuestionVO.setId(item.getId()); + doQuestionVO.setOriginalFile(item.getOriginalFile()); + doQuestionVO.setAudioFile(item.getAudioFile()); - return doQuestionVO; - }).collect(Collectors.toList()); - paperFixQuestionVO.setQuestionList(childQuestions); + // 棰樼洰鍓湰 + QuestionAnswerCopyVO copy = new QuestionAnswerCopyVO(); + copy.setId(item.getId()); + copy.setDifficult(item.getDifficult()); + copy.setAnalyze(JSON.parseObject(item.getContent(), PaperQuestion.class).getAnalyze()); + //濉┖鐨勭瓟妗堝湪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; + }).collect(Collectors.toList()); + //娣诲姞鍒拌繖涓被鍨嬬殑list涓� + childQuestionList.addAll(childQuestions); + } + paperFixQuestionVO.setQuestionList(childQuestionList); examData.add(paperFixQuestionVO); } - return Result.ok(startExamVO); } ExamSubmitTemp examSubmitTemp = new ExamSubmitTemp(); examSubmitTemp.setExamId(id); @@ -470,9 +480,6 @@ // 鐜板湪鍙渶瑕佷繚瀛樺埌涓�寮犱复鏃惰〃 // 璇ユ帴鍙f槸涓诲姩鎻愪氦锛屾墍浠ョ姸鎬侀兘璁剧疆涓哄畬鎴愶紝浠ヤ究鍚庣画鑰佸笀闃呭嵎 saveTempExam(submitData, ExamSubmitTempStatusEnum.finish); - - //TODO:鑰冭瘯鐘舵�佽瀹氫负缁撴潫 - return Result.ok(); } @@ -535,7 +542,7 @@ throw new RuntimeException("鑰冭瘯璇曞嵎涓嶅瓨鍦�"); } List<ExamSubmitTemp> examSubmitTempList = new LambdaQueryChainWrapper<>(examSubmitTempMapper) - .eq(ExamSubmitTemp::getDeleted,0) + .eq(ExamSubmitTemp::getDeleted, 0) .eq(ExamSubmitTemp::getExamId, id) .list(); // 鍙傝�冧汉鏁� @@ -543,15 +550,23 @@ // 鍙傝�冧絾鏈畬鎴愭彁浜や汉鏁� Integer joinButNotFinishedNum = Math.toIntExact(examSubmitTempList.stream().filter(item -> ExamSubmitTempStatusEnum.temp.equals(item.getStatus())).count()); - List<StudentExamInfoVO> studentExamList = classesUserMapper.getClassesUserList(exam.getId(), exam.getClassesId()); + List<StudentExamInfoVO> studentExamList = classesUserMapper.getClassesUserList(exam.getClassesId()); // 搴旇�冧汉鏁� Integer shouldUserNum = studentExamList.size(); - - studentExamList.stream().forEach(item -> { - if (StringUtils.hasText(item.getExamSubmit())) { - item.setQuestionList(JSON.parseArray(item.getExamSubmit(), DoQuestionVO.class)); + for (StudentExamInfoVO studentExamInfoVO : studentExamList) { + Integer userId = studentExamInfoVO.getUserId(); + Optional<ExamSubmitTemp> first = examSubmitTempList.stream().filter(examSubmitTemp -> examSubmitTemp.getUserId().equals(userId)).findFirst(); + if(first.isPresent()){ + ExamSubmitTemp examSubmitTemp = first.get(); + studentExamInfoVO.setMarkPaperStatus(examSubmitTemp.getMarkPaperStatus()); + studentExamInfoVO.setStatus(examSubmitTemp.getStatus()); + studentExamInfoVO.setDoTime(examSubmitTemp.getDoTime()); + }else { + studentExamInfoVO.setMarkPaperStatus(ExamSubmitTempStatusEnum.temp); + studentExamInfoVO.setStatus(ExamSubmitTempStatusEnum.temp); + studentExamInfoVO.setDoTime(0); } - }); + } MarkPaperVO markPaperVO = new MarkPaperVO(); markPaperVO.setExamName(exam.getExamName()); @@ -833,7 +848,7 @@ long questionCorrect = 0; long questionCount = 0; if (!CollectionUtils.isEmpty(examPaperMark.getNavbar())) { - questionCorrect = examPaperMark.getNavbar().stream().filter(vo -> vo.getRight()!=null && vo.getRight()).count(); + questionCorrect = examPaperMark.getNavbar().stream().filter(vo -> vo.getRight() != null && vo.getRight()).count(); questionCount = examPaperMark.getNavbar().size(); } examPaperScore.setQuestionCorrect(Integer.valueOf(questionCorrect + "")); @@ -845,6 +860,13 @@ examPaperScoreMapper.updateById(examPaperScore); } else { examPaperScoreMapper.insert(examPaperScore); + //淇敼鑰冭瘯閲岃瘯鍗风姸鎬佷负宸查槄鍗� + ExamSubmitTemp userExam = new LambdaQueryChainWrapper<>(examSubmitTempMapper) + .eq(ExamSubmitTemp::getExamId, examPaperMark.getExamId()) + .eq(ExamSubmitTemp::getUserId, examPaperMark.getUserId()) + .one(); + userExam.setMarkPaperStatus(ExamSubmitTempStatusEnum.finish); + examSubmitTempMapper.updateById(userExam); } return Result.ok(); } -- Gitblit v1.8.0