<?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.VisitorManageMapper">
    
    <resultMap type="VisitorManage" id="VisitorManageResult">
        <result property="visitorManageId"    column="visitor_manage_id"    />
        <result property="portalId"    column="portal_id"    />
        <result property="houseAddress"    column="house_address"    />
        <result property="name"    column="name"    />
        <result property="num"    column="num"    />
        <result property="reason"    column="reason"    />
        <result property="mobileNumber"    column="mobile_number"    />
        <result property="isCar"    column="is_car"    />
        <result property="plateNumber"    column="plate_number"    />
        <result property="reserveTime"    column="reserve_time"    />
        <result property="visitorTime"    column="visitor_time"    />
        <result property="status"    column="status"    />
        <result property="photo"    column="photo"    />
        <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="selectVisitorManageVo">
        select visitor_manage_id, portal_id, house_address, name, num, reason, mobile_number, is_car, plate_number, reserve_time, visitor_time, status, photo, create_by, create_time, update_by, update_time, remark from visitor_manage
    </sql>

    <select id="selectVisitorManageList" parameterType="VisitorManage" resultMap="VisitorManageResult">
        <include refid="selectVisitorManageVo"/>
        <where>  
            <if test="portalId != null "> and portal_id = #{portalId}</if>
            <if test="houseAddress != null  and houseAddress != ''"> and house_address = #{houseAddress}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="num != null  and num != ''"> and num = #{num}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="mobileNumber != null  and mobileNumber != ''"> and mobile_number = #{mobileNumber}</if>
            <if test="isCar != null  and isCar != ''"> and is_car = #{isCar}</if>
            <if test="plateNumber != null  and plateNumber != ''"> and plate_number = #{plateNumber}</if>
            <if test="reserveTime != null "> and reserve_time = #{reserveTime}</if>
            <if test="visitorTime != null "> and visitor_time = #{visitorTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="photo != null  and photo != ''"> and photo = #{photo}</if>
        </where>
    </select>
    
    <select id="selectVisitorManageByVisitorManageId" parameterType="Long" resultMap="VisitorManageResult">
        <include refid="selectVisitorManageVo"/>
        where visitor_manage_id = #{visitorManageId}
    </select>

    <insert id="insertVisitorManage" parameterType="VisitorManage" useGeneratedKeys="true" keyProperty="visitorManageId">
        insert into visitor_manage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="portalId != null">portal_id,</if>
            <if test="houseAddress != null and houseAddress != ''">house_address,</if>
            <if test="name != null">name,</if>
            <if test="num != null">num,</if>
            <if test="reason != null">reason,</if>
            <if test="mobileNumber != null and mobileNumber != ''">mobile_number,</if>
            <if test="isCar != null">is_car,</if>
            <if test="plateNumber != null and plateNumber != ''">plate_number,</if>
            <if test="reserveTime != null">reserve_time,</if>
            <if test="visitorTime != null">visitor_time,</if>
            <if test="status != null">status,</if>
            <if test="photo != null">photo,</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="portalId != null">#{portalId},</if>
            <if test="houseAddress != null and houseAddress != ''">#{houseAddress},</if>
            <if test="name != null">#{name},</if>
            <if test="num != null">#{num},</if>
            <if test="reason != null">#{reason},</if>
            <if test="mobileNumber != null and mobileNumber != ''">#{mobileNumber},</if>
            <if test="isCar != null">#{isCar},</if>
            <if test="plateNumber != null and plateNumber != ''">#{plateNumber},</if>
            <if test="reserveTime != null">#{reserveTime},</if>
            <if test="visitorTime != null">#{visitorTime},</if>
            <if test="status != null">#{status},</if>
            <if test="photo != null">#{photo},</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="updateVisitorManage" parameterType="VisitorManage">
        update visitor_manage
        <trim prefix="SET" suffixOverrides=",">
            <if test="portalId != null">portal_id = #{portalId},</if>
            <if test="houseAddress != null and houseAddress != ''">house_address = #{houseAddress},</if>
            <if test="name != null">name = #{name},</if>
            <if test="num != null">num = #{num},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="mobileNumber != null and mobileNumber != ''">mobile_number = #{mobileNumber},</if>
            <if test="isCar != null">is_car = #{isCar},</if>
            <if test="plateNumber != null and plateNumber != ''">plate_number = #{plateNumber},</if>
            <if test="reserveTime != null">reserve_time = #{reserveTime},</if>
            <if test="visitorTime != null">visitor_time = #{visitorTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="photo != null">photo = #{photo},</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_manage_id = #{visitorManageId}
    </update>

    <delete id="deleteVisitorManageByVisitorManageId" parameterType="Long">
        delete from visitor_manage where visitor_manage_id = #{visitorManageId}
    </delete>

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