Преглед на файлове

已做题加载已有答案

mingfu преди 1 седмица
родител
ревизия
9a2560e427
променени са 1 файла, в които са добавени 26 реда и са изтрити 25 реда
  1. 26 25
      ie-admin/src/main/java/com/ruoyi/web/service/ExamService.java

+ 26 - 25
ie-admin/src/main/java/com/ruoyi/web/service/ExamService.java

@@ -5,13 +5,11 @@ import com.alibaba.fastjson2.util.DateUtils;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
-import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.enums.ExamType;
 import com.ruoyi.common.enums.UserRegStatus;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.dz.service.IDzSubjectService;
-import com.ruoyi.dz.service.impl.DzSubjectServiceImpl;
 import com.ruoyi.enums.*;
 import com.ruoyi.ie.domain.AMarjorPlan;
 import com.ruoyi.ie.service.IAMarjorPlanService;
@@ -21,7 +19,6 @@ import com.ruoyi.learn.service.ILearnPaperService;
 import com.ruoyi.learn.service.ILearnPlanService;
 import com.ruoyi.mxjb.domain.MxjbContants;
 import com.ruoyi.system.service.ISysUserService;
-import io.swagger.annotations.ApiModelProperty;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
@@ -134,15 +131,10 @@ public class ExamService {
         } else if(ExamineeStatus.Exam.getVal().equals(examinee.getState())) {
             throw new RuntimeException("考试中,不能提取答案");
         }
-        LearnAnswer aCond = new LearnAnswer();
-        aCond.setExamineeId(examineeId);
-        Map<Long, LearnAnswer> answerMap = learnAnswerMapper.selectLearnAnswerList(aCond).stream().collect(Collectors.toMap(LearnAnswer::getQuestionId, t -> t));
         LearnPaper learnPaper = learnPaperService.selectLearnPaperById(examinee.getPaperId());
-        List<PaperVO.QuestionAnswer> questionList = paperService.loadPaperQuestionAnswers(SecurityUtils.getUserId(), examinee.getPaperId(), answerMap, !examContinue);
-        AnswerSheet answerSheet = buildAnswerSheet(learnPaper, examinee);
+        AnswerSheet answerSheet = buildAnswerSheet(learnPaper, examinee, loadQuestionAnswers(examinee, examContinue));
         answerSheet.setTotalCount(learnPaper.getNumber());
         answerSheet.setWrongCount(examinee.getWrongCount());
