Browse Source

交通流

develop
王兴琳 6 months ago
parent
commit
b86fce4a02
  1. 20
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  2. 1
      zc-business/src/main/java/com/zc/business/mapper/DcGantryMetricsStatisticsDataMapper.java
  3. 2
      zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java
  4. 2
      zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java
  5. 2
      zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java
  6. 7
      zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java
  7. 2
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java
  8. 26
      zc-business/src/main/java/com/zc/business/service/impl/IDcGantryMetricsStatisticsDataServiceImpl.java
  9. 49
      zc-business/src/main/resources/mapper/business/DcGantryMetricsStatisticsDataMapper.xml
  10. 105
      zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml

20
zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java

@ -1,7 +1,9 @@
package com.zc.business.controller;
import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.zc.business.domain.*;
import com.zc.business.request.DcTrafficMetricsDataRequest;
import com.zc.business.request.DcTrafficSectionDataRequest;
@ -16,6 +18,7 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* 交通数据统计
*
@ -24,7 +27,7 @@ import java.util.Map;
@Api(tags = "交通数据统计")
@RestController
@RequestMapping("/business/traffic-statistics")
public class DcTrafficStatisticsController {
public class DcTrafficStatisticsController extends BaseController {
@Autowired
private IDcTrafficSectionStatisticsService dcTrafficSectionStatisticsService;
@ -173,10 +176,11 @@ public class DcTrafficStatisticsController {
*/
@ApiOperation("交通流统计")
@GetMapping("/history/trafficFlowStatistics")
public AjaxResult trafficFlowStatistics(String startDate, String endDate,String direction,String periodType){
public TableDataInfo trafficFlowStatistics(String startDate, String endDate, String direction, String periodType){
startPage();
List<Map<String,String>> mapList = dcGantryStatisticsDataService.trafficFlowStatistics(startDate,endDate,direction,periodType);
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
return getDataTable(mapList);
}
@ -187,7 +191,7 @@ public class DcTrafficStatisticsController {
* @param direction 方向
* @param periodType 时间粒子
*/
@ApiOperation("全路段双向实时车流量")
@ApiOperation("全路段车流量状况分析")
@GetMapping("/history/realTimeTrafficFlow")
public AjaxResult realTimeTrafficFlow(String startDate, String direction,String periodType ){
List<Map<String,String>> mapList = dcGantryStatisticsDataService.realTimeTrafficFlow(startDate,direction,periodType);
@ -207,6 +211,14 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
@ApiOperation("断面车流量排名")
@GetMapping("/history/sectionTrafficRanking")
public AjaxResult sectionTrafficRanking(String startDate, String direction,String periodType ){
List<Map<String, String>> dcStatisticsData = dcGantryStatisticsDataService.sectionTrafficRanking(startDate,direction,periodType);
// 将查询结果封装为成功响应并返回
return AjaxResult.success(dcStatisticsData);
}
/**
* sectionTrafficIndexAnalysis
* @param startDate 时间

1
zc-business/src/main/java/com/zc/business/mapper/DcGantryMetricsStatisticsDataMapper.java

@ -33,5 +33,6 @@ public interface DcGantryMetricsStatisticsDataMapper extends BaseMapper<DcGantry
int insertOrUpdateBatch(List<DcGantryMetricsStatisticsData> gantryTrafficMetricsDataList);
List<Map<String, Object>> sectionTrafficIndexAnalysis(@Param("startDate") String startDate, @Param("direction") String direction,@Param("periodType") String periodType);
List<Map<String, Object>> radarMapOfTrafficIndicators(@Param("startDate") String startDate, @Param("direction") String direction,@Param("periodType") String periodType);
}

2
zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java

@ -57,5 +57,7 @@ public interface DcGantryStatisticsDataMapper extends BaseMapper<DcGantryStatist
* @return
*/
List<Map<String, String>> trafficFlowStatistics(@Param("startDate")String startDate, @Param("endDate")String endDate, @Param("direction")String direction, @Param("periodType")String periodType);
List<Map<String, String>> sectionTrafficRanking(@Param("startDate")String startDate, @Param("direction")String direction, @Param("periodType")String periodType);
}

2
zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java

@ -54,4 +54,6 @@ public interface IDcGantryStatisticsDataService extends IService<DcGantryStatist
List<Map<String, String>> trafficFlowStatistics(String startDate, String endDate, String direction, String periodType);
List<Map<String, String>> sectionTrafficRanking(String startDate, String direction, String periodType);
}

2
zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java

@ -392,8 +392,6 @@ public class DcEventServiceImpl extends ServiceImpl<DcEventMapper, DcEvent> impl
dcEvent.setOccurrenceTime(DateUtils.getNowDate());//默认发生时间
dcEventMapper.insertDcEvent(dcEvent);
//首页事件 交通管制事件 添加 状态默认为 1 处置中
updateDcEventState(map.get("facilityId" + i), 1);
int i6 = dcEventTrafficControlMapper.insertDcEventTrafficControl(dcEvent.getDcEventTrafficControl());
updateDcEventState(map.get("facilityId" + i),1);//直接确认

7
zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java

@ -14,6 +14,7 @@ import com.zc.business.statistics.cache.gantry.DailyTrafficGantryStatisticsCache
import com.zc.business.statistics.cache.gantry.MonthlyTrafficGantryStatisticsCache;
import com.zc.business.statistics.cache.gantry.QuarterlyTrafficGantryStatisticsCache;
import com.zc.business.statistics.cache.gantry.YearlyTrafficGantryStatisticsCache;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@ -219,9 +220,15 @@ public class DcGantryStatisticsDataImpl extends ServiceImpl<DcGantryStatisticsDa
@Override
public List<Map<String, String>> trafficFlowStatistics(String startDate, String endDate, String direction, String periodType) {
return dcGantryStatisticsDataMapper.trafficFlowStatistics(startDate,endDate,direction,periodType);
}
@Override
public List<Map<String, String>> sectionTrafficRanking(String startDate, String direction, String periodType) {
return dcGantryStatisticsDataMapper.sectionTrafficRanking(startDate,direction,periodType);
}
public List<Map<String, String>> aggregateTrafficVolume(List<Map<String, Object>> dataList) {
// 创建一个Map,用于存储整点时间的流量数据
Map<Integer, Integer> aggregatedData = new HashMap<>();

2
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

@ -768,7 +768,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
List<Map<String, Object>> mapList = new ArrayList<>();
for (int i = 1; i <= 14; i++) {
Map<String, Object> map = new HashMap<>();
map.put("name", descriptions.get(i));
map.put("name", getDescriptionByIdentification(i));
map.put("totalFlow", flowCounts.get(i));
mapList.add(map);
}

26
zc-business/src/main/java/com/zc/business/service/impl/IDcGantryMetricsStatisticsDataServiceImpl.java

@ -238,17 +238,17 @@ public class IDcGantryMetricsStatisticsDataServiceImpl
// System.out.println("平均饱和度:" + formattedAvgSaturationRate);
}
if (ranking !=null){
if (ranking != null) {
if (ranking == 1) {
mapList.sort(Comparator.comparingDouble(map -> Double.parseDouble(((Map<String, Object>) map).get("saturationRate").toString())).reversed());
}
if (ranking == 2) {
mapList.sort(Comparator.comparingInt(map -> (Integer) ((Map<String, Object>) map).get("crowdingRate")).reversed());
}
if (ranking == 3) {
mapList.sort(Comparator.comparingInt(map -> (Integer) ((Map<String, Object>) map).get("trafficCompositionRate")).reversed());
}
if (ranking == 1) {
mapList.sort(Comparator.comparingDouble(map -> Double.parseDouble(((Map<String, Object>) map).get("saturationRate").toString())).reversed());
}
if (ranking == 2) {
mapList.sort(Comparator.comparingInt(map -> (Integer) ((Map<String, Object>) map).get("crowdingRate")).reversed());
}
if (ranking == 3) {
mapList.sort(Comparator.comparingInt(map -> (Integer) ((Map<String, Object>) map).get("trafficCompositionRate")).reversed());
}
}
return mapList;
}
@ -331,6 +331,7 @@ public class IDcGantryMetricsStatisticsDataServiceImpl
/**
* 交通指标雷达图
*
* @param startDate
* @param direction
* @param periodType
@ -338,7 +339,10 @@ public class IDcGantryMetricsStatisticsDataServiceImpl
*/
@Override
public Map<String, Object> radarMapOfTrafficIndicators(String startDate, String direction, String periodType) {
List<Map<String, Object>> mapOne = gantryMetricsStatisticsDataMapper.sectionTrafficIndexAnalysis(startDate, direction, periodType);
List<Map<String, Object>> mapOne = gantryMetricsStatisticsDataMapper.radarMapOfTrafficIndicators(startDate, direction, periodType);
if (mapOne.isEmpty()) {
return null;
}
// 计算crowdingRate和trafficCompositionRate的众数,以及saturationRate的平均值
int[] rates = {0, 0}; // 用于存储众数,第一个元素为crowdingRate众数,第二个为trafficCompositionRate众数
float sumSaturationRate = 0;

49
zc-business/src/main/resources/mapper/business/DcGantryMetricsStatisticsDataMapper.xml

@ -96,11 +96,54 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
dg.saturation_rate
FROM dc_gantry_metrics_statistics_data as dg
LEFT JOIN dc_facility as fa on fa.facility_code = dg.gantry_code
WHERE DATE(dg.statistical_date) = #{startDate}
WHERE
<if test="periodType == 1">
YEAR(dg.statistical_date) = #{startDate}
AND dg.period_type = 3
</if>
<if test="periodType == 3">
DATE_FORMAT(dg.statistical_date, '%Y-%m') = #{startDate}
AND dg.period_type = 4
</if>
<if test="periodType == 4">
DATE(dg.statistical_date) = DATE(#{startDate})
AND dg.period_type = 5
</if>
<if test="periodType == 5">
DATE(dg.statistical_date) = DATE(#{startDate})
AND dg.period_type = 5
</if>
AND fa.direction = #{direction}
AND dg.period_type = #{periodType}
</select>
<select id="radarMapOfTrafficIndicators" resultMap="countMap" resultType="map" >
SELECT fa.facility_name,
fa.stake_mark,
fa.direction,
dg.statistical_date,
dg.gantry_code,
dg.id,
dg.traffic_composition_rate,
dg.crowding_rate,
dg.saturation_rate
FROM dc_gantry_metrics_statistics_data as dg
LEFT JOIN dc_facility as fa on fa.facility_code = dg.gantry_code
WHERE
<if test="periodType == 1">
YEAR(dg.statistical_date) = #{startDate}
</if>
<if test="periodType == 3">
DATE_FORMAT(dg.statistical_date, '%Y-%m') = #{startDate}
</if>
<if test="periodType == 4">
DATE(dg.statistical_date) = DATE(#{startDate})
</if>
<if test="periodType == 5">
DATE(dg.statistical_date) = DATE(#{startDate})
</if>
AND fa.direction = #{direction}
AND dg.period_type = #{periodType}
</select>
</mapper>

105
zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml

@ -6,6 +6,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="map" id="countMap">
<result property="volume" column="total_traffic_volume"/>
<result property="name" column="interval_name"/>
<result property="totalPassengerFlow" column="total_passenger_flow"/>
<result property="typeSpecialVehicleFlow" column="type_special_vehicle_flow"/>
<result property="typeTruckFlow" column="type_truck_flow"/>
</resultMap>
<resultMap type="map" id="trafficPeriodAnalysisMap">
<result property="gantryCode" column="gantry_code"/>
@ -193,24 +196,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
intervals.interval_name,
intervals.stake_make,
intervals.end_make,
COALESCE(SUM(dgsd.traffic_volume), 0) AS total_traffic_volume
COALESCE(SUM(dgsd.traffic_volume), 0) AS total_traffic_volume,
COALESCE(SUM(dgsd.type1_passenger_flow), 0) +
COALESCE(SUM(dgsd.type2_passenger_flow), 0) +
COALESCE(SUM(dgsd.type3_passenger_flow), 0) +
COALESCE(SUM(dgsd.type4_passenger_flow), 0) AS total_passenger_flow,
COALESCE(SUM(dgsd.type1_truck_flow ), 0) +
COALESCE(SUM(dgsd.type2_truck_flow ), 0) +
COALESCE(SUM(dgsd.type3_truck_flow ), 0) +
COALESCE(SUM(dgsd.type4_truck_flow ), 0) +
COALESCE(SUM(dgsd.type5_truck_flow ), 0) +
COALESCE(SUM(dgsd.type6_truck_flow ), 0) AS type_truck_flow,
COALESCE(SUM(dgsd.type1_special_vehicle_flow ), 0) +
COALESCE(SUM(dgsd.type2_special_vehicle_flow ), 0) +
COALESCE(SUM(dgsd.type3_special_vehicle_flow ), 0) +
COALESCE(SUM(dgsd.type4_special_vehicle_flow ), 0) +
COALESCE(SUM(dgsd.type5_special_vehicle_flow ), 0) +
COALESCE(SUM(dgsd.type6_special_vehicle_flow ), 0) AS type_special_vehicle_flow
FROM
(
SELECT 'K054+394' AS stake_make, 'K059+289' AS end_make, '殷家林枢纽-大学城立交' AS interval_name UNION ALL
SELECT 'K059+289', 'K072+847', '大学城立交-长清立交' UNION ALL
SELECT 'K072+847', 'K083+835', '长清立交-松竹枢纽' UNION ALL
SELECT 'K083+835', 'K086+499', '松竹枢纽-孝里立交' UNION ALL
SELECT 'K086+499', 'K099+750', '孝里立交-平阴北立交' UNION ALL
SELECT 'K099+750', 'K105+904', '平阴北立交-平阴立交' UNION ALL
SELECT 'K105+904', 'K117+878', '平阴立交-孔村枢纽' UNION ALL
SELECT 'K117+878', 'K126+233', '孔村枢纽-平阴南立交' UNION ALL
SELECT 'K126+233', 'K145+933', '平阴南立交-东平立交' UNION ALL
SELECT 'K145+933', 'K155+652', '东平立交-东平湖枢纽' UNION ALL
SELECT 'K155+652', 'K173+950', '东平湖枢纽-梁山东立交' UNION ALL
SELECT 'K173+950', 'K179+396', '梁山东立交-梁山立交' UNION ALL
SELECT 'K179+396', 'K190+495', '梁山立交-嘉祥西立交' UNION ALL
SELECT 'K054+394' AS stake_make, 'K059+289' AS end_make, '殷家林枢纽' AS interval_name UNION ALL
SELECT 'K059+289', 'K072+847', '大学城立交' UNION ALL
SELECT 'K072+847', 'K083+835', '长清立交' UNION ALL
SELECT 'K083+835', 'K086+499', '松竹枢纽' UNION ALL
SELECT 'K086+499', 'K099+750', '孝里立交' UNION ALL
SELECT 'K099+750', 'K105+904', '平阴北立交' UNION ALL
SELECT 'K105+904', 'K117+878', '平阴立交' UNION ALL
SELECT 'K117+878', 'K126+233', '孔村枢纽' UNION ALL
SELECT 'K126+233', 'K145+933', '平阴南立交-' UNION ALL
SELECT 'K145+933', 'K155+652', '东平立交' UNION ALL
SELECT 'K155+652', 'K173+950', '东平湖枢纽' UNION ALL
SELECT 'K173+950', 'K179+396', '梁山东立交' UNION ALL
SELECT 'K179+396', 'K190+495', '梁山立交' UNION ALL
SELECT 'K190+495', 'K202+979', '嘉祥西立交'
) AS intervals
)AS intervals
LEFT JOIN (
SELECT
facility_code,
@ -223,7 +245,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
direction = #{direction}
) AS ps ON ps.stake_mark BETWEEN CONCAT(intervals.stake_make, '+0') AND CONCAT(intervals.end_make, '+0')
LEFT JOIN dc_gantry_statistics_data dgsd ON ps.facility_code = dgsd.gantry_code
AND dgsd.statistical_date =#{startDate}
AND
<if test="periodType == 1">
YEAR(dgsd.statistical_date) = #{startDate}
</if>
<if test="periodType == 3">
DATE_FORMAT(dgsd.statistical_date, '%Y-%m')= #{startDate}
</if>
<if test="periodType == 4">
DATE(dgsd.statistical_date) = DATE(#{startDate})
</if>
AND dgsd.period_type =#{periodType}
GROUP BY
intervals.interval_name,
@ -251,7 +282,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="periodType == 1">
YEAR(dg.statistical_date) = #{startDate}
</if>
<if test="periodType == 2">
<if test="periodType == 3">
DATE_FORMAT(dg.statistical_date, '%Y-%m') = #{startDate}
</if>
<if test="periodType == 4">
@ -302,8 +333,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND dgsd.period_type = #{periodType}
</if>
ORDER BY
dgsd.statistical_date DESC;
dgsd.statistical_date DESC
</select>
<select id="sectionTrafficRanking" resultMap="trafficPeriodAnalysisMap" resultType="map" >
SELECT
fa.facility_code AS gantry_code,
COALESCE(SUM(dg.traffic_volume), 0) AS traffic_volume,
fa.facility_name,
dg.period_type,
MAX(dg.statistical_date) AS statistical_date
FROM
dc_facility AS fa
LEFT JOIN
dc_gantry_statistics_data AS dg
ON
fa.facility_code = dg.gantry_code
AND
<if test="periodType == 1">
YEAR(dg.statistical_date) = #{startDate}
</if>
<if test="periodType == 3">
DATE_FORMAT(dg.statistical_date, '%Y-%m') = #{startDate}
</if>
<if test="periodType == 4 or periodType == 5">
DATE(dg.statistical_date) = DATE(#{startDate})
</if>
AND
dg.period_type = #{periodType}
WHERE
fa.direction = #{direction}
and fa.facility_type=10
GROUP BY
fa.facility_code,
fa.facility_name,
dg.period_type
ORDER BY
traffic_volume DESC;
</select>
</mapper>

Loading…
Cancel
Save