<?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.TEExamBreachLogMapper">

	<select id="getExamBreachPage"
		resultType="com.qmth.themis.business.bean.admin.ExamBreachListBean">
		SELECT
        distinct 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,'违纪' breachStatus,
		teea.code as examActivityCode
		FROM
		t_e_exam_breach_log 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} and f.status=0
		<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>
        order by f.exam_student_id
	</select>

	<select id="getExamRevokeBreachPage"
		resultType="com.qmth.themis.business.bean.admin.ExamBreachListBean">
		SELECT
        distinct tee.name as examName,
		f.exam_student_id as examStudentId,
		t.exam_id as examId,
		t.exam_activity_id as examActivityId,
		t.room_code as roomCode,
		t.course_code as courseCode,
		t.course_name as courseName,
		t.NAME as name,
		t.identity,
		t.room_name as roomName,
		'正常' as breachStatus,
		teea.code as examActivityCode
		FROM
		t_e_exam_breach_log 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} and f.status=1
		<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>
        order by f.exam_student_id
	</select>

	<select id="getExamBreachDetailList"
		resultType="com.qmth.themis.business.bean.admin.ExamBreachDetailListBean">
		SELECT
		(case when f.status=0 then '违纪处理' else '撤销违纪'
		end)status,
		t.name createName,
		f.update_time
		endTime,
		f.type type,
		f.description description
		FROM
		t_e_exam_breach_log f
		left join
		t_b_user t on f.create_id=t.id
		where f.exam_student_id
		=#{examStudentId}
		and f.status = #{status}
		order by f.create_time
	</select>
</mapper>
