<?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.ningdatech.pmapi.leave.mapper.ExpertLeaveDetailMapper">

    <select id="selectLeaveIdByDateAndExpertId"
            resultType="com.ningdatech.pmapi.leave.entity.domain.ExpertLeaveDetail">
        select eld.expert_leave_id, eld.start_time, eld.end_time
        from expert_leave el
                 inner join expert_leave_detail eld on el.id = eld.expert_leave_id
        where leave_user_id = #{leaveUserId}
          and status in (2, 3)
          and ((eld.start_time &gt;= #{startDate} and eld.start_time &lt; #{endDate})
            or (eld.end_time &gt;= #{startDate} and eld.end_time &lt; #{endDate}))
    </select>

    <select id="existsLeaveByLeaveUserIdAndTime" resultType="integer">
        select 1
        from expert_leave el
        inner join expert_leave_detail eld on el.id = eld.expert_leave_id
        where leave_user_id = #{leaveUserId}
        and status not in (4, 5)
        <foreach collection="times" item="item" open="and (" close=")" separator="or">
            ((eld.start_time &gt;= #{item.key} and eld.start_time &lt; #{item.value})
            or (eld.end_time &gt;= #{item.key} and eld.end_time &lt; #{item.value}))
        </foreach>
        limit 1
    </select>

</mapper>
