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

    <resultMap id="Result_TVacationMonitorVO" type="com.yifu.cloud.plus.v1.business.vo.vacation.TVacationMonitorVO">
            <result property="vacationYear" column="VACATION_YEAR" jdbcType="VARCHAR"/>
            <result property="businessTelecomNumber" column="BUSINESS_TELECOM_NUMBER" jdbcType="VARCHAR"/>
            <result property="empIdcard" column="EMP_IDCARD" jdbcType="VARCHAR"/>
            <result property="empName" column="EMP_NAME" jdbcType="VARCHAR"/>
            <result property="businessPost" column="BUSINESS_POST" jdbcType="VARCHAR"/>
            <result property="vacationDuration" column="VACATION_DURATION" jdbcType="DECIMAL"/>
            <result property="notUsedVacationDuration" column="NOT_USED_VACATION_DURATION" jdbcType="DECIMAL"/>
            <result property="businessEnjoinDate" column="BUSINESS_ENJOIN_DATE" jdbcType="TIMESTAMP"/>
            <result property="departCode" column="DEPART_CODE" jdbcType="VARCHAR"/>
            <result property="departName" column="DEPART_NAME" jdbcType="VARCHAR"/>
            <result property="departId" column="DEPART_ID" jdbcType="INTEGER"/>
    </resultMap>


    <sql id="Column_TVacationMonitorVO">
        a.ID,
        a.VACATION_YEAR,
        a.BUSINESS_TELECOM_NUMBER,
        a.EMP_IDCARD,
        a.EMP_NAME,
        b.name as DEPART_NAME,
        b.id as DEPART_ID,
        b.tree_logo as DEPART_CODE,
        a.BUSINESS_POST,
        a.VACATION_DURATION,
        a.NOT_USED_VACATION_DURATION,
        a.BUSINESS_ENJOIN_DATE,
        a.VACATION_STATUS
    </sql>

    <sql id="Where_TVacationMonitorQuery">
        1=1
        <if test="query.businessTelecomNumber != null and query.businessTelecomNumber.trim() != ''">
            and a.BUSINESS_TELECOM_NUMBER like concat('%', #{query.businessTelecomNumber}, '%')
        </if>
        <if test="query.empName != null and query.empName.trim() != ''">
            and a.EMP_NAME like concat('%',#{query.empName}, '%')
        </if>
        <if test="query.empIdcard != null and query.empIdcard.trim() != ''">
            and a.EMP_IDCARD like concat('%',#{query.empIdcard} , '%')
        </if>
        <if test="query.businessPost != null and query.businessPost.trim() != ''">
            and a.BUSINESS_POST = #{query.businessPost}
        </if>
        <if test="query.departId != null and query.departId != 1">
            AND (b.id = #{query.departId} or b.tree_logo like concat('%-', #{query.departId},'-%'))
        </if>
        <if test="query.vacationStatus != null and query.vacationStatus.trim() != ''">
            and a.VACATION_STATUS = #{query.vacationStatus}
        </if>
        <if test="query.vacationYear != null and query.vacationYear.trim() != ''">
            and a.VACATION_YEAR = #{query.vacationYear}
        </if>
    </sql>

    <select id="getListByPage" resultMap="Result_TVacationMonitorVO">
        select
        <include refid="Column_TVacationMonitorVO"/>
        from hr_business.t_vacation_monitor a
        left join hr_business.t_bus_dept b on a.DEPART_ID = b.id
        <where>
            <include refid="Where_TVacationMonitorQuery"/>
        </where>
        order by a.VACATION_YEAR desc
    </select>

    <select id="getList" resultMap="Result_TVacationMonitorVO">
        select
        <include refid="Column_TVacationMonitorVO"/>
        from hr_business.t_vacation_monitor a
        left join hr_business.t_bus_dept b on a.DEPART_ID = b.id
        <where>
            <include refid="Where_TVacationMonitorQuery"/>
        </where>
        order by a.VACATION_YEAR desc
    </select>


</mapper>