<?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.kltj.mapper.PeopleFlowMapper">

    <!-- 查询客流设备列表 -->
    <select id="selectDeviceList" resultType="java.util.HashMap">
        SELECT
            device_code,
            device_name,
            area_id,
            area_name,
            building_id,
            building_name,
            floor_id,
            floor_name
        FROM people_flow_device
        WHERE is_online = 1
    </select>

    <!-- 查询客流统计数据 -->
    <select id="selectFlowDataList" parameterType="pd" resultType="java.util.HashMap">
        SELECT
        d.device_name,
        d.area_name,
        d.building_name,
        d.floor_name,
        f.stat_time,
        f.enter_count,
        f.exit_count,
        f.current_count,
        f.peak_count,
        f.peak_time,
        f.occupancy_rate,
        f.avg_stay_time
        FROM people_flow_data f
        LEFT JOIN people_flow_device d ON f.device_code = d.device_code
        <where>
            <if test="deviceCode != null and deviceCode != ''">
                AND f.device_code = #{deviceCode}
            </if>
            <if test="areaId != null and areaId != ''">
                AND d.area_id = #{areaId}
            </if>
            <if test="buildingId != null and buildingId != ''">
                AND d.building_id = #{buildingId}
            </if>
            <if test="statType != null and statType != ''">
                AND f.stat_type = #{statType}
            </if>
            <if test="beginTime != null and beginTime != ''">
                AND f.stat_time &gt;= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND f.stat_time &lt;= #{endTime}
            </if>
        </where>
        ORDER BY f.stat_time DESC
    </select>
</mapper>