<?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.RecordLeaveMapper">
    
    <resultMap type="RecordLeave" id="RecordLeaveResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="reason"    column="reason"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="absenteeId"    column="absentee_id"    />
        <result property="absenteeName"    column="absentee_name"    />
        <result property="examinersId"    column="examiners_id"    />
        <result property="examinersName"    column="examiners_name"    />
        <result property="category"    column="category"    />
        <result property="isPass"    column="is_pass"    />
        <result property="submitTime"    column="submit_time"    />
    </resultMap>

    <sql id="selectRecordLeaveVo">
        select id, type, start_time, end_time, reason, dept_id, dept_name, absentee_id, absentee_name, examiners_id, examiners_name, category, is_pass, submit_time from record_leave
    </sql>

    <select id="selectRecordLeaveList" parameterType="RecordLeave" resultMap="RecordLeaveResult">
        <include refid="selectRecordLeaveVo"/>
        <where>  
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="absenteeName != null  and absenteeName != ''"> and absentee_name like concat('%', #{absenteeName}, '%')</if>
            <if test="examinersName != null  and examinersName != ''"> and examiners_name like concat('%', #{examinersName}, '%')</if>
            <if test="category != null  and category != ''"> and category = #{category}</if>
            <if test="isPass != null  and isPass != ''"> and is_pass = #{isPass}</if>
            <if test="submitTime != null "> and submit_time = #{submitTime}</if>
        </where>
    </select>
    
    <select id="selectRecordLeaveById" parameterType="Long" resultMap="RecordLeaveResult">
        <include refid="selectRecordLeaveVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertRecordLeave" parameterType="RecordLeave" useGeneratedKeys="true" keyProperty="id">
        insert into record_leave
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">type,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="reason != null">reason,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="absenteeId != null">absentee_id,</if>
            <if test="absenteeName != null">absentee_name,</if>
            <if test="examinersId != null">examiners_id,</if>
            <if test="examinersName != null">examiners_name,</if>
            <if test="category != null">category,</if>
            <if test="isPass != null">is_pass,</if>
            submit_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="reason != null">#{reason},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="absenteeId != null">#{absenteeId},</if>
            <if test="absenteeName != null">#{absenteeName},</if>
            <if test="examinersId != null">#{examinersId},</if>
            <if test="examinersName != null">#{examinersName},</if>
            <if test="category != null">#{category},</if>
            <if test="isPass != null">#{isPass},</if>
            #{submitTime}
         </trim>
    </insert>

    <update id="updateRecordLeave" parameterType="RecordLeave">
        update record_leave
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="absenteeId != null">absentee_id = #{absenteeId},</if>
            <if test="absenteeName != null">absentee_name = #{absenteeName},</if>
            <if test="examinersId != null">examiners_id = #{examinersId},</if>
            <if test="examinersName != null">examiners_name = #{examinersName},</if>
            <if test="category != null">category = #{category},</if>
            <if test="isPass != null">is_pass = #{isPass},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRecordLeaveById" parameterType="Long">
        delete from record_leave where id = #{id}
    </delete>

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