|
|
@ -37,6 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|
|
|
<result property="date" column="date" /> |
|
|
|
<result property="avgTemperature" column="avg_temperature" /> |
|
|
|
<result property="avgVisibility" column="avg_visibility" /> |
|
|
|
<result property="month" column="month" /> |
|
|
|
</resultMap> |
|
|
|
<sql id="selectDcMeteorologicalDetectorDataVo"> |
|
|
|
select id, iot_device_id, rainfall, visibility_type, visibility, atmospheric_pressure, temperature, humidity, wind_direction, wind_speed, precipitation_type, wet_slippery_coefficient,remote_road_surface_temperature, remote_road_surface_status, water_film_ice_snow_value,create_time,stake_mark,device_name,direction from dc_meteorological_detector_data |
|
|
@ -156,23 +157,54 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|
|
|
COALESCE(ROUND(AVG(dc.visibility), 2), 0) AS avg_visibility |
|
|
|
FROM |
|
|
|
( |
|
|
|
SELECT 0 AS time_slot UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 |
|
|
|
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 |
|
|
|
UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 |
|
|
|
UNION ALL SELECT 14 UNION ALL SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 |
|
|
|
UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21 |
|
|
|
UNION ALL SELECT 22 UNION ALL SELECT 23 |
|
|
|
SELECT 0 AS time_slot UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 |
|
|
|
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 |
|
|
|
UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 |
|
|
|
UNION ALL SELECT 14 UNION ALL SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 |
|
|
|
UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21 |
|
|
|
UNION ALL SELECT 22 UNION ALL SELECT 23 |
|
|
|
) AS h |
|
|
|
LEFT JOIN |
|
|
|
LEFT JOIN |
|
|
|
dc_meteorological_detector_data dc |
|
|
|
ON |
|
|
|
DATE(dc.create_time) = CURDATE() |
|
|
|
AND HOUR(dc.create_time) = h.time_slot |
|
|
|
AND dc.device_name = #{deviceName} |
|
|
|
ON |
|
|
|
DATE(dc.create_time) = CURDATE() |
|
|
|
AND HOUR(dc.create_time) = h.time_slot |
|
|
|
AND dc.device_name = #{deviceName} |
|
|
|
GROUP BY |
|
|
|
h.time_slot, |
|
|
|
date; |
|
|
|
</select> |
|
|
|
<select id="selectStatisticsTime" resultMap="countMap" resultType="map"> |
|
|
|
SELECT |
|
|
|
h.time_slot, |
|
|
|
DATE(dc.create_time) AS date, |
|
|
|
COALESCE(ROUND(AVG(dc.temperature), 2), 0) AS avg_temperature, |
|
|
|
COALESCE(ROUND(AVG(dc.visibility), 2), 0) AS avg_visibility |
|
|
|
FROM |
|
|
|
( |
|
|
|
SELECT 0 AS time_slot UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 |
|
|
|
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 |
|
|
|
UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 |
|
|
|
UNION ALL SELECT 14 UNION ALL SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 |
|
|
|
UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21 |
|
|
|
UNION ALL SELECT 22 UNION ALL SELECT 23 |
|
|
|
) AS h |
|
|
|
LEFT JOIN |
|
|
|
dc_meteorological_detector_data dc |
|
|
|
ON |
|
|
|
<if test="specificDate != null and specificDate !=''"> |
|
|
|
DATE(dc.create_time) = #{specificDate} |
|
|
|
</if> |
|
|
|
<if test="specificDate == null or specificDate=='' "> |
|
|
|
DATE(dc.create_time) = CURDATE() |
|
|
|
</if> |
|
|
|
AND HOUR(dc.create_time) = h.time_slot |
|
|
|
AND dc.device_name = #{deviceName} |
|
|
|
GROUP BY |
|
|
|
h.time_slot, |
|
|
|
date; |
|
|
|
|
|
|
|
</select> |
|
|
|
|
|
|
|
<select id="selectlistAll" parameterType="com.zc.business.domain.DcMeteorologicalDetectorData" resultMap="DcMeteorologicalDetectorDataResult"> |
|
|
|
SELECT |
|
|
@ -255,4 +287,63 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|
|
|
AND DATE(m.create_time) = CURDATE() |
|
|
|
</where> |
|
|
|
</select> |
|
|
|
<select id="selectStatisticsDay" resultMap="countMap" resultType="map"> |
|
|
|
WITH RECURSIVE dates_in_month AS ( |
|
|
|
SELECT DATE_FORMAT(STR_TO_DATE(#{specificDate}, '%Y-%m-%d'), '%Y-%m-01') AS date |
|
|
|
UNION ALL |
|
|
|
SELECT DATE_ADD(date, INTERVAL 1 DAY) |
|
|
|
FROM dates_in_month |
|
|
|
<where> |
|
|
|
date < LAST_DAY(#{specificDate}) |
|
|
|
</where> |
|
|
|
) |
|
|
|
SELECT |
|
|
|
d.date, |
|
|
|
COALESCE(ROUND(AVG(dc.temperature), 2), 0) AS avg_temperature, |
|
|
|
COALESCE(ROUND(AVG(dc.visibility), 2), 0) AS avg_visibility |
|
|
|
FROM |
|
|
|
dates_in_month d |
|
|
|
LEFT JOIN |
|
|
|
dc_meteorological_detector_data dc |
|
|
|
ON |
|
|
|
DATE(dc.create_time) = d.date |
|
|
|
AND dc.device_name = #{deviceName} |
|
|
|
GROUP BY |
|
|
|
d.date |
|
|
|
ORDER BY |
|
|
|
d.date ASC; |
|
|
|
|
|
|
|
</select> |
|
|
|
|
|
|
|
<select id="selectStatisticsYears" resultMap="countMap" resultType="map"> |
|
|
|
|
|
|
|
WITH RECURSIVE months_of_year AS ( |
|
|
|
SELECT 1 AS month |
|
|
|
UNION ALL |
|
|
|
SELECT month + 1 |
|
|
|
FROM months_of_year |
|
|
|
<where> |
|
|
|
month < 12 |
|
|
|
</where> |
|
|
|
|
|
|
|
), |
|
|
|
monthly_data AS ( |
|
|
|
SELECT |
|
|
|
DATE_FORMAT(CONCAT(YEAR(#{specificDate}), '-', LPAD(month, 2, '0'), '-01'), '%Y-%m') AS month, |
|
|
|
ROUND(AVG(COALESCE(dc.temperature, 0)), 2) AS avg_temperature, |
|
|
|
ROUND(AVG(COALESCE(dc.visibility, 0)), 2) AS avg_visibility |
|
|
|
FROM |
|
|
|
months_of_year |
|
|
|
LEFT JOIN dc_meteorological_detector_data dc |
|
|
|
ON YEAR(dc.create_time) = YEAR(#{specificDate}) |
|
|
|
AND MONTH(dc.create_time) = months_of_year.month |
|
|
|
AND dc.device_name = #{deviceName} |
|
|
|
GROUP BY |
|
|
|
month |
|
|
|
) |
|
|
|
SELECT * FROM monthly_data order by monthly_data.month asc ; |
|
|
|
</select> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</mapper> |