<?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.pm.fkxt.mapper.VisitorMapper">

    <!-- 查询访客登记信息 -->
    <select id="selectVisitorInfoList" parameterType="pd" resultType="java.util.HashMap">
        SELECT
        visitor_id,
        visitor_name,
        visitor_phone,
        id_card,
        company,
        visit_purpose,
        visited_person,
        visited_dept,
        visited_phone,
        appointment_time,
        visit_start_time,
        visit_end_time,
        actual_start_time,
        actual_end_time,
        visit_status,
        card_no,
        entry_gate,
        exit_gate,
        approval_status,
        approver,
        approval_time
        FROM visitor_info
        <where>
            <if test="visitorName != null and visitorName != ''">
                AND visitor_name LIKE CONCAT('%', #{visitorName}, '%')
            </if>
            <if test="visitedPerson != null and visitedPerson != ''">
                AND visited_person LIKE CONCAT('%', #{visitedPerson}, '%')
            </if>
            <if test="visitStatus != null">
                AND visit_status = #{visitStatus}
            </if>
            <if test="beginTime != null and beginTime != ''">
                AND visit_start_time &gt;= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND visit_end_time &lt;= #{endTime}
            </if>
        </where>
        ORDER BY visit_start_time DESC
    </select>

    <!-- 查询门禁刷卡记录 -->
    <select id="selectAccessRecordList" parameterType="pd" resultType="java.util.HashMap">
        SELECT
        record_id,
        visitor_id,
        visitor_name,
        card_no,
        gate_id,
        gate_name,
        gate_location,
        swipe_time,
        swipe_type,
        swipe_result,
        device_sn,
        fail_reason,
        temperature,
        mask_detection,
        photo_url
        FROM visitor_card_record
        <where>
            <if test="visitorId != null and visitorId != ''">
                AND visitor_id = #{visitorId}
            </if>
            <if test="visitorName != null and visitorName != ''">
                AND visitor_name LIKE CONCAT('%', #{visitorName}, '%')
            </if>
            <if test="gateLocation != null and gateLocation != ''">
                AND gate_location LIKE CONCAT('%', #{gateLocation}, '%')
            </if>
            <if test="swipeType != null">
                AND swipe_type = #{swipeType}
            </if>
            <if test="beginTime != null and beginTime != ''">
                AND swipe_time &gt;= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND swipe_time &lt;= #{endTime}
            </if>
        </where>
        ORDER BY swipe_time DESC
    </select>
</mapper>