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

    <select id="examInvigilateCallQuery" resultType="com.qmth.themis.business.dto.response.TIeExamInvigilateCallDto">
        select
            tieic.*,
            tees.name as examStudentName,
            tes.base_photo_path as basePhotoPath
        from
            t_ie_exam_invigilate_call tieic
        left join t_e_exam_student tees on
            tees.id = tieic.exam_student_id
        left join t_e_student tes on
            tes.id = tees.student_id
        left join t_b_exam_invigilate_user tbeiu on
            tbeiu.exam_id = tieic.exam_id
        and tbeiu.room_code = tees.room_code
        <where>
            <if test="examId != null and examId != ''">
                and tieic.exam_id = #{examId}
            </if>
            <if test="userId != null and userId != ''">
                and tbeiu.user_id = #{userId}
            </if>
            <if test="orgId != null and orgId != ''">
                and tbeiu.org_id = #{orgId}
            </if>
            <if test="status != null and status != ''">
                and tieic.status = #{status}
            </if>
            <if test="callStatus != null and callStatus != ''">
                and tieic.call_status = #{callStatus}
            </if>
        </where>
    </select>

    <select id="examInvigilateCallQueryCount" resultType="java.lang.Integer">
        select
        count(1)
        from
            t_ie_exam_invigilate_call tieic
        left join t_e_exam_student tees on
            tees.id = tieic.exam_student_id
        left join t_e_student tes on
            tes.id = tees.student_id
        left join t_b_exam_invigilate_user tbeiu on
            tbeiu.exam_id = tieic.exam_id
        and tbeiu.room_code = tees.room_code
        <where>
            <if test="examId != null and examId != ''">
                and tieic.exam_id = #{examId}
            </if>
            <if test="userId != null and userId != ''">
                and tbeiu.user_id = #{userId}
            </if>
            <if test="orgId != null and orgId != ''">
                and tbeiu.org_id = #{orgId}
            </if>
            <if test="status != null and status != ''">
                and tieic.status = #{status}
            </if>
            <if test="callStatus != null and callStatus != ''">
                and tieic.call_status = #{callStatus}
            </if>
        </where>
    </select>
</mapper>
