Kaynağa Gözat

随机组卷组合题计算每个子题目分数

yangfeng 1 yıl önce
ebeveyn
işleme
8af91b198c

+ 51 - 5
web/src/main/java/com/ynfy/buss/exam/exam/service/impl/ExamServiceImpl.java

@@ -147,6 +147,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
         }
         List<PaperQuestion> paperQuestionList = null;
         if (paper.getJoinType().equals(JoinType.XT.getCode()) || paper.getJoinType().equals(JoinType.CT.getCode())) {//选题或者抽题
+            //只查询父题目
             paperQuestionList = paperQuestionService.listByPaperId(paper.getId());
             //题目乱序
             if (!Objects.isNull(exam.getQuestionDisorder()) && exam.getQuestionDisorder()) {
@@ -161,7 +162,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
             throw new JeecgBootException("无对应的考题!");
         }
         //保存考试
-        return this.saveExam(userId, exam, paper, paperQuestionList);
+        return this.saveExam(userId, exam, paper, paperQuestionList, paper.getJoinType());
     }
 
     /**
@@ -188,7 +189,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
      * @param paperQuestionList
      * @return
      */
-    public UserExam saveExam(String userId, Exam exam, Paper paper, List<PaperQuestion> paperQuestionList) {
+    public UserExam saveExam(String userId, Exam exam, Paper paper, List<PaperQuestion> paperQuestionList, Integer joinType) {
         UserExam userExam = new UserExam();
         userExam.setId(IdUtil.getSnowflake(1, 1).nextIdStr());
         userExam.setExamId(exam.getId());
@@ -202,7 +203,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
 
         //保存考试关联的试题列表
         if (!CollectionUtils.isEmpty(paperQuestionList)) {
-            this.savePaperQuestion(paper.getId(), userExam.getId(), paperQuestionList);
+            this.savePaperQuestion(paper.getId(), userExam.getId(), paperQuestionList, joinType);
             //保存用户考试的题目答案
             this.saveQuestionAnswer(paper.getId(), userExam.getId(), exam, paperQuestionList);
         }
@@ -309,7 +310,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
     /**
      * 保存试卷试题列表
      */
-    private void savePaperQuestion(String paperId, String userExamId, List<PaperQuestion> paperQuestionList) {
+    private void savePaperQuestion(String paperId, String userExamId, List<PaperQuestion> paperQuestionList, Integer joinType) {
         paperQuestionList = paperQuestionList.stream().sorted(Comparator.comparing(PaperQuestion::getQuestionType)
                 .thenComparing(PaperQuestion::getSort)).collect(Collectors.toList());
         //获取规则组map
@@ -326,13 +327,58 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
         //组合题
         List<String> combinationIdList = paperQuestionList.stream().filter(r -> QuestionType.COMBINATION.getCode().equals(r.getQuestionType()))
                 .map(PaperQuestion::getQuestionId).collect(Collectors.toList());
-        List<PaperQuestion> paperSubQuestionList = paperQuestionService.listPaperSubQuestionByIds(paperId, combinationIdList);
+        List<PaperQuestion> paperSubQuestionList = null;
+        if (!CollectionUtils.isEmpty(combinationIdList)) {
+            if (joinType.equals(JoinType.XT.getCode()) || joinType.equals(JoinType.CT.getCode())) {//选题或者抽题
+                paperSubQuestionList = paperQuestionService.listPaperSubQuestionByIds(paperId, combinationIdList);
+            } else if (joinType.equals(JoinType.SJ.getCode())) {//随机抽题
+                paperSubQuestionList = new ArrayList<>();
+                List<Question> subQuestionList = questionService.listSubQuestionNoAnswerByIds(combinationIdList);
+                Map<String, Long> subQuestionCountMap = subQuestionList.stream().collect(Collectors.groupingBy(Question::getParentId, Collectors.counting()));
+                for (Question sub : subQuestionList) {
+                    PaperQuestion parent = paperQuestionList.stream().filter(r -> r.getQuestionId().equals(sub.getParentId())).findFirst().orElse(null);
+                    PaperQuestion paperSubQuestion = getPaperQuestion(paperId, sub, parent, calcSubQuestionScore(subQuestionCountMap, parent));
+                    paperSubQuestionList.add(paperSubQuestion);
+                }
+            }
+        }
+
         //配置子题目
         configUserExamSubQuestion(userExamId, paperSubQuestionList, groupMap, userExamQuestionList);
 
         userExamQuestionService.saveBatch(userExamQuestionList);
     }
 
+    /**
+     * 随机组卷组合题计算每个子题目分数
+     *
+     * @param subQuestionCountMap
+     * @param parent
+     * @return
+     */
+    public Integer calcSubQuestionScore(Map<String, Long> subQuestionCountMap, PaperQuestion parent) {
+        int subQuestionScore = 0;
+        if (!Objects.isNull(parent) && !Objects.isNull(subQuestionCountMap)
+                && !Objects.isNull(subQuestionCountMap.get(parent.getQuestionId()))) {
+            //TODO 分数改为double
+            subQuestionScore = parent.getQuestionScore() / subQuestionCountMap.get(parent.getQuestionId()).intValue();
+        }
+        return subQuestionScore;
+    }
+
+    private static PaperQuestion getPaperQuestion(String paperId, Question sub, PaperQuestion parent, int subQuestionScore) {
+        PaperQuestion paperSubQuestion = new PaperQuestion();
+        paperSubQuestion.setGroupId(!Objects.isNull(parent) ? parent.getGroupId() : null);
+        paperSubQuestion.setPaperId(paperId);
+        paperSubQuestion.setQuestionId(sub.getId());
+        paperSubQuestion.setQuestionType(sub.getType());
+        paperSubQuestion.setChild(sub.getChild());
+        paperSubQuestion.setQuestionScore(subQuestionScore);
+        paperSubQuestion.setSort(sub.getSort());
+        paperSubQuestion.setParentQuestionId(sub.getParentId());
+        return paperSubQuestion;
+    }
+
     /**
      * 配置用户考试试题
      *

+ 5 - 0
web/src/main/java/com/ynfy/buss/exam/paper/service/impl/PaperServiceImpl.java

@@ -168,6 +168,7 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
         List<Question> ruleQuestions = questionService.listQuestionByCondition(dtoList);
 
         //按每组规则生成试题
+        //key为groupId
         Map<String, List<Question>> groupQuestionMap = generateGroupQuestionMap(ruleGroups, ruleQuestions);
         //生成试卷试题
         List<PaperQuestion> paperQuestions = generatePaperQuestions(paperId, ruleGroups, groupQuestionMap);
@@ -235,6 +236,8 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
                     if (CollectionUtils.isEmpty(questions)) {
                         questions = new ArrayList<>();
                     }
+                    //设置为父题目
+                    questionList.forEach(item -> item.setChild(false));
                     questions.addAll(questionList);
                     groupQuestionMap.put(groupId, questions);
                 } catch (Exception e) {
@@ -291,6 +294,8 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
                     paperQuestion.setQuestionId(q.getId());
                     paperQuestion.setQuestionType(ruleGroup.getQuestionType());
                     paperQuestion.setQuestionScore(ruleGroup.getPerScore());
+                    paperQuestion.setChild(q.getChild());
+                    paperQuestion.setGroupId(entity.getKey());
                     paperQuestions.add(paperQuestion);
                 }
             }

+ 21 - 7
web/src/main/java/com/ynfy/buss/exam/paperquestion/service/impl/PaperQuestionServiceImpl.java

@@ -77,13 +77,9 @@ public class PaperQuestionServiceImpl extends ServiceImpl<PaperQuestionMapper, P
                 int sort = 1;
                 if (!CollectionUtils.isEmpty(questionList)) {
                     for (Question q : questionList) {
-                        //多选题漏选选项分值(漏选也给分)
-                        if (QuestionType.MULTI.getCode().equals(q.getType()) && !Objects.isNull(g.getCanMissOption()) && g.getCanMissOption()) {
-                            paperQuestionAnswerService.save(paperId, q);
-                            //填空题按空给分
-                        } else if (QuestionType.BLANK.getCode().equals(q.getType()) && !Objects.isNull(g.getCanBlankOption()) && g.getCanBlankOption()) {
-                            paperQuestionAnswerService.save(paperId, q);
-                        }
+                        //多选题漏选也给分,填空题按空给分设置
+                        groupAnswerConfig(paperId, g, q);
+
                         PaperQuestion paperQuestion = new PaperQuestion();
                         paperQuestion.setGroupId(g.getId());
                         paperQuestion.setPaperId(paperId);
@@ -104,6 +100,7 @@ public class PaperQuestionServiceImpl extends ServiceImpl<PaperQuestionMapper, P
                                 paperSubQuestion.setQuestionScore(sub.getScore());
                                 paperSubQuestion.setSort(sub.getSort());
                                 paperSubQuestion.setParentQuestionId(q.getId());
+                                //groupAnswerConfig(paperId, g, sub);
                                 paperQuestionList.add(paperSubQuestion);
                             });
                         } else {
@@ -119,6 +116,23 @@ public class PaperQuestionServiceImpl extends ServiceImpl<PaperQuestionMapper, P
         }
     }
 
+    /**
+     * 多选题漏选也给分,填空题按空给分设置
+     *
+     * @param paperId
+     * @param g
+     * @param q
+     */
+    public void groupAnswerConfig(String paperId, PaperRuleGroup g, Question q) {
+        //多选题漏选选项分值(漏选也给分)
+        if (QuestionType.MULTI.getCode().equals(q.getType()) && !Objects.isNull(g.getCanMissOption()) && g.getCanMissOption()) {
+            paperQuestionAnswerService.save(paperId, q);
+            //填空题按空给分
+        } else if (QuestionType.BLANK.getCode().equals(q.getType()) && !Objects.isNull(g.getCanBlankOption()) && g.getCanBlankOption()) {
+            paperQuestionAnswerService.save(paperId, q);
+        }
+    }
+
     @Override
     public List<PaperQuestion> listByPaperId(String paperId) {
         return paperQuestionMapper.listByPaperId(paperId);

+ 8 - 2
web/src/main/java/com/ynfy/buss/exam/paperrulegroup/service/impl/PaperRuleGroupServiceImpl.java

@@ -120,8 +120,14 @@ public class PaperRuleGroupServiceImpl extends ServiceImpl<PaperRuleGroupMapper,
         //保存规则明细
         paperRuleDetailService.saveAll(paper.getId(), groupList);
 
+        //简答题有多少个组
+        long simpleCount = groupList.stream().filter(group -> QuestionType.SIMPLE.getCode()
+                .equals(group.getQuestionType())).count();
+        //如果随机组卷中包含组合题,则认为含有主观题
+        long combinaCount = groupList.stream().filter(group -> QuestionType.COMBINATION.getCode()
+                .equals(group.getQuestionType())).count();
         //更新试卷
-        paper.setHasSubjective(hasSubjective(groupList));
+        paper.setHasSubjective(simpleCount + combinaCount > 0 ? true : false);
         paper.setTotalScore(totalScore);
         paper.setQuestionCount(allQuestionNum);
         paperService.saveOrUpdate(paper);
@@ -151,7 +157,7 @@ public class PaperRuleGroupServiceImpl extends ServiceImpl<PaperRuleGroupMapper,
                     }
                 }
             }
-            if(subjective){
+            if (subjective) {
                 break;
             }
         }