<?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 CAST(teea.code AS UNSIGNED),CAST(t.room_code AS UNSIGNED)
	</select>

    <select id="getExamBreachPageExport" resultType="com.qmth.themis.business.bean.admin.ExamBreachListExportBean">
        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,'违纪' breachStatus,
        teea.code as examActivityCode,
        CONCAT(t.room_name,'(',t.room_code,')') as roomNameCode,
        CONCAT(t.course_name,'(',t.course_code,')') as courseNameCode,
        group_concat(CONCAT('时间：' , DATE_FORMAT(FROM_UNIXTIME(f.update_time / 1000), '%Y-%m-%d %H:%i:%s'), "，违纪类型：" , case when f.type = 'PLAGIARIZE' then '夹带抄袭'
        when f.type = 'LOOK_AROUND' then '左顾右盼'
        when f.type = 'ILLEGAL_ITEMS' then '考中携带违规物品'
        when f.type = 'TAKER' then '他人替考'
        when f.type = 'ASSISTANCE' then '他人协助作答'
        when f.type = 'BLACK_LIST_SOFTWARE' then '考中使用违规(远程协助、直播等)软件'
        else '其它' end, "，违纪说明：" ,f.description) separator '；') as breachDetail
        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>
        group by
        tee.name,
        f.exam_student_id,
        t.exam_id,
        t.exam_activity_id,
        t.room_code,
        t.course_code,
        t.course_name,
        t.NAME,
        t.identity,
        t.room_name,
        teea.code
        order by CAST(teea.code AS UNSIGNED),CAST(t.room_code AS UNSIGNED)
    </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 CAST(teea.code AS UNSIGNED),CAST(t.room_code AS UNSIGNED)
	</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>
