<?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.ruoyi.system.mapper.TdLeaveMapper">
    
    <resultMap type="TdLeave" id="TdLeaveResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="country"    column="country"    />
        <result property="areaname"    column="areaname"    />
        <result property="leavereason"    column="leavereason"    />
        <result property="depart"    column="depart"    />
        <result property="leavedate"    column="leavedate"    />
        <result property="workstate"    column="workstate"    />
        <result property="leavestate"    column="leavestate"    />
        <result property="examinename"    column="examinename"    />
        <result property="examinedate"    column="examinedate"    />
        <result property="examinestate"    column="examinestate"    />
    </resultMap>

    <sql id="selectTdLeaveVo">
        select id, user_id, user_name, country, areaname, leavereason, depart, leavedate, workstate, leavestate, examinename, examinedate, examinestate from td_leave
    </sql>

    <select id="selectTdLeaveList" parameterType="TdLeave" resultMap="TdLeaveResult">
        <include refid="selectTdLeaveVo"/>
        <where>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="country != null  and country != ''"> and country = #{country}</if>
            <if test="areaname != null  and areaname != ''"> and areaname like concat('%', #{areaname}, '%')</if>
            <if test="leavereason != null  and leavereason != ''"> and leavereason = #{leavereason}</if>
            <if test="depart != null  and depart != ''"> and depart = #{depart}</if>
            <if test="leavedate != null "> and leavedate = #{leavedate}</if>
            <if test="workstate != null  and workstate != ''"> and workstate = #{workstate}</if>
            <if test="leavestate != null  and leavestate != ''"> and leavestate = #{leavestate}</if>
            <if test="examinename != null  and examinename != ''"> and examinename like concat('%', #{examinename}, '%')</if>
            <if test="examinedate != null "> and examinedate = #{examinedate}</if>
            <if test="examinestate != null  and examinestate != ''"> and examinestate = #{examinestate}</if>

        </where>
        ORDER BY examinedate ASC
    </select>

    <select id="selectTdLeaveById" parameterType="Long" resultMap="TdLeaveResult">
        <include refid="selectTdLeaveVo"/>
        where id = #{id}
    </select>

    <insert id="insertTdLeave" parameterType="TdLeave" useGeneratedKeys="true" keyProperty="id">
        insert into td_leave
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="country != null">country,</if>
            <if test="areaname != null">areaname,</if>
            <if test="leavereason != null">leavereason,</if>
            <if test="depart != null">depart,</if>
            <if test="leavedate != null">leavedate,</if>
            <if test="workstate != null">workstate,</if>
            <if test="leavestate != null">leavestate,</if>
            <if test="examinename != null">examinename,</if>
            <if test="examinedate != null">examinedate,</if>
            <if test="examinestate != null">examinestate,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="country != null">#{country},</if>
            <if test="areaname != null">#{areaname},</if>
            <if test="leavereason != null">#{leavereason},</if>
            <if test="depart != null">#{depart},</if>
            <if test="leavedate != null">#{leavedate},</if>
            <if test="workstate != null">#{workstate},</if>
            <if test="leavestate != null">#{leavestate},</if>
            <if test="examinename != null">#{examinename},</if>
            <if test="examinedate != null">#{examinedate},</if>
            <if test="examinestate != null">#{examinestate},</if>
         </trim>
    </insert>

    <update id="updateTdLeave" parameterType="TdLeave">
        update td_leave
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="country != null">country = #{country},</if>
            <if test="areaname != null">areaname = #{areaname},</if>
            <if test="leavereason != null">leavereason = #{leavereason},</if>
            <if test="depart != null">depart = #{depart},</if>
            <if test="leavedate != null">leavedate = #{leavedate},</if>
            <if test="workstate != null">workstate = #{workstate},</if>
            <if test="leavestate != null">leavestate = #{leavestate},</if>
            <if test="examinename != null">examinename = #{examinename},</if>
            <if test="examinedate != null">examinedate = #{examinedate},</if>
            <if test="examinestate != null">examinestate = #{examinestate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTdLeaveById" parameterType="Long">
        delete from td_leave where id = #{id}
    </delete>

    <delete id="deleteTdLeaveByIds" parameterType="String">
        delete from td_leave where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>