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);
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
public AjaxResult selectStationAnalysis(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
&& 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("双向"))
//本期数据
List<DcSdhsEvent> thisTimeList = dcSdhsEventMapper.selectStationAnalysis(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime());
Set<String> stationSet = new HashSet<>();
List<DcSdhsEvent> thisTimeCloseList = thisTimeList.stream()
.filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站封闭"))
.collect(Collectors.toList());
} else if (dcSdhsEventQuery.getDirection().equals("3")){
//济南方向
eventList = eventList.stream()
.filter(item -> item.getDirection().equals("济南方向") || item.getDirection().equals("双向"))
//分割站点名称, 然后分组
Map<String, Long> thisTimeCloseStation = thisTimeCloseList.stream().collect(Collectors.groupingBy(item -> getStationName(item.getTitle()),
Collectors.counting()));
//限行
List<DcSdhsEvent> thisTimeRestrictionList = thisTimeList.stream()
.filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站限行"))
.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> closeList = eventList.stream()
List<DcSdhsEvent> lastTimeCloseList = thisTimeList.stream()
.filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站封闭"))
.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()));
//限行
List<DcSdhsEvent> restrictionList = eventList.stream()
List<DcSdhsEvent> lastTimeRestrictionList = lastTimeList.stream()
.filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站限行"))
.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()));
//合并 站点名称
Set<String> stationSet = new HashSet<>();
stationSet.addAll(closeStation.keySet());
stationSet.addAll(restrictionStation.keySet());
stationSet.addAll(lastTimeCloseStation.keySet());
stationSet.addAll(lastTimeRestrictionStation.keySet());
//收费站统
//收费站统计
List<Map<String, Object>> list = new ArrayList<>();
for (String stationName : stationSet) {
Map<String, Object> map = new HashMap<>();
Long allNum = 0L;
map.put("stationName", stationName);
if (closeStation.containsKey(stationName)) {
map.put("close", closeStation.get(stationName));
allNum += closeStation.get(stationName);
map.put("站点名称", stationName);
if (thisTimeCloseStation.containsKey(stationName)) {
map.put(dcSdhsEventQuery.getThisTime() + "封闭", thisTimeCloseStation.get(stationName));
} else {
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 {
map.put("close", 0);
map.put(dcSdhsEventQuery.getLastTime() + "封闭", 0);
}
if (restrictionStation.containsKey(stationName)) {
map.put("restriction", restrictionStation.get(stationName));
allNum += restrictionStation.get(stationName);
if (lastTimeRestrictionStation.containsKey(stationName)) {
map.put(dcSdhsEventQuery.getLastTime() + "限行", lastTimeRestrictionStation.get(stationName));
} else {
map.put("restriction", 0);
map.put(dcSdhsEventQuery.getLastTime() + "限行", 0);
}
map.put("allNum", allNum);
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);
}
@ -1627,29 +1629,8 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
*/
@Override
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
&& 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());
}
List<Map<String,Object>> list = dcSdhsEventMapper.selectAccidentType(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime());
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
</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 into dc_sdhs_event

Loading…
Cancel
Save