ParkMonitorMapper.xml
4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?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 >= #{begin}
AND s.statistic_end_time <= #{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 >= #{begin}
AND s.statistic_begin_time <= #{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>