<?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="classId"    column="class_id"    />
        <result property="className"    column="class_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="photo"    column="photo"    />
        <result property="submitTime"    column="submit_time"    />
        <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="selectRecordLeaveVo">
        select id, type, start_time, end_time, reason, class_id, class_name, absentee_id, absentee_name, examiners_id, examiners_name, category, is_pass, photo, submit_time, create_by, create_time, update_by, update_time, remark 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="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="classId != null and classId!= ''"> and find_in_set(class_id,#{classId})</if>
            <if test="className != null  and className != ''"> and class_name like concat('%', #{className}, '%')</if>
            <if test="absenteeId != null  and absenteeId != ''"> and absentee_id = #{absenteeId}</if>
            <if test="absenteeName != null  and absenteeName != ''"> and absentee_name like concat('%', #{absenteeName}, '%')</if>
            <if test="examinersId != null "> and examiners_id = #{examinersId}</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="photo != null  and photo != ''"> and photo = #{photo}</if>
            <if test="submitTime != null "> and submit_time = #{submitTime}</if>
        </where>
        order by create_time DESC
    </select>
    
    <select id="selectRecordLeaveById" parameterType="Long" resultMap="RecordLeaveResult">
        <include refid="selectRecordLeaveVo"/>
        where id = #{id}
    </select>
    <select id="selectRecordLeaveNum" resultType="java.lang.Integer">
       select count(1) from record_leave
        where   is_pass = '0'  and find_in_set(class_id,#{classId})
    </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="classId != null">class_id,</if>
            <if test="className != null">class_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>
            <if test="photo != null">photo,</if>
            <if test="submitTime != null">submit_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </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="classId != null">#{classId},</if>
            <if test="className != null">#{className},</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>
            <if test="photo != null">#{photo},</if>
            <if test="submitTime != null">#{submitTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </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="classId != null">class_id = #{classId},</if>
            <if test="className != null">class_name = #{className},</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>
            <if test="photo != null">photo = #{photo},</if>
            <if test="submitTime != null">submit_time = #{submitTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</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>