src/main/java/com/mindskip/xzs/controller/student/ExamPaperAnswerController.java
@@ -87,6 +87,7 @@ + " 得分:" + scoreVm + " 耗时:" + ExamUtil.secondToVM(examPaperAnswer.getDoTime()); userEventLog.setContent(content); examPaperAnswerInfo.setTemplateId(examPaperSubmitVM.getTemplatesId()); eventPublisher.publishEvent(new CalculateExamPaperAnswerCompleteEvent(examPaperAnswerInfo)); eventPublisher.publishEvent(new UserEvent(userEventLog)); //首页随机试卷操作 src/main/java/com/mindskip/xzs/domain/ExamPaperAnswerInfo.java
@@ -7,6 +7,15 @@ public ExamPaper examPaper; public ExamPaperAnswer examPaperAnswer; public List<ExamPaperQuestionCustomerAnswer> examPaperQuestionCustomerAnswers; public Integer templateId; public Integer getTemplateId() { return templateId; } public void setTemplateId(Integer templateId) { this.templateId = templateId; } public ExamPaper getExamPaper() { return examPaper; src/main/java/com/mindskip/xzs/listener/CalculateExamPaperAnswerListener.java
@@ -60,7 +60,7 @@ examPaperAnswerService.insertByFilter(examPaperAnswer); // 最优成绩有效,其余无效 examPaperAnswerService.maxGrade(examPaperAnswer); examPaperAnswerService.maxGrade(examPaperAnswer, examPaperAnswerInfo.getTemplateId()); examPaperQuestionCustomerAnswers.stream().filter(a -> QuestionTypeEnum.needSaveTextContent(a.getQuestionType())).forEach(d -> { TextContent textContent = new TextContent(d.getAnswer(), now); src/main/java/com/mindskip/xzs/repository/ExamPaperAnswerMapper.java
@@ -77,7 +77,7 @@ * @param examPaperAnswer 答卷 * @return 最高成绩答卷 */ ExamPaperAnswer getTemplateOtherExamAnswer(ExamPaperAnswer examPaperAnswer); ExamPaperAnswer getTemplateOtherExamAnswer(@Param("examPaperAnswer") ExamPaperAnswer examPaperAnswer, @Param("templateId") Integer templateId); /** * 根据试卷id获取最高成绩答卷 src/main/java/com/mindskip/xzs/service/ExamPaperAnswerService.java
@@ -77,5 +77,5 @@ * 获取之前的成绩,取最优成绩 * @param examPaperAnswer 本次答卷 */ void maxGrade(ExamPaperAnswer examPaperAnswer); void maxGrade(ExamPaperAnswer examPaperAnswer, Integer templateId); } src/main/java/com/mindskip/xzs/service/impl/ExamPaperAnswerServiceImpl.java
@@ -404,25 +404,25 @@ } @Override public void maxGrade(ExamPaperAnswer examPaperAnswer) { // 获取某一场考试的最高成绩 public void maxGrade(ExamPaperAnswer examPaperAnswer, Integer templateId) { // 获取某一场考试曾经的最高成绩 ExamPaperAnswer maxGrade; if (Objects.equals(examPaperAnswer.getPaperType(), 7)) { maxGrade = examPaperAnswerMapper.getTemplateOtherExamAnswer(examPaperAnswer); maxGrade = examPaperAnswerMapper.getTemplateOtherExamAnswer(examPaperAnswer, templateId); } else { maxGrade = examPaperAnswerMapper.getPaperOtherExamAnswer(examPaperAnswer); } if (Objects.isNull(maxGrade)) { return; } // 本次不是最高分 if (!Objects.equals(maxGrade.getId(), examPaperAnswer.getId())) { // 本次考试分数不如之前,本次无效 if (maxGrade.getUserScore() > examPaperAnswer.getUserScore()) { // 之前的成绩有效 maxGrade.setInvalid(AnswerInvalidEnum.VALID); examPaperAnswerMapper.updateByPrimaryKey(maxGrade); examPaperAnswerMapper.updateByPrimaryKeySelective(maxGrade); // 本次的不是最高分,无效 examPaperAnswer.setInvalid(AnswerInvalidEnum.INVALID); examPaperAnswerMapper.updateByPrimaryKey(examPaperAnswer); examPaperAnswerMapper.updateByPrimaryKeySelective(examPaperAnswer); } } src/main/resources/mapper/ExamPaperAnswerMapper.xml
@@ -209,6 +209,9 @@ <if test="taskExamId != null"> task_exam_id = #{taskExamId,jdbcType=INTEGER}, </if> <if test="invalid != null"> invalid = #{invalid}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> @@ -659,14 +662,13 @@ <select id="getTemplateOtherExamAnswer" resultType="com.mindskip.xzs.domain.ExamPaperAnswer"> SELECT id, user_score FROM t_exam_paper_answer WHERE exam_paper_id IN (SELECT exam_paper_id FROM t_exam_templates_user_count WHERE user_id = #{createUser} AND exam_templates_id = (SELECT exam_templates_id FROM t_exam_templates_user_count WHERE exam_paper_id = #{examPaperId} LIMIT 1)) HAVING MAX(user_score) ORDER BY create_time DESC LIMIT 1 (SELECT exam_paper_id FROM t_exam_templates_user_count WHERE user_id = #{examPaperAnswer.createUser} AND exam_templates_id = #{templateId}) ORDER BY user_score DESC LIMIT 1 </select> <select id="getPaperOtherExamAnswer" resultType="com.mindskip.xzs.domain.ExamPaperAnswer"> SELECT id, user_score FROM t_exam_paper_answer WHERE exam_paper_id = #{examPaperId} AND create_user = #{createUser} HAVING MAX(user_score) ORDER BY create_time DESC LIMIT 1 ORDER BY user_score DESC LIMIT 1 </select> </mapper>