Browse Source

高速云事件查询

develop
lau572 3 months ago
parent
commit
9be0a7d874
  1. 5
      zc-business/src/main/java/com/zc/business/mapper/DcSdhsEventMapper.java
  2. 117
      zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java
  3. 62
      zc-business/src/main/resources/mapper/business/DcSdhsEventMapper.xml

5
zc-business/src/main/java/com/zc/business/mapper/DcSdhsEventMapper.java

@ -76,4 +76,9 @@ public interface DcSdhsEventMapper
boolean deleteByTimeRange(@Param("startTime") String startTime,@Param("endTime") String endTime); boolean deleteByTimeRange(@Param("startTime") String startTime,@Param("endTime") String endTime);
List<Map<String,Object>> selectRegionAnalysis(@Param("type") String type,@Param("thisTime") String thisTime, @Param("lastTime") String lastTime); List<Map<String,Object>> selectRegionAnalysis(@Param("type") String type,@Param("thisTime") String thisTime, @Param("lastTime") String lastTime);
List<DcSdhsEvent> selectStationAnalysis(@Param("type") String type,@Param("time") String time);
List<Map<String,Object>> selectAccidentType(@Param("type") String type,@Param("thisTime") String thisTime, @Param("lastTime") String lastTime);
} }

117
zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java

