<?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.xjrsoft.module.teacher.mapper.WfTeacherleaveMapper">
    <select id="getLeaveCount" resultType="java.lang.Long">
        SELECT COUNT(*) FROM wf_teacherleave t1
        INNER JOIN xjr_user t2 ON t1.user_id = t2.id
        WHERE t1.status = 1 AND t2.delete_mark = 0
        AND (
        (leave_start_time BETWEEN #{startTime} and #{endTime})
        OR (leave_end_time BETWEEN #{startTime} and #{endTime})
        OR (leave_start_time > #{startTime} and #{endTime} > leave_end_time)
        OR (#{startTime} > leave_start_time and leave_end_time > #{endTime})
        )
    </select>

    <select id="getLeaveList" resultType="com.xjrsoft.module.teacher.entity.WfTeacherleave">
        SELECT * FROM wf_teacherleave t1
                                 INNER JOIN xjr_user t2 ON t1.user_id = t2.id
        WHERE t1.status = 1 AND t2.delete_mark = 0
          AND (
                (leave_start_time BETWEEN #{startTime} and #{endTime})
                OR (leave_end_time BETWEEN #{startTime} and #{endTime})
                OR (leave_start_time > #{startTime} and #{endTime} > leave_end_time)
                OR (#{startTime} > leave_start_time and leave_end_time > #{endTime})
            )
    </select>
    <select id="getLeaveByUserId" resultType="com.xjrsoft.module.teacher.entity.WfTeacherleave">
        SELECT * FROM wf_teacherleave t1
                          INNER JOIN xjr_user t2 ON t1.user_id = t2.id
        WHERE t1.status = 1 AND t2.delete_mark = 0
          AND (
                (leave_start_time BETWEEN #{startTime} and #{endTime})
                OR (leave_end_time BETWEEN #{startTime} and #{endTime})
                OR (leave_start_time > #{startTime} and #{endTime} > leave_end_time)
                OR (#{startTime} > leave_start_time and leave_end_time > #{endTime})
            )
        and t2.id = #{userId}
    </select>
</mapper>