Selaa lähdekoodia

生成卷计算排序调整

mingfu 1 viikko sitten
vanhempi
commit
e017472e85

+ 32 - 15
ie-admin/src/main/java/com/ruoyi/web/service/PaperService.java

@@ -393,6 +393,7 @@ public class PaperService {
             assignTypeFirst(paperDef.getFillExclude(), ktd, knowTypeAssignMap);
             pqList.addAll(getQuestions2(studentId, ktd.getCount(), pqList.size(), newKnownList, ktd.getTypes(), knowTypeAssignMap, existQuestionIdSet));
         }
+        reSort(pqList);
         return pqList;
     }
 
@@ -423,28 +424,37 @@ public class PaperService {
                 }
                 if(!questions.isEmpty()) {
                     int oldSize = pqList.size();
-                    addRandomList(knowledgeId, knowTypeAssign.getType(), questions, random, total.longValue(), 1L, 1.0, existQuestionIdSet, 1, pqList);
+                    addRandomList(knowledgeId, QuestionType.of(knowTypeAssign.getType()), questions, random, total.longValue(), 1L, 1.0, existQuestionIdSet, 1, pqList);
                     if(oldSize != pqList.size()) {
                         knowTypeAssign.exclAssign++;
-                        for(; oldSize < pqList.size(); oldSize++) {
-                            pqList.get(oldSize).setSeq(QuestionType.of(knowTypeAssign.getType()).getVal());
-                        }
                     }
                 }
             } else {
                 knowTypeAssignList.remove(idx);
             }
         } while(pqList.size() < total);
