Selaa lähdekoodia

优化客观题检查查询性能

yin 11 kuukautta sitten
vanhempi
commit
253fd14003
1 muutettua tiedostoa jossa 46 lisäystä ja 42 poistoa
  1. 46 42
      teachcloud-mark/src/main/resources/mapper/ScanOmrTaskMapper.xml

+ 46 - 42
teachcloud-mark/src/main/resources/mapper/ScanOmrTaskMapper.xml

@@ -38,8 +38,18 @@
 			bes.student_name,
 			s.student_code
 		from mark_student s
-		    left join (select * from basic_exam_student where exam_id = #{examId}) bes on s.basic_student_id = bes.id
-		    left join sys_user su on s.create_id = su.id
+			inner join basic_exam_student bes on s.basic_student_id = bes.id
+			INNER join sys_user su on s.create_id = su.id
+			<if test="dpr != null and dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
+				AND su.org_id IN
+				<foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
+					#{item}
+				</foreach>
+			</if>
+			INNER JOIN mark_paper mp ON s.exam_id = mp.exam_id
+				and s.paper_number = mp.paper_number
+				and s.paper_type = mp.paper_type
+				and mp.status = #{markPaperStatus}
 			<where>
 				<if test="examId != null">
 					and s.exam_id = #{examId}
@@ -56,31 +66,33 @@
 				<if test="studentCodeOrName != null and studentCodeOrName != ''">
 					and (s.student_code = #{studentCodeOrName} or bes.student_name = #{studentCodeOrName})
 				</if>
-					and exists (select 1 from mark_paper mp where s.exam_id = mp.exam_id and s.course_paper_id = mp.course_paper_id and s.paper_type = mp.paper_type and mp.status = #{markPaperStatus})
+				<if test="dpr != null and dpr.requestUserId != null">
+					AND s.create_id = #{dpr.requestUserId}
+				</if>
 					and exists(select 1
 						from scan_omr_task t
 						where t.exam_id = #{examId}
 						and t.status=#{status}
 						and s.id = t.student_id
-				<if test="dpr != null">
-							<if test="dpr.requestUserId != null">
-								AND s.create_id = #{dpr.requestUserId}
-							</if>
-							<if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
-								AND su.org_id IN
-								<foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
-									#{item}
-								</foreach>
-							</if>
-						</if>
-				)
+					)
 			</where>
 	</select>
 	
 	<select id="getStudentCountByExamAndStatusAndUserId" resultType="int">
 		select
 			count(1)
-		from mark_student s left join sys_user su on s.create_id = su.id
+		from mark_student s
+		INNER JOIN sys_user su on s.create_id = su.id
+			<if test="dpr != null and dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
+				AND su.org_id IN
+				<foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
+					#{item}
+				</foreach>
+			</if>
+		INNER JOIN mark_paper mp ON s.exam_id = mp.exam_id
+			and s.paper_number = mp.paper_number
+			and s.paper_type = mp.paper_type
+			and mp.status = #{markPaperStatus}
 		<where>
 			<if test="examId != null">
 				and s.exam_id = #{examId}
@@ -94,23 +106,14 @@
 			<if test="coursePaperId != null and coursePaperId != ''">
 				and s.course_paper_id = #{coursePaperId}
 			</if>
-			and exists (select 1 from mark_paper mp where s.exam_id = mp.exam_id and s.course_paper_id = mp.course_paper_id and s.paper_type = mp.paper_type and mp.status = #{markPaperStatus})
+			<if test="dpr != null and dpr.requestUserId != null">
+				AND s.create_id = #{dpr.requestUserId}
+			</if>
 			and exists(select 1
 			from scan_omr_task t
 			where t.exam_id = #{examId}
 			and t.status=#{status}
 			and s.id = t.student_id
-			<if test="dpr != null">
-				<if test="dpr.requestUserId != null">
-					AND s.create_id = #{dpr.requestUserId}
-				</if>
-				<if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
-					AND su.org_id IN
-					<foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
-						#{item}
-					</foreach>
-				</if>
-			</if>
 			)
 		</where>
 	</select>
@@ -169,28 +172,29 @@
 						1
 					FROM
 						mark_student ms
-							left join sys_user su on ms.create_id = su.id
-					WHERE
-						sot.student_id = ms.id
+						INNER join sys_user su on ms.create_id = su.id
+						<if test="dpr != null and dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
+							AND su.org_id IN
+							<foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
+								#{item}
+							</foreach>
+						</if>
 						<if test="scanOmrTask.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 = #{scanOmrTask.markPaperStatus})
+							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 = #{scanOmrTask.markPaperStatus}
 						</if>
+					WHERE
+						sot.student_id = ms.id
 						<if test="scanOmrTask.courseCode != null">
 							AND ms.course_code = #{scanOmrTask.courseCode}
 						</if>
 						<if test="scanOmrTask.coursePaperId != null">
 							AND ms.course_paper_id = #{scanOmrTask.coursePaperId}
 						</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 su.org_id IN
-								<foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
-									#{item}
-								</foreach>
-							</if>
+						<if test="dpr != null and dpr.requestUserId != null">
+							AND ms.create_id = #{dpr.requestUserId}
 						</if>
 						)
 					</if>