<?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.dcsoft.system.visitor.mapper.VisVisitorRegisterMapper">

    <resultMap type="VisVisitorRegister" id="VisVisitorRegisterResult">
        <result property="id"    column="id"    />
        <result property="userName"    column="user_name"    />
        <result property="nickName"    column="nick_name"    />
        <result property="phone"    column="phone"    />
        <result property="openid"    column="openid"    />
        <result property="deleteState"    column="delete_state"    />
        <result property="createdBy"    column="created_by"    />
        <result property="createdTime"    column="created_time"    />
        <result property="updatedBy"    column="updated_by"    />
        <result property="updatedTime"    column="updated_time"    />
    </resultMap>

    <sql id="selectVisVisitorRegisterVo">
        select id, user_name, nick_name, phone, openid, delete_state, created_by, created_time, updated_by, updated_time from vis_visitor_register
    </sql>

    <select id="selectVisVisitorRegisterList" parameterType="VisVisitorRegister" resultMap="VisVisitorRegisterResult">
        <include refid="selectVisVisitorRegisterVo"/>
        <where>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="openid != null  and openid != ''"> and openid = #{openid}</if>
            <if test="deleteState != null  and deleteState != ''"> and delete_state = #{deleteState}</if>
            <if test="createdBy != null  and createdBy != ''"> and created_by = #{createdBy}</if>
            <if test="createdTime != null "> and created_time = #{createdTime}</if>
            <if test="updatedBy != null  and updatedBy != ''"> and updated_by = #{updatedBy}</if>
            <if test="updatedTime != null "> and updated_time = #{updatedTime}</if>
        </where>
    </select>

    <select id="selectVisVisitorRegisterById" parameterType="String" resultMap="VisVisitorRegisterResult">
        <include refid="selectVisVisitorRegisterVo"/>
        where id = #{id}
    </select>

    <insert id="insertVisVisitorRegister" parameterType="VisVisitorRegister">
        insert into vis_visitor_register
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userName != null">user_name,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="phone != null">phone,</if>
            <if test="openid != null">openid,</if>
            <if test="deleteState != null">delete_state,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedTime != null">updated_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userName != null">#{userName},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="phone != null">#{phone},</if>
            <if test="openid != null">#{openid},</if>
            <if test="deleteState != null">#{deleteState},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
         </trim>
    </insert>

    <update id="updateVisVisitorRegister" parameterType="VisVisitorRegister">
        update vis_visitor_register
        <trim prefix="SET" suffixOverrides=",">
            <if test="userName != null">user_name = #{userName},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="openid != null">openid = #{openid},</if>
            <if test="deleteState != null">delete_state = #{deleteState},</if>
            <if test="createdBy != null">created_by = #{createdBy},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteVisVisitorRegisterById" parameterType="String">
        delete from vis_visitor_register where id = #{id}
    </delete>

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

    <insert id="saveVisitorRegister">
        insert into vis_visitor_register (id, user_name, nick_name, phone, openid)
        values (#{visitorRegisterId}, #{name}, #{name}, #{phone}, #{openid})
    </insert>

    <update id="updateVisitorRegisterByOpenid">
        update vis_visitor_register set openid = #{openid} where user_name = #{name} and phone = #{phone}
    </update>

    <select id="queryVisitorRegister" resultType="java.lang.String">
        select id from vis_visitor_register where user_name = #{name} and phone = #{phone}
    </select>
</mapper>