+        reSort(pqList);
+        return pqList;
+    }
+
+    /**
+     * // diff(type), paperId(parentId), seq(type), questionId(id)
+     * @param pqList
+     */
+    private void reSort(List<LearnPaperQuestion> pqList) {
         Collections.sort(pqList, new Comparator<LearnPaperQuestion>() {
             @Override
             public int compare(LearnPaperQuestion o1, LearnPaperQuestion o2) {
                 int iRet;
-                if(0 != (iRet = o1.getSeq().compareTo(o2.getSeq()))) {
+                if(0 != (iRet = o1.getDiff().compareTo(o2.getDiff()))) {
                     return iRet;
                 }
                 if(0 != (iRet = o1.getPaperId().compareTo(o2.getPaperId()))) {
                     return iRet;
                 }
+                if(0 != (iRet = o1.getSeq().compareTo(o2.getSeq()))) {
+                    return iRet;
+                }
                 return o1.getQuestionId().compareTo(o2.getQuestionId());
             }
         });
@@ -452,8 +462,8 @@ public class PaperService {
         pqList.forEach(t -> {
             t.setSeq(idx[0]++);
             t.setPaperId(null);
+            t.setDiff(null);
         });
-        return pqList;
     }
 
     /**
@@ -684,6 +694,9 @@ public class PaperService {
                     }
                 }
             } while(lackTotal != assignCount.get() && knownIdSet.size() > 0);
+            if(lackTotal < assignCount.get()) {
+                throw new RuntimeException("题数不足: " + typeTitle + "差" + (lackTotal - assignCount.get()));
+            }
         }
     }
 
@@ -752,11 +765,12 @@ public class PaperService {
                 qCond.setKnowledgeId(ktc.getKnowId());
                 qCond.setQtpye(ktc.getType());
                 qCond.setIsSubType("0");
+                QuestionType qt = QuestionType.of(ktc.getType());
                 if(ktc.exclAssign > 0){
                     qCond.setId(studentId);
                     qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) :  0L);
                     List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
-                    ktc.exclAssign = addRandomList(knowId, ktc.getType(), questions, random, paperDef.getTotal(), ktc.exclAssign, typeDef.getScore().doubleValue(), existQuestionIdSet, 1, pqList);
+                    ktc.exclAssign = addRandomList(knowId, qt, questions, random, paperDef.getTotal(), ktc.exclAssign, typeDef.getScore().doubleValue(), existQuestionIdSet, 1, pqList);
                     if(pqList.size() == total) {
                         break;
                     }
@@ -765,7 +779,7 @@ public class PaperService {
                     qCond.setId(null);
                     qCond.setNumber(ktc.assign > 500 ? (long) random.nextInt(ktc.assign.intValue() - 500) :  0L);
                     List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
-                    ktc.assign = addRandomList(knowId, ktc.getType(), questions, random, paperDef.getTotal(), ktc.assign, typeDef.getScore().doubleValue(), existQuestionIdSet, 1, pqList);
+                    ktc.assign = addRandomList(knowId, qt, questions, random, paperDef.getTotal(), ktc.assign, typeDef.getScore().doubleValue(), existQuestionIdSet, 1, pqList);
                     if(pqList.size() == total) {
                         break;
                     }
@@ -778,6 +792,7 @@ public class PaperService {
         if(CollectionUtils.isEmpty(pqList)) {
             throw new RuntimeException("题数不足");
         }
+        reSort(pqList);
         return pqList;
     }
 
@@ -801,7 +816,7 @@ public class PaperService {
                     qCond.setId(studentId);
                     qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) :  0L);
                     List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
-                    ktc.exclAssign = addRandomList(knowId, typeTitle, questions, random, typeDef.getCount().longValue(), ktc.exclAssign, typeDef.getScore(), existQuestionIdSet, seqId, pqList);
+                    ktc.exclAssign = addRandomList(knowId, typeDef.getType(), questions, random, total.longValue(), ktc.exclAssign, typeDef.getScore(), existQuestionIdSet, seqId, pqList);
                     if(pqList.size() == total) {
                         break;
                     }
@@ -810,7 +825,7 @@ public class PaperService {
                     qCond.setId(null);
                     qCond.setNumber(ktc.assign > 500 ? (long) random.nextInt(ktc.assign.intValue() - 500) :  0L);
                     List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
-                    ktc.assign = addRandomList(knowId, typeTitle, questions, random, typeDef.getCount().longValue(), ktc.assign, typeDef.getScore(), existQuestionIdSet, seqId, pqList);
+                    ktc.assign = addRandomList(knowId, typeDef.getType(), questions, random, total.longValue(), ktc.assign, typeDef.getScore(), existQuestionIdSet, seqId, pqList);
                     if(pqList.size() == total) {
                         break;
                     }
@@ -820,7 +835,7 @@ public class PaperService {
                 break;
             }
         }
-        if(CollectionUtils.isEmpty(pqList)) {
+        if(pqList.size() < total) {
             throw new RuntimeException("题数不足 " + types.stream().map( t -> t.getType().getTitle()).collect(Collectors.joining(",")) + ":" + StringUtils.join(knownIds, ","));
         }
         return pqList;
@@ -870,9 +885,9 @@ public class PaperService {
      * @param count  本池分配数
      * @param score 题分
      * @param existQuestionIdSet 不能使用的题
-     * @param pqList 卷题关系
+     * @param pqList 卷题关系  diff(type),paperId(parentId),seq,questionId(id)
      */
-    private Long addRandomList(Long knowId, String type, List<LearnQuestions> questions, Random random, Long totalCount, Long count, Double score, Set<Long> existQuestionIdSet, Integer baseSeq, List<LearnPaperQuestion> pqList) {
+    private Long addRandomList(Long knowId, QuestionType type, List<LearnQuestions> questions, Random random, Long totalCount, Long count, Double score, Set<Long> existQuestionIdSet, Integer baseSeq, List<LearnPaperQuestion> pqList) {
         while(count > 0L && !questions.isEmpty()) {
             LearnQuestions q = questions.size() > 1 ? questions.remove(random.nextInt(questions.size() - 1)) : questions.remove(0);
             if(existQuestionIdSet.add(q.getId())) {
@@ -885,7 +900,8 @@ public class PaperService {
                         pq.setKnowledgeId(knowId);
                         pq.setScore(score);
                         pq.setQuestionId(sq.getId());
-                        pq.setType(type);
+                        pq.setType(type.getTitle());
+                        pq.setDiff(type.getVal());
                         pq.setPaperId(q.getId());
                         pqList.add(pq);
                         count--;
@@ -896,7 +912,8 @@ public class PaperService {
                     pq.setKnowledgeId(knowId);
                     pq.setScore(score);
                     pq.setQuestionId(q.getId());
-                    pq.setType(type);
+                    pq.setType(type.getTitle());
+                    pq.setDiff(type.getVal());
                     pq.setPaperId(0L);
                     pqList.add(pq);
                     count--;

+ 1 - 0
ie-system/src/main/java/com/ruoyi/learn/domain/TestPaperVO.java

@@ -143,6 +143,7 @@ public class TestPaperVO {
                     if(null == cType) {
                         cType = new TypeDef2();
                         BeanUtils.copyProperties(typeDef, cType);
+                        cType.setScore(typeDef.getScore() * typeDef.getCount());
                         types.add(cType);
                         typeMap.put(qt.name(), cType);
                     } else {