From b86fce4a02340c050b134fb50278744cf9a59544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Thu, 13 Jun 2024 16:39:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A4=E9=80=9A=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DcTrafficStatisticsController.java | 20 +++- .../DcGantryMetricsStatisticsDataMapper.java | 1 + .../mapper/DcGantryStatisticsDataMapper.java | 2 + .../IDcGantryStatisticsDataService.java | 2 + .../service/impl/DcEventServiceImpl.java | 2 - .../impl/DcGantryStatisticsDataImpl.java | 7 ++ .../impl/DcTrafficStatisticsServiceImpl.java | 2 +- ...antryMetricsStatisticsDataServiceImpl.java | 26 +++-- .../DcGantryMetricsStatisticsDataMapper.xml | 49 +++++++- .../business/DcGantryStatisticsDataMapper.xml | 105 ++++++++++++++---- 10 files changed, 176 insertions(+), 40 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java index 355d382b..e610e068 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java +++ b/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> 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> 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> dcStatisticsData = dcGantryStatisticsDataService.sectionTrafficRanking(startDate,direction,periodType); + // 将查询结果封装为成功响应并返回 + return AjaxResult.success(dcStatisticsData); + } /** * sectionTrafficIndexAnalysis * @param startDate 时间 diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcGantryMetricsStatisticsDataMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcGantryMetricsStatisticsDataMapper.java index bcd75b82..b60b9613 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcGantryMetricsStatisticsDataMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcGantryMetricsStatisticsDataMapper.java @@ -33,5 +33,6 @@ public interface DcGantryMetricsStatisticsDataMapper extends BaseMapper gantryTrafficMetricsDataList); List> sectionTrafficIndexAnalysis(@Param("startDate") String startDate, @Param("direction") String direction,@Param("periodType") String periodType); + List> radarMapOfTrafficIndicators(@Param("startDate") String startDate, @Param("direction") String direction,@Param("periodType") String periodType); } diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java index bd2fde0b..8249e63b 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java @@ -57,5 +57,7 @@ public interface DcGantryStatisticsDataMapper extends BaseMapper> trafficFlowStatistics(@Param("startDate")String startDate, @Param("endDate")String endDate, @Param("direction")String direction, @Param("periodType")String periodType); + + List> sectionTrafficRanking(@Param("startDate")String startDate, @Param("direction")String direction, @Param("periodType")String periodType); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java b/zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java index 506bad3d..c096d622 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java @@ -54,4 +54,6 @@ public interface IDcGantryStatisticsDataService extends IService> trafficFlowStatistics(String startDate, String endDate, String direction, String periodType); + + List> sectionTrafficRanking(String startDate, String direction, String periodType); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java index 945858fb..ab5c4af3 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java @@ -392,8 +392,6 @@ public class DcEventServiceImpl extends ServiceImpl 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);//直接确认 diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java index 87e831f7..320b654a 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java +++ b/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> trafficFlowStatistics(String startDate, String endDate, String direction, String periodType) { + return dcGantryStatisticsDataMapper.trafficFlowStatistics(startDate,endDate,direction,periodType); } + @Override + public List> sectionTrafficRanking(String startDate, String direction, String periodType) { + return dcGantryStatisticsDataMapper.sectionTrafficRanking(startDate,direction,periodType); + } + public List> aggregateTrafficVolume(List> dataList) { // 创建一个Map,用于存储整点时间的流量数据 Map aggregatedData = new HashMap<>(); diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java index 5f9de246..08f3c11d 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java @@ -768,7 +768,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi List> mapList = new ArrayList<>(); for (int i = 1; i <= 14; i++) { Map map = new HashMap<>(); - map.put("name", descriptions.get(i)); + map.put("name", getDescriptionByIdentification(i)); map.put("totalFlow", flowCounts.get(i)); mapList.add(map); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/IDcGantryMetricsStatisticsDataServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/IDcGantryMetricsStatisticsDataServiceImpl.java index 229fe6ed..7c80c3f4 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/IDcGantryMetricsStatisticsDataServiceImpl.java +++ b/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) map).get("saturationRate").toString())).reversed()); - } - if (ranking == 2) { - mapList.sort(Comparator.comparingInt(map -> (Integer) ((Map) map).get("crowdingRate")).reversed()); - } - if (ranking == 3) { - mapList.sort(Comparator.comparingInt(map -> (Integer) ((Map) map).get("trafficCompositionRate")).reversed()); - } + if (ranking == 1) { + mapList.sort(Comparator.comparingDouble(map -> Double.parseDouble(((Map) map).get("saturationRate").toString())).reversed()); + } + if (ranking == 2) { + mapList.sort(Comparator.comparingInt(map -> (Integer) ((Map) map).get("crowdingRate")).reversed()); + } + if (ranking == 3) { + mapList.sort(Comparator.comparingInt(map -> (Integer) ((Map) 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 radarMapOfTrafficIndicators(String startDate, String direction, String periodType) { - List> mapOne = gantryMetricsStatisticsDataMapper.sectionTrafficIndexAnalysis(startDate, direction, periodType); + List> mapOne = gantryMetricsStatisticsDataMapper.radarMapOfTrafficIndicators(startDate, direction, periodType); + if (mapOne.isEmpty()) { + return null; + } // 计算crowdingRate和trafficCompositionRate的众数,以及saturationRate的平均值 int[] rates = {0, 0}; // 用于存储众数,第一个元素为crowdingRate众数,第二个为trafficCompositionRate众数 float sumSaturationRate = 0; diff --git a/zc-business/src/main/resources/mapper/business/DcGantryMetricsStatisticsDataMapper.xml b/zc-business/src/main/resources/mapper/business/DcGantryMetricsStatisticsDataMapper.xml index 76ea7a78..daf2f8d5 100644 --- a/zc-business/src/main/resources/mapper/business/DcGantryMetricsStatisticsDataMapper.xml +++ b/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 + + YEAR(dg.statistical_date) = #{startDate} + AND dg.period_type = 3 + + + DATE_FORMAT(dg.statistical_date, '%Y-%m') = #{startDate} + AND dg.period_type = 4 + + + DATE(dg.statistical_date) = DATE(#{startDate}) + AND dg.period_type = 5 + + + + DATE(dg.statistical_date) = DATE(#{startDate}) + AND dg.period_type = 5 + AND fa.direction = #{direction} - AND dg.period_type = #{periodType} - + diff --git a/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml b/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml index b5daa978..22921b1b 100644 --- a/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml @@ -6,6 +6,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + @@ -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 + + YEAR(dgsd.statistical_date) = #{startDate} + + + DATE_FORMAT(dgsd.statistical_date, '%Y-%m')= #{startDate} + + + DATE(dgsd.statistical_date) = DATE(#{startDate}) + AND dgsd.period_type =#{periodType} GROUP BY intervals.interval_name, @@ -251,7 +282,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" YEAR(dg.statistical_date) = #{startDate} - + DATE_FORMAT(dg.statistical_date, '%Y-%m') = #{startDate} @@ -302,8 +333,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND dgsd.period_type = #{periodType} ORDER BY - dgsd.statistical_date DESC; - + dgsd.statistical_date DESC +