@ -1430,79 +1430,81 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
@Override @Override
public AjaxResult selectStationAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { public AjaxResult selectStationAnalysis(DcSdhsEventQuery dcSdhsEventQuery) {
List<DcSdhsEvent> eventList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); //本期数据
if (eventList == null || eventList.size() == 0) { List<DcSdhsEvent> thisTimeList = dcSdhsEventMapper.selectStationAnalysis(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime());
return AjaxResult.error("请先导入数据"); Set<String> stationSet = new HashSet<>();
} List<DcSdhsEvent> thisTimeCloseList = thisTimeList.stream()
.filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站封闭"))
eventList = eventList.stream().filter(item -> item.getStartTime() != null
&& item.getStartTime().getTime() >= dcSdhsEventQuery.getStartTime().getTime()
&& item.getStartTime().getTime() <= dcSdhsEventQuery.getEndTime().getTime())
.collect(Collectors.toList());
//筛选方向
/*if (StringUtils.isNotEmpty(dcSdhsEventQuery.getDirection())){
if (dcSdhsEventQuery.getDirection().equals("1")){
//菏泽方向
eventList = eventList.stream()
.filter(item -> item.getDirection().equals("广州方向")
|| item.getDirection().equals("双向"))
.collect(Collectors.toList()); .collect(Collectors.toList());
} else if (dcSdhsEventQuery.getDirection().equals("3")){ //分割站点名称, 然后分组
//济南方向 Map<String, Long> thisTimeCloseStation = thisTimeCloseList.stream().collect(Collectors.groupingBy(item -> getStationName(item.getTitle()),
eventList = eventList.stream() Collectors.counting()));
.filter(item -> item.getDirection().equals("济南方向") || item.getDirection().equals("双向")) //限行
List<DcSdhsEvent> thisTimeRestrictionList = thisTimeList.stream()
.filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站限行"))
.collect(Collectors.toList()); .collect(Collectors.toList());
} //分割站点名称, 然后分组
}*/ Map<String, Long> thisTimeRestrictionStation = thisTimeRestrictionList.stream().collect(Collectors.groupingBy(item -> getStationName(item.getTitle()),
Collectors.counting()));
//合并 站点名称
stationSet.addAll(thisTimeCloseStation.keySet());
stationSet.addAll(thisTimeRestrictionStation.keySet());
//上期数据
List<DcSdhsEvent> lastTimeList = dcSdhsEventMapper.selectStationAnalysis(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getLastTime());
//封闭 List<DcSdhsEvent> lastTimeCloseList = thisTimeList.stream()
List<DcSdhsEvent> closeList = eventList.stream()
.filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站封闭")) .filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站封闭"))
.collect(Collectors.toList()); .collect(Collectors.toList());
//分割站点名称, 然后分组 //分割站点名称, 然后分组
Map<String, Long> closeStation = closeList.stream().collect(Collectors.groupingBy(item -> getStationName(item.getTitle()), Map<String, Long> lastTimeCloseStation = lastTimeCloseList.stream().collect(Collectors.groupingBy(item -> getStationName(item.getTitle()),
Collectors.counting())); Collectors.counting()));
//限行 //限行
List<DcSdhsEvent> restrictionList = eventList.stream() List<DcSdhsEvent> lastTimeRestrictionList = lastTimeList.stream()
.filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站限行")) .filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站限行"))
.collect(Collectors.toList()); .collect(Collectors.toList());
//分割站点名称, 然后分组 //分割站点名称, 然后分组
Map<String, Long> restrictionStation = restrictionList.stream().collect(Collectors.groupingBy(item -> getStationName(item.getTitle()), Map<String, Long> lastTimeRestrictionStation = lastTimeRestrictionList.stream().collect(Collectors.groupingBy(item -> getStationName(item.getTitle()),
Collectors.counting())); Collectors.counting()));
//合并 站点名称 //合并 站点名称
Set<String> stationSet = new HashSet<>(); stationSet.addAll(lastTimeCloseStation.keySet());
stationSet.addAll(closeStation.keySet()); stationSet.addAll(lastTimeRestrictionStation.keySet());
stationSet.addAll(restrictionStation.keySet());
//收费站统
//收费站统计
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
for (String stationName : stationSet) { for (String stationName : stationSet) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
Long allNum = 0L; map.put("站点名称", stationName);
map.put("stationName", stationName); if (thisTimeCloseStation.containsKey(stationName)) {
if (closeStation.containsKey(stationName)) { map.put(dcSdhsEventQuery.getThisTime() + "封闭", thisTimeCloseStation.get(stationName));
map.put("close", closeStation.get(stationName)); } else {
allNum += closeStation.get(stationName); map.put(dcSdhsEventQuery.getThisTime() + "封闭", 0);
}
if (thisTimeRestrictionStation.containsKey(stationName)) {
map.put(dcSdhsEventQuery.getThisTime() + "限行", thisTimeRestrictionStation.get(stationName));
} else {
map.put(dcSdhsEventQuery.getThisTime() + "限行", 0);
}
if (lastTimeCloseStation.containsKey(stationName)) {
map.put(dcSdhsEventQuery.getLastTime() + "封闭", lastTimeCloseStation.get(stationName));
} else { } else {
map.put("close", 0); map.put(dcSdhsEventQuery.getLastTime() + "封闭", 0);
} }
if (restrictionStation.containsKey(stationName)) { if (lastTimeRestrictionStation.containsKey(stationName)) {
map.put("restriction", restrictionStation.get(stationName)); map.put(dcSdhsEventQuery.getLastTime() + "限行", lastTimeRestrictionStation.get(stationName));
allNum += restrictionStation.get(stationName);
} else { } else {
map.put("restriction", 0); map.put(dcSdhsEventQuery.getLastTime() + "限行", 0);
} }
map.put("allNum", allNum);
list.add(map); list.add(map);
} }
//根据总数排序 //根据总数排序
list = list.stream().sorted(Comparator.comparing(item -> Long.parseLong(((Map<String, Object>) item).get("allNum").toString())).reversed()).collect(Collectors.toList());
return AjaxResult.success(list); return AjaxResult.success(list);
} }
@ -1627,29 +1629,8 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
*/ */
@Override @Override
public AjaxResult selectAccidentType(DcSdhsEventQuery dcSdhsEventQuery) { public AjaxResult selectAccidentType(DcSdhsEventQuery dcSdhsEventQuery) {
List<DcSdhsEvent> eventList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT);
if (eventList == null || eventList.size() == 0) {
return AjaxResult.error("请先导入数据");
}
eventList = eventList.stream().filter(item -> item.getStartTime() != null List<Map<String,Object>> list = dcSdhsEventMapper.selectAccidentType(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime());
&& item.getStartTime().getTime() >= dcSdhsEventQuery.getStartTime().getTime()
&& item.getStartTime().getTime() <= dcSdhsEventQuery.getEndTime().getTime()
&& "交通事故".equals(item.getEventType()))
.collect(Collectors.toList());
List<Map<String, Object>> list = new ArrayList<>();
if (eventList.size() > 0) {
//根据详细类型 分组计数
Map<String, Long> subclass = eventList.stream().collect(Collectors.groupingBy(DcSdhsEvent::getEventSubclass, Collectors.counting()));
for (String key : subclass.keySet()) {
Map<String, Object> map = new HashMap<>();
map.put("subclassName", key);
map.put("num", subclass.get(key));
list.add(map);
}
list = list.stream().sorted(Comparator.comparing(item -> Long.valueOf(((Map<String, Object>) item).get("num").toString())).reversed()).collect(Collectors.toList());
}
return AjaxResult.success(list); return AjaxResult.success(list);
} }

