<?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.VisitorRecordsMapper">
    
    <resultMap type="VisitorRecords" id="VisitorRecordsResult">
        <result property="visitorRecordsId"    column="visitor_records_id"    />
        <result property="plateNumber"    column="plate_number"    />
        <result property="portalId"    column="portal_id"    />
        <result property="visitPortal"    column="visit_portal"    />
        <result property="mobileNumber"    column="mobile_number"    />
        <result property="visitName"    column="visit_name"    />
        <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="selectVisitorRecordsVo">
        select visitor_records_id, plate_number, portal_id, visit_portal, mobile_number, visit_name, create_by, create_time, update_by, update_time, remark from visitor_records
    </sql>

    <select id="selectVisitorRecordsList" parameterType="VisitorRecords" resultMap="VisitorRecordsResult">
        <include refid="selectVisitorRecordsVo"/>
        <where>  
            <if test="plateNumber != null  and plateNumber != ''"> and plate_number = #{plateNumber}</if>
            <if test="portalId != null "> and portal_id = #{portalId}</if>
            <if test="visitPortal != null  and visitPortal != ''"> and visit_portal = #{visitPortal}</if>
            <if test="mobileNumber != null  and mobileNumber != ''"> and mobile_number = #{mobileNumber}</if>
            <if test="visitName != null  and visitName != ''"> and visit_name like concat('%', #{visitName}, '%')</if>
        </where>
    </select>
    
    <select id="selectVisitorRecordsByVisitorRecordsId" parameterType="Long" resultMap="VisitorRecordsResult">
        <include refid="selectVisitorRecordsVo"/>
        where visitor_records_id = #{visitorRecordsId}
    </select>

    <insert id="insertVisitorRecords" parameterType="VisitorRecords" useGeneratedKeys="true" keyProperty="visitorRecordsId">
        insert into visitor_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="plateNumber != null and plateNumber != ''">plate_number,</if>
            <if test="portalId != null">portal_id,</if>
            <if test="visitPortal != null and visitPortal != ''">visit_portal,</if>
            <if test="mobileNumber != null and mobileNumber != ''">mobile_number,</if>
            <if test="visitName != null">visit_name,</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="plateNumber != null and plateNumber != ''">#{plateNumber},</if>
            <if test="portalId != null">#{portalId},</if>
            <if test="visitPortal != null and visitPortal != ''">#{visitPortal},</if>
            <if test="mobileNumber != null and mobileNumber != ''">#{mobileNumber},</if>
            <if test="visitName != null">#{visitName},</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="updateVisitorRecords" parameterType="VisitorRecords">
        update visitor_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="plateNumber != null and plateNumber != ''">plate_number = #{plateNumber},</if>
            <if test="portalId != null">portal_id = #{portalId},</if>
            <if test="visitPortal != null and visitPortal != ''">visit_portal = #{visitPortal},</if>
            <if test="mobileNumber != null and mobileNumber != ''">mobile_number = #{mobileNumber},</if>
            <if test="visitName != null">visit_name = #{visitName},</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 visitor_records_id = #{visitorRecordsId}
    </update>

    <delete id="deleteVisitorRecordsByVisitorRecordsId" parameterType="Long">
        delete from visitor_records where visitor_records_id = #{visitorRecordsId}
    </delete>

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