<?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.yifu.cloud.plus.v1.business.mapper.vacation.TBusLeaveMapper">
    <resultMap id="tBusLeaveMap" type="com.yifu.cloud.plus.v1.business.entity.vacation.TBusLeave">
        <id property="id" column="id"/>
        <result property="teleNo" column="tele_no"/>
        <result property="name" column="name"/>
        <result property="idCard" column="id_card"/>
        <result property="post" column="post"/>
        <result property="deptId" column="dept_id"/>
        <result property="deptName" column="dept_name"/>
        <result property="leaveDate" column="leave_date"/>
        <result property="leavePostDate" column="leave_post_date"/>
        <result property="leaveReason" column="leave_reason"/>
        <result property="createUserId" column="create_user_id"/>
        <result property="createUserName" column="create_user_name"/>
        <result property="createTime" column="create_time"/>
        <result property="deleteFlag" column="delete_flag"/>
        <result property="deptTreeLogo" column="dept_tree_logo"/>
    </resultMap>
    <sql id="Base_Column_List">
             a.id,
                  a.tele_no,
                  a.name,
                  a.id_card,
                  a.post,
                  a.dept_id,
                  a.dept_name,
                  a.leave_date,
                  a.leave_post_date,
                  a.leave_reason,
                  a.create_user_id,
                  a.create_user_name,
                  a.create_time,
                  a.delete_flag,
                  a.dept_tree_logo
         </sql>
    <sql id="tBusLeave_where">
        <if test="tBusLeave != null">
            <if test="tBusLeave.id != null and tBusLeave.id.trim() != ''">
                AND a.id = #{tBusLeave.id}
            </if>
            <if test="tBusLeave.teleNo != null and tBusLeave.teleNo.trim() != ''">
                AND a.tele_no like concat('%', #{tBusLeave.teleNo},'%')
            </if>
            <if test="tBusLeave.name != null and tBusLeave.name.trim() != ''">
                AND a.name like concat('%', #{tBusLeave.name},'%')
            </if>
            <if test="tBusLeave.idCard != null and tBusLeave.idCard.trim() != ''">
                AND a.id_card = #{tBusLeave.idCard}
            </if>
            <if test="tBusLeave.post != null and tBusLeave.post.trim() != ''">
                AND a.post like concat('%', #{tBusLeave.post},'%')
            </if>

            /* 查找部门树以及底下的数据 */
            <if test="tBusLeave.deptId != null and tBusLeave.deptId != 1">
                AND (a.dept_id = #{tBusLeave.deptId} or a.dept_tree_logo like concat('%-', #{tBusLeave.deptId},'-%'))
            </if>

            <if test="tBusLeave.deptName != null and tBusLeave.deptName.trim() != ''">
                AND a.dept_name = #{tBusLeave.deptName}
            </if>
            <if test="tBusLeave.leaveDate != null">
                AND a.leave_date = #{tBusLeave.leaveDate}
            </if>
            <if test="tBusLeave.leavePostDate != null">
                AND a.leave_post_date = #{tBusLeave.leavePostDate}
            </if>
            <if test="tBusLeave.leaveReason != null and tBusLeave.leaveReason.trim() != ''">
                AND a.leave_reason = #{tBusLeave.leaveReason}
            </if>
            <if test="tBusLeave.createUserId != null and tBusLeave.createUserId.trim() != ''">
                AND a.create_user_id = #{tBusLeave.createUserId}
            </if>
            <if test="tBusLeave.createUserName != null and tBusLeave.createUserName.trim() != ''">
                AND a.create_user_name = #{tBusLeave.createUserName}
            </if>
            <if test="tBusLeave.createTime != null">
                AND a.create_time = #{tBusLeave.createTime}
            </if>
            <if test="tBusLeave.deleteFlag != null">
                AND a.delete_flag = #{tBusLeave.deleteFlag}
            </if>
            <if test="tBusLeave.leaveDateStart != null">
                AND a.leave_date >= #{tBusLeave.leaveDateStart}
            </if>
            <if test="tBusLeave.leaveDateEnd != null">
                AND a.leave_date <![CDATA[ <= ]]> #{tBusLeave.leaveDateEnd}
            </if>
            <if test="tBusLeave.leavePostStart != null">
                AND a.leave_post_date >= #{tBusLeave.leavePostStart}
            </if>
            <if test="tBusLeave.leavePostEnd != null">
                AND a.leave_post_date <![CDATA[ <= ]]> #{tBusLeave.leavePostEnd}
            </if>
            <if test="tBusLeave.deptTreeLogo != null and tBusLeave.deptTreeLogo.trim() != '' ">
                AND a.dept_tree_logo like concat(#{tBusLeave.deptTreeLogo},'%')
            </if>
        </if>
    </sql>
    <!--tBusLeave简单分页查询-->
    <select id="getTBusLeavePage" resultMap="tBusLeaveMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_bus_leave a
        <where>
            a.delete_flag = 0
            <include refid="tBusLeave_where"/>
        </where>
        order by a.create_time desc
    </select>

    <!--获取list-->
    <select id="getTBusLeaveList" resultMap="tBusLeaveMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_bus_leave a
        <where>
            a.delete_flag = 0
            <include refid="tBusLeave_where"/>
        </where>
        order by a.create_time desc
    </select>

</mapper>
