Ver código fonte

刷题放开题型限制,随机提取各类题练习

mingfu 1 semana atrás
pai
commit
d15468ec8e

+ 2 - 15
ie-admin/src/main/java/com/ruoyi/web/service/ExamService.java

@@ -12,10 +12,7 @@ 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.ExamineeStatus;
-import com.ruoyi.enums.PaperStatus;
-import com.ruoyi.enums.PaperType;
-import com.ruoyi.enums.UserTypeEnum;
+import com.ruoyi.enums.*;
 import com.ruoyi.ie.domain.AMarjorPlan;
 import com.ruoyi.ie.service.IAMarjorPlanService;
 import com.ruoyi.learn.domain.*;
@@ -473,17 +470,7 @@ public class ExamService {
             up.setStatus(PaperStatus.Valid.getVal());
             paperMapper.updateLearnPaper(up);
         }
-
-        TestPaperVO.PaperDef paperDef = new TestPaperVO.PaperDef();
-        paperDef.setTotal(15L);
-        paperDef.setFillExclude(true);
-        paperDef.setKnowIds(Lists.newArrayList(knowledgeId));
-        List<TestPaperVO.TypeDef> typeDefList= Lists.newArrayList();
-        typeDefList.add(new TestPaperVO.TypeDef("单选题", "单选题", 9, 1));
-        typeDefList.add(new TestPaperVO.TypeDef("判断题", "判断题", 4, 1));
-        typeDefList.add(new TestPaperVO.TypeDef("主观题", "主观题", 2, 1));
-        paperDef.setTypes(typeDefList);
-        List<LearnPaperQuestion> pqList = paperService.getQuestions(studentId,  paperDef);
+        List<LearnPaperQuestion> pqList = paperService.getQuestionsByRandom(studentId,  15, knowledgeId, Arrays.stream(QuestionType.values()).map(QuestionType::getTitle).collect(Collectors.toList()));
         paper.setPaperSource(0);
         paper.setFenshu(0);
         paper.setSubjectId(knowledgeTree.getSubjectId());

+ 0 - 1
ie-admin/src/main/java/com/ruoyi/web/service/LearnTeacherService.java

@@ -306,7 +306,6 @@ public class LearnTeacherService {
             Map cond = Maps.newHashMap();
             cond.put("studentId", studentId);
             cond.put("knowIds", ktList.stream().map(LearnKnowledgeTree::getId).collect(Collectors.toList()));
-            cond.put("types", Lists.newArrayList("单选题", "判断题"));
             knowCountMap = Maps.newHashMap();
             for(LearnQuestions qs : learnQuestionsMapper.statByKnowledge(cond)) {
                 knowCountMap.put(qs.getKnowledgeId(), new Integer[] { qs.getNumber().intValue(), qs.getId().intValue(), qs.getYear().intValue()} );

+ 92 - 13
ie-admin/src/main/java/com/ruoyi/web/service/PaperService.java

@@ -56,7 +56,7 @@ public class PaperService {
         // buildAllPapers(2);
         // buildSimulatedPaper(20154L, 1001L);
         // buildSimulatedPaper(20950L, 1001L);
-        // buildSimulatedPaperForUniversity(20972L, 11L, 215L, 2);
+        // buildSimulatedPaperForUniversity(20950L, 11L, 78L, 2);
         // test2();
         // testCulture();
     }
@@ -389,13 +389,72 @@ public class PaperService {
             }
             newKnownList.addAll(tailKnownList);
             ktd.setKnowledges(newKnownList);
-            Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, ktd.getTypes().stream().map(t -> t.getType().getTitle()).collect(Collectors.toList()), newKnownList, paperDef.getFillExclude());
+            Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, "0", ktd.getTypes().stream().map(t -> t.getType().getTitle()).collect(Collectors.toList()), newKnownList, paperDef.getFillExclude());
             assignTypeFirst(paperDef.getFillExclude(), ktd, knowTypeAssignMap);
             pqList.addAll(getQuestions2(studentId, ktd.getCount(), pqList.size(), newKnownList, ktd.getTypes(), knowTypeAssignMap, existQuestionIdSet));
         }
         return pqList;
     }
 
