yangfeng пре 1 година
родитељ
комит
7d615f2a49

+ 17 - 0
web/src/main/java/com/ynfy/buss/exam/exam/service/IExamService.java

@@ -7,9 +7,11 @@ import com.ynfy.buss.exam.exam.dto.UserExamDTO;
 import com.ynfy.buss.exam.exam.entity.Exam;
 import com.ynfy.buss.exam.question.entity.Question;
 import com.ynfy.buss.exam.userexam.entity.UserExam;
+import com.ynfy.buss.exam.userexamquestion.entity.UserExamQuestion;
 import org.jeecg.common.system.vo.LoginUser;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: exam
@@ -142,4 +144,19 @@ public interface IExamService extends IService<Exam> {
      * @return
      */
     Integer getExamState(Exam exam);
+
+    /**
+     * 根据题目序号中获取考题
+     *
+     * @param index
+     * @param userExamQuestionMap
+     * @return
+     */
+    UserExamQuestion getUserExamQuestionByIndex(String index, Map<Integer, UserExamQuestion> userExamQuestionMap);
+
+    //组装题目、子题目和答案
+    void assembleUserExamQuestion(String userExamId, List<UserExamQuestion> rootExamQuestionList,
+                                  List<UserExamQuestion> childQuestionList, boolean needAnswerFlag,
+                                  boolean needAnalysis, boolean needPathScore, boolean needSubjective,
+                                  boolean needClearBlankContent);
 }

+ 27 - 12
web/src/main/java/com/ynfy/buss/exam/exam/service/impl/ExamServiceImpl.java

@@ -659,6 +659,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
     }
 
     //组装题目、子题目和答案
+    @Override
     public void assembleUserExamQuestion(String userExamId, List<UserExamQuestion> rootExamQuestionList,
                                          List<UserExamQuestion> childQuestionList, boolean needAnswerFlag,
                                          boolean needAnalysis, boolean needPathScore, boolean needSubjective,
@@ -842,18 +843,8 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
      * @param userExamQuestionMap
      */
     public void calcQuestionScoreByType(ExamAnswerDTO o, Map<Integer, UserExamQuestion> userExamQuestionMap) {
-        UserExamQuestion userExamQuestion = null;
-        if (o.getIndex().indexOf(".") != -1) {
-            //获取子题目
-            String[] indexArray = o.getIndex().split("\\.");
-            UserExamQuestion userExamRootQuestion = userExamQuestionMap.get(Integer.parseInt(indexArray[0]));
-            if (!Objects.isNull(userExamRootQuestion)) {
-                userExamQuestion = userExamRootQuestion.getSubQuestionList().stream().filter(item -> item.getQuestionIndex()
-                        .equals(Integer.parseInt(indexArray[1]))).findFirst().orElse(null);
-            }
-        } else {
-            userExamQuestion = userExamQuestionMap.get(Integer.parseInt(o.getIndex()));
-        }
+        //根据题目序号中获取考题
+        UserExamQuestion userExamQuestion = getUserExamQuestionByIndex(o.getIndex(), userExamQuestionMap);
         if (Objects.isNull(userExamQuestion)) {
             return;
         }
@@ -896,6 +887,30 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
         }
     }
 
+    /**
+     * 根据题目序号中获取考题
+     *
+     * @param index               题目序号
+     * @param userExamQuestionMap 考题
+     * @return
+     */
+    @Override
+    public UserExamQuestion getUserExamQuestionByIndex(String index, Map<Integer, UserExamQuestion> userExamQuestionMap) {
+        UserExamQuestion userExamQuestion = null;
+        if (index.indexOf(".") != -1) {
+            //获取子题目
+            String[] indexArray = index.split("\\.");
+            UserExamQuestion userExamRootQuestion = userExamQuestionMap.get(Integer.parseInt(indexArray[0]));
+            if (!Objects.isNull(userExamRootQuestion)) {
+                userExamQuestion = userExamRootQuestion.getSubQuestionList().stream().filter(item -> item.getQuestionIndex()
+                        .equals(Integer.parseInt(indexArray[1]))).findFirst().orElse(null);
+            }
+        } else {
+            userExamQuestion = userExamQuestionMap.get(Integer.parseInt(index));
+        }
+        return userExamQuestion;
+    }
+
     /**
      * 提交的答案和题目答案对比计算得分--填空题
      *

+ 1 - 1
web/src/main/java/com/ynfy/buss/exam/examreview/dto/ExamPreviewDTO.java

@@ -9,7 +9,7 @@ public class ExamPreviewDTO {
     /**
      * 试卷序号
      */
