<?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.work.mapper.WorkLeaveMapper">

    <resultMap type="WorkLeave" id="WorkLeaveResult">
        <result property="leaveId"    column="leave_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="definitionId"    column="definition_id"    />
        <result property="processId"    column="process_id"    />
        <result property="processName"    column="process_name"    />
        <result property="category"    column="category"    />
        <result property="holiday"    column="holiday"    />
        <result property="position"    column="position"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="content"    column="content"    />
        <result property="isRepair"    column="is_repair"    />
        <result property="schedule"    column="schedule"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <resultMap type="WorkLeaveVo" id="WorkLeaveVoResult">
        <result property="leaveId"    column="leave_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="definitionId"    column="definition_id"    />
        <result property="processId"    column="process_id"    />
        <result property="processName"    column="process_name"    />
        <result property="category"    column="category"    />
        <result property="holiday"    column="holiday"    />
        <result property="position"    column="position"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="content"    column="content"    />
        <result property="isRepair"    column="is_repair"    />
        <result property="schedule"    column="schedule"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectWorkLeaveVo">
        select leave_id, user_id, user_name, definition_id, process_id, process_name, category, holiday, position, start_time, end_time, content, is_repair, schedule, remark, del_flag, create_time, update_time from work_leave
    </sql>

    <select id="selectWorkLeaveList" parameterType="WorkLeaveVo" resultMap="WorkLeaveVoResult">
        <include refid="selectWorkLeaveVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="definitionId != null  and definitionId != ''"> and definition_id = #{definitionId}</if>
            <if test="processId != null  and processId != ''"> and process_id = #{processId}</if>
            <if test="processName != null  and processName != ''"> and process_name like concat('%', #{processName}, '%')</if>
            <if test="category != null  and category != ''"> and category = #{category}</if>
            <if test="holiday != null "> and holiday = #{holiday}</if>
            <if test="position != null  and position != ''"> and position = #{position}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="isRepair != null  and isRepair != ''"> and is_repair = #{isRepair}</if>
            <if test="schedule != null  and schedule != ''"> and schedule = #{schedule}</if>
            and del_flag = '0'
        </where>
        ORDER BY create_time DESC
    </select>

    <select id="selectWorkLeaveByLeaveId" parameterType="Long" resultMap="WorkLeaveVoResult">
        <include refid="selectWorkLeaveVo"/>
        where leave_id = #{leaveId}
    </select>

    <insert id="insertWorkLeave" parameterType="WorkLeave" useGeneratedKeys="true" keyProperty="leaveId">
        insert into work_leave
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null and userName != ''">user_name,</if>
            <if test="definitionId != null">definition_id,</if>
            <if test="processId != null">process_id,</if>
            <if test="processName != null">process_name,</if>
            <if test="category != null and category != ''">category,</if>
            <if test="holiday != null">holiday,</if>
            <if test="position != null and position != ''">position,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="isRepair != null">is_repair,</if>
            <if test="schedule != null">schedule,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null and userName != ''">#{userName},</if>
            <if test="definitionId != null">#{definitionId},</if>
            <if test="processId != null">#{processId},</if>
            <if test="processName != null">#{processName},</if>
            <if test="category != null and category != ''">#{category},</if>
            <if test="holiday != null">#{holiday},</if>
            <if test="position != null and position != ''">#{position},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="isRepair != null">#{isRepair},</if>
            <if test="schedule != null">#{schedule},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateWorkLeave" parameterType="WorkLeave">
        update work_leave
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null and userName != ''">user_name = #{userName},</if>
            <if test="definitionId != null">definition_id = #{definitionId},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="processName != null">process_name = #{processName},</if>
            <if test="category != null and category != ''">category = #{category},</if>
            <if test="holiday != null">holiday = #{holiday},</if>
            <if test="position != null and position != ''">position = #{position},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="isRepair != null">is_repair = #{isRepair},</if>
            <if test="schedule != null">schedule = #{schedule},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where leave_id = #{leaveId}
    </update>

    <delete id="deleteWorkLeaveByLeaveId" parameterType="Long">
        update work_leave
        set del_flag = "1" from hx_leave
        where leave_id = #{leaveId}
    </delete>

    <delete id="deleteWorkLeaveByLeaveIds" parameterType="String">
        update work_leave
        set del_flag = "1" where leave_id in
        <foreach item="leaveId" collection="array" open="(" separator="," close=")">
            #{leaveId}
        </foreach>
    </delete>
</mapper>
