From f0f00e9ba8a755e4317e029d73b69a92ad9f9df1 Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: 星期六, 14 九月 2024 17:02:41 +0800
Subject: [PATCH] update

---
 exam-system/src/main/resources/mapper/system/ExQuestionMapper.xml |   66 +++++++++++++++++++++------------
 1 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/exam-system/src/main/resources/mapper/system/ExQuestionMapper.xml b/exam-system/src/main/resources/mapper/system/ExQuestionMapper.xml
index dc2acc3..86c2181 100644
--- a/exam-system/src/main/resources/mapper/system/ExQuestionMapper.xml
+++ b/exam-system/src/main/resources/mapper/system/ExQuestionMapper.xml
@@ -18,6 +18,7 @@
         <result property="updateBy"       column="update_by"       />
         <result property="updateTime"     column="update_time"     />
         <result property="remark"         column="remark"          />
+        <result property="bankName"         column="bank_name"          />
         <association property="exExerciseAnswer" javaType="com.gkhy.exam.system.domain.ExExerciseAnswer" resultMap="ExerciseAnswerResult" />
         <association property="studentAnswer" javaType="com.gkhy.exam.system.domain.ExStudentAnswer" resultMap="StudentAnswerResult" />
     </resultMap>
@@ -51,32 +52,33 @@
     </select>
 
     <select id="selectQuestionWithLimit" resultType="com.gkhy.exam.system.domain.ExQuestion">
-        select id,title from ex_question where bank_id=#{bankId} and question_type=#{questionType} and (company_id=#{companyId} or privatize=1) limit #{startIndex},{questionCount}
+        select id,title from ex_question where bank_id=#{bankId} and question_type=#{questionType} and (company_id=#{companyId} or privatize=1) limit #{startIndex},#{questionCount}
     </select>
 
     <select id="selectRandomQuestion" resultType="com.gkhy.exam.system.domain.ExQuestion">
         select id,title from ex_question where bank_id=#{bankId} and question_type=#{questionType} and (company_id=#{companyId} or privatize=1) order by RAND()
-        limit {questionCount}
+        limit #{questionCount}
     </select>
 
     <select id="selectQuestionList" resultType="com.gkhy.exam.system.domain.ExQuestion">
-        select id,question_type, bank_id, status, company_id,answer,title,privatize from ex_question
+        select a.id,a.question_type, a.bank_id, a.status, a.company_id,a.title,a.privatize,b.name as bank_name from ex_question a
+        left join ex_question_bank b on b.id=a.bank_id
         <where>
             <if test="title!=null and title!=''">
-            title like concat(#{title},"%")
+                and a.title like concat(#{title},"%")
             </if>
             <if test="bankId!=null">
-                bank_id=#{bankId}
+                and a.bank_id=#{bankId}
             </if>
             <if test="companyId!=null">
-                company_id=#{companyId}
+                and (a.company_id=#{companyId} or a.privatize=1)
             </if>
             <if test="questionType!=null">
-                question_type=#{questionType}
+                and a.question_type=#{questionType}
             </if>
-            <if test="privatize!=null">
-                privatize=#{privatize}
-            </if>
+<!--            <if test="privatize!=null">-->
+<!--                and privatize=#{privatize}-->
+<!--            </if>-->
         </where>
         order by id desc
     </select>
@@ -85,12 +87,7 @@
         select a.id,b.passed from ex_question a
         left join ex_exercise_answer b on b.question_id=a.id and b.student_id=#{studentId}
         where a.bank_id=#{bankId}
-        <if test="exerciseType=2">
-            order by a.question_type asc,a.id asc
-        </if>
-        <if test="exerciseType=1">
-            order by a.id asc
-        </if>
+        order by a.question_type asc,a.id asc
     </select>
 
     <select id="getExeriseQuestionById" resultMap="ExQuestionResult">
@@ -106,18 +103,25 @@
         <foreach collection="questionIds" item="questionId" open="(" separator="," close=")">
             #{questionId}
         </foreach>
+        ORDER BY FIELD(a.id, <foreach collection="questionIds" item="questionId" separator=",">#{questionId}</foreach>)
     </select>
 
     <select id="getPaperQuestionList" resultType="java.util.Map">
         select a.id
-             <if test="completed=1">
-             ,c.passed
+             <if test="viewType==1">
+                ,
+                 case when c.answer is null then 0
+                 else 1
+                 end as state
              </if>
+            <if test="viewType==2">
+                <if test="state!=0">
+                    ,c.passed
+                </if>
+            </if>
         from ex_question a
         inner join ex_paper_question b on b.question_id=a.id
-        <if test="completed=1">
         left join ex_student_answer c on c.question_id=a.id and c.student_id=#{studentId} and c.paper_id=#{paperId}
-        </if>
         where b.paper_id=#{paperId}
         order by a.question_type asc,a.id asc
     </select>
@@ -125,7 +129,7 @@
     <select id="getPaperQuestionById" resultMap="ExQuestionResult">
         select a.id,a.question_type,a.bank_id,a.company_id,a.title,a.content,a.privatize,
                b.id as student_answer_id, b.answer as student_answer,b.question_id,b.student_id
-               <if test="completed=1">
+               <if test="state!=0">
                    ,a.answer,b.passed as student_passed
                </if>
         from ex_question a
@@ -133,10 +137,10 @@
         where a.id=#{questionId}
     </select>
 
-    <select id="getPaperQuestionByIds" resultType="com.gkhy.exam.system.domain.ExQuestion">
+    <select id="getPaperQuestionByIds" resultMap="ExQuestionResult">
         select a.id,a.question_type,a.bank_id,a.company_id,a.title,a.content,a.privatize,
         b.id as student_answer_id, b.answer as student_answer,b.question_id,b.student_id
-        <if test="completed=1">
+        <if test="state!=0">
             ,a.answer,b.passed as student_passed
         </if>
         from ex_question a
@@ -145,14 +149,28 @@
         <foreach collection="questionIds" item="questionId" open="(" separator="," close=")">
             #{questionId}
         </foreach>
+        ORDER BY FIELD(a.id, <foreach collection="questionIds" item="questionId" separator=",">#{questionId}</foreach>)
     </select>
 
     <select id="getExerciseErrorQuestionList" resultType="java.lang.Long">
         select a.id from ex_question a
         inner join ex_exercise_answer b on b.question_id=a.id
-        where a.bank_id=#{bankId} and b.student_id=#{studentId}
+        where a.bank_id=#{bankId} and b.student_id=#{studentId} and b.passed=0
         order by a.question_type asc,a.id asc
     </select>
 
+    <select id="selectByQuestionId" resultType="com.gkhy.exam.system.domain.ExQuestion">
+        select a.*,b.name as bank_name from ex_question a
+        left join ex_question_bank b on b.id=a.bank_id
+        where a.id=#{questionId}
+    </select>
+
+    <select id="selectQuestionByPaperId" resultType="com.gkhy.exam.system.domain.ExQuestion"
+            parameterType="java.lang.Long">
+        select a.* from ex_question a
+        inner join ex_paper_question b on b.question_id=a.id
+        where b.paper_id=#{paperId}
+    </select>
+
 
 </mapper>

--
Gitblit v1.9.2