62
zc-business/src/main/resources/mapper/business/DcSdhsEventMapper.xml

@ -109,6 +109,68 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
on t1.city = t3.city on t1.city = t3.city
</select> </select>
<select id="selectStationAnalysis" resultType="com.zc.business.domain.DcSdhsEvent">
SELECT * FROM `dc_sdhs_event`
<where>
event_type = '交通管制' and (event_subclass = '收费站封闭' or event_subclass = '收费站限行')
<if test="type != null and type == '0'.toString">
and DATE_FORMAT(start_time,'%Y') = #{time}
</if>
<if test="type != null and type == '1'.toString">
and DATE_FORMAT(start_time,'%Y-%m') = #{time}
</if>
<if test="type != null and type == '2'.toString">
and DATE_FORMAT(start_time,'%Y-%m-%d') = #{time}
</if>
</where>
</select>
<select id="selectAccidentType" resultType="java.util.Map">
SELECT t1.event_subclass,IFNULL(t2.num,0) as #{thisTime},IFNULL(t3.num,0) as #{lastTime}
from
(select '追尾' event_subclass
union all select '撞护栏' event_subclass
union all select '自燃' event_subclass
union all select '侧翻' event_subclass
union all select '货物洒落' event_subclass
union all select '撞障碍物' event_subclass) t1
LEFT JOIN
(SELECT
event_subclass,count(*) num
FROM `dc_sdhs_event`
<where>
event_type = '交通事故'
<if test="type != null and type == '0'.toString">
and DATE_FORMAT(start_time,'%Y') = #{thisTime}
</if>
<if test="type != null and type == '1'.toString">
and DATE_FORMAT(start_time,'%Y-%m') = #{thisTime}
</if>
<if test="type != null and type == '2'.toString">
and DATE_FORMAT(start_time,'%Y-%m-%d') = #{thisTime}
</if>
</where>
group by event_subclass) t2
on t1.event_subclass = t2.event_subclass
LEFT JOIN
(SELECT
event_subclass,count(*) num
FROM `dc_sdhs_event`
<where>
event_type = '交通事故'
<if test="type != null and type == '0'.toString">
and DATE_FORMAT(start_time,'%Y') = #{lastTime}
</if>
<if test="type != null and type == '1'.toString">
and DATE_FORMAT(start_time,'%Y-%m') = #{lastTime}
</if>
<if test="type != null and type == '2'.toString">
and DATE_FORMAT(start_time,'%Y-%m-%d') = #{lastTime}
</if>
</where>
group by event_subclass) t3
on t1.event_subclass = t3.event_subclass
</select>
<insert id="insertDcSdhsEvent" parameterType="DcSdhsEvent" useGeneratedKeys="true" keyProperty="id"> <insert id="insertDcSdhsEvent" parameterType="DcSdhsEvent" useGeneratedKeys="true" keyProperty="id">
insert into dc_sdhs_event insert into dc_sdhs_event

Loading…
Cancel
Save