소스 검색

优化首页统计查询

yin 11 달 전
부모
커밋
f2b6f0bff3
1개의 변경된 파일30개의 추가작업 그리고 30개의 파일을 삭제
  1. 30 30
      teachcloud-mark/src/main/resources/mapper/MarkStudentMapper.xml

+ 30 - 30
teachcloud-mark/src/main/resources/mapper/MarkStudentMapper.xml

@@ -696,9 +696,21 @@
         group by bes.teacher_id, su.real_name, bes.teach_class_name
     </select>
     <select id="selectCountByQuery" resultType="java.lang.Integer">
-        select count(1) from mark_student ms left join basic_course bc on ms.course_id = bc.id
+        select count(1) from mark_student ms INNER join basic_course bc on ms.course_id = bc.id
+        <if test="dpr != null and dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
+                AND bc.teaching_room_id IN
+                <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+        </if>
+        <if test="markStudent.markPaperStatus != null">
+            INNER JOIN mark_paper mp ON ms.exam_id = mp.exam_id
+                                            and ms.paper_number = mp.paper_number
+                                            and ms.paper_type = mp.paper_type
+                                            and mp.status = #{markStudent.markPaperStatus}
+        </if>
         <where>
-            and ms.exam_id = #{markStudent.examId}
+            ms.exam_id = #{markStudent.examId}
             <if test="markStudent.courseId != null">
                 and ms.course_id = #{markStudent.courseId}
             </if>
@@ -726,20 +738,8 @@
             <if test="markStudent.missScan != null">
                 and ms.miss_scan = #{markStudent.missScan}
             </if>
-            <if test="dpr != null">
-                <if test="dpr.requestUserId != null">
-                    AND ms.create_id = #{dpr.requestUserId}
-                </if>
-                <if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
-                    AND bc.teaching_room_id IN
-                    <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
-                        #{item}
-                    </foreach>
-                </if>
-            </if>
-            <if test="markStudent.markPaperStatus != null">
-                AND exists(select 1 from mark_paper mp where ms.exam_id = mp.exam_id and ms.paper_number =
-                mp.paper_number and ms.paper_type = mp.paper_type and mp.status = #{markStudent.markPaperStatus})
+            <if test="dpr != null and dpr.requestUserId != null">
+                AND ms.create_id = #{dpr.requestUserId}
             </if>
         </where>
     </select>
@@ -749,6 +749,18 @@
         FROM
         mark_student ms
         LEFT JOIN basic_course bc ON ms.course_id = bc.id
+        <if test="dpr != null and dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
+            AND bc.teaching_room_id IN
+            <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="markStudent.markPaperStatus != null">
+            INNER JOIN mark_paper mp ON ms.exam_id = mp.exam_id
+            and ms.paper_number = mp.paper_number
+            and ms.paper_type = mp.paper_type
+            and mp.status = #{markStudent.markPaperStatus}
+        </if>
         <where>
             ms.exam_id = #{markStudent.examId}
             <if test="markStudent.courseId != null">
@@ -763,20 +775,8 @@
             <if test="markStudent.assignConfirmed != null">
                 AND ms.assign_confirmed = #{markStudent.assignConfirmed}
             </if>
-            <if test="dpr != null">
-                <if test="dpr.requestUserId != null">
-                    AND ms.create_id = #{dpr.requestUserId}
-                </if>
-                <if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
-                    AND bc.teaching_room_id IN
-                    <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
-                        #{item}
-                    </foreach>
-                </if>
-            </if>
-            <if test="markStudent.markPaperStatus != null">
-                AND exists(select 1 from mark_paper mp where ms.exam_id = mp.exam_id and ms.paper_number =
-                mp.paper_number and ms.paper_type = mp.paper_type and mp.status = #{markStudent.markPaperStatus})
+            <if test="dpr != null and dpr.requestUserId != null">
+                AND ms.create_id = #{dpr.requestUserId}
             </if>
         </where>
     </select>