<?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.bst.realName.mapper.RealNameMapper">

    <resultMap type="RealNameVO" id="RealNameResult" autoMapping="true"/>

    <sql id="selectRealNameVo">
        select
            brn.id,
            brn.user_id,
            brn.user_name,
            brn.id_card,
            brn.picture,
            brn.score,
            brn.mobile,
            brn.status,
            brn.create_time,
            brn.type,
            brn.result
        from bst_real_name brn
    </sql>

    <sql id="searchCondition">
        <if test="query.userName != null  and query.userName != ''"> and user_name like concat('%', #{query.userName}, '%')</if>
        <if test="query.idCard != null  and query.idCard != ''"> and id_card = #{query.idCard}</if>
        <if test="query.picture != null  and query.picture != ''"> and picture = #{query.picture}</if>
        <if test="query.score != null "> and score = #{query.score}</if>
        <if test="query.mobile != null  and query.mobile != ''"> and mobile = #{query.mobile}</if>
        <if test="query.status != null  and query.status != ''"> and status = #{query.status}</if>
        <if test="query.userId != null"> and user_id = #{query.userId}</if>
        <if test="query.type != null  and query.type != ''"> and type = #{query.type}</if>
        <if test="query.result != null  and query.result != ''"> and result like concat('%', #{query.result}, '%')</if>
        ${query.params.dataScope}
    </sql>

    <select id="selectRealNameList" parameterType="RealNameQuery" resultMap="RealNameResult">
        <include refid="selectRealNameVo"/>
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="selectRealNameById" parameterType="Long" resultMap="RealNameResult">
        <include refid="selectRealNameVo"/>
        where id = #{id}
    </select>

    <insert id="insertRealName" parameterType="RealName" useGeneratedKeys="true" keyProperty="id">
        insert into bst_real_name
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userName != null">user_name,</if>
            <if test="idCard != null">id_card,</if>
            <if test="picture != null">picture,</if>
            <if test="score != null">score,</if>
            <if test="mobile != null">mobile,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="userId != null">user_id,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="result != null and result != ''">result,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userName != null">#{userName},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="picture != null">#{picture},</if>
            <if test="score != null">#{score},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="userId != null">#{userId},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="result != null and result != ''">#{result},</if>
         </trim>
    </insert>

    <update id="updateRealName" parameterType="RealName">
        update bst_real_name
        <trim prefix="SET" suffixOverrides=",">
            <include refid="updateColumns"/>
        </trim>
        where id = #{data.id}
    </update>

    <sql id="updateColumns">
        <if test="data.userName != null">user_name = #{data.userName},</if>
        <if test="data.idCard != null">id_card = #{data.idCard},</if>
        <if test="data.picture != null">picture = #{data.picture},</if>
        <if test="data.score != null">score = #{data.score},</if>
        <if test="data.mobile != null">mobile = #{data.mobile},</if>
        <if test="data.status != null and data.status != ''">status = #{data.status},</if>
        <if test="data.createTime != null">create_time = #{data.createTime},</if>
        <if test="data.userId != null">user_id = #{data.userId},</if>
        <if test="data.type != null and data.type != ''">type = #{data.type},</if>
        <if test="data.result != null and data.result != ''">result = #{data.result},</if>
    </sql>

    <delete id="deleteRealNameById" parameterType="Long">
        delete from bst_real_name where id = #{id}
    </delete>

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