<?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.api.app.dao.butler.AppVisitorAccessDao">
    <insert id="insertVisitorInfo" parameterType="com.api.model.butlerService.UserVisitors">
        insert into user_visitors(
            building_unit_estate_id,
            invite_people_id,
            type,
            name,
            sex,
            tel,
            is_drive,
            car_num,
            expected_visit_date,
            effective_time,
            visitor_status,
            create_id,
            create_date,
            access_code
        )values (
            #{buildingUnitEstateId},
            #{invitePeopleId},
            #{type},
            #{name},
            #{sex},
            #{tel},
            #{isDrive},
            #{carNum},
            #{expectedVisitDate},
            #{effectiveTime},
            #{visitorStatus},
            #{createId},
            #{createDate},
            #{accessCode}
        )
        <selectKey keyProperty="id" resultType="java.lang.Integer">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>

    <select id="findVisitorByAC" parameterType="java.lang.Long" resultType="com.api.vo.app.VisitorAccessFindByIdVo">
        select * from user_visitors where access_code = #{accessCode}
    </select>

    <select id="list" parameterType="com.api.model.app.SearchVisitorAccess" resultType="com.api.vo.app.VisitorAccessVo">
        select * from user_visitors
        <where>
            invite_people_id = #{id}
            <if test="visitorStatus != null">
                and visitor_status = #{visitorStatus}
            </if>
        </where>
        order by create_date DESC
    </select>

</mapper>