<?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.willalp.clockingin.mapper.HsPnsVacateTimeMapper">

    <resultMap type="com.willalp.clockingin.domain.HsPnsVacateTime" id="HsPnsVacateTimeResult">
        <result property="vacateId" column="vacate_id"/>
        <result property="userName" column="user_name"/>
        <result property="userId" column="user_id"/>
        <result property="userNo" column="user_no"/>
        <result property="orgNo" column="org_no"/>
        <result property="vacateStartTime" column="vacate_start_time"/>
        <result property="vacateEndTime" column="vacate_end_time"/>
        <result property="vacateType" column="vacate_type"/>
        <result property="isDelete" column="is_delete"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectHsPnsVacateTimeVo">
        select vacate_id,
               user_name,
               user_id,
               user_no,
               org_no,
               vacate_start_time,
               vacate_end_time,
               vacate_type,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from hs_pns_vacate_time
    </sql>

    <select id="selectHsPnsVacateTimeList" parameterType="HsPnsVacateTime" resultMap="HsPnsVacateTimeResult">
        <include refid="selectHsPnsVacateTimeVo"/>
        <where>
            is_delete = 0
            <if test="userName != null  and userName != ''">
                  and user_name like concat('%', #{userName}, '%')
            </if>
            <if test="userNo != null  and userNo != ''">
                  and user_no like concat('%', #{userNo}, '%')
            </if>
            <if test="orgNo != null  and orgNo != ''">
                  and org_no like concat('%', #{orgNo}, '%')
            </if>
            <if test="vacateStartTime != null ">
                  and vacate_start_time = #{vacateStartTime}
            </if>
            <if test="vacateEndTime != null ">
                  and vacate_end_time = #{vacateEndTime}
            </if>
            <if test="vacateType != null  and vacateType != ''">
                  and vacate_type = #{vacateType}
            </if>
            <if test="isDelete != null ">
                  and is_delete = #{isDelete}
                        </if>
        </where>
    </select>
    <select id="selectNewVacateInfo" resultMap="HsPnsVacateTimeResult">
        SELECT vacate_id,
               user_name,
               user_id,
               user_no,
               org_no,
               vacate_start_time,
               vacate_end_time,
               vacate_type,
               max(create_time) create_time,
               remark
        FROM hs_pns_vacate_time
        GROUP BY user_no
    </select>
</mapper>