-        answerSheet.setQuestions(questionList);
 
         if(null != examinee.getPaperInfo()) {
             JSONObject info = JSONObject.parseObject(examinee.getPaperInfo());
@@ -159,6 +151,14 @@ public class ExamService {
         return answerSheet;
     }
 
+    private List<PaperVO.QuestionAnswer> loadQuestionAnswers(LearnExaminee examinee, boolean examContinue) {
+        LearnAnswer aCond = new LearnAnswer();
+        aCond.setExamineeId(examinee.getExamineeId());
+        Map<Long, LearnAnswer> answerMap = learnAnswerMapper.selectLearnAnswerList(aCond).stream().collect(Collectors.toMap(LearnAnswer::getQuestionId, t -> t));
+        List<PaperVO.QuestionAnswer> questionList = paperService.loadPaperQuestionAnswers(SecurityUtils.getUserId(), examinee.getPaperId(), answerMap, !examContinue);
+        return questionList;
+    }
+
     /**
      * 交卷
      * @param answerSheet
@@ -373,8 +373,11 @@ public class ExamService {
         learnExaminee.setPaperType(paperType.getVal());
         learnExaminee.setState(ExamineeStatus.Exam.getVal());
         List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(learnExaminee);
+
+        List<PaperVO.QuestionAnswer> questionAnswerList = null;
         if (CollectionUtils.isNotEmpty(examineeList)) {
             learnExaminee = examineeList.get(0);
+            questionAnswerList = loadQuestionAnswers(learnExaminee, true);
         } else {
             if(StringUtils.isNotBlank(ts.getDirectKey())) { // 全量,只分科目
                 LearnStudent ls = learnStudentMapper.selectLearnStudentByStudentId(ts.getStudentId());
@@ -386,7 +389,7 @@ public class ExamService {
             learnExaminee.setDuration(0L);
             examineeMapper.insertLearnExaminee(learnExaminee);
         }
-        return buildAnswerSheet(paper, learnExaminee);
+        return buildAnswerSheet(paper, learnExaminee, questionAnswerList);
     }
 
     private AnswerSheet openExaminee(PaperType paperType, Long paperId, Long studentId) {
@@ -398,15 +401,17 @@ public class ExamService {
         learnExaminee.setPaperType(paperType.getVal());
         learnExaminee.setState(ExamineeStatus.Exam.getVal());
         List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(learnExaminee);
+        List<PaperVO.QuestionAnswer> questionAnswerList = null;
         if (CollectionUtils.isNotEmpty(examineeList)) {
             learnExaminee = examineeList.get(0);
+            questionAnswerList = loadQuestionAnswers(learnExaminee, true);
         } else {
             learnExaminee.setState(ExamineeStatus.Exam.getVal());
             learnExaminee.setBeginTime(new Date());
             learnExaminee.setDuration(0L);
             examineeMapper.insertLearnExaminee(learnExaminee);
         }
-        return buildAnswerSheet(paper, learnExaminee);
+        return buildAnswerSheet(paper, learnExaminee, questionAnswerList);
     }
     @Transactional
     public AnswerSheet openExamineeForTest(LearnTestStudent ts, SysUser sysUser) {
@@ -440,7 +445,7 @@ public class ExamService {
         for(LearnExaminee e : examineeList) {
             if(ExamineeStatus.Sign.getVal().equals(e.getState())) {
                 LearnPaper learnPaper = paperMapper.selectLearnPaperById(e.getPaperId());
-                return buildAnswerSheet(learnPaper, e);
+                return buildAnswerSheet(learnPaper, e, loadQuestionAnswers(e, true));
             }
             existPaperIdSet.add(e.getPaperId());
         }
@@ -458,7 +463,7 @@ public class ExamService {
         sysUserService.updateUserProfile(upUser);
 
         examinee.setPaperInfo(buildPaperInfo(ls, plan));
-        AnswerSheet answerSheet = openExamineeByPaper(examinee, paper);
+        AnswerSheet answerSheet = openNewExamineeByPaper(examinee, paper);
         answerSheet.setCollegeId(ls.getUniversityId());
         answerSheet.setCollegeName(plan.getUniversityName());
         answerSheet.setMajorId(ls.getMajorPlanId());
@@ -474,16 +479,16 @@ public class ExamService {
         List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(examinee);
         LearnPaper learnPaper = paperMapper.selectLearnPaperById(paperId);
         if(CollectionUtils.isNotEmpty(examineeList)) {
-            return buildAnswerSheet(learnPaper, examineeList.get(0));
+            return buildAnswerSheet(learnPaper, examineeList.get(0), loadQuestionAnswers(examinee, true));
         }
-        return openExamineeByPaper(examinee, learnPaper);
+        return openNewExamineeByPaper(examinee, learnPaper);
     }
-    private AnswerSheet openExamineeByPaper(LearnExaminee examinee, LearnPaper paper) {
+    private AnswerSheet openNewExamineeByPaper(LearnExaminee examinee, LearnPaper paper) {
         examinee.setPaperId(paper.getId());
         examinee.setState(ExamineeStatus.Sign.getVal());
         examinee.setDuration(0L);
         examineeMapper.insertLearnExaminee(examinee);
-        AnswerSheet answerSheet = buildAnswerSheet(paper, examinee);
+        AnswerSheet answerSheet = buildAnswerSheet(paper, examinee, null);
         answerSheet.setSubjectId(paper.getSubjectId());
         answerSheet.setSubjectName(dzSubjectService.selectDzSubjectBySubjectId(paper.getSubjectId()).getSubjectName());
         return answerSheet;
@@ -549,12 +554,7 @@ public class ExamService {
             List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(learnExaminee);
             if (CollectionUtils.isNotEmpty(examineeList) && ExamineeStatus.Exam.getVal().equals(examineeList.get(0).getState())) {
                 LearnExaminee examinee = examineeList.get(0);
-                LearnAnswer aCond = new LearnAnswer();
-                aCond.setExamineeId(examinee.getExamineeId());
-                Map<Long, LearnAnswer> answerMap = learnAnswerMapper.selectLearnAnswerList(aCond).stream().collect(Collectors.toMap(LearnAnswer::getQuestionId, t -> t));
-                List<PaperVO.QuestionAnswer> questionList = paperService.loadPaperQuestionAnswers(SecurityUtils.getUserId(), examinee.getPaperId(), answerMap, true);
-                AnswerSheet answerSheet = buildAnswerSheet(existPaper, examinee);
-                answerSheet.setQuestions(questionList);
+                AnswerSheet answerSheet = buildAnswerSheet(existPaper, examinee, loadQuestionAnswers(examinee, true));
                 answerSheet.setKnowledgeId(existPaper.getRelateId());
                 return answerSheet;
             }
@@ -596,7 +596,7 @@ public class ExamService {
         }
         examineeMapper.insertLearnExaminee(learnExaminee);
 
-        AnswerSheet answerSheet = buildAnswerSheet(paper, learnExaminee);
+        AnswerSheet answerSheet = buildAnswerSheet(paper, learnExaminee, null);
         List<PaperVO.QuestionAnswer> questionList = paperService.loadPaperQuestionAnswers(SecurityUtils.getUserId(), paper.getId(), null, true);
         answerSheet.setQuestions(questionList);
         answerSheet.setKnowledgeId(paper.getRelateId());
@@ -681,7 +681,7 @@ public class ExamService {
         throw new ValidationException("未初始化院校定向模拟题库: " + subjectId + ":" + plan.getId());
     }
 
-    private AnswerSheet buildAnswerSheet(LearnPaper paper, LearnExaminee examinee) {
+    private AnswerSheet buildAnswerSheet(LearnPaper paper, LearnExaminee examinee, List<PaperVO.QuestionAnswer> questionList) {
         AnswerSheet answerSheet = new AnswerSheet();
         answerSheet.setExamineeId(examinee.getExamineeId());
         answerSheet.setPaperId(examinee.getPaperId());
@@ -709,6 +709,7 @@ public class ExamService {
             answerSheet.setSubjectId(paper.getSubjectId());
             answerSheet.setSubjectName(dzSubjectService.selectDzSubjectBySubjectId(paper.getSubjectId()).getSubjectName());
         }
+        answerSheet.setQuestions(questionList);
         return answerSheet;
     }
 }