+    public List<LearnPaperQuestion> getQuestionsByRandom(Long studentId, Integer total, Long knowledgeId, List<String> types) {
+        Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, "1", types, Lists.newArrayList(knowledgeId), false);
+        List<KnowTypeAssign> knowTypeAssignList = Lists.newArrayList(knowTypeAssignMap.values());
+        List<LearnPaperQuestion> pqList = Lists.newArrayList();
+        Set<Long> existQuestionIdSet = Sets.newHashSet();
+        Random random = new Random();
+        Map<String, List<LearnQuestions>> typeQuestionMap = Maps.newHashMap();
+        LearnQuestions qCond = new LearnQuestions();
+        do {
+            if(knowTypeAssignList.isEmpty()) {
+                break;
+            }
+            int idx = random.nextInt(knowTypeAssignList.size());
+            KnowTypeAssign knowTypeAssign = knowTypeAssignList.get(idx);
+            if(knowTypeAssign.getExclCount() > knowTypeAssign.getExclAssign()) {
+                List<LearnQuestions> questions = typeQuestionMap.get(knowTypeAssign.getType());
+                if(null == questions) {
+                    qCond.setKnowledgeId(knowledgeId);
+                    qCond.setQtpye(knowTypeAssign.getType());
+                    qCond.setId(studentId);
+                    qCond.setNumber(knowTypeAssign.exclAssign > 500 ? (long) random.nextInt(knowTypeAssign.exclAssign.intValue() - 500) :  0L);
+                    qCond.setIsSubType("1");
+                    questions = questionsMapper.selectQuestionsForPaper(qCond);
+                    typeQuestionMap.put(knowTypeAssign.getType(), questions);
+                }
+                if(!questions.isEmpty()) {
+                    int oldSize = pqList.size();
+                    knowTypeAssign.exclAssign = addRandomList(knowledgeId, knowTypeAssign.getType(), questions, random, total.longValue(), 1L, 1.0, existQuestionIdSet, 1, pqList);
+                    if(oldSize != pqList.size()) {
+                        for(; oldSize < pqList.size(); oldSize++) {
+                            pqList.get(oldSize).setSeq(QuestionType.of(knowTypeAssign.getType()).getVal());
+                        }
+                    }
+                }
+            } else {
+                knowTypeAssignList.remove(idx);
+            }
+        } while(pqList.size() < total);
+        Collections.sort(pqList, new Comparator<LearnPaperQuestion>() {
+            @Override
+            public int compare(LearnPaperQuestion o1, LearnPaperQuestion o2) {
+                int iRet;
+                if(0 != (iRet = o1.getSeq().compareTo(o2.getSeq()))) {
+                    return iRet;
+                }
+                if(0 != (iRet = o1.getPaperId().compareTo(o2.getPaperId()))) {
+                    return iRet;
+                }
+                return o1.getQuestionId().compareTo(o2.getQuestionId());
+            }
+        });
+        Integer[] idx = {1};
+        pqList.forEach(t -> {
+            t.setSeq(idx[0]++);
+            t.setPaperId(null);
+        });
+        return pqList;
+    }
+
     /**
      * 按知识点,题型平均分配组卷
      * @param studentId
@@ -691,6 +750,7 @@ public class PaperService {
                 }
                 qCond.setKnowledgeId(ktc.getKnowId());
                 qCond.setQtpye(ktc.getType());
+                qCond.setIsSubType("0");
                 if(ktc.exclAssign > 0){
                     qCond.setId(studentId);
                     qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) :  0L);
@@ -735,6 +795,7 @@ public class PaperService {
                 }
                 qCond.setKnowledgeId(ktc.getKnowId());
                 qCond.setQtpye(typeTitle);
+                qCond.setIsSubType("0");
                 if(ktc.exclAssign > 0){
                     qCond.setId(studentId);
                     qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) :  0L);
@@ -772,7 +833,7 @@ public class PaperService {
      * @return
      */
     private Map<String, KnowTypeAssign> buildKnowTypeAssignMap(Long studentId, TestPaperVO.PaperDef paperDef) {
-        return buildKnowTypeAssignMap(studentId, paperDef.getTypes().stream().map(TestPaperVO.TypeDef::getType).collect(Collectors.toList()), paperDef.getKnowIds(), paperDef.getFillExclude());
+        return buildKnowTypeAssignMap(studentId, "0", paperDef.getTypes().stream().map(TestPaperVO.TypeDef::getType).collect(Collectors.toList()), paperDef.getKnowIds(), paperDef.getFillExclude());
     }
 
     /**
@@ -783,12 +844,13 @@ public class PaperService {
      * @param fillExclude
      * @return
      */
