<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qmth.themis.business.dao.TIeInvigilateExceptionInfoMapper">

<select id="getExamExceptionPage"
		resultType="com.qmth.themis.business.bean.admin.ExamExceptionListBean">
		SELECT
		tee.name as examName,
		f.exam_student_id examStudentId,
		t.exam_id examId,
		t.exam_activity_id examActivityId,
		t.room_code roomCode,
		t.course_code courseCode,
		t.course_name courseName,
		t.NAME,
		t.identity,
		t.room_name roomName,
		count(f.exam_student_id) exceptionCount,
		sum(f.difference) exceptionTotalTime,
		teea.code as examActivityCode
		FROM
		t_ie_invigilate_exception_info f
		LEFT JOIN t_e_exam_student t ON f.exam_student_id = t.id
		left join t_e_student h on t.student_id=h.id
		left join t_e_exam_activity teea on teea.id = t.exam_activity_id
		join t_e_exam tee on tee.id = f.exam_id
		where f.exam_id =#{examId}
		<if test="orgId != null">
		 	and h.org_id=#{orgId}
		</if>
		<if test="activityId != null and activityId != ''">
			and f.exam_activity_id = #{activityId}
		</if>
		<if test="roomCode != null and roomCode != ''">
			and t.room_code =#{roomCode}
		</if>
		<if test="courseCode != null and courseCode != ''">
			and t.course_code = #{courseCode}
		</if>
		<if test="identity != null and identity != ''">
			and t.identity like concat('%',#{identity},'%')
		</if>
		<if test="name != null and name != ''">
			and t.name like concat('%',#{name},'%')
		</if>
		GROUP BY f.exam_student_id
        order by CAST(teea.code AS UNSIGNED),CAST(t.room_code AS UNSIGNED)
	</select>
	
	<select id="getExamExceptionDetailList"
		resultType="com.qmth.themis.business.bean.admin.ExamExceptionDetailListBean">
		SELECT
		f.create_time startTime,
		f.update_time endTime,
		f.type reason,
		f.difference totalTime
		FROM
		t_ie_invigilate_exception_info f
		where f.exam_student_id =#{examStudentId}
		order by f.exam_student_id
	</select>
</mapper>
