diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcPerceivedEventsWarningServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcPerceivedEventsWarningServiceImpl.java index 0b69ff3c..9eec57a3 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcPerceivedEventsWarningServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcPerceivedEventsWarningServiceImpl.java @@ -327,24 +327,17 @@ public class DcPerceivedEventsWarningServiceImpl implements IDCPerceivedEventsWa switch (type){ case "day": hashMap.put("currentlyMap", perceivedEventsWarningMapper.newSelectSectionDay(dcWarning)); - break; - case "month": - hashMap.put("currentlyMap", perceivedEventsWarningMapper.newSelectSectionMonth(dcWarning)); - break; - case "year": - hashMap.put("currentlyMap", perceivedEventsWarningMapper.newSelectSectionYear(dcWarning)); - break; - } - - dcWarning.setCurrently(dcWarning.getLastYear());//把传入的去年的时间参数,转为当下时间作为查询参数(因为mapper中的查询提交参数是当下时间) - switch (type) { - case "day": + dcWarning.setCurrently(dcWarning.getLastYear()); hashMap.put("lastYearMap", perceivedEventsWarningMapper.newSelectSectionDay(dcWarning)); break; case "month": + hashMap.put("currentlyMap", perceivedEventsWarningMapper.newSelectSectionMonth(dcWarning)); + dcWarning.setCurrently(dcWarning.getLastYear()); hashMap.put("lastYearMap", perceivedEventsWarningMapper.newSelectSectionMonth(dcWarning)); break; case "year": + hashMap.put("currentlyMap", perceivedEventsWarningMapper.newSelectSectionYear(dcWarning)); + dcWarning.setCurrently(dcWarning.getLastYear()); hashMap.put("lastYearMap", perceivedEventsWarningMapper.newSelectSectionYear(dcWarning)); break; } @@ -368,10 +361,15 @@ public class DcPerceivedEventsWarningServiceImpl implements IDCPerceivedEventsWa @Override public HashMap<String, Object> newSelectSection(DcWarning dcWarning) { HashMap<String, Object> hashMap = new HashMap<>(); - String startStakeMark = StakeMarkUtils.formatMetre(dcWarning.getStartStakeMark()); - dcWarning.setStartStakeMark(startStakeMark); - String endStakeMark = StakeMarkUtils.formatMetre(dcWarning.getEndStakeMark()); - dcWarning.setEndStakeMark(endStakeMark); + if (StringUtils.isNotEmpty(dcWarning.getStartStakeMark())){ + String startStakeMark = StakeMarkUtils.formatMetre(dcWarning.getStartStakeMark()); + dcWarning.setStartStakeMark(startStakeMark); + } + + if (StringUtils.isNotEmpty(dcWarning.getEndStakeMark())){ + String endStakeMark = StakeMarkUtils.formatMetre(dcWarning.getEndStakeMark()); + dcWarning.setEndStakeMark(endStakeMark); + } hashMap.put("currentlyMap", selectSectionUtils(dcWarning)); dcWarning.setCurrently(dcWarning.getLastYear());//时间参数转换,把去年的时间替换为查询时间参数 hashMap.put("lastYearMap", selectSectionUtils(dcWarning)); diff --git a/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml b/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml index 76ce6b7e..1703737b 100644 --- a/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml @@ -28,15 +28,13 @@ where warning.`id`=#{id} </select> <select id="selectPerceivedEventsList" resultType="com.zc.business.domain.DcWarning"> - SELECT facility.facility_name, warning.`id`,warning.`stake_mark`, warning.`direction`, - mark.longitude,mark.latitude,warning.lane,duration, + SELECT warning.`id`,warning.`stake_mark`, warning.`direction`, + warning.lane,duration, warning.`dept_id`,warning.`warning_state`,warning.`warning_time`, warning.`user_id`, warning.`warning_source`,warning.`warning_level`, warning.`remark`, warning.`create_time`,warning.`update_time`, warning.`warning_type`,warning.`warning_subclass`,warning.`warning_title`, warning.`other_config` FROM dc_warning AS warning - left JOIN dc_stake_mark AS mark ON mark.stake_mark=warning.stake_mark and mark.direction=warning.direction - left join dc_facility as facility on facility.stake_mark=warning.stake_mark and facility.facility_type=1 <where> <if test="warningSource == null || warningSource == ''"> and warning.warning_source !=6</if> <if test="warningSource != null and warningSource != ''"> and warning.warning_source = #{warningSource}</if> @@ -587,9 +585,12 @@ UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23 ) AS a - LEFT JOIN dc_warning dw ON DATE_FORMAT(dw.warning_time, '%Y-%m-%d %H') - = DATE_FORMAT(#{currently} + INTERVAL a.a HOUR, '%Y-%m-%d %H') and dw.warning_source!=6 + LEFT JOIN dc_warning dw ON dw.warning_time >= DATE_ADD(#{currently}, INTERVAL a.a HOUR) + AND dw.warning_time < DATE_ADD(#{currently}, INTERVAL a.a + 1 HOUR) + and dw.warning_source!=6 and dw.direction=#{direction} + where dw.warning_time >= #{currently} + AND dw.warning_time < DATE_ADD( #{currently}, INTERVAL 1 DAY) GROUP BY time ORDER BY time; </select> @@ -598,8 +599,7 @@ h.hour_num AS time, COUNT(dw.warning_time) AS number FROM ( - SELECT 0 AS hour_num UNION ALL - SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 + SELECT 0 AS hour_num 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 @@ -608,15 +608,16 @@ UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23 ) h - LEFT JOIN dc_warning dw ON HOUR(dw.warning_time) = h.hour_num - AND DATE_FORMAT(dw.warning_time, '%Y-%m') = DATE_FORMAT(#{currently}, '%Y-%m') + INNER JOIN dc_warning dw + ON HOUR(dw.warning_time) = h.hour_num + AND dw.warning_time >= DATE_FORMAT(#{currently}, '%Y-%m-01 00:00:00') + AND dw.warning_time < DATE_FORMAT(DATE_ADD(#{currently}, INTERVAL 1 MONTH), '%Y-%m-01') AND dw.warning_source != 6 AND ( CAST(SUBSTRING(SUBSTRING_INDEX(dw.stake_mark, '+', 1), 2) AS UNSIGNED) * 1000 + - CAST(SUBSTRING_INDEX(dw.stake_mark, '+', -1) AS UNSIGNED) >= #{startStakeMark} AND - CAST(SUBSTRING(SUBSTRING_INDEX(dw.stake_mark, '+', 1), 2) AS UNSIGNED) * 1000 + - CAST(SUBSTRING_INDEX(dw.stake_mark, '+', -1) AS UNSIGNED) <#{endStakeMark} - ) and dw.direction=#{direction} + CAST(SUBSTRING_INDEX(dw.stake_mark, '+', -1) AS UNSIGNED) BETWEEN #{startStakeMark} AND #{endStakeMark} - 1 + ) + AND dw.direction = #{direction} GROUP BY h.hour_num ORDER BY h.hour_num; </select> @@ -652,8 +653,9 @@ COUNT(*) AS number FROM dc_warning as warning where - <if test = 'type == "day"' > DATE_FORMAT(warning.warning_time,'%Y-%m-%d')=DATE_FORMAT(#{currently},'%Y-%m-%d')</if> - <if test = 'type == "month"' > DATE_FORMAT(warning_time,'%Y-%m') =DATE_FORMAT(#{currently},'%Y-%m')</if> + <if test = 'type == "day"' > warning_time >= #{currently} AND warning_time < #{currently} + INTERVAL 1 DAY</if> + <if test = 'type == "month"' > warning.warning_time >= #{currently} + AND warning.warning_time < DATE_ADD( #{currently}, INTERVAL 1 month)</if> <if test = 'type == "year"' > YEAR(warning_time) =DATE_FORMAT(#{currently},'%Y')</if> AND warning.direction=#{direction} and warning.warning_source!=6 AND ( @@ -670,15 +672,16 @@ COUNT(*) AS number FROM dc_warning as warning where - <if test = 'type == "day"' > DATE_FORMAT(warning.warning_time,'%Y-%m-%d')=DATE_FORMAT(#{currently},'%Y-%m-%d')</if> - <if test = 'type == "month"' > DATE_FORMAT(warning_time,'%Y-%m') =DATE_FORMAT(#{currently},'%Y-%m')</if> + <if test = 'type == "day"' > warning_time >= #{currently} AND warning_time < #{currently} + INTERVAL 1 DAY</if> + <if test = 'type == "month"' > warning.warning_time >= #{currently} + AND warning.warning_time < DATE_ADD( #{currently}, INTERVAL 1 month)</if> <if test = 'type == "year"' > YEAR(warning_time) =DATE_FORMAT(#{currently},'%Y')</if> AND warning.direction=#{direction} and warning.warning_source!=6 AND ( - CAST(SUBSTRING(SUBSTRING_INDEX(warning.stake_mark, '+', 1), 2) AS UNSIGNED) * 1000 + - CAST(SUBSTRING_INDEX(warning.stake_mark, '+', -1) AS UNSIGNED) >= #{startStakeMark} AND - CAST(SUBSTRING(SUBSTRING_INDEX(warning.stake_mark, '+', 1), 2) AS UNSIGNED) * 1000 + - CAST(SUBSTRING_INDEX(warning.stake_mark, '+', -1) AS UNSIGNED)<#{endStakeMark} + CAST(SUBSTRING(SUBSTRING_INDEX(warning.stake_mark,'+',1),2)AS UNSIGNED)*1000 + +CAST(SUBSTRING_INDEX(warning.stake_mark, '+', -1) AS UNSIGNED)>#{startStakeMark} AND + CAST(SUBSTRING(SUBSTRING_INDEX(warning.stake_mark,'+',1),2)AS UNSIGNED)*1000 + +CAST(SUBSTRING_INDEX(warning.stake_mark, '+', -1) AS UNSIGNED)<#{endStakeMark} ) GROUP BY stakeMark ORDER BY number DESC @@ -688,8 +691,8 @@ FROM dc_warning AS w LEFT JOIN dc_stake_mark AS sm ON w.stake_mark = sm.stake_mark and w.direction=sm.direction LEFT JOIN dc_road_section AS s ON sm.section_id = s.id - WHERE w.warning_source != 6 AND DATE_FORMAT(w.warning_time, '%Y-%m-%d') = DATE_FORMAT(#{currently}, '%Y-%m-%d') - GROUP BY w.warning_state,sectionName + WHERE w.warning_source != 6 AND DATE(w.warning_time) = DATE(#{currently}) + GROUP BY w.warning_state,s.section_name ORDER BY s.start_stake_mark </select> <select id="newStateDuration" resultType="java.util.HashMap"> @@ -701,7 +704,8 @@ LEFT JOIN dc_road_section AS s ON sm.section_id = s.id WHERE w.warning_source != 6 - AND DATE_FORMAT(w.warning_time, '%Y-%m-%d') = DATE_FORMAT(#{currently}, '%Y-%m-%d') + AND w.warning_time >= #{currently} + AND w.warning_time < DATE_ADD(#{currently}, INTERVAL 1 DAY) GROUP BY s.section_name; </select> </mapper>