<?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.zhongzheng.modules.exam.mapper.ExamArrangementStudentMapper">

    <resultMap type="com.zhongzheng.modules.exam.domain.ExamArrangementStudent" id="ExamArrangementStudentResult">
        <result property="arrangementId" column="arrangement_id"/>
        <result property="studentId" column="student_id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.exam.vo.ExamUserVo" id="UserResult">
        <result property="userId" column="user_id"/>
        <result property="userAccout" column="user_accout"/>
        <result property="nickname" column="nickname"/>
        <result property="realname" column="realname"/>
        <result property="sex" column="sex"/>
        <result property="idCard" column="id_card"/>
        <result property="telphone" column="telphone"/>
        <result property="userLevel" column="user_level"/>
        <result property="userBirth" column="user_birth"/>
        <result property="eduLevel" column="edu_level"/>
        <result property="schoolId" column="school_id"/>
        <result property="major" column="major"/>
        <result property="entranceTime" column="entrance_time"/>
        <result property="openId" column="open_id"/>
        <result property="idCardImg1" column="id_card_img1"/>
        <result property="idCardImg2" column="id_card_img2"/>
        <result property="country" column="country"/>
        <result property="province" column="province"/>
        <result property="city" column="city"/>
        <result property="examId" column="id"/>
        <result property="integral" column="integral"/>
        <result property="examTypeId" column="exam_type_id"/>
        <result property="examType" column="exam_type"/>
        <result property="signStartTime" column="sign_start_time"/>
        <result property="signEndTime" column="sign_end_time"/>
        <result property="examAdress" column="exam_adress"/>
        <result property="examUrl" column="exam_url"/>
        <result property="remarks" column="remarks"/>
        <result property="releaseNum" column="release_num"/>
        <result property="subscrPe" column="subscr_pe"/>
        <result property="signUpPe" column="sign_up_pe"/>
        <result property="releaseTime" column="release_time"/>
        <result property="examTime" column="exam_time"/>
        <result property="regGuide" column="reg_guide"/>
        <result property="examPeriod" column="exam_period"/>
        <result property="status" column="status"/>
        <result property="examForm" column="exam_form"/>
        <result property="examFromUrl" column="exam_from_url"/>
        <result property="printUrl" column="print_url"/>
        <result property="gradesUrl" column="grades_url"/>
        <result property="scoreLineUrl" column="score_line_url"/>
        <result property="certificate" column="certificate"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.exam.vo.ExamArrangementVo" id="ExamArrangementResult">
        <result property="id" column="id"/>
        <result property="examTypeId" column="uexam_type_id"/>
        <result property="examType" column="exam_type"/>
        <result property="signStartTime" column="sign_start_time"/>
        <result property="signEndTime" column="sign_end_time"/>
        <result property="examAdress" column="exam_adress"/>
        <result property="examUrl" column="exam_url"/>
        <result property="remarks" column="remarks"/>
        <result property="releaseNum" column="release_num"/>
        <result property="subscrPe" column="subscr_pe"/>
        <result property="signUpPe" column="sign_up_pe"/>
        <result property="releaseTime" column="release_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createTime" column="create_time"/>
        <result property="examTime" column="exam_time"/>
        <result property="regGuide" column="reg_guide"/>
        <result property="examPeriod" column="exam_period"/>
        <result property="status" column="status"/>
        <result property="examForm" column="exam_form"/>
        <result property="examFromUrl" column="exam_from_url"/>
        <result property="printUrl" column="print_url"/>
        <result property="gradesUrl" column="grades_url"/>
        <result property="scoreLineUrl" column="score_line_url"/>
        <result property="certificate" column="certificate"/>
    </resultMap>

    <select id="selectExamUserList" parameterType="com.zhongzheng.modules.exam.bo.ExamArrangementQueryBo" resultMap="UserResult">
        SELECT
        u.user_id,
        u.user_account,
        u.nickname,
        u.realname,
        u.sex,
        u.id_card,
        u.telphone,
        u.user_level,
        u.user_birth,
        u.edu_level,
        u.school_id,
        u.major,
        u.entrance_time,
        u.open_id,
        u.id_card_img1,
        u.id_card_img2,
        u.country,
        u.province,
        u.city,
        u.integral,
        u.create_time,
        u.update_time,
        u.status,
        e.id,
        e.exam_type_id,
        e.exam_type,
        e.sign_start_time,
        e.sign_end_time,
        e.exam_adress,
        e.exam_url,
        e.remarks,
        e.release_num,
        e.subscr_pe,
        e.sign_up_pe,
        e.release_time,
        e.exam_time,
        e.exam_period,
        e.exam_form,
        e.exam_from_url,
        e.print_url,
        e.grades_url,
        e.score_line_url,
        e.certificate
        FROM
            exam_arrangement_student s
                LEFT JOIN `user` u ON s.student_id = u.user_id
                LEFT JOIN exam_arrangement e ON s.arrangement_id = e.id
        WHERE 1=1
          AND e.status != 0
        <if test="startTime != null and startTime != ''">
            and exists(select * from exam_arrangement_time where start_time BETWEEN #{startTime} and #{endTime}
            or  end_time BETWEEN #{startTime} and #{endTime})
        </if>
        <if test="examTypeId != null and examTypeId != ''">
            AND e.exam_type_id = #{examTypeId}
        </if>
        <if test="examPeriod != null and examPeriod != ''">
            and e.exam_period like concat('%',#{examPeriod},'%')
        </if>
        <if test="idCard != null and idCard != ''">
            AND u.id_card like concat('%',#{idCard},'%')
        </if>
        <if test="realname != null and realname != ''">
            AND u.realname like concat('%',#{realname},'%')
        </if>
    </select>

    <select id="selectSubList" parameterType="com.zhongzheng.modules.exam.bo.ExamArrangementQueryBo" resultMap="UserResult">
        SELECT
        u.user_id,
        u.user_account,
        u.nickname,
        u.realname,
        u.sex,
        u.id_card,
        u.telphone,
        u.user_level,
        u.user_birth,
        u.edu_level,
        u.school_id,
        u.major,
        u.entrance_time,
        u.open_id,
        u.student_certificate_img,
        u.id_card_img1,
        u.id_card_img2,
        u.country,
        u.province,
        u.city,
        u.integral,
        u.create_time,
        u.update_time,
        u.status,
        e.id,
        e.exam_type_id,
        e.exam_type,
        e.sign_start_time,
        e.sign_end_time,
        e.exam_adress,
        e.exam_url,
        e.remarks,
        e.release_num,
        e.subscr_pe,
        e.sign_up_pe,
        e.release_time,
        e.exam_time,
        e.exam_period,
        e.exam_form,
        e.exam_from_url,
        e.print_url,
        e.grades_url,
        e.score_line_url,
        e.certificate
        FROM
        exam_arrangement_sub s
        LEFT JOIN `user` u ON s.sub_id = u.user_id
        LEFT JOIN exam_arrangement e ON s.exam_id = e.id
        WHERE 1=1
        AND e.status != 0

        <if test="examId != null and examId != ''">
            AND s.exam_id = #{examId}
        </if>
    </select>
</mapper>