From e19d696d2e9cc405c73f469f916b3c3b6f76e77f Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Tue, 16 Jan 2024 17:21:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=AE=A1=E6=8E=A7=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DcTrafficIncidentsController.java | 95 +++++- .../mapper/DcTrafficIncidentsMapper.java | 68 +++++ .../service/IDcTrafficIncidentsService.java | 84 ++++- .../impl/DcTrafficIncidentsServiceImpl.java | 287 +++++++++++++++++- .../business/DcTrafficIncidentsMapper.xml | 192 +++++++++++- 5 files changed, 690 insertions(+), 36 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTrafficIncidentsController.java b/zc-business/src/main/java/com/zc/business/controller/DcTrafficIncidentsController.java index a044397b..32a8c616 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTrafficIncidentsController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcTrafficIncidentsController.java @@ -6,10 +6,9 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; /** * @Description 交通事件统计 @@ -82,16 +81,100 @@ public class DcTrafficIncidentsController { } /** - * @Description 路网管控-事件管控分析-统计各类型的交通事件数量 + * @Description 路网管控-事件管控分析-事件类型分析占比 * * @author liuwenge * @date 2024/1/13 15:07 * @param * @return com.ruoyi.common.core.domain.AjaxResult */ - @ApiOperation("统计各类型的交通事件数量") + @ApiOperation("事件类型分析占比") @GetMapping("/getAllEventNum") public AjaxResult getAllEventNum(){ return trafficIncidentsService.getAllEventNum(); } + + /** + * @Description 路网管控-事件管控分析-事件源分析占比 + * + * @author liuwenge + * @date 2024/1/13 15:07 + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @ApiOperation("事件源分析占比") + @GetMapping("/getEventSourceRatio") + public AjaxResult getEventSourceRatio(){ + return trafficIncidentsService.getEventSourceRatio(); + } + + /** + * @Description 路网管控-事件管控分析-今日事件趋势 + * + * @author liuwenge + * @date 2024/1/15 14:30 + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @ApiOperation("今日事件趋势") + @GetMapping("/getEventTrend") + public AjaxResult getEventTrend(){ + return trafficIncidentsService.getEventTrend(); + } + + /** + * @Description 路网管控-事件管控分析-事故车型分析 + * + * @author liuwenge + * @date 2024/1/15 15:38 + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @ApiOperation("事故车型分析") + @GetMapping("/getAccidentVehicleAnalysis") + public AjaxResult getAccidentVehicleAnalysis(){ + return trafficIncidentsService.getAccidentVehicleAnalysis(); + } + + /** + * @Description 路网管控-事件管控分析-收费站统计分析table + * + * @author liuwenge + * @date 2024/1/15 17:31 + * @param params + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @ApiOperation("收费站统计分析table") + @PostMapping("/selectTollStationAnalysis") + public AjaxResult selectTollStationAnalysis(@RequestBody Map params){ + return trafficIncidentsService.selectTollStationAnalysis(params); + } + + /** + * @Description 路网管控-事件管控分析-收费站统计分析echarts(当月) + * + * @author liuwenge + * @date 2024/1/16 11:09 + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @ApiOperation("收费站统计分析echarts(当月)") + @GetMapping("/getTollStationAnalysis") + public AjaxResult getTollStationAnalysis(){ + return trafficIncidentsService.getTollStationAnalysis(); + } + + /** + * @Description 路网管控-事件管控分析-事故多发路段分析 + * + * @author liuwenge + * @date 2024/1/16 15:52 + * @param params + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @ApiOperation("收费站统计分析table") + @PostMapping("/selectRoadSectionAnalysis") + public AjaxResult selectRoadSectionAnalysis(@RequestBody Map params){ + return trafficIncidentsService.selectRoadSectionAnalysis(params); + } } diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcTrafficIncidentsMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcTrafficIncidentsMapper.java index 4cb7bbcd..e5273281 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcTrafficIncidentsMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcTrafficIncidentsMapper.java @@ -121,5 +121,73 @@ public interface DcTrafficIncidentsMapper { */ List> selectStatusCountByEventType(String eventType); + /** + * @Description 路网管控-事件管控分析-事件类型分析占比 + * + * @author liuwenge + * @date 2024/1/13 17:42 + * @param + * @return java.util.List> + */ + List> getEventTypeRatio(); + + /** + * @Description 路网管控-事件管控分析-事件源分析占比 + * + * @author liuwenge + * @date 2024/1/13 17:42 + * @param + * @return java.util.List> + */ + List> getEventSourceRatio(); + + /** + * @Description 当日交通事件趋势 + * + * @author liuwenge + * @date 2024/1/15 14:33 + * @param + * @return java.util.List> + */ + List> getTrafficTrend(); + + /** + * @Description 当日感知事件趋势 + * + * @author liuwenge + * @date 2024/1/15 14:33 + * @param + * @return java.util.List> + */ + List> getPerceptionTrend(); + + /** + * @Description 事故车型分析 + * + * @author liuwenge + * @date 2024/1/15 15:41 + * @param + * @return java.util.List> + */ + List> getAccidentVehicleAnalysis(); + /** + * @Description 收费站统计分析table + * + * @author liuwenge + * @date 2024/1/16 14:18 + * @param params + * @return java.util.List> + */ + List> selectTollStationAnalysis(Map params); + + /** + * @Description 收费站统计分析echarts + * + * @author liuwenge + * @date 2024/1/16 14:18 + * @param + * @return java.util.List> + */ + List> getTollStationAnalysis(); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcTrafficIncidentsService.java b/zc-business/src/main/java/com/zc/business/service/IDcTrafficIncidentsService.java index bdc46528..be68a5ee 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcTrafficIncidentsService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcTrafficIncidentsService.java @@ -1,6 +1,11 @@ package com.zc.business.service; import com.ruoyi.common.core.domain.AjaxResult; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.Map; /** * @Description 交通事件统计Service接口 @@ -11,52 +16,103 @@ import com.ruoyi.common.core.domain.AjaxResult; public interface IDcTrafficIncidentsService { /** + * @param + * @return com.ruoyi.common.core.domain.AjaxResult * @Description 首页-重点数据 - * * @author liuwenge * @date 2024/1/13 10:09 - * @param - * @return com.ruoyi.common.core.domain.AjaxResult */ AjaxResult getKeyData(); /** + * @param eventType + * @return com.ruoyi.common.core.domain.AjaxResult * @Description 首页-事件专题-根据事件类型获取事件列表 - * * @author liuwenge * @date 2024/1/13 14:26 - * @param eventType - * @return com.ruoyi.common.core.domain.AjaxResult */ AjaxResult getEventListByType(String eventType); /** + * @param eventId + * @return com.ruoyi.common.core.domain.AjaxResult * @Description 首页-事件专题-根据事件id获取详情 - * * @author liuwenge * @date 2024/1/13 14:43 - * @param eventId - * @return com.ruoyi.common.core.domain.AjaxResult */ AjaxResult getEventInfo(String eventId); /** + * @param + * @return com.ruoyi.common.core.domain.AjaxResult * @Description 首页-状况统计-获取日、周、月、年的交通事件数量 - * * @author liuwenge * @date 2024/1/13 15:08 + */ + AjaxResult getTrafficIncidentsNum(); + + /** * @param * @return com.ruoyi.common.core.domain.AjaxResult + * @Description 路网管控-事件管控分析-事件类型分析占比 + * @author liuwenge + * @date 2024/1/13 15:46 */ - AjaxResult getTrafficIncidentsNum(); + AjaxResult getAllEventNum(); + + /** + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + * @Description 路网管控-事件管控分析-事件源分析占比 + * @author liuwenge + * @date 2024/1/13 17:37 + */ + AjaxResult getEventSourceRatio(); /** - * @Description 路网管控-事件管控分析-统计各类型的交通事件数量 + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + * @Description 路网管控-事件管控分析-今日事件趋势 + * @author liuwenge + * @date 2024/1/15 14:30 + */ + AjaxResult getEventTrend(); + + /** + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + * @Description 路网管控-事件管控分析-事故车型分析 + * @author liuwenge + * @date 2024/1/15 15:38 + */ + AjaxResult getAccidentVehicleAnalysis(); + + /** + * @param params + * @return com.ruoyi.common.core.domain.AjaxResult + * @Description 路网管控-事件管控分析-收费站统计分析table + * @author liuwenge + * @date 2024/1/15 17:31 + */ + AjaxResult selectTollStationAnalysis(Map params); + + /** + * @Description 路网管控-事件管控分析-收费站统计分析echarts(当月) * * @author liuwenge - * @date 2024/1/13 15:46 + * @date 2024/1/16 11:11 * @param * @return com.ruoyi.common.core.domain.AjaxResult */ - AjaxResult getAllEventNum(); + AjaxResult getTollStationAnalysis(); + + /** + * @Description 路网管控-事件管控分析-事故多发路段分析 + * + * @author liuwenge + * @date 2024/1/16 15:52 + * @param params + * @return com.ruoyi.common.core.domain.AjaxResult + */ + AjaxResult selectRoadSectionAnalysis(Map params); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficIncidentsServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficIncidentsServiceImpl.java index 30b0de4c..b7013880 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficIncidentsServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficIncidentsServiceImpl.java @@ -8,9 +8,12 @@ import com.zc.business.service.IDcTrafficIncidentsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; +import java.text.SimpleDateFormat; +import java.time.Year; +import java.util.*; /** * @Description 交通事件统计Service业务层处理 @@ -101,7 +104,7 @@ public class DcTrafficIncidentsServiceImpl implements IDcTrafficIncidentsService } /** - * @Description 路网管控-事件管控分析-统计各类型的交通事件数量 + * @Description 路网管控-事件管控分析-事件类型分析占比 * * @author liuwenge * @date 2024/1/13 15:46 @@ -110,7 +113,7 @@ public class DcTrafficIncidentsServiceImpl implements IDcTrafficIncidentsService */ @Override public AjaxResult getAllEventNum(){ - //事件类型 + /*//事件类型 List> eventTypeList = trafficIncidentsMapper.selectEventTypeList(); for (Map eventType : eventTypeList) { @@ -135,19 +138,289 @@ public class DcTrafficIncidentsServiceImpl implements IDcTrafficIncidentsService total += Integer.parseInt(eventTypeData.get("num").toString()); } eventType.put("total",total); - } else { + } + + if (!eventType.containsKey("unconfirmed")){ //待确认 eventType.put("unconfirmed", "0"); + } else if (!eventType.containsKey("processing")){ //处理中 eventType.put("processing", "0"); + } else if (!eventType.containsKey("finished")){ //已完成 eventType.put("finished", "0"); + } else if (!eventType.containsKey("total")){ //总数 eventType.put("total", "0"); } + }*/ + + List> eventTypeRatio = trafficIncidentsMapper.getEventTypeRatio(); + + return AjaxResult.success(eventTypeRatio); + } + + /** + * @Description 路网管控-事件管控分析-事件源分析占比 + * + * @author liuwenge + * @date 2024/1/13 17:38 + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @Override + public AjaxResult getEventSourceRatio(){ + List> eventSourceRatio = trafficIncidentsMapper.getEventSourceRatio(); + return AjaxResult.success(eventSourceRatio); + } + + /** + * @Description 路网管控-事件管控分析-今日事件趋势 + * + * @author liuwenge + * @date 2024/1/15 14:31 + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @Override + public AjaxResult getEventTrend(){ + Map result = new HashMap<>(); + //交通事件趋势 + List> traffic = trafficIncidentsMapper.getTrafficTrend(); + //感知世间趋势 + List> perception = trafficIncidentsMapper.getPerceptionTrend(); + result.put("traffic",traffic); + result.put("perception",perception); + return AjaxResult.success(result); + } + + /** + * @Description 路网管控-事件管控分析-事故车型分析 + * + * @author liuwenge + * @date 2024/1/15 15:38 + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @Override + public AjaxResult getAccidentVehicleAnalysis(){ + + List> list = trafficIncidentsMapper.getAccidentVehicleAnalysis(); + + Map smallCar = new HashMap<>(); + smallCar.put("type","smallCar"); + smallCar.put("num",0); + smallCar.put("allTime",0); + Map trucks = new HashMap<>(); + trucks.put("type","trucks"); + trucks.put("num",0); + trucks.put("allTime",0); + Map buses = new HashMap<>(); + buses.put("type","buses"); + buses.put("num",0); + buses.put("allTime",0); + Map tankers = new HashMap<>(); + tankers.put("type","tankers"); + tankers.put("num",0); + tankers.put("allTime",0); + + //计算各车型总处理时长 + for (Map data : list) { + if (data.get("smallCar") > 0){ + smallCar.put("num",Integer.parseInt(smallCar.get("num").toString()) + 1); + smallCar.put("allTime",Long.parseLong(smallCar.get("allTime").toString()) + data.get("minuteTime")); + } + if (data.get("trucks") > 0){ + trucks.put("num",Integer.parseInt(trucks.get("num").toString()) + 1); + trucks.put("allTime",Long.parseLong(trucks.get("allTime").toString()) + data.get("minuteTime")); + } + if (data.get("buses") > 0){ + buses.put("num",Integer.parseInt(buses.get("num").toString()) + 1); + buses.put("allTime",Long.parseLong(buses.get("allTime").toString()) + data.get("minuteTime")); + } + if (data.get("tankers") > 0){ + tankers.put("num",Integer.parseInt(tankers.get("num").toString()) + 1); + tankers.put("allTime",Long.parseLong(tankers.get("allTime").toString()) + data.get("minuteTime")); + } + } + + List> result = new ArrayList<>(); + + //小型车平均时长 + if (Long.parseLong(smallCar.get("num").toString()) > 0){ + smallCar.put("avgTime",Long.parseLong(smallCar.get("allTime").toString()) / Long.parseLong(smallCar.get("num").toString())); + } else { + smallCar.put("avgTime",0); + } + result.add(smallCar); + + //货车平均时长 + if (Long.parseLong(trucks.get("num").toString()) > 0){ + trucks.put("avgTime",Long.parseLong(trucks.get("allTime").toString()) / Long.parseLong(trucks.get("num").toString())); + } else { + trucks.put("avgTime",0); + } + result.add(trucks); + + //客车平均时长 + if (Long.parseLong(buses.get("num").toString()) > 0){ + buses.put("avgTime",Long.parseLong(buses.get("allTime").toString()) / Long.parseLong(buses.get("num").toString())); + } else { + buses.put("avgTime",0); } + result.add(buses); + + //罐车平均时长 + if (Long.parseLong(tankers.get("num").toString()) > 0){ + tankers.put("avgTime",Long.parseLong(tankers.get("allTime").toString()) / Long.parseLong(tankers.get("num").toString())); + } else { + tankers.put("avgTime",0); + } + result.add(tankers); + + return AjaxResult.success(result); + } + + + + /** + * @Description 路网管控-事件管控分析-收费站统计分析table + * @param params + * @return com.ruoyi.common.core.domain.AjaxResult + * @author liuwenge + * @date 2024/1/15 17:31 + */ + @Override + public AjaxResult selectTollStationAnalysis(Map params){ + + //目标时段 + List> list = trafficIncidentsMapper.selectTollStationAnalysis(params); + BigDecimal allNum = BigDecimal.ZERO; + BigDecimal allTime = BigDecimal.ZERO; + for (Map data : list) { + allNum = allNum.add(new BigDecimal(data.get("num").toString())); + allTime = allTime.add(new BigDecimal(data.get("minuteTime").toString())); + } + for (Map data : list) { + //计算站次占比 + if (allNum.compareTo(BigDecimal.ZERO) > 0){ + BigDecimal numRatio = new BigDecimal(data.get("num").toString()).multiply(new BigDecimal("100")).divide(allNum,2, RoundingMode.HALF_UP); + data.put("numRatio",numRatio); + } else { + data.put("numRatio",0); + } + + //计算时长占比 + if (allTime.compareTo(BigDecimal.ZERO) > 0){ + BigDecimal timeRatio = new BigDecimal(data.get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(allTime,2, RoundingMode.HALF_UP); + data.put("timeRatio",timeRatio); + } else { + data.put("timeRatio",0); + } + } + + //去年同期 + try { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar cal = Calendar.getInstance(); + + Date startDate = dateFormat.parse(params.get("startTime").toString()); + cal.setTime(startDate); + cal.add(Calendar.YEAR,-1); + String lastStartTime = dateFormat.format(cal.getTime()); + + Date endDate = dateFormat.parse(params.get("endTime").toString()); + cal.setTime(endDate); + cal.add(Calendar.YEAR,-1); + String lastEndTime = dateFormat.format(cal.getTime()); + + params.put("startTime",lastStartTime); + params.put("endTime",lastEndTime); + + List> lastList = trafficIncidentsMapper.selectTollStationAnalysis(params); + BigDecimal lastAllNum = BigDecimal.ZERO; + BigDecimal lastAllTime = BigDecimal.ZERO; + + for (int i = 0; i < lastList.size(); i++) { + //去年同期站次 + lastAllNum = lastAllNum.add(new BigDecimal(lastList.get(i).get("num").toString())); + list.get(i).put("lastYearNum",lastList.get(i).get("num").toString()); + + //去年同期时长 + lastAllTime = lastAllTime.add(new BigDecimal(lastList.get(i).get("minuteTime").toString())); + list.get(i).put("lastYearTime",lastList.get(i).get("minuteTime").toString()); + } + + for (int i = 0; i < lastList.size(); i++) { + //去年同期站次占比 + if (lastAllNum.compareTo(BigDecimal.ZERO) > 0){ + BigDecimal numRatio = new BigDecimal(lastList.get(i).get("num").toString()).multiply(new BigDecimal("100")).divide(lastAllNum,2, RoundingMode.HALF_UP); + list.get(i).put("lastYearNumRatio",numRatio); + } else { + list.get(i).put("lastYearNumRatio",0); + } + ////去年同期时长占比 + if (lastAllTime.compareTo(BigDecimal.ZERO) > 0) { + BigDecimal timeRatio = new BigDecimal(lastList.get(i).get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(lastAllTime, 2, RoundingMode.HALF_UP); + list.get(i).put("lastYearTimeRatio", timeRatio); + } else { + list.get(i).put("lastYearTimeRatio", 0); + } + } + + //同比 + for (Map map : list) { + //站次同比 + if (new BigDecimal(map.get("lastYearNum").toString()).compareTo(BigDecimal.ZERO) > 0){ + BigDecimal yearNumRatio = new BigDecimal(map.get("num").toString()).multiply(new BigDecimal("100")).divide(new BigDecimal(map.get("lastYearNum").toString()),2, RoundingMode.HALF_UP); + map.put("yearNumRatio",yearNumRatio); + } else { + map.put("ratio",0); + } + + //时长同比 + if (new BigDecimal(map.get("lastYearTime").toString()).compareTo(BigDecimal.ZERO) > 0){ + BigDecimal yearTimeRatio = new BigDecimal(map.get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(new BigDecimal(map.get("lastYearTime").toString()),2, RoundingMode.HALF_UP); + map.put("yearTimeRatio",yearTimeRatio); + } else { + map.put("yearTimeRatio",0); + } + } + + } catch (Exception e){ + e.printStackTrace(); + } + + return AjaxResult.success(list); + + } + + /** + * @Description 路网管控-事件管控分析-收费站统计分析echarts(当月) + * + * @author liuwenge + * @date 2024/1/16 11:11 + * @param + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @Override + public AjaxResult getTollStationAnalysis(){ + List> list = trafficIncidentsMapper.getTollStationAnalysis(); + return AjaxResult.success(list); + } + + /** + * @Description 路网管控-事件管控分析-事故多发路段分析 + * + * @author liuwenge + * @date 2024/1/16 15:52 + * @param params + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @Override + public AjaxResult selectRoadSectionAnalysis(Map params){ - return AjaxResult.success(eventTypeList); + return AjaxResult.success(); } } diff --git a/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml b/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml index 904cd063..3e2083fd 100644 --- a/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml @@ -1,19 +1,19 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> select count(*) from dc_event - where date_format(create_time,'%y%m%d') = date_format(now(),'%y%m%d') + where date_format(start_time,'%y%m%d') = date_format(now(),'%y%m%d') select event_state eventState,count(*) num from dc_event - where event_type = #{eventType} and date_format(create_time,'%y%m%d') = date_format(now(),'%y%m%d') + where event_type = #{eventType} and date_format(start_time,'%y%m%d') = date_format(now(),'%y%m%d') group by event_state + + + + + + + + + + + + + + \ No newline at end of file