Просмотр исходного кода

科目知识点过滤时使用知识点树,修正练习统计与查题条件不一致问题

mingfu 1 месяц назад
Родитель
Сommit
99947c8b9e

+ 17 - 2
ie-admin/src/main/java/com/ruoyi/web/service/PaperService.java

@@ -570,6 +570,7 @@ public class PaperService {
         Map<String, List<LearnQuestions>> typeQuestionMap = Maps.newHashMap();
         LearnQuestions qCond = new LearnQuestions();
         qCond.setTypeId(questionType);
+        // excl
         do {
             if(knowTypeAssignList.isEmpty()) {
                 break;
@@ -598,7 +599,21 @@ public class PaperService {
                 } else {
                     knowTypeAssignList.remove(idx);
                 }
-            } else if(knowTypeAssign.getTotal() > knowTypeAssign.getAssign()) {
+            } else {
+                knowTypeAssignList.remove(idx);
+            }
+        } while(pqList.size() < total);
+
+        // 补充
+        typeQuestionMap.clear();
+        knowTypeAssignList = Lists.newArrayList(knowTypeAssignMap.values());
+        while(pqList.size() < total) {
+            if(knowTypeAssignList.isEmpty()) {
+                break;
+            }
+            int idx = random.nextInt(knowTypeAssignList.size());
+            KnowTypeAssign knowTypeAssign = knowTypeAssignList.get(idx);
+            if(knowTypeAssign.getTotal() > knowTypeAssign.getAssign()) {
                 List<LearnQuestions> questions = typeQuestionMap.get(knowTypeAssign.getType());
                 if (null == questions) {
                     qCond.setKnowledgeId(knowTypeAssign.getKnowId());
@@ -622,7 +637,7 @@ public class PaperService {
             } else {
                 knowTypeAssignList.remove(idx);
             }
-        } while(pqList.size() < total);
+        };
         reSort(pqList);
         return pqList;
     }

+ 11 - 17
ie-system/src/main/resources/mapper/learn/LearnQuestionsMapper.xml

@@ -71,22 +71,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="answer1 != null  and answer1 != ''"> and answer1 = #{answer1}</if>
             <if test="answer2 != null  and answer2 != ''"> and answer2 = #{answer2}</if>
             <if test="qtpye != null  and qtpye != ''"> and qtpye = #{qtpye}</if>
-            <if test="subjectId != null "> and subjectId = #{subjectId}</if>
             <if test="paperId != null "> and paperId = #{paperId}</if>
-            <if test="knowledgeId != null ">
-                and EXISTS (
-                    SELECT 1
-                    FROM learn_knowledge_question lkq
-                    WHERE lkq.question_id = learn_questions.id
-                      AND (
-                          lkq.knowledge_id = #{knowledgeId}
-                          OR EXISTS (
-                              SELECT 1
-                              FROM learn_knowledge_tree lkt
-                              WHERE lkt.id = lkq.knowledge_id
-                                AND (lkt.pid = #{knowledgeId} OR FIND_IN_SET(#{knowledgeId}, lkt.ancestors) > 0)
-                          )
-                      )
+            <if test="subjectId != null or knowledgeId != null ">
+                and EXISTS ( SELECT 1 FROM learn_knowledge_question lkq WHERE lkq.question_id = learn_questions.id AND (
+                          EXISTS (SELECT 1 FROM learn_knowledge_tree lkt
+                                 WHERE lkt.id = lkq.knowledge_id <if test="subjectId != null"> and lkt.subjectId = #{subjectId}</if>
+                                 <if test="knowledgeId != null"> AND (lkt.pid = #{knowledgeId} OR FIND_IN_SET(#{knowledgeId}, lkt.ancestors) > 0)</if>
+                          ) <if test="knowledgeId != null"> OR lkq.knowledge_id = #{knowledgeId}</if>
+                    )
                 )
             </if>
             <if test="diff != null "> and diff = #{diff}</if>
@@ -320,6 +312,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          FROM `learn_knowledge_question` kq
          <if test="studentId != null">
              LEFT JOIN `learn_answer` a ON kq.`question_id` = a.`question_id` AND a.`student_id` = #{studentId}
+             LEFT JOIN `learn_examinee` e ON a.`examinee_id` = e.`examinee_id` AND e.`state` >= 4
          </if>
          JOIN `learn_questions` q ON q.`id` = kq.`question_id`
         <where>
@@ -328,7 +321,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <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>
+            <if test="studentId != null"> AND e.`examinee_id` IS NULL</if>
             <if test="typeId != null"> AND kq.`type` = #{typeId}</if>
         </where>
         GROUP BY kq.knowledge_id, q.`qtpye`
@@ -339,6 +332,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         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}
+            LEFT JOIN `learn_examinee` e ON a.`examinee_id` = e.`examinee_id` AND e.`state` >= 4
         </if>
         JOIN `learn_questions` q ON q.`id` = kq.`question_id`
         <where>
@@ -347,7 +341,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isSubType != null  and isSubType == 0"> and (kq.sub = 0)</if>
             <if test="qtpye != null  and qtpye != ''"> and qtpye = #{qtpye}</if>
             <if test="typeId != null"> and kq.type = #{typeId}</if>
-            <if test="id != null ">  AND a.`student_id` IS NULL</if>
+            <if test="id != null ">  AND e.`examinee_id` IS NULL</if>
             <if test="knowledgeId != null "> and kq.knowledge_id  = #{knowledgeId}</if>
         </where>
         limit #{number}, 500