<?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.exam.reserve.dao.TimePeriodExamSiteDao">

    <select id="findExamSiteTimePeriods" resultType="com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodInfo">
        select p.id as time_period_id,
        p.start_time,
        p.end_time,
        (case when pe.enable = 0 then 0 else 1 end) as enable
        from t_time_period p
        left join t_time_period_exam_site pe on pe.time_period_id = p.id and pe.exam_site_id = #{query.examSiteId}

        where p.apply_task_id = #{query.applyTaskId}

        <if test="query.timePeriodId != null">
            and p.id = #{query.timePeriodId}
        </if>

        <if test="query.timeBegin != null and query.timeEnd != null">
            and p.start_time between #{query.timeBegin} and #{query.timeEnd}
        </if>
    </select>

</mapper>
