<?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.SysUserIdcardMapper">
    
    <resultMap type="SysUserIdcard" id="SysUserIdcardResult">
        <result property="userId"    column="user_id"    />
        <result property="idCard"    column="id_card"    />
        <result property="realName"    column="real_name"    />
        <result property="expirationDate"    column="expiration_date"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="address"    column="address"    />
        <result property="front"    column="front"    />
        <result property="back"    column="back"    />
        <result property="delFlag"    column="del_flag"    />
        <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="selectSysUserIdcardVo">
        select user_id, id_card, real_name, expiration_date, phonenumber, address, front, back, del_flag, create_by, create_time, update_by, update_time, remark from sys_user_idcard
    </sql>

    <select id="selectSysUserIdcardList" parameterType="SysUserIdcard" resultMap="SysUserIdcardResult">
        <include refid="selectSysUserIdcardVo"/>
        <where>  
            <if test="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="expirationDate != null  and expirationDate != ''"> and expiration_date = #{expirationDate}</if>
            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="front != null  and front != ''"> and front = #{front}</if>
            <if test="back != null  and back != ''"> and back = #{back}</if>
        </where>
        order by create_time
    </select>
    
    <select id="selectSysUserIdcardByUserId" parameterType="Long" resultMap="SysUserIdcardResult">
        <include refid="selectSysUserIdcardVo"/>
        where user_id = #{userId}
    </select>
        
    <insert id="insertSysUserIdcard" parameterType="SysUserIdcard">
        insert into sys_user_idcard
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="idCard != null">id_card,</if>
            <if test="realName != null and realName != ''">real_name,</if>
            <if test="expirationDate != null and expirationDate != ''">expiration_date,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="address != null and address != ''">address,</if>
            <if test="front != null and front != ''">front,</if>
            <if test="back != null and back != ''">back,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            create_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="realName != null and realName != ''">#{realName},</if>
            <if test="expirationDate != null and expirationDate != ''">#{expirationDate},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="address != null and address != ''">#{address},</if>
            <if test="front != null and front != ''">#{front},</if>
            <if test="back != null and back != ''">#{back},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
        sysdate()
    </insert>

    <update id="updateSysUserIdcard" parameterType="SysUserIdcard">
        update sys_user_idcard
        <trim prefix="SET" suffixOverrides=",">
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="realName != null and realName != ''">real_name = #{realName},</if>
            <if test="expirationDate != null and expirationDate != ''">expiration_date = #{expirationDate},</if>
            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
            <if test="address != null and address != ''">address = #{address},</if>
            <if test="front != null and front != ''">front = #{front},</if>
            <if test="back != null and back != ''">back = #{back},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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 user_id = #{userId}
    </update>

    <delete id="deleteSysUserIdcardByUserId" parameterType="Long">
        delete from sys_user_idcard where user_id = #{userId}
    </delete>

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