|
|
@ -20,11 +20,16 @@ import com.zc.business.service.*; |
|
|
|
import com.zc.common.core.httpclient.exception.HttpException; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
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.http.HttpServletResponse; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
@ -587,4 +592,136 @@ public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endD |
|
|
|
return AjaxResult.success(mapList); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导出全路段双向实时车流量 |
|
|
|
*/ |
|
|
|
@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<Map<String,Object>> thisYearHZ = dcTrafficStatisticsService.realTimeTrafficFlowHour(now,1L); |
|
|
|
List<Map<String,Object>> thisYearJN = dcTrafficStatisticsService.realTimeTrafficFlowHour(now,3L); |
|
|
|
List<Map<String,Object>> lastYearHZ = dcTrafficStatisticsService.realTimeTrafficFlowHour(lastYear,1L); |
|
|
|
List<Map<String,Object>> 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("导出感知事件多发时段成功"); |
|
|
|
} |
|
|
|
|
|
|
|
} |