|
|
@ -236,4 +236,108 @@ |
|
|
|
on t3.id = t4.facilityId |
|
|
|
</select> |
|
|
|
|
|
|
|
<select id="selectRoadSectionAnalysis" resultType="java.util.Map"> |
|
|
|
|
|
|
|
select t3.section_name,t3.mileage,IFNULL(t4.num,0) num,IFNULL(t5.lastNum,0) lastNum, |
|
|
|
ROUND(IFNULL( t4.num / t3.mileage * 100, 0 ),2) avgNum |
|
|
|
from |
|
|
|
(select * from dc_road_section) t3 |
|
|
|
LEFT JOIN |
|
|
|
(select t2.section_id, count(*) num |
|
|
|
from dc_event t1 |
|
|
|
left join dc_stake_mark t2 on t1.stake_mark = t2.id and t1.direction = t2.direction |
|
|
|
where |
|
|
|
t1.event_type = '1' and t1.direction = #{direction} |
|
|
|
<if test="type != null and type == '1'.toString"> |
|
|
|
and DATE_FORMAT(t1.start_time,'%Y%m%d') = DATE_FORMAT(#{startTime},'%Y%m%d') |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '2'.toString"> |
|
|
|
and DATE_FORMAT(t1.start_time,'%Y%m') = DATE_FORMAT(#{startTime},'%Y%m') |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '3'.toString"> |
|
|
|
and YEAR(t1.start_time) = YEAR(#{startTime}) and QUARTER(t1.start_time) = QUARTER(#{startTime}) |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '4'.toString"> |
|
|
|
and YEAR(t1.start_time) = YEAR(#{startTime}) |
|
|
|
</if> |
|
|
|
GROUP BY t2.section_id) t4 |
|
|
|
on t3.id = t4.section_id |
|
|
|
LEFT JOIN |
|
|
|
(select t2.section_id, count(*) lastNum |
|
|
|
from dc_event t1 |
|
|
|
left join dc_stake_mark t2 on t1.stake_mark = t2.id and t1.direction = t2.direction |
|
|
|
where |
|
|
|
t1.event_type = '1' and t1.direction = #{direction} |
|
|
|
<if test="type != null and type == '1'.toString"> |
|
|
|
and DATE_FORMAT(t1.start_time,'%Y%m%d') = DATE_FORMAT(DATE_SUB(#{startTime},INTERVAL 1 DAY),'%Y%m%d') |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '2'.toString"> |
|
|
|
and DATE_FORMAT(t1.start_time,'%Y%m') = DATE_FORMAT(DATE_SUB(#{startTime},INTERVAL 1 MONTH),'%Y%m') |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '3'.toString"> |
|
|
|
and YEAR(t1.start_time) = YEAR(DATE_SUB(#{startTime},INTERVAL 1 QUARTER)) and QUARTER(t1.start_time) = QUARTER(DATE_SUB(#{startTime},INTERVAL 1 QUARTER)) |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '4'.toString"> |
|
|
|
and YEAR(t1.start_time) = YEAR(DATE_SUB(#{startTime},INTERVAL 1 YEAR)) |
|
|
|
</if> |
|
|
|
GROUP BY t2.section_id) t5 |
|
|
|
on t3.id = t5.section_id |
|
|
|
</select> |
|
|
|
|
|
|
|
<select id="selectEventTypeAnalysis" resultType="java.util.Map"> |
|
|
|
|
|
|
|
select t1.eventSubclass,t1.eventSubclassName, |
|
|
|
IFNULL(t2.minuteTime,0) minuteTime,ROUND(IFNULL(t2.minuteTime/t2.num,0)) avgTime, |
|
|
|
IFNULL(t3.minuteTime,0) lastMinuteTime,ROUND(IFNULL(t3.minuteTime/t3.num,0)) lastAvgTime |
|
|
|
from |
|
|
|
(select '1-1' eventSubclass, '追尾' eventSubclassName |
|
|
|
UNION ALL select '1-2' eventSubclass, '侧翻' eventSubclassName |
|
|
|
UNION ALL select '1-3' eventSubclass, '撞护栏' eventSubclassName |
|
|
|
UNION ALL select '1-4' eventSubclass, '自燃' eventSubclassName |
|
|
|
UNION ALL select '1-5' eventSubclass, '其他事故' eventSubclassName) t1 |
|
|
|
LEFT JOIN |
|
|
|
(select event_subclass, count(*) num , |
|
|
|
sum(case when ISNULL(end_time) |
|
|
|
then TIMESTAMPDIFF(MINUTE,start_time,now()) |
|
|
|
else TIMESTAMPDIFF(MINUTE,start_time,end_time) |
|
|
|
end) minuteTime |
|
|
|
from dc_event |
|
|
|
where event_type = '1' |
|
|
|
<if test="type != null and type == '1'.toString"> |
|
|
|
and DATE_FORMAT(start_time,'%Y%m%d') = DATE_FORMAT(#{startTime},'%Y%m%d') |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '2'.toString"> |
|
|
|
and DATE_FORMAT(start_time,'%Y%m') = DATE_FORMAT(#{startTime},'%Y%m') |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '3'.toString"> |
|
|
|
and YEAR(start_time) = YEAR(#{startTime}) and QUARTER(start_time) = QUARTER(#{startTime}) |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '4'.toString"> |
|
|
|
and YEAR(start_time) = YEAR(#{startTime}) |
|
|
|
</if> |
|
|
|
group by event_subclass) t2 |
|
|
|
on t1.eventSubclass = t2.event_subclass |
|
|
|
LEFT JOIN |
|
|
|
(select event_subclass, count(*) num , |
|
|
|
sum(case when ISNULL(end_time) |
|
|
|
then TIMESTAMPDIFF(MINUTE,start_time,now()) |
|
|
|
else TIMESTAMPDIFF(MINUTE,start_time,end_time) |
|
|
|
end) minuteTime |
|
|
|
from dc_event |
|
|
|
where event_type = '1' |
|
|
|
<if test="type != null and type == '1'.toString"> |
|
|
|
and DATE_FORMAT(start_time,'%Y%m%d') = DATE_FORMAT(DATE_SUB(#{startTime},INTERVAL 1 DAY),'%Y%m%d') |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '2'.toString"> |
|
|
|
and DATE_FORMAT(start_time,'%Y%m') = DATE_FORMAT(DATE_SUB(#{startTime},INTERVAL 1 MONTH),'%Y%m') |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '3'.toString"> |
|
|
|
and YEAR(start_time) = YEAR(DATE_SUB(#{startTime},INTERVAL 1 QUARTER)) and QUARTER(start_time) = QUARTER(DATE_SUB(#{startTime},INTERVAL 1 QUARTER)) |
|
|
|
</if> |
|
|
|
<if test="type != null and type == '4'.toString"> |
|
|
|
and YEAR(start_time) = YEAR(DATE_SUB(#{startTime},INTERVAL 1 YEAR)) |
|
|
|
</if> |
|
|
|
group by event_subclass) t3 on t1.eventSubclass = t3.event_subclass |
|
|
|
</select> |
|
|
|
|
|
|
|
</mapper> |