济菏高速数据中心代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

348 lines
18 KiB

<?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.zc.business.mapper.DcMeteorologicalDetectorDataMapper">
<resultMap type="com.zc.business.domain.DcMeteorologicalDetectorData" id="DcMeteorologicalDetectorDataResult">
<result property="id" column="id" />
<result property="iotDeviceId" column="iot_device_id" />
<result property="rainfall" column="rainfall" />
<result property="visibilityType" column="visibility_type" />
<result property="visibility" column="visibility" />
<result property="atmosphericPressure" column="atmospheric_pressure" />
<result property="temperature" column="temperature" />
<result property="humidity" column="humidity" />
<result property="windDirection" column="wind_direction" />
<result property="windSpeed" column="wind_speed" />
<result property="precipitationType" column="precipitation_type" />
<result property="wetSlipperyCoefficient" column="wet_slippery_coefficient" />
<result property="remoteRoadSurfaceTemperature" column="remote_road_surface_temperature" />
<result property="remoteRoadSurfaceStatus" column="remote_road_surface_status" />
<result property="waterFilmIceSnowValue" column="water_film_ice_snow_value" />
<result property="createTime" column="create_time" />
<result property="deviceName" column="device_name" />
<result property="stakeMark" column="stake_mark" />
<result property="direction" column="direction" />
<result property="deviceState" column="device_state" />
<result property="stakeMarkRange" column="stake_mark_range" />
<result property="remark" column="remark" />
<result property="otherConfig" column="other_config" />
<result property="installationSite" column="installation_site" />
<result property="installationSite" column="installation_site" />
<result property="networkSegment" column="network_segment" />
</resultMap>
<resultMap type="map" id="countMap">
<result property="timeSlot" column="time_slot" />
<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
</sql>
<select id="selectDcMeteorologicalDetectorDataList" parameterType="com.zc.business.domain.DcMeteorologicalDetectorData" resultMap="DcMeteorologicalDetectorDataResult">
<include refid="selectDcMeteorologicalDetectorDataVo"/>
<where>
<if test="iotDeviceId != null and iotDeviceId != ''"> and iot_device_id = #{iotDeviceId}</if>
<if test="direction != null and direction != ''"> and direction = #{direction}</if>
<if test="stakeMark != null and stakeMark != ''"> and stake_mark = #{stakeMark}</if>
<if test="deviceName != null and deviceName != ''"> and device_name = #{deviceName}</if>
<if test="rainfall != null and rainfall != ''"> and rainfall = #{rainfall}</if>
<if test="visibilityType != null and visibilityType != ''"> and visibility_type = #{visibilityType}</if>
<if test="visibility != null and visibility != ''"> and visibility = #{visibility}</if>
<if test="atmosphericPressure != null and atmosphericPressure != ''"> and atmospheric_pressure = #{atmosphericPressure}</if>
<if test="temperature != null and temperature != ''"> and temperature = #{temperature}</if>
<if test="humidity != null and humidity != ''"> and humidity = #{humidity}</if>
<if test="windDirection != null and windDirection != ''"> and wind_direction = #{windDirection}</if>
<if test="windSpeed != null and windSpeed != ''"> and wind_speed = #{windSpeed}</if>
<if test="precipitationType != null and precipitationType != ''"> and precipitation_type = #{precipitationType}</if>
<if test="wetSlipperyCoefficient != null and wetSlipperyCoefficient != ''"> and wet_slippery_coefficient = #{wetSlipperyCoefficient}</if>
<if test="remoteRoadSurfaceTemperature != null and remoteRoadSurfaceTemperature != ''"> and remote_road_surface_temperature = #{remoteRoadSurfaceTemperature}</if>
<if test="remoteRoadSurfaceStatus != null and remoteRoadSurfaceStatus != ''"> and remote_road_surface_status = #{remoteRoadSurfaceStatus}</if>
<if test="waterFilmIceSnowValue != null and waterFilmIceSnowValue != ''"> and water_film_ice_snow_value = #{waterFilmIceSnowValue}</if>
</where>
</select>
<select id="selectDcMeteorologicalDetectorDataById" parameterType="Long" resultMap="DcMeteorologicalDetectorDataResult">
<include refid="selectDcMeteorologicalDetectorDataVo"/>
where id = #{id}
</select>
<insert id="insertDcMeteorologicalDetectorData" parameterType="com.zc.business.domain.DcMeteorologicalDetectorData" useGeneratedKeys="true" keyProperty="id">
insert into dc_meteorological_detector_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="iotDeviceId != null">iot_device_id,</if>
<if test="direction != null">direction,</if>
<if test="stakeMark != null">stake_mark,</if>
<if test="deviceName != null">device_name,</if>
<if test="rainfall != null">rainfall,</if>
<if test="visibilityType != null">visibility_type,</if>
<if test="visibility != null">visibility,</if>
<if test="atmosphericPressure != null">atmospheric_pressure,</if>
<if test="temperature != null">temperature,</if>
<if test="humidity != null">humidity,</if>
<if test="windDirection != null">wind_direction,</if>
<if test="windSpeed != null">wind_speed,</if>
<if test="precipitationType != null">precipitation_type,</if>
<if test="wetSlipperyCoefficient != null">wet_slippery_coefficient,</if>
<if test="remoteRoadSurfaceTemperature != null">remote_road_surface_temperature,</if>
<if test="remoteRoadSurfaceStatus != null">remote_road_surface_status,</if>
<if test="waterFilmIceSnowValue != null">water_film_ice_snow_value,</if>
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="iotDeviceId != null">#{iotDeviceId},</if>
<if test="direction != null">#{direction},</if>
<if test="stakeMark != null">#{stakeMark},</if>
<if test="deviceName != null">#{deviceName},</if>
<if test="rainfall != null">#{rainfall},</if>
<if test="visibilityType != null">#{visibilityType},</if>
<if test="visibility != null">#{visibility},</if>
<if test="atmosphericPressure != null">#{atmosphericPressure},</if>
<if test="temperature != null">#{temperature},</if>
<if test="humidity != null">#{humidity},</if>
<if test="windDirection != null">#{windDirection},</if>
<if test="windSpeed != null">#{windSpeed},</if>
<if test="precipitationType != null">#{precipitationType},</if>
<if test="wetSlipperyCoefficient != null">#{wetSlipperyCoefficient},</if>
<if test="remoteRoadSurfaceTemperature != null">#{remoteRoadSurfaceTemperature},</if>
<if test="remoteRoadSurfaceStatus != null">#{remoteRoadSurfaceStatus},</if>
<if test="waterFilmIceSnowValue != null">#{waterFilmIceSnowValue},</if>
CURRENT_TIMESTAMP
</trim>
</insert>
<update id="updateDcMeteorologicalDetectorData" parameterType="com.zc.business.domain.DcMeteorologicalDetectorData">
update dc_meteorological_detector_data
<trim prefix="SET" suffixOverrides=",">
<if test="iotDeviceId != null">iot_device_id = #{iotDeviceId},</if>
<if test="direction != null">iot_device_id = #{direction},</if>
<if test="deviceName != null">device_name = #{deviceName},</if>
<if test="stakeMark != null">stake_mark = #{stakeMark},</if>
<if test="rainfall != null">rainfall = #{rainfall},</if>
<if test="visibilityType != null">visibility_type = #{visibilityType},</if>
<if test="visibility != null">visibility = #{visibility},</if>
<if test="atmosphericPressure != null">atmospheric_pressure = #{atmosphericPressure},</if>
<if test="temperature != null">temperature = #{temperature},</if>
<if test="humidity != null">humidity = #{humidity},</if>
<if test="windDirection != null">wind_direction = #{windDirection},</if>
<if test="windSpeed != null">wind_speed = #{windSpeed},</if>
<if test="precipitationType != null">precipitation_type = #{precipitationType},</if>
<if test="wetSlipperyCoefficient != null">wet_slippery_coefficient = #{wetSlipperyCoefficient},</if>
<if test="remoteRoadSurfaceTemperature != null">remote_road_surface_temperature = #{remoteRoadSurfaceTemperature},</if>
<if test="remoteRoadSurfaceStatus != null">remote_road_surface_status = #{remoteRoadSurfaceStatus},</if>
<if test="waterFilmIceSnowValue != null">water_film_ice_snow_value = #{waterFilmIceSnowValue},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteDcMeteorologicalDetectorDataById" parameterType="Long">
delete from dc_meteorological_detector_data where id = #{id}
</delete>
<delete id="deleteDcMeteorologicalDetectorDataByIds" parameterType="String">
delete from dc_meteorological_detector_data where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectStatistics" 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
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 dc.visibility,dc.temperature,
CONCAT(
LPAD(HOUR(dc.create_time), 2, '0'),
':',
LPAD(MINUTE(dc.create_time), 2, '0')
) AS date
FROM dc_meteorological_detector_data dc
<where>
<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 dc.device_name = #{deviceName}
</where>
ORDER BY
dc.create_time ASC
</select>
<select id="selectlistAll" parameterType="com.zc.business.domain.DcMeteorologicalDetectorData" resultMap="DcMeteorologicalDetectorDataResult">
SELECT
m.iot_device_id,
m.device_name,
m.create_time,
m.rainfall,
m.visibility_type,
m.visibility,
m.atmospheric_pressure,
m.temperature,
m.humidity,
m.wind_direction,
m.wind_speed,
m.precipitation_type,
m.wet_slippery_coefficient,
m.remote_road_surface_temperature,
m.remote_road_surface_status,
m.water_film_ice_snow_value
FROM
dc_meteorological_detector_data m
JOIN (
SELECT
iot_device_id, MAX(create_time) AS max_create_time
FROM
dc_meteorological_detector_data
GROUP BY
iot_device_id
) latest ON m.iot_device_id = latest.iot_device_id AND m.create_time = latest.max_create_time;
</select>
<select id="selectDeviceNameList" parameterType="com.zc.business.domain.DcMeteorologicalDetectorData" resultMap="DcMeteorologicalDetectorDataResult">
SELECT
d.iot_device_id, d.stake_mark, d.direction, d.device_name, d.device_state,d.network_segment,d.installation_site,d.other_config,d.remark,d.stake_mark_range,
m.create_time,
m.rainfall, m.visibility_type, m.visibility, m.atmospheric_pressure,
m.temperature, m.humidity, m.wind_direction, m.wind_speed,
m.precipitation_type, m.wet_slippery_coefficient,
m.remote_road_surface_temperature, m.remote_road_surface_status,
m.water_film_ice_snow_value
FROM
dc_device d
LEFT JOIN
dc_meteorological_detector_data m
ON
d.iot_device_id = m.iot_device_id
AND m.create_time = (
SELECT MAX(create_time)
FROM dc_meteorological_detector_data m2
WHERE m2.iot_device_id = d.iot_device_id
)
WHERE
d.device_type = 3 AND d.device_name = #{deviceName}
ORDER BY d.stake_mark ASC;
</select>
<select id="selectlistVisibility" parameterType="com.zc.business.domain.DcMeteorologicalDetectorData" resultMap="DcMeteorologicalDetectorDataResult">
SELECT
d.iot_device_id,
d.stake_mark,
d.direction,
d.device_name,
d.device_state,
d.stake_mark_range,
m.create_time,
m.rainfall,
m.visibility_type,
m.visibility,
m.atmospheric_pressure,
m.temperature,
m.humidity,
m.wind_direction,
m.wind_speed,
m.precipitation_type,
m.wet_slippery_coefficient,
m.remote_road_surface_temperature,
m.remote_road_surface_status,
m.water_film_ice_snow_value
FROM
dc_meteorological_detector_data AS m
LEFT JOIN
dc_device AS d ON d.iot_device_id = m.iot_device_id
<where>
m.visibility_type != 4
<if test="visibilityType != null and visibilityType != ''">AND m.visibility_type = #{visibilityType}</if>
/* AND DATE(m.create_time) = CURDATE()
*/ </where>
ORDER BY
m.create_time desc
</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 &lt; 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 &lt; 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>