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 1/6] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=AE=A1=E6=8E=A7?= =?UTF-8?q?=E5=88=86=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 From 5e1eba3360d0c8c90a3446d1e41b3977018389c4 Mon Sep 17 00:00:00 2001 From: "Mr.Wang" Date: Wed, 17 Jan 2024 10:23:47 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E7=9B=91=E6=8E=A7=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E3=80=81=E6=91=84=E5=83=8F=E5=A4=B4=E6=8E=A7=E5=88=B6=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/controller/VideoController.java | 305 ++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 zc-business/src/main/java/com/zc/business/controller/VideoController.java diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java new file mode 100644 index 00000000..17bed0e4 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -0,0 +1,305 @@ +package com.zc.business.controller; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.zc.common.core.httpclient.OkHttp; +import com.zc.common.core.httpclient.exception.HttpException; +import com.zc.common.core.httpclient.request.RequestParams; +import okhttp3.Response; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static com.ruoyi.common.constant.Constants.HTTP; + + +/** + * License + * + * @author Athena-xiepufeng + */ +@RestController +@RequestMapping("/video") +public class VideoController extends BaseController { + + private static final String USERNAME = "jhgskj"; + private static final String PASSWORD = "jhgskj@2023"; + private static String TOKEN; + + private final static String URL = HTTP + "10.166.147.60:9021"; + + public static final Integer UNAUTHORIZED = 401; + + + public static final Integer ERROR = 500; + + /** + * 查询附近相机 + */ + @GetMapping(value = "/nearCamListDistance") + public JSONObject nearCamListDistance(String devLat, String devLon) throws HttpException, IOException { + + JSONObject jsonResult = null; + + // 1000 米 + String distance = "1000"; + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("devLat", devLat); + requestParams.put("devLon", devLon); + requestParams.put("distance", distance); + + Map header = new HashMap<>(); + + if (VideoController.TOKEN == null) { + getToken(); + } + + header.put("Authorization", TOKEN); + + Response response // 请求响应 + = okHttp + .headers(header) + .url(URL + "/videoInfo/api/nearCamListDistance") // 请求地址 + .data(requestParams) // 请求参数 + .get(); // 请求方法 + + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + + if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { + getToken(); + okHttp.get(); + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + } + } + } + + return jsonResult; + + } + + /** + * 根据桩号查询附近相机 + */ + @GetMapping(value = "/nearCamListPileNum") + public Object nearCamListPileNum(String pileNum) throws HttpException, IOException { + + // 获取济菏运管中心相机信息 + JSONObject camInfo = getCamByDept("1301730"); + + if (!camInfo.containsKey("data")) { + return camInfo; + } + + JSONArray camData = camInfo.getJSONArray("data"); + + List resultList = new ArrayList<>(); + + camData.forEach(item -> { + JSONObject jsonObject = (JSONObject) item; + if (isNearbyPileNum(pileNum, jsonObject.getString("pileNum"))) { + resultList.add(item); + } + }); + + return AjaxResult.success(resultList); + } + + /** + * 获取视频流信息 + */ + @GetMapping(value = "/externalVideoStreaming") + public JSONObject externalVideoStreaming(String camId) throws HttpException, IOException { + + JSONObject jsonResult = null; + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("type", "1"); + requestParams.put("camId", camId); + + Map header = new HashMap<>(); + + if (VideoController.TOKEN == null) { + getToken(); + } + + header.put("Authorization", TOKEN); + + Response response // 请求响应 + = okHttp + .headers(header) + .url(URL + "/videoInfo/api/externalVideoStreaming") // 请求地址 + .data(requestParams) // 请求参数 + .post(); // 请求方法 + + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + + if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { + getToken(); + okHttp.post(); + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + } + } + } + + return jsonResult; + } + + + /** + * 云平台控制 + */ + @GetMapping(value = "/PTZControl") + public JSONObject PTZControl(String camId, String cmdType, String speed) throws HttpException, IOException { + + JSONObject jsonResult = null; + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("msgType", "3"); + requestParams.put("camId", camId); + requestParams.put("cmdType", cmdType); + requestParams.put("speed", speed); + + Map header = new HashMap<>(); + + if (VideoController.TOKEN == null) { + getToken(); + } + + header.put("Authorization", TOKEN); + + Response response // 请求响应 + = okHttp + .headers(header) + .url(URL + "/videoInfo/api/PTZControl") // 请求地址 + .data(requestParams) // 请求参数 + .get(); // 请求方法 + + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + + if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { + getToken(); + okHttp.get(); + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + } + } + } + + return jsonResult; + } + + + public void getToken() throws HttpException, IOException { + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("username", USERNAME); + requestParams.put("password", PASSWORD); + + Response response // 请求响应 + = okHttp + .url(URL + "/apiLogin") // 请求地址 + .data(requestParams) // 请求参数 + .post(); // 请求方法 + + if (response.body() != null) { + JSONObject jsonResult = JSONObject.parseObject(response.body().string()); + if (jsonResult.containsKey("token")) { + VideoController.TOKEN = jsonResult.getString("token"); + } + } + } + + + /** + * 根据组织机构获取摄像机信息 + * @param deptId 机构id + * @return + */ + public JSONObject getCamByDept(String deptId) throws HttpException, IOException { + JSONObject jsonResult = null; + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("deptId", deptId); + + Map header = new HashMap<>(); + + if (VideoController.TOKEN == null) { + getToken(); + } + + header.put("Authorization", TOKEN); + + Response response // 请求响应 + = okHttp + .headers(header) + .url(URL + "/system/camera/camList") // 请求地址 + .data(requestParams) // 请求参数 + .get(); // 请求方法 + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + + if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { + getToken(); + okHttp.get(); + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + } + } + } + + return jsonResult; + } + + /** + * 判断是否是附近桩号 + * @return + */ + private boolean isNearbyPileNum(String centralPileNum, String nearbyPileNum) { + + int centralPileNumMetre = pileNumTransformMetre(centralPileNum); + int nearbyPileNumMetre = pileNumTransformMetre(nearbyPileNum); + + return (nearbyPileNumMetre <= centralPileNumMetre + 1000) && (nearbyPileNumMetre >= centralPileNumMetre - 1000); + } + + + /** + * 转换转换成米 + * @param pileNum 桩号 + * @return + */ + private int pileNumTransformMetre(String pileNum) { + String[] parts = pileNum.split("[+ ]"); + if (parts.length < 2) { + return 0; + } + int kilometer = Integer.parseInt(parts[0].substring(1)); // 移除开头的字母 + int meter = Integer.parseInt(parts[1]); + return kilometer * 1000 + meter; + } + +} From 9d21d9c29dc6fd2f4fe4c59d549f2af95e234418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Wed, 17 Jan 2024 10:25:48 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=8E=8B=E8=BD=A6(=E5=85=AC=E9=87=8C)=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=20Float=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/zc/business/domain/DcEventAccident.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zc-business/src/main/java/com/zc/business/domain/DcEventAccident.java b/zc-business/src/main/java/com/zc/business/domain/DcEventAccident.java index 31b34a3c..bbcdca0a 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcEventAccident.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcEventAccident.java @@ -65,7 +65,7 @@ public class DcEventAccident extends BaseEntity { * 压车(公里) */ @ApiModelProperty("压车(公里)") - private Long trafficJam; + private Float trafficJam; /** * 天气情况: From 81dcd0385287eaef1d3fc3ae5cc3d1e7e85ef204 Mon Sep 17 00:00:00 2001 From: "Mr.Wang" Date: Wed, 17 Jan 2024 11:12:30 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=B0=E6=96=87=E6=A1=A3=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/controller/VideoController.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java index 17bed0e4..9593991d 100644 --- a/zc-business/src/main/java/com/zc/business/controller/VideoController.java +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -7,6 +7,9 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.zc.common.core.httpclient.OkHttp; import com.zc.common.core.httpclient.exception.HttpException; import com.zc.common.core.httpclient.request.RequestParams; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import okhttp3.Response; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -26,6 +29,7 @@ import static com.ruoyi.common.constant.Constants.HTTP; * * @author Athena-xiepufeng */ +@Api(tags = "视频接口") @RestController @RequestMapping("/video") public class VideoController extends BaseController { @@ -44,8 +48,10 @@ public class VideoController extends BaseController { /** * 查询附近相机 */ + @ApiOperation("查询附近相机") @GetMapping(value = "/nearCamListDistance") - public JSONObject nearCamListDistance(String devLat, String devLon) throws HttpException, IOException { + public JSONObject nearCamListDistance(@ApiParam(value = "纬度", name = "devLat",required = true)String devLat, + @ApiParam(value = "经度", name = "devLon",required = true)String devLon) throws HttpException, IOException { JSONObject jsonResult = null; @@ -93,8 +99,9 @@ public class VideoController extends BaseController { /** * 根据桩号查询附近相机 */ + @ApiOperation("根据桩号查询附近相机") @GetMapping(value = "/nearCamListPileNum") - public Object nearCamListPileNum(String pileNum) throws HttpException, IOException { + public Object nearCamListPileNum(@ApiParam(value = "桩号", name = "pileNum", required = true) String pileNum) throws HttpException, IOException { // 获取济菏运管中心相机信息 JSONObject camInfo = getCamByDept("1301730"); @@ -120,8 +127,9 @@ public class VideoController extends BaseController { /** * 获取视频流信息 */ + @ApiOperation("获取视频流信息") @GetMapping(value = "/externalVideoStreaming") - public JSONObject externalVideoStreaming(String camId) throws HttpException, IOException { + public JSONObject externalVideoStreaming(@ApiParam(value = "摄像头标识", name = "camId", required = true) String camId) throws HttpException, IOException { JSONObject jsonResult = null; @@ -165,8 +173,11 @@ public class VideoController extends BaseController { /** * 云平台控制 */ + @ApiOperation("云平台控制") @GetMapping(value = "/PTZControl") - public JSONObject PTZControl(String camId, String cmdType, String speed) throws HttpException, IOException { + public JSONObject PTZControl(@ApiParam(value = "相机id", name = "camId", required = true) String camId, + @ApiParam(value = "相机类型", name = "cmdType", required = true) String cmdType, + @ApiParam(value = "速度", name = "speed", required = true) String speed) throws HttpException, IOException { JSONObject jsonResult = null; @@ -234,6 +245,7 @@ public class VideoController extends BaseController { /** * 根据组织机构获取摄像机信息 + * * @param deptId 机构id * @return */ @@ -276,6 +288,7 @@ public class VideoController extends BaseController { /** * 判断是否是附近桩号 + * * @return */ private boolean isNearbyPileNum(String centralPileNum, String nearbyPileNum) { @@ -289,6 +302,7 @@ public class VideoController extends BaseController { /** * 转换转换成米 + * * @param pileNum 桩号 * @return */ From 708ee9059b1c0e94cd0dbdf5be4ddf8a3e147511 Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Wed, 17 Jan 2024 15:08:08 +0800 Subject: [PATCH 5/6] =?UTF-8?q?1.=E4=BA=8B=E4=BB=B6=E7=AE=A1=E6=8E=A7?= =?UTF-8?q?=E5=88=86=E6=9E=90=E6=8E=A5=E5=8F=A3=202.=E6=A1=A9=E5=8F=B7?= =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E8=AE=A1=E7=AE=97=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/utils/StakeMarkUtils.java | 44 ++++++++ .../DcTrafficIncidentsController.java | 16 ++- .../mapper/DcTrafficIncidentsMapper.java | 23 ++++ .../service/IDcTrafficIncidentsService.java | 10 ++ .../impl/DcTrafficIncidentsServiceImpl.java | 19 +++- .../business/DcTrafficIncidentsMapper.xml | 104 ++++++++++++++++++ 6 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java new file mode 100644 index 00000000..b68119ea --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java @@ -0,0 +1,44 @@ +package com.ruoyi.common.utils; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +/** + * @Description 桩号距离计算工具 + * + * @author liuwenge + * @date 2024/1/17 14:43 + */ +public class StakeMarkUtils { + + /** + * @Description 计算桩号距离(公里) + * + * @author liuwenge + * @date 2024/1/17 14:45 + * @param startStakeMark 开始桩号 + * @param endStakeMark 结束桩号 + * @return java.math.BigDecimal 距离 + */ + public static BigDecimal getKilometre(String startStakeMark, String endStakeMark){ + String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); + String end = endStakeMark.toLowerCase().replace("k","").replace("+","."); + return new BigDecimal(end).subtract(new BigDecimal(start)).setScale(3, RoundingMode.HALF_UP); + } + + /** + * @Description 计算桩号距离(米) + * + * @author liuwenge + * @date 2024/1/17 15:04 + * @param startStakeMark 开始桩号 + * @param endStakeMark 结束桩号 + * @return java.math.BigDecimal 距离 + */ + public static BigDecimal getMetre(String startStakeMark, String endStakeMark){ + String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); + String end = endStakeMark.toLowerCase().replace("k","").replace("+","."); + return new BigDecimal(end).subtract(new BigDecimal(start)).multiply(new BigDecimal("1000")).setScale(0, RoundingMode.HALF_UP); + } + +} 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 32a8c616..6c5ed6b5 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 @@ -172,9 +172,23 @@ public class DcTrafficIncidentsController { * @param params * @return com.ruoyi.common.core.domain.AjaxResult */ - @ApiOperation("收费站统计分析table") + @ApiOperation("事故多发路段分析") @PostMapping("/selectRoadSectionAnalysis") public AjaxResult selectRoadSectionAnalysis(@RequestBody Map params){ return trafficIncidentsService.selectRoadSectionAnalysis(params); } + + /** + * @Description 路网管控-事件管控分析-事故类型分析 + * + * @author liuwenge + * @date 2024/1/16 15:52 + * @param params + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @ApiOperation("事故类型分析") + @PostMapping("/selectEventTypeAnalysis") + public AjaxResult selectEventTypeAnalysis(@RequestBody Map params){ + return trafficIncidentsService.selectEventTypeAnalysis(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 e5273281..2ed3bdc3 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 @@ -1,5 +1,7 @@ package com.zc.business.mapper; +import org.apache.ibatis.annotations.Param; + import java.util.List; import java.util.Map; @@ -190,4 +192,25 @@ public interface DcTrafficIncidentsMapper { * @return java.util.List> */ List> getTollStationAnalysis(); + + /** + * @Description 事故多发路段分析 + * + * @author liuwenge + * @date 2024/1/17 14:18 + * @param params + * @return java.util.List> + */ + List> selectRoadSectionAnalysis(Map params); + + /** + * @Description 事故类型分析 + * + * @author liuwenge + * @date 2024/1/17 14:18 + * @param params + * @return java.util.List> + */ + List> selectEventTypeAnalysis(Map params); + } 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 be68a5ee..2d822a76 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 @@ -115,4 +115,14 @@ public interface IDcTrafficIncidentsService { * @return com.ruoyi.common.core.domain.AjaxResult */ AjaxResult selectRoadSectionAnalysis(Map params); + + /** + * @Description 路网管控-事件管控分析-事故类型分析 + * + * @author liuwenge + * @date 2024/1/16 15:52 + * @param params + * @return com.ruoyi.common.core.domain.AjaxResult + */ + AjaxResult selectEventTypeAnalysis(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 b7013880..9757ee00 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 @@ -1,6 +1,7 @@ package com.zc.business.service.impl; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.StakeMarkUtils; import com.zc.business.domain.DcEvent; import com.zc.business.domain.DcEventType; import com.zc.business.mapper.DcTrafficIncidentsMapper; @@ -421,6 +422,22 @@ public class DcTrafficIncidentsServiceImpl implements IDcTrafficIncidentsService @Override public AjaxResult selectRoadSectionAnalysis(Map params){ - return AjaxResult.success(); + List> list = trafficIncidentsMapper.selectRoadSectionAnalysis(params); + 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 selectEventTypeAnalysis(Map params){ + + List> list = trafficIncidentsMapper.selectEventTypeAnalysis(params); + return AjaxResult.success(list); } } diff --git a/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml b/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml index 3e2083fd..1587360d 100644 --- a/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml @@ -236,4 +236,108 @@ on t3.id = t4.facilityId + + + + \ No newline at end of file From 4805a0c0a74c0bcf8e92317f2f0266b645e4b864 Mon Sep 17 00:00:00 2001 From: mengff <1198151809@qq.com> Date: Wed, 17 Jan 2024 17:07:53 +0800 Subject: [PATCH 6/6] =?UTF-8?q?--=E6=A3=80=E6=B5=8B=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/constant/Constants.java | 2 +- .../zc/business/controller/DeviceStatus.java | 181 ++++++++++++++++ .../business/controller/StatusController.java | 147 +++++++++++++ .../java/com/zc/business/domain/Device.java | 65 ++++++ .../java/com/zc/business/domain/Status.java | 205 ++++++++++++++++++ .../com/zc/business/mapper/DeviceMapper.java | 16 ++ .../com/zc/business/mapper/StatusMapper.java | 21 ++ .../business/service/impl/DeviceService.java | 23 ++ .../service/impl/ExcelExportService.java | 192 ++++++++++++++++ .../business/service/impl/StatusService.java | 33 +++ .../mapper/business/DeviceMapper.xml | 16 ++ .../mapper/business/StatusMapper.xml | 94 ++++++++ 12 files changed, 994 insertions(+), 1 deletion(-) create mode 100644 zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java create mode 100644 zc-business/src/main/java/com/zc/business/controller/StatusController.java create mode 100644 zc-business/src/main/java/com/zc/business/domain/Device.java create mode 100644 zc-business/src/main/java/com/zc/business/domain/Status.java create mode 100644 zc-business/src/main/java/com/zc/business/mapper/DeviceMapper.java create mode 100644 zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java create mode 100644 zc-business/src/main/java/com/zc/business/service/impl/DeviceService.java create mode 100644 zc-business/src/main/java/com/zc/business/service/impl/ExcelExportService.java create mode 100644 zc-business/src/main/java/com/zc/business/service/impl/StatusService.java create mode 100644 zc-business/src/main/resources/mapper/business/DeviceMapper.xml create mode 100644 zc-business/src/main/resources/mapper/business/StatusMapper.xml diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java index 6e5c8940..8dedcb62 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java @@ -157,7 +157,7 @@ public class Constants /** * 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加) */ - public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" }; + public static final String[] JOB_WHITELIST_STR = { "com.ruoyi","com.zc" }; /** * 定时任务违规的字符 diff --git a/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java b/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java new file mode 100644 index 00000000..31db1c3c --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java @@ -0,0 +1,181 @@ +package com.zc.business.controller; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.zc.business.service.impl.DeviceService; +import com.zc.business.service.impl.ExcelExportService; +import com.zc.business.service.impl.StatusService; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.stereotype.Component; +import com.zc.business.domain.Status; +import com.zc.business.domain.Device; + +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.*; +import java.util.stream.Collectors; + +@Component +@EnableScheduling +public class DeviceStatus { + @Autowired + private DeviceService deviceService; + + @Autowired + private StatusService statusService; + + @Autowired + private ExcelExportService excelExportService; + + + //每天凌晨0点到晚上23点整点测试设备状态 + // @Scheduled(cron = "0 0 0-23 * * ?") + // @Scheduled(cron = "0 0 1,5,7,8,11,14,17,19,21,23") + public void deviceStatus() { + DeviceService deviceService= SpringUtils.getBean(DeviceService.class); + StatusService statusService= SpringUtils.getBean(StatusService.class); + ExecutorService executor = Executors.newFixedThreadPool(100); + List deviceList = deviceService.SelectList(); + + List> futures = new ArrayList<>(); + + for (Device device : deviceList) { + Callable task = () -> { + try { + Status status = new Status(); + InetAddress address = InetAddress.getByName(device.getDeviceIp()); + String lostRate = getPingPacketLossRate(device.getDeviceIp()); + boolean reachable = address.isReachable(5000); // Timeout: 5 seconds + + status.setDeviceNo(device.getDeviceNo()); + status.setDeviceName(device.getDeviceName()); + status.setDeviceIp(device.getDeviceIp()); + LocalDateTime localDateTime = LocalDateTime.now(); + status.setTime(localDateTime); + status.setLostRate(lostRate); + + if (reachable) { + status.setDeviceStatus(1); + status.setSuccessRate("100.00%"); + } else { + status.setDeviceStatus(0); + status.setSuccessRate("0.00%"); + } + + statusService.Add(status); + } catch (IOException e) { + System.out.println("Error pinging " + device.getDeviceIp() + ": " + e.getMessage()); + } + + return null; + }; + + futures.add(executor.submit(task)); + } + + for (Future future : futures) { + try { + future.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } + + executor.shutdown(); + } + + + /** + * 计算丢包率 + */ + public String getPingPacketLossRate(String ipAddress) { + try { + // Execute the ping command + Process process = Runtime.getRuntime().exec("ping -c 4 " + ipAddress); // Sending 4 ICMP Echo Request packets + + // Read the output of the command + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + int packetsSent = 0; + int packetsLost = 0; + + while ((line = reader.readLine()) != null) { + // Check for lines containing packet loss information + if (line.contains("packets transmitted")) { + // Extract the number of packets sent and lost + String[] stats = line.split(", "); + packetsSent = Integer.parseInt(stats[0].split(" ")[0]); + packetsLost = Integer.parseInt(stats[0].split(" ")[0])-Integer.parseInt(stats[1].split(" ")[0]); + } + } + + // Calculate and return the packet loss rate + if (packetsSent > 0) { + return String.format("%.2f%%", (double) packetsLost / packetsSent * 100); + } else { + return "0.00%"; // No packets sent + } + } catch (IOException e) { + e.printStackTrace(); + return "-1.00%"; // Error occurred + } + } + + + /** + * 成功率和丢包率按小时分组 + * 每天17点 23点 30分导出excel表 + */ + + // @Scheduled(cron = "0 30 17,23 * * ?") + public void calculateSuccessRate() { + StatusService statusService= SpringUtils.getBean(StatusService.class); + ExcelExportService excelExportService= SpringUtils.getBean(ExcelExportService.class); + + LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS); + LocalDateTime currentTime = LocalDateTime.now(); + + + Status status = new Status(); + status.setStartTime(todayStart); + status.setTime(currentTime); + List listStatus = statusService.list(status); + //根据时间分组 + Map> map = listStatus.stream() + .collect(Collectors.groupingBy(Status -> Status.getTime().getHour())); + //根据类型分组 + Map> maps = listStatus.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType)); + + String filePath=CreateNamedExcel(); + excelExportService.exportDataToExcel(map,maps,filePath); + } + + + public String CreateNamedExcel() { + LocalDateTime dateTime = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String formattedDateTime = dateTime.format(formatter); + //修改成服务器地址 + String filePath = "/Users/mengfanfeng/Downloads/excel/"+formattedDateTime+"--deviceStatus.xlsx"; + try (Workbook workbook = new XSSFWorkbook()) { + FileOutputStream fileOut = new FileOutputStream(filePath); + workbook.write(fileOut); + System.out.println("Empty named Excel created successfully."); + } catch (IOException e) { + e.printStackTrace(); + } + return filePath; + } + +} + diff --git a/zc-business/src/main/java/com/zc/business/controller/StatusController.java b/zc-business/src/main/java/com/zc/business/controller/StatusController.java new file mode 100644 index 00000000..84029a24 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/StatusController.java @@ -0,0 +1,147 @@ +package com.zc.business.controller; +import com.ruoyi.common.core.domain.AjaxResult; +import com.zc.business.domain.Status; +import com.zc.business.service.impl.StatusService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.stream.Collectors; +@Api("设备状态") +@RestController +@RequestMapping("/system/status") +public class StatusController { + + @Autowired + private StatusService statusService; + + //设备列表 + @ApiOperation("设备状态柱状按时间和类型") + @GetMapping ("/tablist") + public AjaxResult getTabList(Status status) + { + LocalDateTime todayStart = status.getStartTime().truncatedTo(ChronoUnit.DAYS); + LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(1); + status.setStartTime(todayStart); + status.setTime(currentTime); + List listStatus = statusService.list(status); + return AjaxResult.success(listStatus); + } + + //按时间划分设备柱状图 + @ApiOperation("设备状态列表按时间和类型") + @GetMapping ("/list") + public AjaxResult getStatusList(Status status) + { + LocalDateTime todayStart = status.getStartTime().truncatedTo(ChronoUnit.DAYS); + LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(1); + status.setStartTime(todayStart); + status.setTime(currentTime); + String type=status.getType(); + List listStatus = statusService.list(status); + List listStatu=listStatus.stream().filter(iteam ->iteam.getType()!=null && iteam.getType().equals(type)).collect(Collectors.toList()); + //根据时间分组 + Map> map = listStatu.stream() + .collect(Collectors.groupingBy(Status -> (Status.getTime().getYear()+"-"+Status.getTime().getMonthValue()+"-"+Status.getTime().getDayOfYear()))); + //根据类型分组 + // Map> maps = listStatu.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType)); + //生成有序map + Map> mapTime = new TreeMap<>(map); + Map mapSort=new TreeMap<>(); + for (Map.Entry> entry : mapTime.entrySet()) { + List groupItems = entry.getValue(); + long count = groupItems.stream().filter(iteam -> iteam.getDeviceStatus() == 1).count(); + String onlineRate=String.format("%.2f%%", (double) count / groupItems.size() * 100); + mapSort.put(entry.getKey(),onlineRate); + } + // Map> mapStatus = new TreeMap<>(maps); + return AjaxResult.success(mapSort); + } + + //按类型划分设备 + @ApiOperation("设备状态列表按类型") + @GetMapping ("/type") + public AjaxResult getTypeList() + { + HashMap itemTypeMap = new HashMap<>(); + itemTypeMap.put("1", "高清网络枪型固定摄像机"); + itemTypeMap.put("2", "高清网络球形摄像机"); + itemTypeMap.put("3", "桥下高清网络球形摄像机"); + itemTypeMap.put("4", "360°全景摄像机"); + itemTypeMap.put("5", "180°全景摄像机"); + itemTypeMap.put("6", "门架式可变信息标志"); + itemTypeMap.put("7", "雨棚可变信息标志"); + itemTypeMap.put("8", "站前悬臂式可变信息标志"); + itemTypeMap.put("9", "气象检测器"); + itemTypeMap.put("10", "路段语音广播系统"); + itemTypeMap.put("11", "护栏碰撞预警系统"); + itemTypeMap.put("12", "毫米波雷达"); + itemTypeMap.put("13", "合流区预警系统"); + itemTypeMap.put("14", "激光疲劳唤醒"); + itemTypeMap.put("15", "一类交通量调查站"); + itemTypeMap.put("16", "智能行车诱导系统"); + itemTypeMap.put("17", "智能设备箱"); + LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS); + LocalDateTime currentTime = LocalDateTime.now(); + Status status = new Status(); + status.setStartTime(todayStart); + status.setTime(currentTime); + List listStatus = statusService.list(status); + //根据时间分组 + Map> map = listStatus.stream() + .collect(Collectors.groupingBy(Status -> Status.getTime().getHour())); + Map> ipMap = new TreeMap<>(map); + Integer lastKey = Collections.max(ipMap.keySet()); + List lastEntry = ipMap.get(lastKey); + Map> typeMap = lastEntry.stream().filter(iteam -> iteam.getType() != null).collect(Collectors.groupingBy(Status::getType)); + Map> subMap=new HashMap<>(); + + for (Map.Entry> entrys : typeMap.entrySet()) { + Map maps=new HashMap<>(); + List groupItems = entrys.getValue(); + double lostRate = groupItems.stream() + .mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace("%", ""))) // 去掉%,并转换为double + .average().getAsDouble(); + double sucessRate = groupItems.stream() + .mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace("%", ""))) // 去掉%,并转换为double + .average().getAsDouble(); + String failRate=String.format("%.2f", (100-sucessRate))+"%"; + //丢包率 + maps.put("lostRate",String.format("%.2f", lostRate)+"%"); + //在线率 + maps.put("sucessRate",String.format("%.2f", sucessRate)+"%"); + //离线率 + maps.put("failRate",failRate); + //总数 + maps.put("sum",String.valueOf(groupItems.size())); + subMap.put(itemTypeMap.get(entrys.getKey()),maps); + } + Map maps=new HashMap<>(); + double lostRate = lastEntry.stream() + .mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace("%", ""))) // 去掉%,并转换为double + .average().getAsDouble(); + double sucessRate = lastEntry.stream() + .mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace("%", ""))) // 去掉%,并转换为double + .average().getAsDouble(); + String failRate=String.format("%.2f", (100-sucessRate))+"%"; + //丢包率 + maps.put("lostRate",String.format("%.2f", lostRate)+"%"); + //在线率 + maps.put("sucessRate",String.format("%.2f", sucessRate)+"%"); + //离线率 + maps.put("failRate",failRate); + //总数 + maps.put("sum",String.valueOf(lastEntry.size())); + subMap.put("全部设备",maps); + + return AjaxResult.success(subMap); + } + + +} diff --git a/zc-business/src/main/java/com/zc/business/domain/Device.java b/zc-business/src/main/java/com/zc/business/domain/Device.java new file mode 100644 index 00000000..de6dbbff --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/Device.java @@ -0,0 +1,65 @@ +package com.zc.business.domain; + +/** + * @author mengff + * @Date 2020/03/03 + */ +public class Device { + private long id; + + public String getDeviceNo() { + return deviceNo; + } + + public void setDeviceNo(String deviceNo) { + this.deviceNo = deviceNo; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceIp() { + return deviceIp; + } + + @Override + public String toString() { + return "Device{" + + "id=" + id + + ", deviceNo='" + deviceNo + '\'' + + ", deviceName='" + deviceName + '\'' + + ", deviceIp='" + deviceIp + '\'' + + '}'; + } + + public Device(long id, String deviceNo, String deviceName, String deviceIp) { + this.id = id; + this.deviceNo = deviceNo; + this.deviceName = deviceName; + this.deviceIp = deviceIp; + } + + public void setDeviceIp(String deviceIp) { + this.deviceIp = deviceIp; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + private String deviceNo; + private String deviceName; + private String deviceIp; + + private String type; + +} \ No newline at end of file diff --git a/zc-business/src/main/java/com/zc/business/domain/Status.java b/zc-business/src/main/java/com/zc/business/domain/Status.java new file mode 100644 index 00000000..dbb055bc --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/Status.java @@ -0,0 +1,205 @@ +package com.zc.business.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +/** + * @author mengff + * @Date 2024/01/04 + */ +public class Status { + public String getDeviceIp() { + return deviceIp; + } + + public void setDeviceIp(String deviceIp) { + this.deviceIp = deviceIp; + } + public LocalDateTime getStartTime() { + return startTime; + } + + public Status(long id, String deviceNo, String deviceName, int deviceStatus, LocalDateTime time, LocalDateTime startTime, String deviceIp, String successRate, String lostRate, String direction, String production, String model, String network, String content, String type) { + this.id = id; + this.deviceNo = deviceNo; + this.deviceName = deviceName; + this.deviceStatus = deviceStatus; + this.time = time; + this.startTime = startTime; + this.deviceIp = deviceIp; + this.successRate = successRate; + this.lostRate = lostRate; + this.direction = direction; + this.production = production; + this.model = model; + this.network = network; + this.content = content; + this.type = type; + } + + public void setStartTime(LocalDateTime startTime) { + this.startTime = startTime; + } + + @Override + public String toString() { + return "Status{" + + "id=" + id + + ", deviceNo='" + deviceNo + '\'' + + ", deviceName='" + deviceName + '\'' + + ", deviceStatus=" + deviceStatus + + ", time=" + time + + ", startTime=" + startTime + + ", deviceIp='" + deviceIp + '\'' + + ", successRate='" + successRate + '\'' + + ", lostRate='" + lostRate + '\'' + + ", direction='" + direction + '\'' + + ", production='" + production + '\'' + + ", model='" + model + '\'' + + ", network='" + network + '\'' + + ", content='" + content + '\'' + + ", type='" + type + '\'' + + '}'; + } + + public LocalDateTime getTime() { + return time; + } + + public void setTime(LocalDateTime time) { + this.time = time; + } + + public String getDeviceNo() { + return deviceNo; + } + + public Status(long id, String deviceNo, String deviceName, int deviceStatus) { + this.id = id; + this.deviceNo = deviceNo; + this.deviceName = deviceName; + this.deviceStatus = deviceStatus; + } + + public Status() { + } + + public void setDeviceNo(String deviceNo) { + this.deviceNo = deviceNo; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public int getDeviceStatus() { + return deviceStatus; + } + + public void setDeviceStatus(int deviceStatus) { + this.deviceStatus = deviceStatus; + } + + private long id; + + private String deviceNo; + + + private String deviceName; + private int deviceStatus; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss") + private LocalDateTime time; + + public String getSuccessRate() { + return successRate; + } + + public void setSuccessRate(String successRate) { + this.successRate = successRate; + } + + public String getLostRate() { + return lostRate; + } + + public void setLostRate(String lostRate) { + this.lostRate = lostRate; + } + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss") + private LocalDateTime startTime; + + private String deviceIp; + + private String successRate; + + private String lostRate; + + private String direction; + + private String production; + + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + + public String getProduction() { + return production; + } + + public void setProduction(String production) { + this.production = production; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public String getNetwork() { + return network; + } + + public void setNetwork(String network) { + this.network = network; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + private String model; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + private String network; + + private String content; + + private String type; + +} diff --git a/zc-business/src/main/java/com/zc/business/mapper/DeviceMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DeviceMapper.java new file mode 100644 index 00000000..270a9e83 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/mapper/DeviceMapper.java @@ -0,0 +1,16 @@ +package com.zc.business.mapper; + +import com.zc.business.domain.Device; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author mengff + * @Date 2024/01/04 + */ +@Repository +public interface DeviceMapper { + + List SelectList(); +} \ No newline at end of file diff --git a/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java b/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java new file mode 100644 index 00000000..1980b0c8 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java @@ -0,0 +1,21 @@ +package com.zc.business.mapper; +import com.zc.business.domain.Status; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author mengff + * @Date 2024/01/04 + */ +@Repository +public interface StatusMapper { + + + + int Add(@Param("status")Status status); + + List listStatus(@Param("status")Status status); + +} diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DeviceService.java b/zc-business/src/main/java/com/zc/business/service/impl/DeviceService.java new file mode 100644 index 00000000..416a0256 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/DeviceService.java @@ -0,0 +1,23 @@ +package com.zc.business.service.impl; + +import com.zc.business.domain.Device; +import com.zc.business.mapper.DeviceMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author mengff + * @Date 2024/01/04 + */ +@Service +public class DeviceService { + @Autowired + DeviceMapper deviceMapper; + + public List SelectList() { + return deviceMapper.SelectList(); + } + +} \ No newline at end of file diff --git a/zc-business/src/main/java/com/zc/business/service/impl/ExcelExportService.java b/zc-business/src/main/java/com/zc/business/service/impl/ExcelExportService.java new file mode 100644 index 00000000..012ae181 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/ExcelExportService.java @@ -0,0 +1,192 @@ +package com.zc.business.service.impl; + +import com.zc.business.domain.Status; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.stereotype.Service; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.stream.Collectors; + +@Service +public class ExcelExportService { + + public void exportDataToExcel(Map> ipMap, Map >categoryMap, String filePath) { + Workbook workbook = new XSSFWorkbook(); + Map> map = new TreeMap<>(ipMap); + Sheet sheet = workbook.createSheet("设备故障率分时统计页"); + int rowNum = 0; + Row row0 = sheet.createRow(0); + row0.createCell(0).setCellValue("设备名称"); + row0.createCell(1).setCellValue("设备IP"); + row0.createCell(2).setCellValue("设备桩号"); + row0.createCell(3).setCellValue("设备方向"); + row0.createCell(4).setCellValue("设备厂家"); + row0.createCell(5).setCellValue("设备型号"); + row0.createCell(6).setCellValue("备注"); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 6, 6)); + int i=0; + boolean flag = true; + Row row1= sheet.createRow(1); + for (Map.Entry> entry : map.entrySet()) { + row0.createCell(2*i+7).setCellValue(entry.getKey()+"时"); + sheet.addMergedRegion(new CellRangeAddress(0, 0, 2*i+7, 2*i+8)); + row1.createCell(2*i+7).setCellValue("在线率"); + row1.createCell(2*i+8).setCellValue("丢包率"); + rowNum = 2; + List groupItems = entry.getValue(); + for (Status ignored : groupItems) { + int a=rowNum++; + Row row = sheet.getRow(a); // 获取指定索引的行 + if (row == null) { // 如果行不存在,则创建新行 + row = sheet.createRow(a); + } + if(flag) { + row.createCell(0).setCellValue(ignored.getDeviceName()); + row.createCell(1).setCellValue(ignored.getDeviceIp()); + row.createCell(2).setCellValue(ignored.getDeviceNo()); + row.createCell(3).setCellValue(ignored.getDirection()); + row.createCell(4).setCellValue(ignored.getProduction()); + row.createCell(5).setCellValue(ignored.getModel()); + row.createCell(6).setCellValue(ignored.getContent()); + } + row.createCell(2*i+7).setCellValue(ignored.getSuccessRate()); + row.createCell(2*i+8).setCellValue(ignored.getLostRate()); + } + i++; + flag = false; + } + Sheet sheets = workbook.createSheet("设备故障率汇总页"); + createSheet(sheets,categoryMap); + Sheet sheet1 = workbook.createSheet("设备故障率分时汇总页"); + createSheet1(sheet1,ipMap); + try (FileOutputStream outputStream = new FileOutputStream(filePath)) { + workbook.write(outputStream); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("excel写入成功!!!!!!"); + + } + public void createSheet1(Sheet sheet,Map> ipMap){ + Map> map = new TreeMap<>(ipMap); + int rowNum = 0; + Row row0 = sheet.createRow(rowNum); + row0.createCell(0).setCellValue("设备分类"); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0)); + int i=0; + boolean flag = true; + Row row1= sheet.createRow(1); + for (Map.Entry> entry : map.entrySet()) { + row0.createCell(3 * i + 1).setCellValue(entry.getKey() + "时"); + sheet.addMergedRegion(new CellRangeAddress(0, 0, 3 * i + 1, 3 * i + 3)); + row1.createCell(3 * i + 1).setCellValue("总统计数"); + row1.createCell(3 * i + 2).setCellValue("在线统计数"); + row1.createCell(3 * i + 3).setCellValue("在线率"); + rowNum = 2; + List groupItem = entry.getValue(); + Map> maps = groupItem.stream().filter(iteam -> iteam.getType() != null).collect(Collectors.groupingBy(Status::getType)); + for (Map.Entry> entrys : maps.entrySet()) { + List groupItems = entrys.getValue(); + long b = groupItems.stream().filter(iteam -> iteam.getDeviceStatus() == 1).count(); +// for (Status ignored : groupItems) { + int a = rowNum++; + Row row = sheet.getRow(a); // 获取指定索引的行 + if (row == null) { // 如果行不存在,则创建新行 + row = sheet.createRow(a); + } + HashMap itemTypeMap = new HashMap<>(); + itemTypeMap.put("1", "高清网络枪型固定摄像机"); + itemTypeMap.put("2", "高清网络球形摄像机"); + itemTypeMap.put("3", "桥下高清网络球形摄像机"); + itemTypeMap.put("4", "360°全景摄像机"); + itemTypeMap.put("5", "180°全景摄像机"); + itemTypeMap.put("6", "门架式可变信息标志"); + itemTypeMap.put("7", "雨棚可变信息标志"); + itemTypeMap.put("8", "站前悬臂式可变信息标志"); + itemTypeMap.put("9", "气象检测器"); + itemTypeMap.put("10", "路段语音广播系统"); + itemTypeMap.put("11", "护栏碰撞预警系统"); + itemTypeMap.put("12", "毫米波雷达"); + itemTypeMap.put("13", "合流区预警系统"); + itemTypeMap.put("14", "激光疲劳唤醒"); + itemTypeMap.put("15", "一类交通量调查站"); + itemTypeMap.put("16", "智能行车诱导系统"); + itemTypeMap.put("17", "智能设备箱"); + String type = groupItems.get(0).getType(); + String description = itemTypeMap.get(type); + if (flag) { + row.createCell(0).setCellValue(description); + } + row.createCell(3 * i + 1).setCellValue(groupItems.size()); + row.createCell(3 * i + 2).setCellValue(b); + row.createCell(3 * i + 3).setCellValue(String.format("%.2f%%", (double) b / groupItems.size() * 100)); + } + i++; + flag = false; + // } + } + + } + + public void createSheet(Sheet sheet,Map >categoryMap){ + int rowNum = 0; + Row row = sheet.createRow(rowNum); + row.createCell(0).setCellValue("设备分类"); + row.createCell(1).setCellValue("总统计数"); + row.createCell(2).setCellValue("在线统计数"); + row.createCell(3).setCellValue("在线率"); + rowNum = 1; + for (Map.Entry> entry : categoryMap.entrySet()) { + List groupItems = entry.getValue(); + long a=groupItems.stream().filter(iteam->iteam.getDeviceStatus()==1).count(); + row = sheet.createRow(rowNum++); + HashMap itemTypeMap = new HashMap<>(); + itemTypeMap.put("1", "高清网络枪型固定摄像机"); + itemTypeMap.put("2", "高清网络球形摄像机"); + itemTypeMap.put("3", "桥下高清网络球形摄像机"); + itemTypeMap.put("4", "360°全景摄像机"); + itemTypeMap.put("5", "180°全景摄像机"); + itemTypeMap.put("6", "门架式可变信息标志"); + itemTypeMap.put("7", "雨棚可变信息标志"); + itemTypeMap.put("8", "站前悬臂式可变信息标志"); + itemTypeMap.put("9", "气象检测器"); + itemTypeMap.put("10", "路段语音广播系统"); + itemTypeMap.put("11", "护栏碰撞预警系统"); + itemTypeMap.put("12", "毫米波雷达"); + itemTypeMap.put("13", "合流区预警系统"); + itemTypeMap.put("14", "激光疲劳唤醒"); + itemTypeMap.put("15", "一类交通量调查站"); + itemTypeMap.put("16", "智能行车诱导系统"); + itemTypeMap.put("17", "智能设备箱"); + String type = groupItems.get(0).getType(); + String description = itemTypeMap.get(type); + row.createCell(0).setCellValue(description); + row.createCell(1).setCellValue(groupItems.size()); + row.createCell(2).setCellValue(a); + row.createCell(3).setCellValue(String.format("%.2f%%", (double) a / groupItems.size() * 100)); + + } + + } + + + + + +} + diff --git a/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java b/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java new file mode 100644 index 00000000..f1e4ef64 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java @@ -0,0 +1,33 @@ +package com.zc.business.service.impl; +import com.zc.business.domain.Status; +import com.zc.business.mapper.StatusMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author mengff + * @Date 2024/01/04 + */ +@Service +public class StatusService { + @Autowired + StatusMapper statusMapper; + + + public String Add(Status status) { + int a = statusMapper.Add(status); + if (a == 1) { + return "添加成功"; + } else { + return "添加失败"; + } + } + + public List list(Status status) { + List list = statusMapper.listStatus(status); + return list; + } + +} diff --git a/zc-business/src/main/resources/mapper/business/DeviceMapper.xml b/zc-business/src/main/resources/mapper/business/DeviceMapper.xml new file mode 100644 index 00000000..a64ae26f --- /dev/null +++ b/zc-business/src/main/resources/mapper/business/DeviceMapper.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/zc-business/src/main/resources/mapper/business/StatusMapper.xml b/zc-business/src/main/resources/mapper/business/StatusMapper.xml new file mode 100644 index 00000000..1947948f --- /dev/null +++ b/zc-business/src/main/resources/mapper/business/StatusMapper.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO status + + + device_no, + + + device_name, + + + device_status, + + + time, + + + success_rate, + + + + lost_rate, + + + device_ip, + + + + + #{status.deviceNo,jdbcType=VARCHAR}, + + + #{status.deviceName,jdbcType=VARCHAR}, + + + #{status.deviceStatus,jdbcType=INTEGER}, + + + #{status.time,jdbcType=DATE}, + + + #{status.successRate,jdbcType=VARCHAR}, + + + #{status.lostRate,jdbcType=VARCHAR}, + + + + #{status.deviceIp,jdbcType=VARCHAR}, + + + + + + select id, device_no, device_name, device_status, time from status + + + + +