瀏覽代碼

在线考试过滤已经达到限制次数的考试

yangfeng 1 年之前
父節點
當前提交
93fa6c332c
共有 1 個文件被更改,包括 49 次插入28 次删除
  1. 49 28
      web/src/main/java/com/ynfy/buss/exam/exam/mapper/xml/ExamMapper.xml

+ 49 - 28
web/src/main/java/com/ynfy/buss/exam/exam/mapper/xml/ExamMapper.xml

@@ -72,39 +72,60 @@
 
     <select id="selectExamList"  resultType="com.ynfy.buss.exam.exam.entity.Exam">
         SELECT
-               tmp.*
+            tmp1.*
         FROM
-            (
-                 SELECT
-                        *
-                 FROM exam
-                 WHERE
-                       open_type = 1
-                <choose>
-                    <when test="user.orgCode!=null and user.orgCode!=''">
-                 UNION
-                 SELECT
-                        *
-                 FROM exam
-                 WHERE
-                       open_type = 2
-                       AND examiner like concat('%', #{user.orgCode}, '%')
-                    </when>
-                </choose>
-                 UNION
-                 SELECT
-                        *
-                 FROM exam
-                 WHERE
-                       open_type = 3
-                       AND examiner like concat('%', #{user.username}, '%')
-             ) tmp
+        (
+            SELECT
+                    *
+            FROM exam
+            WHERE
+                open_type = 1
+            <choose>
+                <when test="user.orgCode!=null and user.orgCode!=''">
+            UNION
+            SELECT
+                    *
+            FROM exam
+            WHERE
+                open_type = 2
+                AND examiner like concat('%', #{user.orgCode}, '%')
+                </when>
+            </choose>
+            UNION
+            SELECT
+                *
+            FROM exam
+            WHERE
+                open_type = 3
+                AND examiner like concat('%', #{user.username}, '%')
+        ) tmp1
+        LEFT JOIN (
+            SELECT
+                exam_id,
+                COUNT ( * ) AS try_count
+            FROM
+                user_exam uer
+            WHERE
+                uer.user_id = #{user.id}
+            GROUP BY
+                exam_id
+        ) tmp2
+        ON tmp1.ID = tmp2.exam_id
         <where>
+            (
+                CASE WHEN
+                    tmp1.limit_count IS NOT NULL AND tmp2.try_count IS NOT NULL
+                THEN
+                    tmp2.try_count &lt; tmp1.limit_count
+                ELSE
+                    1 = 1
+                END
+            )
             <if test="exam.title!=null and exam.title!=''">
-                AND tmp.title like concat('%', #{exam.title}, '%')
+                AND tmp1.title like concat('%', #{exam.title}, '%')
             </if>
             <if test="exam.openType!=null">
-                AND tmp.open_type = #{exam.openType}
+                AND tmp1.open_type = #{exam.openType}
             </if>
         </where>
     </select>