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

	<select id="currentApplyTask" resultType="com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO">
		select t.id task_id,t.name task_name,t.org_id,org.name org_name,
			   t.allow_apply_days,t.allow_apply_cancel_days,
			   t.self_apply_start_time,t.self_apply_end_time,
			   t.open_apply_start_time,t.open_apply_end_time
		from t_apply_task t
		left join t_org org on org.id = t.org_id
		where t.`enable` = 1
		<if test="orgId != null">
			and t.org_id = #{orgId}
		</if>
		order by t.id desc
		limit 1
	</select>

	<select id="page"
		resultType="com.qmth.exam.reserve.bean.task.ApplyTaskVO">
		select id,name,self_apply_start_time selfApplyStartTime,
		self_apply_end_time selfApplyEndTime,
		open_apply_start_time
		openApplyStartTime,
		open_apply_end_time openApplyEndTime,
		enable,update_time updateTime from t_apply_task t
		<if test="req.name != null and req.name!=''">
			where t.name like concat('%', #{req.name}, '%')
		</if>
		order by t.update_time desc
	</select>

	<select id="find"
		resultType="com.qmth.exam.reserve.bean.task.ApplyTaskRuleVO">
		select * from t_apply_task where id=#{id}
	</select>

	<select id="getTimePeriodList"
		resultType="com.qmth.exam.reserve.bean.task.TimePeriodVO">
		select id,start_time startTime,end_time endTime from
		t_time_period where apply_task_id=#{id}
		order by start_time
	</select>

</mapper>
