<?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.CardReplacementRecordMapper">
    
    <resultMap type="CardReplacementRecord" id="CardReplacementRecordResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="applicationTime"    column="application_time"    />
        <result property="reason"    column="reason"    />
        <result property="examinersId"    column="examiners_id"    />
        <result property="examinersName"    column="examiners_name"    />
        <result property="isPass"    column="is_pass"    />
    </resultMap>

    <sql id="selectCardReplacementRecordVo">
        select id, user_id, user_name, dept_id,dept_name, application_time, reason, examiners_id, examiners_name, is_pass from card_replacement_record
    </sql>

    <select id="selectCardReplacementRecordList" parameterType="CardReplacementRecord" resultMap="CardReplacementRecordResult">
        <include refid="selectCardReplacementRecordVo"/>
        <where>
            <if test="userId != null  and userId != 0"> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="deptId != null  and deptId != 0"> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="applicationTime != null "> and application_time = #{applicationTime}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="examinersName != null  and examinersName != ''"> and examiners_name like concat('%', #{examinersName}, '%')</if>
            <if test="isPass != null  and isPass != ''"> and is_pass = #{isPass}</if>
            <if test="deptIds!=null and deptIds.size() >0">
                and dept_id in
                <foreach item="deptId" collection="deptIds" open="(" separator="," close=")">
                    #{deptId}
                </foreach>
            </if>
        </where>
    </select>
    
    <select id="selectCardReplacementRecordById" parameterType="Long" resultMap="CardReplacementRecordResult">
        <include refid="selectCardReplacementRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCardReplacementRecord" parameterType="CardReplacementRecord" useGeneratedKeys="true" keyProperty="id">
        insert into card_replacement_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="applicationTime != null">application_time,</if>
            <if test="reason != null">reason,</if>
            <if test="examinersId != null">examiners_id,</if>
            <if test="examinersName != null">examiners_name,</if>
            <if test="isPass != null">is_pass,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="applicationTime != null">#{applicationTime},</if>
            <if test="reason != null">#{reason},</if>
            <if test="examinersId != null">#{examinersId},</if>
            <if test="examinersName != null">#{examinersName},</if>
            <if test="isPass != null">#{isPass},</if>
         </trim>
    </insert>

    <update id="updateCardReplacementRecord" parameterType="CardReplacementRecord">
        update card_replacement_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="applicationTime != null">application_time = #{applicationTime},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="examinersId != null">examiners_id = #{examinersId},</if>
            <if test="examinersName != null">examiners_name = #{examinersName},</if>
            <if test="isPass != null">is_pass = #{isPass},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCardReplacementRecordById" parameterType="Long">
        delete from card_replacement_record where id = #{id}
    </delete>

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