-    private Integer index;
+    private String index;
 
     private Boolean isRight;
 

+ 24 - 11
web/src/main/java/com/ynfy/buss/exam/examreview/service/impl/ExamReviewServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ynfy.buss.exam.exam.enums.PaperState;
+import com.ynfy.buss.exam.exam.service.IExamService;
 import com.ynfy.buss.exam.examreview.dto.ExamPreviewDTO;
 import com.ynfy.buss.exam.examreview.dto.PreviewSubmitDTO;
 import com.ynfy.buss.exam.examreview.entity.ExamReview;
@@ -24,10 +25,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -51,6 +49,8 @@ public class ExamReviewServiceImpl extends ServiceImpl<ExamReviewMapper, ExamRev
     @Autowired
     private IUserExamResultService userExamResultService;
 
+    @Autowired
+    private IExamService examService;
 
     /**
      * 统计需阅卷的考试
@@ -97,23 +97,36 @@ public class ExamReviewServiceImpl extends ServiceImpl<ExamReviewMapper, ExamRev
             throw new JeecgBootException("考题查询失败");
         }
 
-        //获取主观题
-        List<UserExamQuestion> subjectiveList = userExamQuestionList.stream().filter(o -> o.getQuestionType()
-                .equals(QuestionType.SIMPLE.getCode())).collect(Collectors.toList());
-        Map<Integer, UserExamQuestion> subjectiveMap = subjectiveList.stream().collect(Collectors
-                .toMap(UserExamQuestion::getQuestionIndex, a -> a, (k1, k2) -> k1));
+        List<UserExamQuestion> rootQuestionList = userExamQuestionList.stream().filter(r -> !Objects.isNull(r.getChild()) && !r.getChild())
+                .sorted(Comparator.comparing(UserExamQuestion::getQuestionIndex)).collect(Collectors.toList());
+        List<UserExamQuestion> childQuestionList = userExamQuestionList.stream().filter(r -> !Objects.isNull(r.getChild()) && r.getChild())
+                .sorted(Comparator.comparing(UserExamQuestion::getQuestionIndex)).collect(Collectors.toList());
+        if (!CollectionUtils.isEmpty(rootQuestionList)) {
+            //组装题目、子题目和答案
+            examService.assembleUserExamQuestion(dto.getUserExamId(), rootQuestionList, childQuestionList, true, false, true, true, false);
+        }
+        Map<Integer, UserExamQuestion> userExamQuestionMap = rootQuestionList.stream().collect(Collectors.toMap(UserExamQuestion::getQuestionIndex, a -> a, (k1, k2) -> k1));
+
         List<ExamPreviewDTO> examPreviews = dto.getExamPreviews();
 
         if (!CollectionUtils.isEmpty(examPreviews)) {
+            List<UserExamQuestion> resultList = new ArrayList<>();
             int subjectiveScore = 0;
             for (ExamPreviewDTO o : examPreviews) {
-                UserExamQuestion userExamQuestion = subjectiveMap.get(o.getIndex());
+                //根据题目序号中获取考题
+                UserExamQuestion userExamQuestion = examService.getUserExamQuestionByIndex(o.getIndex(), userExamQuestionMap);
+                if (Objects.isNull(userExamQuestion) || userExamQuestion.getQuestionType() != QuestionType.SIMPLE.getCode()) {
+                    return;
+                }
                 userExamQuestion.setActualScore(o.getActualScore());
                 userExamQuestion.setIsRight(o.getIsRight());
+                resultList.add(userExamQuestion);
                 subjectiveScore += o.getActualScore();
             }
             //更新评分
-            userExamQuestionService.updateBatchById(userExamQuestionList);
+            if(!CollectionUtils.isEmpty(resultList)){
+                userExamQuestionService.updateBatchById(resultList);
+            }
 
             //用户得分,主观题得分,更新阅卷人,阅卷时间,考试状态
             userExam.setSubjectiveScore(subjectiveScore);//主观题得分