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.
351 lines
19 KiB
351 lines
19 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.DcTrafficSurveyDataMapper">
|
|
|
|
<resultMap type="DcTrafficSurveyData" id="DcTrafficSurveyDataResult">
|
|
<result property="id" column="id" />
|
|
<result property="iotDeviceId" column="iot_device_id" />
|
|
<result property="stakeMark" column="stake_mark" />
|
|
<result property="direction" column="direction" />
|
|
<result property="timestamp" column="timestamp" />
|
|
<result property="trafficVolume" column="traffic_volume" />
|
|
</resultMap>
|
|
|
|
<sql id="selectDcTrafficSurveyDataVo">
|
|
select id, iot_device_id, stake_mark, direction, timestamp, traffic_volume from dc_traffic_survey_data
|
|
</sql>
|
|
|
|
<select id="selectDcTrafficSurveyDataList" parameterType="DcTrafficSurveyData" resultMap="DcTrafficSurveyDataResult">
|
|
<include refid="selectDcTrafficSurveyDataVo"/>
|
|
<where>
|
|
<if test="iotDeviceId != null and iotDeviceId != ''"> and iot_device_id = #{iotDeviceId}</if>
|
|
<if test="stakeMark != null and stakeMark != ''"> and stake_mark = #{stakeMark}</if>
|
|
<if test="direction != null and direction != ''"> and direction = #{direction}</if>
|
|
<if test="trafficVolume != null "> and traffic_volume = #{trafficVolume}</if>
|
|
<if test="type != null and type == 'year'.toString">
|
|
and DATE_FORMAT(timestamp,'%Y') = DATE_FORMAT(#{thisTime},'%Y')
|
|
</if>
|
|
<if test="type != null and type == 'month'.toString">
|
|
and DATE_FORMAT(timestamp,'%Y-%m') = DATE_FORMAT(#{thisTime},'%Y-%m')
|
|
</if>
|
|
<if test="type != null and type == 'year'.toString">
|
|
and DATE_FORMAT(timestamp,'%Y-%m-%d') = DATE_FORMAT(#{thisTime},'%Y-%m-%d')
|
|
</if>
|
|
</where>
|
|
</select>
|
|
|
|
<select id="selectDcTrafficSurveyDataById" parameterType="Long" resultMap="DcTrafficSurveyDataResult">
|
|
<include refid="selectDcTrafficSurveyDataVo"/>
|
|
where id = #{id}
|
|
</select>
|
|
<select id="selectDeviceList" resultType="com.zc.business.domain.DcDevice">
|
|
SELECT * FROM `dc_device` where device_type = '11' and iot_device_id is not null
|
|
</select>
|
|
<select id="selectDay" resultType="com.zc.business.domain.DcTrafficSurveyData">
|
|
SELECT iot_device_id,stake_mark,direction,HOUR(`timestamp`) times,SUM(traffic_volume) trafficVolume,
|
|
SUM(traffic_number_of_in_and_small) + SUM(bus_traffic_volume) bus,
|
|
SUM(traffic_volume_of_small_trucks) + SUM(medium_truck_traffic_volume)
|
|
+ SUM(large_truck_traffic_volume) + SUM(extra_large_trucks_traffic_volume) goodsCar
|
|
FROM `dc_traffic_survey_data`
|
|
where DATE_FORMAT(`timestamp`,'%Y-%m-%d') = DATE_FORMAT(#{timestamp},'%Y-%m-%d')
|
|
GROUP BY iot_device_id,direction,times
|
|
</select>
|
|
<select id="selectMonth" resultType="com.zc.business.domain.DcTrafficSurveyData">
|
|
SELECT iot_device_id,stake_mark,direction,DAY(`timestamp`) times,SUM(traffic_volume) trafficVolume,
|
|
SUM(traffic_number_of_in_and_small) + SUM(bus_traffic_volume) bus,
|
|
SUM(traffic_volume_of_small_trucks) + SUM(medium_truck_traffic_volume)
|
|
+ SUM(large_truck_traffic_volume) + SUM(extra_large_trucks_traffic_volume) goodsCar
|
|
FROM `dc_traffic_survey_data`
|
|
where DATE_FORMAT(`timestamp`,'%Y-%m') = DATE_FORMAT(#{timestamp},'%Y-%m')
|
|
GROUP BY iot_device_id,direction,times
|
|
</select>
|
|
<select id="selectYear" resultType="com.zc.business.domain.DcTrafficSurveyData">
|
|
SELECT iot_device_id,stake_mark,direction,MONTH(`timestamp`) times,SUM(traffic_volume) trafficVolume,
|
|
SUM(traffic_number_of_in_and_small) + SUM(bus_traffic_volume) bus,
|
|
SUM(traffic_volume_of_small_trucks) + SUM(medium_truck_traffic_volume)
|
|
+ SUM(large_truck_traffic_volume) + SUM(extra_large_trucks_traffic_volume) goodsCar
|
|
FROM `dc_traffic_survey_data`
|
|
where DATE_FORMAT(`timestamp`,'%Y') = DATE_FORMAT(#{timestamp},'%Y')
|
|
GROUP BY iot_device_id,direction,times
|
|
</select>
|
|
<select id="selectRange" resultType="com.zc.business.domain.DcTrafficSurveyData">
|
|
SELECT iot_device_id,stake_mark,direction,DATE_FORMAT(`timestamp`, '%m-%d') times,
|
|
SUM(traffic_volume) trafficVolume,
|
|
SUM(traffic_number_of_in_and_small) + SUM(bus_traffic_volume) bus,
|
|
SUM(traffic_volume_of_small_trucks) + SUM(medium_truck_traffic_volume)
|
|
+ SUM(large_truck_traffic_volume) + SUM(extra_large_trucks_traffic_volume) goodsCar
|
|
FROM `dc_traffic_survey_data`
|
|
where DATE_FORMAT(`timestamp`,'%Y-%m-%d') >= DATE_FORMAT(#{timestamp},'%Y-%m-%d')
|
|
and DATE_FORMAT(`timestamp`,'%Y-%m-%d') <= DATE_FORMAT(#{endTime},'%Y-%m-%d')
|
|
GROUP BY iot_device_id,direction,times
|
|
</select>
|
|
|
|
<select id="selectTrafficVolume" resultType="com.zc.business.domain.DcTrafficVolumeData">
|
|
select
|
|
<choose>
|
|
<when test="type != null and type == '1'.toString">
|
|
date_format(`timestamp`, '%Y-%m-%d %H')
|
|
</when>
|
|
<when test="type != null and type == '2'.toString">
|
|
date_format(`timestamp`, '%Y-%m-%d')
|
|
</when>
|
|
<when test="type != null and type == '3'.toString">
|
|
date_format(`timestamp`, '%Y-%m')
|
|
</when>
|
|
<when test="type != null and type == '4'.toString">
|
|
date_format(`timestamp`, '%Y-%m-%d')
|
|
</when>
|
|
</choose> time,direction,
|
|
sum(traffic_volume) trafficVolume ,
|
|
sum(traffic_number_of_in_and_small) trafficNumberOfInAndSmall,
|
|
sum(bus_traffic_volume) busTrafficVolume,
|
|
sum(traffic_volume_of_small_trucks) trafficVolumeOfSmallTrucks,
|
|
sum(medium_truck_traffic_volume) mediumTruckTrafficVolume,
|
|
sum(large_truck_traffic_volume) largeTruckTrafficVolume,
|
|
sum(extra_large_trucks_traffic_volume) extraLargeTrucksTrafficVolume,
|
|
sum(container_truck_traffic_volume) containerTruckTrafficVolume,
|
|
sum(motorcycle_traffic_volume) motorcycleTrafficVolume,
|
|
sum(tractor_traffic_volume) tractorTrafficVolume
|
|
FROM `dc_traffic_survey_data`
|
|
<where>
|
|
<if test="iotDeviceId != null and iotDeviceId != ''">
|
|
and iot_device_id = #{iotDeviceId}
|
|
</if>
|
|
<if test="type != null and type == '1'.toString">
|
|
and DATE_FORMAT(`timestamp`,'%Y-%m-%d') = DATE_FORMAT(#{date},'%Y-%m-%d')
|
|
</if>
|
|
<if test="type != null and type == '2'.toString">
|
|
and DATE_FORMAT(`timestamp`,'%Y-%m') = DATE_FORMAT(#{date},'%Y-%m')
|
|
</if>
|
|
<if test="type != null and type == '3'.toString">
|
|
and DATE_FORMAT(`timestamp`,'%Y') = DATE_FORMAT(#{date},'%Y')
|
|
</if>
|
|
<if test="type != null and type == '4'.toString">
|
|
and DATE_FORMAT(`timestamp`,'%Y-%m-%d') >= DATE_FORMAT(#{startTime},'%Y-%m-%d')
|
|
and DATE_FORMAT(`timestamp`,'%Y-%m-%d') <= DATE_FORMAT(#{endTime},'%Y-%m-%d')
|
|
</if>
|
|
</where>
|
|
GROUP BY time
|
|
<if test="direction != null and direction == '1'.toString">,direction</if>
|
|
order by time
|
|
</select>
|
|
|
|
<select id="selectSpeed" resultType="com.zc.business.domain.DcTrafficSpeedData">
|
|
select *,
|
|
ROUND(
|
|
(
|
|
t1.inAndSmallAverageVehicleSpeed +
|
|
t1.averageSpeedOfBus +
|
|
t1.smallTrucksAverageVehicleSpeed +
|
|
t1.averageSpeedOfMediumSizeTrucks +
|
|
t1.averageSpeedOfLargeTrucks +
|
|
t1.averageSpeedOfExtraLargeTrucks +
|
|
t1.averageSpeedOfContainerTruck +
|
|
t1.averageSpeedOfMotorcycle +
|
|
t1.averageSpeedOfTractor
|
|
) /
|
|
NULLIF(
|
|
CASE WHEN t1.inAndSmallAverageVehicleSpeed = 0 THEN 0 ELSE 1 END +
|
|
CASE WHEN t1.averageSpeedOfBus = 0 THEN 0 ELSE 1 END +
|
|
CASE WHEN t1.smallTrucksAverageVehicleSpeed = 0 THEN 0 ELSE 1 END +
|
|
CASE WHEN t1.averageSpeedOfMediumSizeTrucks = 0 THEN 0 ELSE 1 END +
|
|
CASE WHEN t1.averageSpeedOfLargeTrucks = 0 THEN 0 ELSE 1 END +
|
|
CASE WHEN t1.averageSpeedOfExtraLargeTrucks = 0 THEN 0 ELSE 1 END +
|
|
CASE WHEN t1.averageSpeedOfContainerTruck = 0 THEN 0 ELSE 1 END +
|
|
CASE WHEN t1.averageSpeedOfMotorcycle = 0 THEN 0 ELSE 1 END +
|
|
CASE WHEN t1.averageSpeedOfTractor = 0 THEN 0 ELSE 1 END,
|
|
0
|
|
)
|
|
,0) AS avgSpeed
|
|
from
|
|
(select direction,
|
|
<choose>
|
|
<when test="type != null and type == '1'.toString">
|
|
date_format(`timestamp`, '%Y-%m-%d %H')
|
|
</when>
|
|
<when test="type != null and type == '2'.toString">
|
|
date_format(`timestamp`, '%Y-%m-%d')
|
|
</when>
|
|
<when test="type != null and type == '3'.toString">
|
|
date_format(`timestamp`, '%Y-%m')
|
|
</when>
|
|
<when test="type != null and type == '4'.toString">
|
|
date_format(`timestamp`, '%Y-%m-%d')
|
|
</when>
|
|
</choose> time,
|
|
ROUND(IFNULL(AVG(NULLIF(in_and_small_average_vehicle_speed, 0)),0), 0) AS inAndSmallAverageVehicleSpeed,
|
|
ROUND(IFNULL(AVG(NULLIF(average_speed_of_bus, 0)),0), 0) AS averageSpeedOfBus,
|
|
ROUND(IFNULL(AVG(NULLIF(small_trucks_average_vehicle_speed, 0)),0), 0) AS smallTrucksAverageVehicleSpeed,
|
|
ROUND(IFNULL(AVG(NULLIF(average_speed_of_medium_size_trucks, 0)),0), 0) AS averageSpeedOfMediumSizeTrucks,
|
|
ROUND(IFNULL(AVG(NULLIF(average_speed_of_large_trucks, 0)),0), 0) AS averageSpeedOfLargeTrucks,
|
|
ROUND(IFNULL(AVG(NULLIF(average_speed_of_extra_large_trucks, 0)),0), 0) AS averageSpeedOfExtraLargeTrucks,
|
|
ROUND(IFNULL(AVG(NULLIF(average_speed_of_container_truck, 0)),0), 0) AS averageSpeedOfContainerTruck,
|
|
ROUND(IFNULL(AVG(NULLIF(average_speed_of_motorcycle, 0)),0), 0) AS averageSpeedOfMotorcycle,
|
|
ROUND(IFNULL(AVG(NULLIF(average_speed_of_tractor, 0)),0), 0) AS averageSpeedOfTractor
|
|
FROM `dc_traffic_survey_data`
|
|
<where>
|
|
<if test="iotDeviceId != null and iotDeviceId != ''">
|
|
and iot_device_id = #{iotDeviceId}
|
|
</if>
|
|
<if test="type != null and type == '1'.toString">
|
|
and DATE_FORMAT(`timestamp`,'%Y-%m-%d') = DATE_FORMAT(#{date},'%Y-%m-%d')
|
|
</if>
|
|
<if test="type != null and type == '2'.toString">
|
|
and DATE_FORMAT(`timestamp`,'%Y-%m') = DATE_FORMAT(#{date},'%Y-%m')
|
|
</if>
|
|
<if test="type != null and type == '3'.toString">
|
|
and DATE_FORMAT(`timestamp`,'%Y') = DATE_FORMAT(#{date},'%Y')
|
|
</if>
|
|
<if test="type != null and type == '4'.toString">
|
|
and DATE_FORMAT(`timestamp`,'%Y-%m-%d') >= DATE_FORMAT(#{startTime},'%Y-%m-%d')
|
|
and DATE_FORMAT(`timestamp`,'%Y-%m-%d') <= DATE_FORMAT(#{endTime},'%Y-%m-%d') </if>
|
|
</where>
|
|
GROUP BY time
|
|
<if test="direction != null and direction == '1'.toString">,direction</if>
|
|
) t1
|
|
</select>
|
|
<select id="selectDeviceByIotId" resultType="com.zc.business.domain.DcDevice">
|
|
SELECT * FROM `dc_device` where device_type = '11' and iot_device_id = #{iotDeviceId}
|
|
</select>
|
|
<select id="getTrafficSurveyDataList" resultType="com.zc.business.domain.DcTrafficSurveyData">
|
|
select * from dc_traffic_survey_data
|
|
<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="startTime != null and endTime != null">
|
|
and `timestamp` BETWEEN #{startTime} and #{endTime}
|
|
</if>
|
|
</where>
|
|
</select>
|
|
|
|
<insert id="insertDcTrafficSurveyData" parameterType="DcTrafficSurveyData" useGeneratedKeys="true" keyProperty="id">
|
|
insert into dc_traffic_survey_data
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
<if test="iotDeviceId != null">iot_device_id,</if>
|
|
<if test="stakeMark != null and stakeMark != ''">stake_mark,</if>
|
|
<if test="direction != null">direction,</if>
|
|
<if test="timestamp != null">timestamp,</if>
|
|
<if test="trafficVolume != null">traffic_volume,</if>
|
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
<if test="iotDeviceId != null">#{iotDeviceId},</if>
|
|
<if test="stakeMark != null and stakeMark != ''">#{stakeMark},</if>
|
|
<if test="direction != null">#{direction},</if>
|
|
<if test="timestamp != null">#{timestamp},</if>
|
|
<if test="trafficVolume != null">#{trafficVolume},</if>
|
|
</trim>
|
|
</insert>
|
|
<insert id="batchInsert">
|
|
INSERT INTO dc_traffic_survey_data (
|
|
iot_device_id,
|
|
stake_mark,
|
|
direction,
|
|
`timestamp`,
|
|
traffic_volume,
|
|
following_percentage,
|
|
time_occupancy_rate,
|
|
average_headway,
|
|
traffic_number_of_in_and_small,
|
|
in_and_small_average_vehicle_speed,
|
|
bus_traffic_volume,
|
|
average_speed_of_bus,
|
|
traffic_volume_of_small_trucks,
|
|
small_trucks_average_vehicle_speed,
|
|
medium_truck_traffic_volume,
|
|
average_speed_of_medium_size_trucks,
|
|
large_truck_traffic_volume,
|
|
average_speed_of_large_trucks,
|
|
average_speed_of_extra_large_trucks,
|
|
extra_large_trucks_traffic_volume,
|
|
container_truck_traffic_volume,
|
|
average_speed_of_container_truck,
|
|
motorcycle_traffic_volume,
|
|
average_speed_of_motorcycle,
|
|
tractor_traffic_volume,
|
|
average_speed_of_tractor
|
|
) VALUES
|
|
<foreach collection="list" item="dcTrafficSurveyData" separator=",">
|
|
(
|
|
#{dcTrafficSurveyData.iotDeviceId},
|
|
#{dcTrafficSurveyData.stakeMark},
|
|
#{dcTrafficSurveyData.direction},
|
|
#{dcTrafficSurveyData.timestamp},
|
|
#{dcTrafficSurveyData.trafficVolume},
|
|
#{dcTrafficSurveyData.followingPercentage},
|
|
#{dcTrafficSurveyData.timeOccupancyRate},
|
|
#{dcTrafficSurveyData.averageHeadway},
|
|
#{dcTrafficSurveyData.trafficNumberOfInAndSmall},
|
|
#{dcTrafficSurveyData.inAndSmallAverageVehicleSpeed},
|
|
#{dcTrafficSurveyData.busTrafficVolume},
|
|
#{dcTrafficSurveyData.averageSpeedOfBus},
|
|
#{dcTrafficSurveyData.trafficVolumeOfSmallTrucks},
|
|
#{dcTrafficSurveyData.smallTrucksAverageVehicleSpeed},
|
|
#{dcTrafficSurveyData.mediumTruckTrafficVolume},
|
|
#{dcTrafficSurveyData.averageSpeedOfMediumSizeTrucks},
|
|
#{dcTrafficSurveyData.largeTruckTrafficVolume},
|
|
#{dcTrafficSurveyData.averageSpeedOfLargeTrucks},
|
|
#{dcTrafficSurveyData.averageSpeedOfExtraLargeTrucks},
|
|
#{dcTrafficSurveyData.extraLargeTrucksTrafficVolume},
|
|
#{dcTrafficSurveyData.containerTruckTrafficVolume},
|
|
#{dcTrafficSurveyData.averageSpeedOfContainerTruck},
|
|
#{dcTrafficSurveyData.motorcycleTrafficVolume},
|
|
#{dcTrafficSurveyData.averageSpeedOfMotorcycle},
|
|
#{dcTrafficSurveyData.tractorTrafficVolume},
|
|
#{dcTrafficSurveyData.averageSpeedOfTractor}
|
|
)
|
|
</foreach>
|
|
ON DUPLICATE KEY UPDATE
|
|
stake_mark = VALUES(stake_mark),
|
|
traffic_volume = VALUES(traffic_volume),
|
|
following_percentage = VALUES(following_percentage),
|
|
time_occupancy_rate = VALUES(time_occupancy_rate),
|
|
average_headway = VALUES(average_headway),
|
|
traffic_number_of_in_and_small = VALUES(traffic_number_of_in_and_small),
|
|
in_and_small_average_vehicle_speed = VALUES(in_and_small_average_vehicle_speed),
|
|
bus_traffic_volume = VALUES(bus_traffic_volume),
|
|
average_speed_of_bus = VALUES(average_speed_of_bus),
|
|
traffic_volume_of_small_trucks = VALUES(traffic_volume_of_small_trucks),
|
|
small_trucks_average_vehicle_speed = VALUES(small_trucks_average_vehicle_speed),
|
|
medium_truck_traffic_volume = VALUES(medium_truck_traffic_volume),
|
|
average_speed_of_medium_size_trucks = VALUES(average_speed_of_medium_size_trucks),
|
|
large_truck_traffic_volume = VALUES(large_truck_traffic_volume),
|
|
average_speed_of_large_trucks = VALUES(average_speed_of_large_trucks),
|
|
average_speed_of_extra_large_trucks = VALUES(average_speed_of_extra_large_trucks),
|
|
extra_large_trucks_traffic_volume = VALUES(extra_large_trucks_traffic_volume),
|
|
container_truck_traffic_volume = VALUES(container_truck_traffic_volume),
|
|
average_speed_of_container_truck = VALUES(average_speed_of_container_truck),
|
|
motorcycle_traffic_volume = VALUES(motorcycle_traffic_volume),
|
|
average_speed_of_motorcycle = VALUES(average_speed_of_motorcycle),
|
|
tractor_traffic_volume = VALUES(tractor_traffic_volume),
|
|
average_speed_of_tractor = VALUES(average_speed_of_tractor)
|
|
</insert>
|
|
|
|
<update id="updateDcTrafficSurveyData" parameterType="DcTrafficSurveyData">
|
|
update dc_traffic_survey_data
|
|
<trim prefix="SET" suffixOverrides=",">
|
|
<if test="iotDeviceId != null">iot_device_id = #{iotDeviceId},</if>
|
|
<if test="stakeMark != null and stakeMark != ''">stake_mark = #{stakeMark},</if>
|
|
<if test="direction != null">direction = #{direction},</if>
|
|
<if test="timestamp != null">timestamp = #{timestamp},</if>
|
|
<if test="trafficVolume != null">traffic_volume = #{trafficVolume},</if>
|
|
</trim>
|
|
where id = #{id}
|
|
</update>
|
|
|
|
<delete id="deleteDcTrafficSurveyDataById" parameterType="Long">
|
|
delete from dc_traffic_survey_data where id = #{id}
|
|
</delete>
|
|
|
|
<delete id="deleteDcTrafficSurveyDataByIds" parameterType="String">
|
|
delete from dc_traffic_survey_data where id in
|
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
</delete>
|
|
</mapper>
|