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

    <resultMap type="com.zhongzheng.modules.exam.domain.ExamArrangement" id="ExamArrangementResult">
        <result property="id" column="id"/>
        <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="updateTime" column="update_time"/>
        <result property="createTime" column="create_time"/>
        <result property="examTime" column="exam_time"/>
        <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="ExamArrangementResultVo">
        <result property="id" column="id"/>
        <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="updateTime" column="update_time"/>
        <result property="createTime" column="create_time"/>
        <result property="examTime" column="exam_time"/>
        <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"/>
        <collection property="examArrangementTimeVo" javaType="java.util.List" resultMap="ExamArrangementTimeResult"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.exam.domain.ExamArrangementTime" id="ExamArrangementTimeResult">
        <result property="arrangementId" column="arrangement_id"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
    </resultMap>

    <select id="selectExamgement" parameterType="com.zhongzheng.modules.exam.bo.ExamArrangementQueryBo" resultMap="ExamArrangementResultVo">
        SELECT
            s.*
        FROM
            exam_arrangement s
                LEFT JOIN exam_arrangement_time e ON e.arrangement_id = s.id
        WHERE 1=1
          AND s.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="signStartTime != null and signStartTime != ''">
            and exists(select * from exam_arrangement where sign_start_time BETWEEN #{signStartTime} and #{signEndTime}
        or sign_end_time BETWEEN #{signStartTime} and #{signEndTime})

        </if>
        <if test="examPeriod != null and examPeriod != ''">
            and s.exam_period like concat('%',#{examPeriod},'%')
        </if>
        <if test="examTypeId != null and examTypeId != ''">
            and s.exam_type_id = #{examTypeId}
        </if>
        group by s.id
    </select>
</mapper>