ParkMonitorMapper.xml 4.16 KB
<?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.zteits.parking.module.park.dal.mysql.monitor.ParkMonitorMapper">

    <!--
      综合监测聚合 SQL(只读)

      口径:
        1. 在用停车场 = parking_lot.data_status = 1 AND state = 1,且只看赤峰市;
        2. region 传区县名称(pl_country_name),空 = 全市;
        3. 实时泊位来自 parking_lot_berth_temp_info,没有实时行时 free_berth 为 NULL;
        4. 车流 / 占用率来自 parking_running_statistic:
             每小时 = time_cycle 40,按 HOUR(statistic_end_time) 聚合;
             每天   = time_cycle 50,按 DATE(statistic_begin_time) 聚合;
           固定 data_source = 10(与监管总览同一口径)。
    -->

    <sql id="monitorLotCondition">
        l.data_status = 1
        AND l.state = 1
        AND l.pl_city_name = '赤峰市'
        <if test="region != null and region != ''">
            AND l.pl_country_name = #{region}
        </if>
    </sql>

    <select id="selectMonitorLots"
            resultType="com.zteits.parking.module.park.dal.mysql.monitor.row.MonitorLotRow">
        SELECT l.pl_no,
               TRIM(REPLACE(REPLACE(l.pl_name, CHAR(10), ''), CHAR(13), '')) AS pl_name,
               l.pl_type,
               l.pl_country_name AS district,
               l.pl_berth_num,
               t.berthNum        AS temp_berth_num,
               t.pl_berth_num    AS temp_pl_berth_num,
               t.free_berth,
               g.lon_id          AS lng,
               g.lat_id          AS lat,
               g.lon_lat_type    AS coord_type
        FROM parking_lot l
        LEFT JOIN parking_lot_berth_temp_info t ON t.pl_no = l.pl_no
        LEFT JOIN parking_lot_geo g ON g.geo_id = (
            SELECT g2.geo_id
            FROM parking_lot_geo g2
            WHERE g2.pl_no = l.pl_no
              AND g2.data_status = 1
            ORDER BY CASE g2.lon_lat_type WHEN 3 THEN 0 WHEN 1 THEN 1 WHEN 2 THEN 2 ELSE 3 END,
                     g2.geo_id
            LIMIT 1
        )
        WHERE <include refid="monitorLotCondition"/>
        ORDER BY l.pl_country_name, l.pl_no
    </select>

    <select id="selectHourlyTrend"
            resultType="com.zteits.parking.module.park.dal.mysql.monitor.row.MonitorTrendRow">
        SELECT HOUR(s.statistic_end_time) AS hour,
               SUM(s.unit_park_in_count)  AS in_count,
               SUM(s.unit_park_out_count) AS out_count,
               AVG(1 - s.free_ratio)      AS avg_occupy_rate
        FROM parking_running_statistic s
        INNER JOIN parking_lot l ON l.pl_no = s.pl_no
        WHERE <include refid="monitorLotCondition"/>
          AND s.data_status = 1
          AND s.data_source = 10
          AND s.time_cycle = 40
          AND s.statistic_end_time &gt;= #{begin}
          AND s.statistic_end_time &lt;= #{end}
        GROUP BY HOUR(s.statistic_end_time)
        ORDER BY hour
    </select>

    <select id="selectDailyTrend"
            resultType="com.zteits.parking.module.park.dal.mysql.monitor.row.MonitorTrendRow">
        SELECT DATE_FORMAT(s.statistic_begin_time, '%Y-%m-%d') AS stat_date,
               SUM(s.unit_park_in_count)  AS in_count,
               SUM(s.unit_park_out_count) AS out_count,
               AVG(1 - s.free_ratio)      AS avg_occupy_rate
        FROM parking_running_statistic s
        INNER JOIN parking_lot l ON l.pl_no = s.pl_no
        WHERE <include refid="monitorLotCondition"/>
          AND s.data_status = 1
          AND s.data_source = 10
          AND s.time_cycle = 50
          AND s.statistic_begin_time &gt;= #{begin}
          AND s.statistic_begin_time &lt;= #{end}
        GROUP BY DATE_FORMAT(s.statistic_begin_time, '%Y-%m-%d')
        ORDER BY stat_date
    </select>

    <select id="selectDataThrough" resultType="java.time.LocalDateTime">
        SELECT MAX(s.statistic_end_time)
        FROM parking_running_statistic s
        INNER JOIN parking_lot l ON l.pl_no = s.pl_no
        WHERE <include refid="monitorLotCondition"/>
          AND s.data_status = 1
          AND s.data_source = 10
    </select>

</mapper>