From d42f11ed37a64e2b76fd5625239565350291cc4d Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Fri, 28 Jun 2024 15:26:51 +0800 Subject: [PATCH] =?UTF-8?q?echasts=E5=AF=BC=E5=87=BA=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DCPerceivedEventsWarningController.java | 24 +- .../DcTrafficStatisticsController.java | 283 +++++++++--------- 2 files changed, 152 insertions(+), 155 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DCPerceivedEventsWarningController.java b/zc-business/src/main/java/com/zc/business/controller/DCPerceivedEventsWarningController.java index 1bc47768..aed69b54 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DCPerceivedEventsWarningController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DCPerceivedEventsWarningController.java @@ -266,11 +266,11 @@ public class DCPerceivedEventsWarningController extends BaseController { */ @ApiOperation(value = "导出感知事件多发时段",tags = {"ECharts导出"}) @GetMapping("/exportManyTimesInterval") - public AjaxResult exportManyTimesInterval(HttpServletResponse response,DcWarning dcWarning){ + public void exportManyTimesInterval(HttpServletResponse response,DcWarning dcWarning){ if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null ||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark()) ||StringUtils.isBlank(dcWarning.getDirection())){ - return AjaxResult.error("参数错误"); + return ; } HashMap map = perceivedEventsWarningService.selectManyTimesInterval(dcWarning); List list = new ArrayList<>(); @@ -289,7 +289,6 @@ public class DCPerceivedEventsWarningController extends BaseController { ExcelUtil util = new ExcelUtil<>(ManyTimesInterval.class); util.exportExcel(response, list, "感知事件多发时段"); - return AjaxResult.success("导出感知事件多发时段成功"); } //新-感知事件类型分析 @@ -304,11 +303,11 @@ public class DCPerceivedEventsWarningController extends BaseController { } @ApiOperation(value = "导出感知事件类型分析",tags = {"ECharts导出"}) @GetMapping("/exportSelectWarningType") - public AjaxResult exportSelectWarningType(HttpServletResponse response,DcWarning dcWarning){ + public void exportSelectWarningType(HttpServletResponse response,DcWarning dcWarning){ if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null ||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark()) ||StringUtils.isBlank(dcWarning.getDirection())){ - return AjaxResult.error("参数错误"); + return; } HashMap map = perceivedEventsWarningService.newSelectWarningType(dcWarning); List list = new ArrayList<>(); @@ -330,7 +329,6 @@ public class DCPerceivedEventsWarningController extends BaseController { ExcelUtil util = new ExcelUtil<>(SelectWarningType.class); util.exportExcel(response, list, "感知事件类型分析"); - return AjaxResult.success("导出感知事件类型分析成功"); } //新-感知事件桩号范围内事件分析 @PostMapping("/selectSection") @@ -345,11 +343,11 @@ public class DCPerceivedEventsWarningController extends BaseController { @ApiOperation(value = "导出桩号范围内事件分析",tags = {"ECharts导出"}) @GetMapping("/exportSelectSection") - public AjaxResult exportSelectSection(HttpServletResponse response,DcWarning dcWarning){ + public void exportSelectSection(HttpServletResponse response,DcWarning dcWarning){ if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null ||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark()) ||StringUtils.isBlank(dcWarning.getDirection())){ - return AjaxResult.error("参数错误"); + return; } HashMap map = perceivedEventsWarningService.newSelectSection(dcWarning); List list = new ArrayList<>(); @@ -376,7 +374,6 @@ public class DCPerceivedEventsWarningController extends BaseController { ExcelUtil util = new ExcelUtil<>(SelectSection.class); util.exportExcel(response, list, "桩号范围内事件分析"); - return AjaxResult.success("导出桩号范围内事件分析成功"); } //新-感知事件路段处置类型分析 @PostMapping("/selectStateType") @@ -388,9 +385,9 @@ public class DCPerceivedEventsWarningController extends BaseController { } @ApiOperation(value = "导出感知事件路段分析",tags = {"ECharts导出"}) @GetMapping("/exportSelectStateType") - public AjaxResult exportSelectStateType(HttpServletResponse response, DcWarning dcWarning){ + public void exportSelectStateType(HttpServletResponse response, DcWarning dcWarning){ if (dcWarning==null||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null){ - return AjaxResult.error("参数错误"); + return; } List list = new ArrayList<>(); @@ -443,7 +440,6 @@ public class DCPerceivedEventsWarningController extends BaseController { ExcelUtil util = new ExcelUtil<>(SelectStateType.class); util.exportExcel(response, list, "感知事件路段分析"); - return AjaxResult.success("导出感知事件路段分析成功"); } //查询感知数量按照路段数量进行排名 @PostMapping("/sectionPerceivedList") @@ -453,7 +449,7 @@ public class DCPerceivedEventsWarningController extends BaseController { @ApiOperation(value = "导出感知事件路段排名",tags = {"ECharts导出"}) @GetMapping("/exportSectionPerceivedList") - public AjaxResult exportSectionPerceivedList(HttpServletResponse response){ + public void exportSectionPerceivedList(HttpServletResponse response){ List> dataList = perceivedEventsWarningService.selectSectionPerceivedEventsList(); List list = new ArrayList<>(); if (dataList != null && dataList.size() > 0){ @@ -467,7 +463,5 @@ public class DCPerceivedEventsWarningController extends BaseController { } ExcelUtil util = new ExcelUtil<>(SectionPerceivedList.class); util.exportExcel(response, list, "感知事件路段排名"); - - return AjaxResult.success("导出感知事件路段排名成功"); } } diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java index 7de250ee..8f493fc2 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java @@ -24,6 +24,7 @@ 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.FileOutputStream; import java.io.IOException; @@ -222,9 +223,9 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String */ @ApiOperation(value="导出全路段车流量状况分析",tags = {"ECharts导出"}) @GetMapping("/history/exportRealTimeTrafficFlow") - public AjaxResult exportRealTimeTrafficFlow(HttpServletResponse response,String startDate, String direction,String periodType ){ + public void exportRealTimeTrafficFlow(HttpServletResponse response,String startDate, String direction,String periodType ){ if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(direction) || StringUtils.isEmpty(periodType)){ - return AjaxResult.error("参数错误"); + return; } String endDate = ""; if ("4".equals(periodType)){ @@ -280,7 +281,6 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String ExcelUtil util = new ExcelUtil<>(RealTimeTrafficFlow.class); util.exportExcel(response, list, "全路段双向实时车流量"); // 将查询结果封装为成功响应并返回 - return AjaxResult.success("导出成功"); } /** * 车流量时段分析 @@ -304,9 +304,9 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String */ @ApiOperation(value="导出车流量时段分析",tags = {"ECharts导出"}) @GetMapping("/history/exportTrafficPeriodAnalysis") - public AjaxResult exportTrafficPeriodAnalysis(HttpServletResponse response,String startDate, String direction,String periodType ){ + public void exportTrafficPeriodAnalysis(HttpServletResponse response,String startDate, String direction,String periodType ){ if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(direction) || StringUtils.isEmpty(periodType)){ - return AjaxResult.error("参数错误"); + return; } String endDate = ""; if ("4".equals(periodType)){ @@ -361,8 +361,6 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String ExcelUtil util = new ExcelUtil<>(TrafficPeriodAnalysis.class); util.exportExcel(response, list, "车流量时段分析"); - // 将查询结果封装为成功响应并返回 - return AjaxResult.success("导出成功"); } @ApiOperation("断面车流量排名") @@ -383,7 +381,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String */ @ApiOperation(value="导出断面车流量排名",tags = {"ECharts导出"}) @GetMapping("/history/exportSectionTrafficRanking") - public AjaxResult exportSectionTrafficRanking(HttpServletResponse response,String startDate, String direction,String periodType ){ + public void exportSectionTrafficRanking(HttpServletResponse response,String startDate, String direction,String periodType ){ List list = new ArrayList<>(); List> dcStatisticsData = dcGantryStatisticsDataService.sectionTrafficRanking(startDate,direction,periodType); for (int i = 0; i < dcStatisticsData.size(); i++) { @@ -396,8 +394,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String ExcelUtil util = new ExcelUtil<>(SectionTrafficRanking.class); util.exportExcel(response, list, "断面车流量排名"); - // 将查询结果封装为成功响应并返回 - return AjaxResult.success("导出成功"); + } /** @@ -418,7 +415,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String @ApiOperation(value="导出路段交通指标分析",tags = {"ECharts导出"}) @GetMapping("/history/exportSectionTrafficIndexAnalysis") - public AjaxResult exportSectionTrafficIndexAnalysis(HttpServletResponse response,String startDate, String direction,String periodType,Long ranking){ + public void exportSectionTrafficIndexAnalysis(HttpServletResponse response,String startDate, String direction,String periodType,Long ranking){ List list = new ArrayList<>(); String endDate = ""; @@ -482,7 +479,6 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String ExcelUtil util = new ExcelUtil<>(SectionTrafficIndexAnalysis.class); util.exportExcel(response, list, "路段交通指标分析"); // 将查询结果封装为成功响应并返回 - return AjaxResult.success("导出成功"); } @ApiOperation("通指标时间分布") @@ -670,133 +666,140 @@ public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endD /** * 导出全路段双向实时车流量 */ -// @ApiOperation(value = "导出全路段双向实时车流量",tags = {"ECharts导出"}) -// @GetMapping("/history/exportRealTimeTrafficFlowHour") -// public AjaxResult exportRealTimeTrafficFlowHour(HttpServletResponse response) throws IOException, HttpException { -// -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); -// LocalDate currentDate = LocalDate.now(); -// String now = currentDate.format(formatter); -// -// // 获取一年前的日期 -// LocalDate oneYearAgo = currentDate.minusYears(1); -// String lastYear = oneYearAgo.format(formatter); -// -// List> thisYearHZ = dcTrafficStatisticsService.realTimeTrafficFlowHour(now,1L); -// List> thisYearJN = dcTrafficStatisticsService.realTimeTrafficFlowHour(now,3L); -// List> lastYearHZ = dcTrafficStatisticsService.realTimeTrafficFlowHour(lastYear,1L); -// List> lastYearJN = dcTrafficStatisticsService.realTimeTrafficFlowHour(lastYear,3L); -// -// Workbook workbook = new XSSFWorkbook(); // 创建工作簿 -// Sheet sheet = workbook.createSheet("全路段双向实时车流量"); // 创建工作表 -// -// // 创建数据行样式 -// 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("Arial"); -// dataFont.setFontHeightInPoints((short) 10); -// 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); -// Font headerFont = workbook.createFont(); -// headerFont.setFontName("Arial"); -// headerFont.setFontHeightInPoints((short) 10); -// headerFont.setBold(true); -// headerFont.setColor(IndexedColors.WHITE.getIndex()); -// headerStyle.setFont(headerFont); -// -// // 添加第一层级表头 -// Row row = sheet.createRow(0); -// Cell cell = row.createCell(0); -// cell.setCellValue("路段名称"); -// cell.setCellStyle(headerStyle); -// cell = row.createCell(1); -// cell.setCellValue("济南方向"); -// cell.setCellStyle(headerStyle); -// cell = row.createCell(2); -// cell.setCellValue(""); -// cell.setCellStyle(headerStyle);; -// cell = row.createCell(3); -// cell.setCellValue("菏泽方向"); -// cell.setCellStyle(headerStyle); -// cell = row.createCell(4); -// cell.setCellValue(""); -// cell.setCellStyle(headerStyle); -// -// // 添加第二层级表头(与第一层级对齐) -// Row subHeaderRow1 = sheet.createRow(1); -// cell = subHeaderRow1.createCell(0); -// cell.setCellValue(""); -// cell.setCellStyle(headerStyle); -// cell = subHeaderRow1.createCell(1); -// cell.setCellValue("本期车流量"); -// cell.setCellStyle(headerStyle); -// -// cell = subHeaderRow1.createCell(2); -// cell.setCellValue("去年同期"); -// cell.setCellStyle(headerStyle); -// cell = subHeaderRow1.createCell(3); -// cell.setCellValue("本期车流量"); -// cell.setCellStyle(headerStyle); -// -// cell = subHeaderRow1.createCell(4); -// cell.setCellValue("去年同期"); -// cell.setCellStyle(headerStyle); -// -// //合并单元格,参数依次为起始行,结束行,起始列,结束列 (从0开始) -// //路段名称 -// sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0)); -// //济南方向 -// sheet.addMergedRegion(new CellRangeAddress(0, 0, 1, 2)); -// //菏泽方向 -// sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 4)); -// -// for (int i = 0; i < thisYearHZ.size(); i++) { -// Row subHeaderRow = sheet.createRow(i+2); -// cell = subHeaderRow.createCell(0); -// cell.setCellValue(thisYearJN.get(i).get("name").toString()); -// cell.setCellStyle(dataStyle); -// cell = subHeaderRow.createCell(1); -// cell.setCellValue(thisYearJN.get(i).get("totalFlow").toString()); -// cell.setCellStyle(dataStyle); -// cell = subHeaderRow.createCell(2); -// cell.setCellValue(lastYearJN.get(i).get("totalFlow").toString()); -// cell.setCellStyle(dataStyle); -// cell = subHeaderRow.createCell(3); -// cell.setCellValue(thisYearHZ.get(i).get("totalFlow").toString()); -// cell.setCellStyle(dataStyle); -// cell = subHeaderRow.createCell(4); -// cell.setCellValue(lastYearHZ.get(i).get("totalFlow").toString()); -// cell.setCellStyle(dataStyle); -// } -// -// -// // 写入文件 -// try { -// response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); -// response.setCharacterEncoding("utf-8"); -// workbook.write(response.getOutputStream()); -// } finally { -// workbook.close(); -// } -// -// return AjaxResult.success("导出感知事件多发时段成功"); -// } + @ApiOperation(value = "导出全路段双向实时车流量",tags = {"ECharts导出"}) + @GetMapping("/history/exportRealTimeTrafficFlowHour") + public void exportRealTimeTrafficFlowHour(HttpServletResponse response) throws IOException, HttpException { + + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String fileName = "全路段双向实时车流量.xlsx"; + response.setHeader("Content-Disposition", "attachment; filename=" + fileName); + + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate currentDate = LocalDate.now(); + String now = currentDate.format(formatter); + + // 获取一年前的日期 + LocalDate oneYearAgo = currentDate.minusYears(1); + String lastYear = oneYearAgo.format(formatter); + + Map>> map = dcTrafficStatisticsService.realTimeTrafficFlowHour(); + if (map != null){ + List> thisYearHZ = map.get("1"); + List> thisYearJN = map.get("2"); + List> lastYearHZ = map.get("3"); + List> lastYearJN = map.get("4"); + + XSSFWorkbook workbook = new XSSFWorkbook(); // 创建工作簿 + Sheet sheet = workbook.createSheet("全路段双向实时车流量"); // 创建工作表 + + // 创建数据行样式 + 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("Arial"); + dataFont.setFontHeightInPoints((short) 10); + 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); + Font headerFont = workbook.createFont(); + headerFont.setFontName("Arial"); + headerFont.setFontHeightInPoints((short) 10); + headerFont.setBold(true); + headerFont.setColor(IndexedColors.WHITE.getIndex()); + headerStyle.setFont(headerFont); + + // 添加第一层级表头 + Row row = sheet.createRow(0); + Cell cell = row.createCell(0); + cell.setCellValue("路段名称"); + cell.setCellStyle(headerStyle); + cell = row.createCell(1); + cell.setCellValue("济南方向"); + cell.setCellStyle(headerStyle); + cell = row.createCell(2); + cell.setCellValue(""); + cell.setCellStyle(headerStyle);; + cell = row.createCell(3); + cell.setCellValue("菏泽方向"); + cell.setCellStyle(headerStyle); + cell = row.createCell(4); + cell.setCellValue(""); + cell.setCellStyle(headerStyle); + + // 添加第二层级表头(与第一层级对齐) + Row subHeaderRow1 = sheet.createRow(1); + cell = subHeaderRow1.createCell(0); + cell.setCellValue(""); + cell.setCellStyle(headerStyle); + cell = subHeaderRow1.createCell(1); + cell.setCellValue("本期车流量"); + cell.setCellStyle(headerStyle); + + cell = subHeaderRow1.createCell(2); + cell.setCellValue("去年同期"); + cell.setCellStyle(headerStyle); + cell = subHeaderRow1.createCell(3); + cell.setCellValue("本期车流量"); + cell.setCellStyle(headerStyle); + + cell = subHeaderRow1.createCell(4); + cell.setCellValue("去年同期"); + cell.setCellStyle(headerStyle); + + //合并单元格,参数依次为起始行,结束行,起始列,结束列 (从0开始) + //路段名称 + sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0)); + //济南方向 + sheet.addMergedRegion(new CellRangeAddress(0, 0, 1, 2)); + //菏泽方向 + sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 4)); + + for (int i = 0; i < thisYearHZ.size(); i++) { + Row subHeaderRow = sheet.createRow(i+2); + cell = subHeaderRow.createCell(0); + cell.setCellValue(thisYearJN.get(i).get("name").toString()); + cell.setCellStyle(dataStyle); + cell = subHeaderRow.createCell(1); + cell.setCellValue(thisYearJN.get(i).get("totalFlow").toString()); + cell.setCellStyle(dataStyle); + cell = subHeaderRow.createCell(2); + cell.setCellValue(lastYearJN.get(i).get("totalFlow").toString()); + cell.setCellStyle(dataStyle); + cell = subHeaderRow.createCell(3); + cell.setCellValue(thisYearHZ.get(i).get("totalFlow").toString()); + cell.setCellStyle(dataStyle); + cell = subHeaderRow.createCell(4); + cell.setCellValue(lastYearHZ.get(i).get("totalFlow").toString()); + cell.setCellStyle(dataStyle); + } + + + // 写入文件 + try (ServletOutputStream outputStream = response.getOutputStream()){ + workbook.write(outputStream); + } finally { + workbook.close(); + } + + } + + } } \ No newline at end of file