-    private Map<String, KnowTypeAssign> buildKnowTypeAssignMap(Long studentId, List<String> types, Collection<Long> knownIds, Boolean fillExclude) {
+    private Map<String, KnowTypeAssign> buildKnowTypeAssignMap(Long studentId, String isSubType, List<String> types, Collection<Long> knownIds, Boolean fillExclude) {
         Map<String, KnowTypeAssign> knowTypeAssignMap = Maps.newHashMap();
         Map cond = Maps.newHashMap();
         cond.put("studentId", studentId);
         cond.put("knowIds", knownIds);
         cond.put("types", types);
+        cond.put("isSubType", isSubType);
         setValue(knowTypeAssignMap, cond, 1); // 填充排除后总量
         if (null != studentId && fillExclude) {
             cond.remove("studentId");
@@ -813,15 +875,32 @@ public class PaperService {
         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())) {
-                LearnPaperQuestion pq = new LearnPaperQuestion();
-                pq.setSeq(baseSeq + pqList.size());
-                pq.setKnowledgeId(knowId);
-                pq.setScore(score);
-                pq.setQuestionId(q.getId());
-                pq.setType(type);
-                pqList.add(pq);
-                count--;
-                if(pqList.size() == totalCount) {
+                if("1".equals(q.getIsSubType())) {
+                    LearnQuestions subCond = new LearnQuestions();
+                    subCond.setKnowId(q.getId());
+                    for(LearnQuestions sq : questionsMapper.selectLearnQuestionsList(subCond)) {
+                        LearnPaperQuestion pq = new LearnPaperQuestion();
+                        pq.setSeq(baseSeq + pqList.size());
+                        pq.setKnowledgeId(knowId);
+                        pq.setScore(score);
+                        pq.setQuestionId(sq.getId());
+                        pq.setType(type);
+                        pq.setPaperId(q.getId());
+                        pqList.add(pq);
+                        count--;
+                    }
+                } else {
+                    LearnPaperQuestion pq = new LearnPaperQuestion();
+                    pq.setSeq(baseSeq + pqList.size());
+                    pq.setKnowledgeId(knowId);
+                    pq.setScore(score);
+                    pq.setQuestionId(q.getId());
+                    pq.setType(type);
+                    pq.setPaperId(0L);
+                    pqList.add(pq);
+                    count--;
+                }
+                if(pqList.size() >= totalCount) {
                     break;
                 }
             }

+ 8 - 4
ie-system/src/main/resources/mapper/learn/LearnQuestionsMapper.xml

@@ -285,7 +285,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM `learn_knowledge_question` kq
         LEFT JOIN `learn_answer` a ON kq.`question_id` = a.`question_id` AND a.`student_id` = #{studentId}
         JOIN `learn_questions` q ON q.`id` = kq.`question_id`
-        <where> kq.sub = 0
+        <where>
             <if test="knowIds != null"> and kq.`knowledge_id` in <foreach item="id" collection="knowIds" open="(" separator="," close=")">#{id}</foreach></if>
             <if test="types != null"> and q.`qtpye` in <foreach item="id" collection="types" open="(" separator="," close=")">#{id}</foreach></if>
         </where>
@@ -299,7 +299,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
              LEFT JOIN `learn_answer` a ON kq.`question_id` = a.`question_id` AND a.`student_id` = #{studentId}
          </if>
          JOIN `learn_questions` q ON q.`id` = kq.`question_id`
-        <where> kq.sub = 0
+        <where>
+            <if test="isSubType != null  and isSubType == 1"> and (kq.sub = 0 or q.knowId = q.id)</if>
+            <if test="isSubType != null  and isSubType == 0"> and (kq.sub = 0)</if>
             <if test="knowIds != null"> and kq.`knowledge_id` in <foreach item="id" collection="knowIds" open="(" separator="," close=")">#{id}</foreach></if>
             <if test="types != null"> and q.`qtpye` in <foreach item="id" collection="types" open="(" separator="," close=")">#{id}</foreach></if>
             <if test="studentId != null"> AND a.`student_id` IS NULL</if>
@@ -308,13 +310,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="selectQuestionsForPaper" parameterType="LearnQuestions" resultMap="LearnQuestionsResult">
-        SELECT q.`id`, kq.knowledge_id `knowledgeId`
+        SELECT q.`id`, kq.knowledge_id `knowledgeId`, q.isSubType
         FROM `learn_knowledge_question` kq
         <if test="id != null">
             LEFT JOIN `learn_answer` a ON kq.`question_id` = a.`question_id` AND a.`student_id` = #{id}
         </if>
         JOIN `learn_questions` q ON q.`id` = kq.`question_id`
-        <where> kq.sub = 0
+        <where>
+            <if test="isSubType != null  and isSubType == 1"> and (kq.sub = 0 or q.knowId = q.id)</if>
+            <if test="isSubType != null  and isSubType == 0"> and (kq.sub = 0)</if>
             <if test="qtpye != null  and qtpye != ''"> and qtpye = #{qtpye}</if>
             <if test="id != null ">  AND a.`student_id` IS NULL</if>
             <if test="knowledgeId != null "> and kq.knowledge_id  = #{knowledgeId}</if>