package com.zc.business.controller; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.StakeMarkUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.zc.business.domain.DcEvent; import com.zc.business.domain.DcEventListQuery; import com.zc.business.domain.DcWarning; import com.zc.business.domain.export.*; import com.zc.business.enums.UniversalEnum; import com.zc.business.service.IDcTrafficIncidentsService; import com.zc.common.core.httpclient.exception.HttpException; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.annotations.Param; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; /** * @Description 交通事件统计 * * @author liuwenge * @date 2024/1/13 9:41 */ @Api(tags = "交通事件统计") @RestController @RequestMapping("/business/trafficIncidents") public class DcTrafficIncidentsController { @Autowired private IDcTrafficIncidentsService trafficIncidentsService; /** * @Description 首页-重点数据 * * @author liuwenge * @date 2024/1/13 10:10 * @param * @return com.ruoyi.common.core.domain.AjaxResult */ @ApiOperation("首页-重点监控") @GetMapping("/getKeyData") public AjaxResult getKeyData(){ return trafficIncidentsService.getKeyData(); } /** * @Description 首页-事件专题-根据事件类型获取事件列表 * * @author liuwenge * @date 2024/1/13 14:27 * @param * @return com.ruoyi.common.core.domain.AjaxResult */ @ApiOperation("根据类型获取事件列表") @PostMapping("/getEventList") public AjaxResult getEventList(DcEventListQuery dcEventListQuery){ return trafficIncidentsService.getEventListByType(dcEventListQuery); } /** * @Description 首页-事件专题-根据事件id获取事件详情 * * @author liuwenge * @date 2024/1/13 14:43 * @param eventId * @return com.ruoyi.common.core.domain.AjaxResult */ @ApiOperation("获取交通事件详情") @GetMapping("/getEventInfo/{eventId}") public AjaxResult getEventInfo(@ApiParam(value = "事件id", name = "eventId",required = true) @PathVariable("eventId") String eventId){ return trafficIncidentsService.getEventInfo(eventId); } /** * @Description 首页-状况统计-获取日周月年交通事件数量 * * @author liuwenge * @date 2024/1/13 15:07 * @param * @return com.ruoyi.common.core.domain.AjaxResult */ @ApiOperation("获取日、周、月、年的交通事件数量") @GetMapping("/getTrafficIncidentsNum") public AjaxResult getTrafficIncidentsNum(){ return trafficIncidentsService.getTrafficIncidentsNum(); } /** * @Description 路网管控-事件管控分析-各类事件的状态数量 * * @author liuwenge * @date 2024/1/13 15:07 * @param * @return com.ruoyi.common.core.domain.AjaxResult */ @ApiOperation("各类事件的状态数量") @GetMapping("/getEventStatusNum") public AjaxResult getEventStatusNum(){ return trafficIncidentsService.getEventStatusNum(); } /** * @Description 路网管控-事件管控分析-事件类型分析占比 * * @author liuwenge * @date 2024/1/13 15:07 * @param * @return com.ruoyi.common.core.domain.AjaxResult */ @ApiOperation("事件类型分析占比") @GetMapping("/getAllEventNum") public AjaxResult getAllEventNum(){ return trafficIncidentsService.getAllEventNum(); } @ApiOperation(value = "导出事件类型分析",tags = {"ECharts导出"}) @GetMapping("/exportGetAllEventNum") public void exportGetAllEventNum(HttpServletResponse response){ AjaxResult ajaxResult = trafficIncidentsService.getAllEventNum(); List list = new ArrayList<>(); if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { List> data = (List>) ajaxResult.get("data"); Long total = data.stream().mapToLong(item -> (long) item.get("num")).sum(); for (Map datum : data) { AllEventNum allEventNum = new AllEventNum(); allEventNum.setEventName(datum.get("eventName").toString()); allEventNum.setNum(datum.get("num").toString()); //计算百分比 double ratio = (double) Long.parseLong(datum.get("num").toString()) / total * 100; ratio = Math.round(ratio * 100.0) / 100.0; allEventNum.setRatio(ratio + "%"); list.add(allEventNum); } } ExcelUtil util = new ExcelUtil<>(AllEventNum.class); util.exportExcel(response, list, "事件类型分析"); } /** * @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(); } @ApiOperation(value="导出今日事件趋势",tags = {"ECharts导出"}) @PostMapping("/exportGetEventTrend") public void exportGetEventTrend(HttpServletResponse response,@RequestBody Map params) throws IOException { String fileUrl = params.get("fileUrl"); AjaxResult ajaxResult = trafficIncidentsService.getEventTrend(); List list = new ArrayList<>(); if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { Map data = (Map) ajaxResult.get("data"); List> perception = (List>)data.get("perception"); List> traffic = (List>)data.get("traffic"); for (int i = 0; i < perception.size(); i++) { EventTrend eventTrend = new EventTrend(); eventTrend.setHours(perception.get(i).get("hours").toString() + "时"); eventTrend.setPerception(perception.get(i).get("num").toString()); eventTrend.setTraffic(traffic.get(i).get("num").toString()); list.add(eventTrend); } } ExcelUtil util = new ExcelUtil<>(EventTrend.class); int commaIndex = fileUrl.indexOf(','); if (commaIndex == -1) { throw new IllegalArgumentException("Invalid Data URL, no comma found to separate base64 data"); } String base64Data = fileUrl.substring(commaIndex + 1); byte[] imageBytes = Base64.getDecoder().decode(base64Data); util.exportImgExcel(response, list, "今日事件趋势",imageBytes,7,14); } /** * @Description 路网管控-事件管控分析-事故车型分析 * * @author liuwenge * @date 2024/1/15 15:38 * @param direction 方向 * @param direction 类型(1:日, 2:月, 3:季度, 4-年) * @param direction 时间 * @return com.ruoyi.common.core.domain.AjaxResult */ @ApiOperation("事故车型分析") // @GetMapping("/getAccidentVehicleAnalysis") @PostMapping("/selectAccidentVehicleAnalysis") public AjaxResult getAccidentVehicleAnalysis(@ApiParam(value="方向", name="direction", required=true) @RequestParam ("direction") String direction, @ApiParam(value="类型(1:日, 2:月, 3:季度, 4-年)", name="type", required=true) @RequestParam ("type") String type, @ApiParam(value="时间", name="startTime", required=true) @RequestParam ("startTime") String startTime){ return trafficIncidentsService.getAccidentVehicleAnalysis(direction,type,startTime); } @ApiOperation(value="导出事故车型分析",tags = {"ECharts导出"}) @GetMapping("/exportSelectAccidentVehicleAnalysis") public void exportSelectAccidentVehicleAnalysis(HttpServletResponse response, @ApiParam(value="方向", name="direction", required=true) @RequestParam ("direction") String direction, @ApiParam(value="类型(1:日, 2:月, 3:季度, 4-年)", name="type", required=true) @RequestParam ("type") String type, @ApiParam(value="时间", name="startTime", required=true) @RequestParam ("startTime") String startTime){ AjaxResult ajaxResult = trafficIncidentsService.getAccidentVehicleAnalysis(direction,type,startTime); List list = new ArrayList<>(); if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { List> data = (List>) ajaxResult.get("data"); for (Map datum : data) { AccidentVehicleAnalysis accidentVehicleAnalysis = new AccidentVehicleAnalysis(); accidentVehicleAnalysis.setTypeName(datum.get("typeName").toString()); accidentVehicleAnalysis.setNum(datum.get("num").toString()); accidentVehicleAnalysis.setAvgTime(datum.get("avgTime").toString()); list.add(accidentVehicleAnalysis); } } ExcelUtil util = new ExcelUtil<>(AccidentVehicleAnalysis.class); util.exportExcel(response, list, "事故车型分析"); } /** * @Description 路网管控-事件管控分析-收费站统计分析table * * @author liuwenge * @date 2024/1/15 17:31 * @param searchType 查询条件(1:站点,2:原因) * @param facilityIdList 站点id * @param controlType 类型(1:封闭,2:限行) * @param startTime 开始时间 * @param endTime 结束时间 * @return com.ruoyi.common.core.domain.AjaxResult */ @ApiOperation("收费站统计分析table") @PostMapping("/selectTollStationAnalysis") public AjaxResult selectTollStationAnalysis(@ApiParam(value="查询条件(1:站点,2:原因)", name="searchType", required=true) @RequestParam ("searchType") String searchType, @ApiParam(value="站点id", name="facilityId", required=false) @RequestParam (name="facilityId",required = false) String[] facilityIdList, @ApiParam(value="类型(1:封闭,2:限行)", name="controlType", required=false) @RequestParam (name="controlType",required = false) String controlType, @ApiParam(value="开始时间", name="startTime", required=true) @RequestParam ("startTime") String startTime, @ApiParam(value="结束时间", name="endTime", required=true) @RequestParam ("endTime") String endTime){ return trafficIncidentsService.selectTollStationAnalysis(searchType,facilityIdList,controlType,startTime,endTime); } @ApiOperation(value="导出收费站统计分析table",tags = {"ECharts导出"}) @GetMapping("/exportSelectTollStationAnalysis") public void exportSelectTollStationAnalysis(HttpServletResponse response, @ApiParam(value="查询条件(1:站点,2:原因)", name="searchType", required=true) @RequestParam ("searchType") String searchType, @ApiParam(value="站点id", name="facilityId", required=false) @RequestParam (name="facilityId",required = false) String[] facilityIdList, @ApiParam(value="类型(1:封闭,2:限行)", name="controlType", required=false) @RequestParam (name="controlType",required = false) String controlType, @ApiParam(value="开始时间", name="startTime", required=true) @RequestParam ("startTime") String startTime, @ApiParam(value="结束时间", name="endTime", required=true) @RequestParam ("endTime") String endTime) throws IOException, HttpException { AjaxResult ajaxResult = trafficIncidentsService.selectTollStationAnalysis(searchType,facilityIdList,controlType,startTime,endTime); if ("1".equals(searchType)){ List list = new ArrayList<>(); if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { List> data = (List>) ajaxResult.get("data"); Integer closeTotal = 0; Integer restrictionTotal = 0; Integer total = 0; for (Map datum : data) { SelectTollStationAnalysis selectTollStationAnalysis = new SelectTollStationAnalysis(); Integer facilityClose = Integer.parseInt(datum.get("facilityClose").toString()); Integer facilityRestriction = Integer.parseInt(datum.get("facilityRestriction").toString()); Integer sum = facilityClose + facilityRestriction; selectTollStationAnalysis.setFacilityName(datum.get("facilityName").toString()); selectTollStationAnalysis.setFacilityClose(facilityClose.toString()); selectTollStationAnalysis.setFacilityRestriction(facilityRestriction.toString()); selectTollStationAnalysis.setSum(sum.toString()); list.add(selectTollStationAnalysis); closeTotal += facilityClose; restrictionTotal += facilityRestriction; total += sum; } SelectTollStationAnalysis selectTollStationAnalysis = new SelectTollStationAnalysis(); selectTollStationAnalysis.setFacilityName("合计"); selectTollStationAnalysis.setFacilityClose(closeTotal.toString()); selectTollStationAnalysis.setFacilityRestriction(restrictionTotal.toString()); selectTollStationAnalysis.setSum(total.toString()); list.add(selectTollStationAnalysis); } ExcelUtil util = new ExcelUtil<>(SelectTollStationAnalysis.class); util.exportExcel(response, list, "收费站统计分析列表"); } else { XSSFWorkbook workbook = new XSSFWorkbook(); // 创建工作簿 Sheet sheet = workbook.createSheet(UniversalEnum.THE_WHOLE_SECTION_TWO_WAY_REAL_TIME_TRAFFIC_FLOW.getValue()); // 创建工作表 // 创建数据行样式 CellStyle dataStyle = workbook.createCellStyle(); dataStyle.setAlignment(HorizontalAlignment.CENTER); dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); dataStyle.setBorderRight(BorderStyle.THIN); dataStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); dataStyle.setBorderLeft(BorderStyle.THIN); dataStyle.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); dataStyle.setBorderTop(BorderStyle.THIN); dataStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); dataStyle.setBorderBottom(BorderStyle.THIN); dataStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); Font dataFont = workbook.createFont(); dataFont.setFontName(UniversalEnum.ARIAL.getValue()); dataFont.setFontHeightInPoints((short) UniversalEnum.TEN.getNumber()); dataStyle.setFont(dataFont); // 创建表头样式 CellStyle headerStyle = workbook.createCellStyle(); headerStyle.cloneStyleFrom(dataStyle); headerStyle.setAlignment(HorizontalAlignment.CENTER); headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); headerStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); headerStyle.setBorderRight(BorderStyle.THIN); headerStyle.setRightBorderColor(IndexedColors.WHITE.getIndex()); headerStyle.setBorderLeft(BorderStyle.THIN); headerStyle.setLeftBorderColor(IndexedColors.WHITE.getIndex()); headerStyle.setBorderTop(BorderStyle.THIN); headerStyle.setTopBorderColor(IndexedColors.WHITE.getIndex()); headerStyle.setBorderBottom(BorderStyle.THIN); headerStyle.setBottomBorderColor(IndexedColors.WHITE.getIndex()); Font headerFont = workbook.createFont(); headerFont.setFontName(UniversalEnum.ARIAL.getValue()); headerFont.setFontHeightInPoints((short) UniversalEnum.TEN.getNumber()); headerFont.setBold(true); headerFont.setColor(IndexedColors.WHITE.getIndex()); headerStyle.setFont(headerFont); // 添加第一层级表头 Row row = sheet.createRow(UniversalEnum.ZERO.getNumber()); String[] row1 = new String[]{}; if ("2".equals(controlType)){ row1 = new String[]{"限行原因","","限行站次","","","","","限行时长","","","",""}; } else { row1 = new String[]{"封闭原因","","封闭站次","","","","","封闭时长","","","",""}; } for (int i = 0; i < row1.length; i++) { Cell cell = row.createCell(i); cell.setCellValue(row1[i]); cell.setCellStyle(headerStyle); } // 添加第二层级表头(与第一层级对齐) String[] row2 = new String[]{"","","目标时段","","去年同期时段","","同比(%)","目标时段","","去年同期时段","","同比(%)"}; Row subHeaderRow1 = sheet.createRow(UniversalEnum.ONE.getNumber()); for (int i = 0; i < row2.length; i++) { Cell cell = subHeaderRow1.createCell(i); cell.setCellValue(row2[i]); cell.setCellStyle(headerStyle); } // 添加第三层级表头 String[] row3 = new String[]{"","","站次","占比(%)","站次","占比(%)","","站次","占比(%)","站次","占比(%)",""}; Row subHeaderRow2 = sheet.createRow(UniversalEnum.TWO.getNumber()); for (int i = 0; i < row3.length; i++) { Cell cell = subHeaderRow2.createCell(i); cell.setCellValue(row3[i]); cell.setCellStyle(headerStyle); } //合并表头单元格,参数依次为起始行,结束行,起始列,结束列 (从0开始) sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.TWO.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.TWO.getNumber(), UniversalEnum.SIX.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.SEVEN.getNumber(), UniversalEnum.ELEVEN.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.TWO.getNumber(), UniversalEnum.THREE.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.FOUR.getNumber(), UniversalEnum.FIVE.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.TWO.getNumber(), UniversalEnum.SIX.getNumber(), UniversalEnum.SIX.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.SEVEN.getNumber(), UniversalEnum.EIGHT.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.NINE.getNumber(), UniversalEnum.TEN.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.TWO.getNumber(), UniversalEnum.ELEVEN.getNumber(), UniversalEnum.ELEVEN.getNumber())); if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { List> data = (List>) ajaxResult.get("data"); //行号 int rowIndex = 3; //先塞入恶劣天气类型数据 for (int i = 2; i < 9; i++) { Map map = data.get(i); Row subHeaderRow = sheet.createRow(rowIndex); Cell cell = subHeaderRow.createCell(UniversalEnum.ZERO.getNumber()); cell.setCellValue(map.get("controlCauseName").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.ONE.getNumber()); cell.setCellValue(map.get("causeTypeName").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.TWO.getNumber()); cell.setCellValue(map.get("num").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.THREE.getNumber()); cell.setCellValue(map.get("numRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.FOUR.getNumber()); cell.setCellValue(map.get("lastYearNum").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.FIVE.getNumber()); cell.setCellValue(map.get("lastYearNumRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.SIX.getNumber()); cell.setCellValue(map.get("yearNumRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.SEVEN.getNumber()); cell.setCellValue(map.get("minuteTime").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.EIGHT.getNumber()); cell.setCellValue(map.get("timeRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.NINE.getNumber()); cell.setCellValue(map.get("lastYearTime").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.TEN.getNumber()); cell.setCellValue(map.get("lastYearTimeRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.ELEVEN.getNumber()); cell.setCellValue(map.get("yearTimeRatio").toString()); cell.setCellStyle(dataStyle); rowIndex++; } //再塞入车流量大、交通事故 for (int i = 0; i < 2; i++) { Map map = data.get(i); Row subHeaderRow = sheet.createRow(rowIndex); Cell cell = subHeaderRow.createCell(UniversalEnum.ZERO.getNumber()); cell.setCellValue(map.get("controlCauseName").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.ONE.getNumber()); cell.setCellValue(map.get("causeTypeName").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.TWO.getNumber()); cell.setCellValue(map.get("num").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.THREE.getNumber()); cell.setCellValue(map.get("numRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.FOUR.getNumber()); cell.setCellValue(map.get("lastYearNum").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.FIVE.getNumber()); cell.setCellValue(map.get("lastYearNumRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.SIX.getNumber()); cell.setCellValue(map.get("yearNumRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.SEVEN.getNumber()); cell.setCellValue(map.get("minuteTime").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.EIGHT.getNumber()); cell.setCellValue(map.get("timeRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.NINE.getNumber()); cell.setCellValue(map.get("lastYearTime").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.TEN.getNumber()); cell.setCellValue(map.get("lastYearTimeRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.ELEVEN.getNumber()); cell.setCellValue(map.get("yearTimeRatio").toString()); cell.setCellStyle(dataStyle); rowIndex++; } //最后塞入施工、警备任务、其他 for (int i = 9; i < 12; i++) { Map map = data.get(i); Row subHeaderRow = sheet.createRow(rowIndex); Cell cell = subHeaderRow.createCell(UniversalEnum.ZERO.getNumber()); cell.setCellValue(map.get("controlCauseName").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.ONE.getNumber()); cell.setCellValue(map.get("causeTypeName").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.TWO.getNumber()); cell.setCellValue(map.get("num").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.THREE.getNumber()); cell.setCellValue(map.get("numRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.FOUR.getNumber()); cell.setCellValue(map.get("lastYearNum").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.FIVE.getNumber()); cell.setCellValue(map.get("lastYearNumRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.SIX.getNumber()); cell.setCellValue(map.get("yearNumRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.SEVEN.getNumber()); cell.setCellValue(map.get("minuteTime").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.EIGHT.getNumber()); cell.setCellValue(map.get("timeRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.NINE.getNumber()); cell.setCellValue(map.get("lastYearTime").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.TEN.getNumber()); cell.setCellValue(map.get("lastYearTimeRatio").toString()); cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(UniversalEnum.ELEVEN.getNumber()); cell.setCellValue(map.get("yearTimeRatio").toString()); cell.setCellStyle(dataStyle); rowIndex++; } //合并数据单元格,参数依次为起始行,结束行,起始列,结束列 (从0开始) sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.THREE.getNumber(), UniversalEnum.NINE.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.TEN.getNumber(), UniversalEnum.TEN.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ELEVEN.getNumber(), UniversalEnum.ELEVEN.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.TWELVE.getNumber(), UniversalEnum.TWELVE.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.THIRTEEN.getNumber(), UniversalEnum.THIRTEEN.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber())); sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.FOURTEEN.getNumber(), UniversalEnum.FOURTEEN.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber())); } response.setContentType(UniversalEnum.DERIVE_THE_TWO_WAY_REAL_TIME_TRAFFIC_FLOW_OF_THE_WHOLE_SECTION.getValue()); response.setCharacterEncoding(UniversalEnum.LOWERCASE_UTF_8.getValue()); String fileName = "收费站统计分析列表.xlsx"; response.setHeader("Content-Disposition", "attachment; filename=" + fileName); // 写入文件 try (ServletOutputStream outputStream = response.getOutputStream()){ workbook.write(outputStream); } finally { workbook.close(); } } } /** * @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(); } @ApiOperation(value="导出收费站管制分析",tags = {"ECharts导出"}) @GetMapping("/exportGetTollStationAnalysis") public void exportGetTollStationAnalysis(HttpServletResponse response){ AjaxResult ajaxResult = trafficIncidentsService.getTollStationAnalysis(); List list = new ArrayList<>(); if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { List> data = (List>) ajaxResult.get("data"); for (Map datum : data) { TollStationAnalysis tollStationAnalysis = new TollStationAnalysis(); tollStationAnalysis.setFacilityName(datum.get("facilityName").toString()); tollStationAnalysis.setTrafficClose(datum.get("trafficClose").toString()); tollStationAnalysis.setTrafficRestriction(datum.get("trafficRestriction").toString()); list.add(tollStationAnalysis); } } ExcelUtil util = new ExcelUtil<>(TollStationAnalysis.class); util.exportExcel(response, list, "收费站管制分析"); } /** * @Description 路网管控-事件管控分析-事故多发路段分析 * * @author liuwenge * @date 2024/1/16 15:52 * @param direction 方向 * @param direction 类型(1:日, 2:月, 3:季度, 4-年) * @param direction 时间 * @return com.ruoyi.common.core.domain.AjaxResult */ @ApiOperation("事故多发路段分析") @PostMapping("/selectRoadSectionAnalysis") public AjaxResult selectRoadSectionAnalysis(@ApiParam(value="方向", name="direction", required=true) @RequestParam ("direction") String direction, @ApiParam(value="类型(1:日, 2:月, 3:季度, 4-年)", name="type", required=true) @RequestParam ("type") String type, @ApiParam(value="时间", name="startTime", required=true) @RequestParam ("startTime") String startTime){ return trafficIncidentsService.selectRoadSectionAnalysis(direction,type,startTime); } @ApiOperation(value="导出事故多发路段分析",tags = {"ECharts导出"}) @PostMapping("/exportSelectRoadSectionAnalysis") public void exportSelectRoadSectionAnalysis(HttpServletResponse response, @RequestBody Map params) throws IOException { String direction = params.get("direction"); String type = params.get("type"); String startTime = params.get("startTime"); String fileUrl = params.get("fileUrl"); AjaxResult ajaxResult = trafficIncidentsService.selectRoadSectionAnalysis(direction,type,startTime); List list = new ArrayList<>(); if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { List> data = (List>) ajaxResult.get("data"); for (Map datum : data) { RoadSectionAnalysis roadSectionAnalysis = new RoadSectionAnalysis(); roadSectionAnalysis.setSection_name(datum.get("section_name").toString()); roadSectionAnalysis.setNum(datum.get("num").toString()); roadSectionAnalysis.setAvgNum(datum.get("avgNum").toString()); roadSectionAnalysis.setLastNum(datum.get("lastNum").toString()); roadSectionAnalysis.setMileage(datum.get("mileage").toString()); list.add(roadSectionAnalysis); } } ExcelUtil util = new ExcelUtil<>(RoadSectionAnalysis.class); int commaIndex = fileUrl.indexOf(','); if (commaIndex == -1) { throw new IllegalArgumentException("Invalid Data URL, no comma found to separate base64 data"); } String base64Data = fileUrl.substring(commaIndex + 1); byte[] imageBytes = Base64.getDecoder().decode(base64Data); util.exportImgExcel(response, list, "事故多发路段分析",imageBytes,8,12); } /** * @Description 路网管控-事件管控分析-事故类型分析 * * @author liuwenge * @date 2024/1/16 15:52 * @param direction 方向 * @param direction 类型(1:日, 2:月, 3:季度, 4-年) * @param direction 时间 * @return com.ruoyi.common.core.domain.AjaxResult */ @ApiOperation("事故类型分析") @PostMapping("/selectEventTypeAnalysis") public AjaxResult selectEventTypeAnalysis(@ApiParam(value="方向", name="direction", required=true) @RequestParam ("direction") String direction, @ApiParam(value="类型(1:日, 2:月, 3:季度, 4-年)", name="type", required=true) @RequestParam ("type") String type, @ApiParam(value="时间", name="startTime", required=true) @RequestParam ("startTime") String startTime){ return trafficIncidentsService.selectEventTypeAnalysis(direction,type,startTime); } @ApiOperation(value="导出事故类型分析",tags = {"ECharts导出"}) @PostMapping("/exportSelectEventTypeAnalysis") public void exportSelectEventTypeAnalysis(HttpServletResponse response,@RequestBody Map params) throws IOException { String direction = params.get("direction"); String type = params.get("type"); String startTime = params.get("startTime"); String fileUrl = params.get("fileUrl"); AjaxResult ajaxResult = trafficIncidentsService.selectEventTypeAnalysis(direction,type,startTime); List list = new ArrayList<>(); if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { List> data = (List>) ajaxResult.get("data"); for (Map datum : data) { EventTypeAnalysis eventTypeAnalysis = new EventTypeAnalysis(); eventTypeAnalysis.setEventSubclassName(datum.get("eventSubclassName").toString()); eventTypeAnalysis.setNum(datum.get("num").toString()); eventTypeAnalysis.setLastNum(datum.get("lastNum").toString()); eventTypeAnalysis.setAvgTime(datum.get("avgTime").toString()); eventTypeAnalysis.setLastAvgTime(datum.get("lastAvgTime").toString()); list.add(eventTypeAnalysis); } } ExcelUtil util = new ExcelUtil<>(EventTypeAnalysis.class); int commaIndex = fileUrl.indexOf(','); if (commaIndex == -1) { throw new IllegalArgumentException("Invalid Data URL, no comma found to separate base64 data"); } String base64Data = fileUrl.substring(commaIndex + 1); byte[] imageBytes = Base64.getDecoder().decode(base64Data); util.exportImgExcel(response, list, "事故类型分析",imageBytes,8,12); } //事件时间数量占比 @PostMapping("/selectEventTimeProportion") public AjaxResult selectEventTimeProportion(@RequestBody DcWarning dcWarning){ if (dcWarning==null|| StringUtils.isBlank(dcWarning.getDirection())||StringUtils.isBlank(dcWarning.getType())|| dcWarning.getCurrently()==null||dcWarning.getLastYear()==null){ return AjaxResult.success("参数存在异常"); } Date currently = dcWarning.getCurrently(); Date lastYear = dcWarning.getLastYear(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String formattedDate = sdf.format(currently); String format = sdf.format(lastYear); List> currentlyMap = trafficIncidentsService.selectEventTimeProportion(dcWarning.getDirection(), dcWarning.getType(), formattedDate); List> lastYearMap = trafficIncidentsService.selectEventTimeProportion(dcWarning.getDirection(), dcWarning.getType(), format); HashMap hashMap = new HashMap<>(); hashMap.put("currentlyMap",currentlyMap); hashMap.put("lastYearMap",lastYearMap); return AjaxResult.success(hashMap); } //事件时间数量占比 @PostMapping("/exportSelectEventTimeProportion") public void exportSelectEventTimeProportion(HttpServletResponse response,@RequestBody DcWarning dcWarning) throws IOException { if (dcWarning==null|| StringUtils.isBlank(dcWarning.getDirection())||StringUtils.isBlank(dcWarning.getType())|| dcWarning.getCurrently()==null||dcWarning.getLastYear()==null){ return ; } Date currently = dcWarning.getCurrently(); Date lastYear = dcWarning.getLastYear(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String formattedDate = sdf.format(currently); String format = sdf.format(lastYear); List> currentlyMap = trafficIncidentsService.selectEventTimeProportion(dcWarning.getDirection(), dcWarning.getType(), formattedDate); List> lastYearMap = trafficIncidentsService.selectEventTimeProportion(dcWarning.getDirection(), dcWarning.getType(), format); HashMap hashMap = new HashMap<>(); hashMap.put("currentlyMap",currentlyMap); hashMap.put("lastYearMap",lastYearMap); Set dateKey = new HashSet<>(); String type = dcWarning.getType(); List list = new ArrayList<>(); if ("1".equals(type)){ currentlyMap.forEach(item ->{ dateKey.add(item.get("time").toString()); }); lastYearMap.forEach(item ->{ dateKey.add(item.get("time").toString()); }); //排序 Set sortedDateKey = dateKey.stream() .sorted(Comparator.comparingInt(Integer::parseInt)) .collect(Collectors.toCollection(LinkedHashSet::new)); for (String date : sortedDateKey) { EventTimeProportion eventTimeProportion = new EventTimeProportion(); eventTimeProportion.setTime(date); for (HashMap map : currentlyMap) { if (date.equals(map.get("time").toString())){ eventTimeProportion.setCurrentData(map.get("number").toString()); break; } } for (HashMap map : lastYearMap) { if (date.equals(map.get("time").toString())){ eventTimeProportion.setContemporaneousData(map.get("number").toString()); break; } } list.add(eventTimeProportion); } } else if ("2".equals(type)){ currentlyMap.forEach(item ->{ dateKey.add(item.get("day").toString()); }); lastYearMap.forEach(item ->{ dateKey.add(item.get("day").toString()); }); //排序 Set sortedDateKey = dateKey.stream() .sorted().collect(Collectors.toCollection(LinkedHashSet::new)); for (String date : sortedDateKey) { EventTimeProportion eventTimeProportion = new EventTimeProportion(); eventTimeProportion.setTime(date); for (HashMap map : currentlyMap) { if (date.equals(map.get("day").toString())){ eventTimeProportion.setCurrentData(map.get("num").toString()); break; } } for (HashMap map : lastYearMap) { if (date.equals(map.get("day").toString())){ eventTimeProportion.setContemporaneousData(map.get("num").toString()); break; } } list.add(eventTimeProportion); } } else if ("3".equals(type) || "4".equals(type)){ currentlyMap.forEach(item ->{ dateKey.add(item.get("month").toString()); }); lastYearMap.forEach(item ->{ dateKey.add(item.get("month").toString()); }); //排序 Set sortedDateKey = dateKey.stream() .sorted(Comparator.comparingInt(Integer::parseInt)) .collect(Collectors.toCollection(LinkedHashSet::new)); for (String date : sortedDateKey) { EventTimeProportion eventTimeProportion = new EventTimeProportion(); eventTimeProportion.setTime(date); for (HashMap map : currentlyMap) { if (date.equals(map.get("month").toString())){ eventTimeProportion.setCurrentData(map.get("number").toString()); break; } } for (HashMap map : lastYearMap) { if (date.equals(map.get("month").toString())){ eventTimeProportion.setContemporaneousData(map.get("number").toString()); break; } } list.add(eventTimeProportion); } } ExcelUtil util = new ExcelUtil<>(EventTimeProportion.class); int commaIndex = dcWarning.getFileUrl().indexOf(','); if (commaIndex == -1) { throw new IllegalArgumentException("Invalid Data URL, no comma found to separate base64 data"); } String base64Data = dcWarning.getFileUrl().substring(commaIndex + 1); byte[] imageBytes = Base64.getDecoder().decode(base64Data); util.exportImgExcel(response, list, "事故时间分布",imageBytes,8,12); } }