You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1392 lines
73 KiB
1392 lines
73 KiB
package com.zc.business.controller;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.ruoyi.common.annotation.Log;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
import com.ruoyi.common.utils.StakeMarkUtils;
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
import com.zc.business.domain.*;
|
|
import com.zc.business.domain.export.*;
|
|
import com.zc.business.enums.LocationEnum;
|
|
import com.zc.business.enums.StakeMarkRange;
|
|
import com.zc.business.enums.UniversalEnum;
|
|
import com.zc.business.request.DcTrafficMetricsDataRequest;
|
|
import com.zc.business.request.DcTrafficSectionDataRequest;
|
|
import com.zc.business.service.*;
|
|
import com.zc.business.service.impl.DcNoStakeWarningTableServiceImpl;
|
|
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.stereotype.Component;
|
|
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.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalTime;
|
|
import java.time.ZoneId;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
* 交通数据统计
|
|
*
|
|
* @author xiepufeng
|
|
*/
|
|
@Component
|
|
@Api(tags = "交通数据统计")
|
|
@RestController
|
|
@RequestMapping("/business/traffic-statistics")
|
|
public class DcTrafficStatisticsController extends BaseController {
|
|
|
|
@Autowired
|
|
private IDcTrafficSectionStatisticsService dcTrafficSectionStatisticsService;
|
|
|
|
@Autowired
|
|
private IDcTrafficStatisticsService dcTrafficStatisticsService;
|
|
|
|
@Autowired
|
|
private IDcTollStationStatisticsDataService dcTollStationStatisticsDataService;
|
|
|
|
@Autowired
|
|
private IDcGantryStatisticsDataService dcGantryStatisticsDataService;
|
|
|
|
@Autowired
|
|
private IDcGantryMetricsStatisticsDataService dcGantryMetricsStatisticsDataService;
|
|
|
|
public void TrafficFlowAnomalies() throws HttpException {
|
|
IDcTrafficStatisticsService ben = SpringUtils.getBean(IDcTrafficStatisticsService.class);
|
|
DcNoStakeWarningTableServiceImpl dcNoStakeWarningTableService = SpringUtils.getBean(DcNoStakeWarningTableServiceImpl.class);
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
LocalDate date = LocalDate.now();
|
|
// 获取一天的开始时间
|
|
LocalDateTime startOfDay = LocalDateTime.of(date, LocalTime.MIN);
|
|
// 获取一天的结束时间
|
|
LocalDateTime endOfDay = LocalDateTime.of(date, LocalTime.of(23, 59, 59));
|
|
|
|
// 格式化为字符串
|
|
String startOfDayStr = startOfDay.format(formatter);
|
|
String endOfDayStr = endOfDay.format(formatter);
|
|
JSONArray mapList = ben.exampleQueryTrafficFlowAnomalies(startOfDayStr, endOfDayStr);
|
|
mapList.forEach(item -> {
|
|
// 设置时区
|
|
ZoneId zoneId = ZoneId.of("Asia/Shanghai");
|
|
|
|
Map<String, Object> map = (Map<String, Object>) item;
|
|
long occur_time = (long) map.get("occur_time");
|
|
long end_time = (long) map.get("end_time");
|
|
// 创建一个SimpleDateFormat对象,定义你想要的日期格式
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
// 使用Date对象将时间戳转换为日期
|
|
Date date2 = new Date(occur_time);
|
|
Date date3 = new Date(end_time);
|
|
// 将Date对象格式化为字符串
|
|
String occurTime = sdf.format(date2);
|
|
String endTime = sdf.format(date3);
|
|
|
|
|
|
String stakeNum = (String) map.get("opma_stake_num");
|
|
int direction = (int) map.get("direction");
|
|
DcNoStakeWarningTable dcNoStakeWarningTable = new DcNoStakeWarningTable();
|
|
String description = direction == 1 ? "菏泽方向" : "济南方向";
|
|
dcNoStakeWarningTable.setWarningDescription(occurTime + " " + stakeNum + " " + description + "发生交通流异常事件");
|
|
dcNoStakeWarningTable.setWarningType("3");
|
|
Date warningTime = getDate(occurTime, formatter);// 获取开始时间
|
|
dcNoStakeWarningTable.setWarningTime(warningTime);
|
|
List<DcNoStakeWarningTable> dcNoStakeWarningTables = dcNoStakeWarningTableService.listDcNoStakeWarningTable(dcNoStakeWarningTable, getDate(endOfDayStr, formatter), getDate(startOfDayStr, formatter));
|
|
if (dcNoStakeWarningTables.isEmpty()) {
|
|
dcNoStakeWarningTableService.addDcNoStakeWarningTable(dcNoStakeWarningTable);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private static Date getDate(String occurTime, DateTimeFormatter formatter) {
|
|
// 解析字符串为 LocalDateTime
|
|
LocalDateTime localDateTime = LocalDateTime.parse(occurTime, formatter);
|
|
// 转换为 Date 对象
|
|
Date warningTime = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
return warningTime;
|
|
}
|
|
|
|
/**
|
|
* 获取当前交通截面数据
|
|
*
|
|
* @param request 请求参数,封装了对于交通截面数据查询的详细要求
|
|
* @return 返回一个AjaxResult对象,其中包含了查询结果。如果查询成功,则结果中封装了当前交通截面的数据(DcTrafficSectionData类型)
|
|
*/
|
|
@ApiOperation("获取当前交通截面数据")
|
|
@GetMapping("/current/sections")
|
|
public AjaxResult currentSections(DcTrafficSectionDataRequest request) {
|
|
// 调用服务层方法,查询当前交通截面数据
|
|
List<DcTrafficSectionData> dcTrafficMetricsData = dcTrafficSectionStatisticsService.currentSections(request);
|
|
// 将查询结果封装为AjaxResult对象返回
|
|
return AjaxResult.success(dcTrafficMetricsData);
|
|
}
|
|
|
|
/**
|
|
* 获取历史交通截面数据
|
|
*
|
|
* @param request 包含交通截面数据请求参数的对象
|
|
* @return 返回一个包含历史交通截面数据的AjaxResult对象
|
|
*/
|
|
@ApiOperation("获取历史交通截面数据")
|
|
@GetMapping("/history/sections")
|
|
public AjaxResult historySections(DcTrafficSectionDataRequest request) {
|
|
// 调用服务层方法,获取历史交通截面的统计数据
|
|
List<DcTrafficSectionData> dcTrafficMetricsData = dcTrafficSectionStatisticsService.historySections(request);
|
|
// 将获取到的历史交通截面数据封装成AjaxResult对象并返回
|
|
return AjaxResult.success(dcTrafficMetricsData);
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取当前交通特征指数
|
|
*
|
|
* @param request 请求参数,封装了获取交通指标所需的数据和条件
|
|
* @return 返回当前交通特征指数的数据结果,使用AjaxResult包装
|
|
*/
|
|
@ApiOperation("获取当前交通特征指数")
|
|
@GetMapping("/current/metrics")
|
|
public AjaxResult currentTrafficMetrics(DcTrafficMetricsDataRequest request) {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
List<DcTrafficMetricsData> dcTrafficMetricsData = dcTrafficSectionStatisticsService.currentTrafficMetrics(request);
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(dcTrafficMetricsData);
|
|
}
|
|
|
|
/**
|
|
* 获取历史交通特征指数
|
|
*
|
|
* @param request 请求参数,包含需要查询的历史交通特征指数的详细信息
|
|
* @return 返回一个AjaxResult对象,其中包含了查询结果的成功状态和历史交通特征指数数据列表
|
|
*/
|
|
@ApiOperation("获取历史交通特征指数")
|
|
@GetMapping("/history/metrics")
|
|
public AjaxResult historyTrafficMetrics(DcTrafficMetricsDataRequest request) {
|
|
// 调用服务层方法,查询历史交通特征指数数据
|
|
List<DcTrafficMetricsData> dcTrafficMetricsDataList = dcTrafficSectionStatisticsService.historyTrafficMetrics(request);
|
|
// 将查询结果封装成成功响应并返回
|
|
return AjaxResult.success(dcTrafficMetricsDataList);
|
|
}
|
|
|
|
/**
|
|
* 获取当前拥堵路段
|
|
*
|
|
* @param direction 交通方向,指定查询哪个方向的拥堵路段。具体方向的定义根据实际业务而定。
|
|
* @return 返回一个AjaxResult对象,其中包含了查询结果。如果查询成功,则结果中封装了当前拥堵路段的数据列表。
|
|
*/
|
|
@ApiOperation("获取当前拥堵路段")
|
|
@GetMapping("/current/congested")
|
|
public AjaxResult currentCongestedSection(Byte direction) {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
List<DcCongestedSectionData> dcTrafficMetricsData = dcTrafficSectionStatisticsService.currentCongestedSection(direction);
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(dcTrafficMetricsData);
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取收费站统计数据
|
|
*
|
|
* @param request 包含查询条件的请求对象,用于筛选历史收费站统计数据
|
|
* @return 返回一个AjaxResult对象,其中包含了查询到的收费站统计数据列表
|
|
*/
|
|
@ApiOperation("获取收费站统计数据")
|
|
@GetMapping("/history/toll-station")
|
|
public AjaxResult historyTollStation(DcTollStationStatisticsData request) {
|
|
// 调用服务层方法,根据请求条件查询历史车收费站数据
|
|
List<DcTollStationStatisticsData> dcStatisticsData = dcTollStationStatisticsDataService.tollStationData(request);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(dcStatisticsData);
|
|
}
|
|
|
|
/**
|
|
* 获取累计车流量
|
|
*
|
|
* @param request 包含查询条件的请求对象,用于筛选历史收费站统计数据
|
|
* @return 返回一个AjaxResult对象,其中包含了查询到的收费站统计数据列表
|
|
*/
|
|
@ApiOperation("获取累计车流量")
|
|
@GetMapping("/history/accumulated-flow")
|
|
public AjaxResult accumulatedFlow(DcTollStationStatisticsData request) {
|
|
// 调用服务层方法,根据请求条件查询历史车收费站数据
|
|
List<DcTollStationStatisticsData> dcStatisticsData = dcTollStationStatisticsDataService.accumulatedFlow(request);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(dcStatisticsData);
|
|
}
|
|
|
|
/**
|
|
* 获取门架统计数据
|
|
*
|
|
* @param request 包含查询条件的请求对象,用于筛选历史门架统计数据
|
|
* @return 返回一个AjaxResult对象,其中包含了查询到的门架统计数据列表
|
|
*/
|
|
@ApiOperation("获取门架统计数据")
|
|
@GetMapping("/history/gantry")
|
|
public AjaxResult historyGantryData(DcGantryStatisticsData request) {
|
|
// 调用服务层方法,根据请求条件查询历史车门架数据
|
|
List<DcGantryStatisticsData> dcStatisticsData = dcGantryStatisticsDataService.gantryData(request);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(dcStatisticsData);
|
|
}
|
|
|
|
/**
|
|
* 交通流统计 列表
|
|
*
|
|
* @param startDate
|
|
* @param endDate
|
|
* @param direction
|
|
* @param periodType
|
|
* @return
|
|
*/
|
|
@ApiOperation("交通流统计")
|
|
@GetMapping("/history/trafficFlowStatistics")
|
|
public TableDataInfo trafficFlowStatistics(String startDate, String endDate, String direction, String periodType) {
|
|
startPage();
|
|
List<Map<String, String>> mapList = dcGantryStatisticsDataService.trafficFlowStatistics(startDate, endDate, direction, periodType);
|
|
// 将查询结果封装为成功响应并返回
|
|
return getDataTable(mapList);
|
|
}
|
|
|
|
|
|
/**
|
|
* 全路段双向实时车流量
|
|
*
|
|
* @param startDate 时间
|
|
* @param direction 方向
|
|
* @param periodType 时间粒子
|
|
*/
|
|
@ApiOperation("全路段车流量状况分析")
|
|
@GetMapping("/history/realTimeTrafficFlow")
|
|
public AjaxResult realTimeTrafficFlow(String startDate, String direction, String periodType) {
|
|
List<Map<String, String>> mapList = dcGantryStatisticsDataService.realTimeTrafficFlow(startDate, direction, periodType);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(mapList);
|
|
}
|
|
|
|
/**
|
|
* 导出全路段双向实时车流量
|
|
*
|
|
* @param startDate 时间
|
|
* @param direction 方向
|
|
* @param periodType 时间粒子
|
|
*/
|
|
@ApiOperation(value = "导出全路段车流量状况分析", tags = {"ECharts导出"})
|
|
@PostMapping("/history/exportRealTimeTrafficFlow")
|
|
public void exportRealTimeTrafficFlow(HttpServletResponse response,@RequestBody Map<String,String> params) throws IOException {
|
|
String startDate = params.get("startDate");
|
|
String direction = params.get("direction");
|
|
String periodType = params.get("periodType");
|
|
String fileUrl = params.get("fileUrl");
|
|
if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(direction) || StringUtils.isEmpty(periodType)) {
|
|
return;
|
|
}
|
|
String endDate = UniversalEnum.EMPTY_STRING.getValue();
|
|
if (UniversalEnum.FOUR.getValue().equals(periodType)) {
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue());
|
|
LocalDate inputDate = LocalDate.parse(startDate, formatter);
|
|
// 获取一年前的日期
|
|
LocalDate end = inputDate.minusYears(UniversalEnum.ONE.getNumber());
|
|
endDate = end.format(formatter);
|
|
} else if (UniversalEnum.THREE.getValue().equals(periodType)) {
|
|
String[] parts = startDate.split(UniversalEnum.SHORT_BAR.getValue());
|
|
int year = Integer.parseInt(parts[UniversalEnum.ZERO.getNumber()]);
|
|
int month = Integer.parseInt(parts[UniversalEnum.ONE.getNumber()]);
|
|
|
|
// 计算一年前的年份和月份
|
|
year -= UniversalEnum.ONE.getNumber();
|
|
// 如果计算后月份为0,则调整为上一年的12月
|
|
if (month == UniversalEnum.ZERO.getNumber()) {
|
|
year -= UniversalEnum.ONE.getNumber();
|
|
month = UniversalEnum.TWELVE.getNumber();
|
|
}
|
|
endDate = String.format("%04d-%02d", year, month);
|
|
} else if (UniversalEnum.ONE.getValue().equals(periodType)) {
|
|
int year = Integer.parseInt(startDate) - UniversalEnum.ONE.getNumber();
|
|
endDate = String.valueOf(year);
|
|
}
|
|
|
|
|
|
List<RealTimeTrafficFlow> list = new ArrayList<>();
|
|
List<Map<String, String>> mapList = dcGantryStatisticsDataService.realTimeTrafficFlow(startDate, direction, periodType);
|
|
List<Map<String, String>> lastList = dcGantryStatisticsDataService.realTimeTrafficFlow(endDate, direction, periodType);
|
|
mapList = mapList.stream().sorted(
|
|
Comparator.comparing(map -> {
|
|
String stakeMark = map.get("stake_make");
|
|
return StakeMarkUtils.formatMetre(stakeMark);
|
|
}))
|
|
.collect(Collectors.toList());
|
|
lastList = lastList.stream().sorted(
|
|
Comparator.comparing(map -> {
|
|
String stakeMark = map.get("stake_make");
|
|
return StakeMarkUtils.formatMetre(stakeMark);
|
|
}))
|
|
.collect(Collectors.toList());
|
|
for (int i = 0; i < mapList.size(); i++) {
|
|
RealTimeTrafficFlow realTimeTrafficFlow = new RealTimeTrafficFlow();
|
|
realTimeTrafficFlow.setName(mapList.get(i).get("name"));
|
|
realTimeTrafficFlow.setTotalPassengerFlow(String.valueOf(mapList.get(i).get("totalPassengerFlow")));
|
|
realTimeTrafficFlow.setTypeSpecialVehicleFlow(String.valueOf(mapList.get(i).get("typeSpecialVehicleFlow")));
|
|
realTimeTrafficFlow.setTypeTruckFlow(String.valueOf(mapList.get(i).get("typeTruckFlow")));
|
|
realTimeTrafficFlow.setLastYearTotal(String.valueOf(lastList.get(i).get("volume")));
|
|
list.add(realTimeTrafficFlow);
|
|
}
|
|
|
|
ExcelUtil<RealTimeTrafficFlow> util = new ExcelUtil<>(RealTimeTrafficFlow.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, UniversalEnum.THE_WHOLE_SECTION_TWO_WAY_REAL_TIME_TRAFFIC_FLOW.getValue(),imageBytes,5,12);
|
|
// 将查询结果封装为成功响应并返回
|
|
}
|
|
|
|
/**
|
|
* 车流量时段分析
|
|
*
|
|
* @param startDate 时间
|
|
* @param direction 方向
|
|
* @param periodType 时间粒子
|
|
*/
|
|
@ApiOperation("车流量时段分析")
|
|
@GetMapping("/history/trafficPeriodAnalysis")
|
|
public AjaxResult trafficPeriodAnalysis(String startDate, String direction, String periodType) {
|
|
List<Map<String, String>> mapList = dcGantryStatisticsDataService.trafficPeriodAnalysis(startDate, direction, periodType);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(mapList);
|
|
}
|
|
|
|
/**
|
|
* 车流量异常事件流量查询
|
|
*
|
|
* @param eventId 事件id
|
|
*/
|
|
@ApiOperation("车流量异常事件流量查询")
|
|
@GetMapping("/history/eventtrafficflowcnt")
|
|
public AjaxResult eventtrafficflowcnt(String eventId) throws HttpException {
|
|
JSONArray mapList = dcTrafficStatisticsService.eventtrafficflowcnt(eventId);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(mapList);
|
|
}
|
|
|
|
/**
|
|
* 交通流统计分析重点数据查询交通流异常信息
|
|
*/
|
|
@ApiOperation("交通流统计分析重点数据查询交通流异常信息")
|
|
@GetMapping("/history/exampleQueryTrafficFlowAnomalies")
|
|
public AjaxResult exampleQueryTrafficFlowAnomalies(String startTime, String endTime) throws HttpException {
|
|
JSONArray mapList = dcTrafficStatisticsService.exampleQueryTrafficFlowAnomalies(startTime, endTime);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(mapList);
|
|
}
|
|
|
|
/**
|
|
* 导出车流量时段分析
|
|
*
|
|
* @param startDate 时间
|
|
* @param direction 方向
|
|
* @param periodType 时间粒子
|
|
*/
|
|
@ApiOperation(value = "导出车流量时段分析", tags = {"ECharts导出"})
|
|
@PostMapping("/history/exportTrafficPeriodAnalysis")
|
|
public void exportTrafficPeriodAnalysis(HttpServletResponse response,@RequestBody Map<String,String> params) throws IOException {
|
|
String startDate = params.get("startDate");
|
|
String direction = params.get("direction");
|
|
String periodType = params.get("periodType");
|
|
String fileUrl = params.get("fileUrl");
|
|
if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(direction) || StringUtils.isEmpty(periodType)) {
|
|
return;
|
|
}
|
|
String endDate = UniversalEnum.EMPTY_STRING.getValue();
|
|
if (UniversalEnum.FOUR.getValue().equals(periodType)) {
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue());
|
|
LocalDate inputDate = LocalDate.parse(startDate, formatter);
|
|
// 获取一年前的日期
|
|
LocalDate end = inputDate.minusYears(1);
|
|
endDate = end.format(formatter);
|
|
} else if (UniversalEnum.THREE.getValue().equals(periodType)) {
|
|
String[] parts = startDate.split(UniversalEnum.SHORT_BAR.getValue());
|
|
int year = Integer.parseInt(parts[UniversalEnum.ZERO.getNumber()]);
|
|
int month = Integer.parseInt(parts[UniversalEnum.ONE.getNumber()]);
|
|
|
|
// 计算一年前的年份和月份
|
|
year -= UniversalEnum.ONE.getNumber();
|
|
// 如果计算后月份为0,则调整为上一年的12月
|
|
if (month == UniversalEnum.ZERO.getNumber()) {
|
|
year -= UniversalEnum.ONE.getNumber();
|
|
month = UniversalEnum.TWELVE.getNumber();
|
|
}
|
|
endDate = String.format("%04d-%02d", year, month);
|
|
} else if (UniversalEnum.ONE.getValue().equals(periodType)) {
|
|
int year = Integer.parseInt(startDate) - UniversalEnum.ONE.getNumber();
|
|
endDate = String.valueOf(year);
|
|
}
|
|
|
|
|
|
List<TrafficPeriodAnalysis> list = new ArrayList<>();
|
|
List<Map<String, String>> mapList = dcGantryStatisticsDataService.trafficPeriodAnalysis(startDate, direction, periodType);
|
|
Map<String, String> mapData = new HashMap<>();
|
|
if (mapList != null && mapList.size() > UniversalEnum.ZERO.getNumber()) {
|
|
for (Map<String, String> item : mapList) {
|
|
mapData.put(item.get("statisticalHour"), item.get("trafficVolume"));
|
|
}
|
|
}
|
|
List<Map<String, String>> lastList = dcGantryStatisticsDataService.trafficPeriodAnalysis(endDate, direction, periodType);
|
|
Map<String, String> lastData = new HashMap<>();
|
|
if (lastList != null && lastList.size() > UniversalEnum.ZERO.getNumber()) {
|
|
for (Map<String, String> item : lastList) {
|
|
lastData.put(item.get("statisticalHour"), item.get("trafficVolume"));
|
|
}
|
|
}
|
|
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < UniversalEnum.TWENTY_FOUR.getNumber(); i++) {
|
|
TrafficPeriodAnalysis trafficPeriodAnalysis = new TrafficPeriodAnalysis();
|
|
trafficPeriodAnalysis.setTime(i + "点至" + (i + UniversalEnum.ONE.getNumber()) + "点");
|
|
trafficPeriodAnalysis.setCurrentData(mapData.getOrDefault(String.valueOf(i), UniversalEnum.ZERO.getValue()));
|
|
|
|
trafficPeriodAnalysis.setContemporaneousData(lastData.getOrDefault(String.valueOf(i), UniversalEnum.ZERO.getValue()));
|
|
list.add(trafficPeriodAnalysis);
|
|
}
|
|
|
|
ExcelUtil<TrafficPeriodAnalysis> util = new ExcelUtil<>(TrafficPeriodAnalysis.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, UniversalEnum.TRAFFIC_PERIOD_ANALYSIS.getValue(),imageBytes,5,12);
|
|
}
|
|
|
|
@ApiOperation("断面车流量排名")
|
|
@GetMapping("/history/sectionTrafficRanking")
|
|
public AjaxResult sectionTrafficRanking(String startDate, String direction, String periodType) {
|
|
List<Map<String, String>> dcStatisticsData = dcGantryStatisticsDataService.sectionTrafficRanking(startDate, direction, periodType);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(dcStatisticsData);
|
|
}
|
|
|
|
|
|
/**
|
|
* 导出断面车流量排名
|
|
*
|
|
* @param startDate 时间
|
|
* @param direction 方向
|
|
* @param periodType 时间粒子
|
|
*/
|
|
@ApiOperation(value = "导出断面车流量排名", tags = {"ECharts导出"})
|
|
@PostMapping("/history/exportSectionTrafficRanking")
|
|
public void exportSectionTrafficRanking(HttpServletResponse response,@RequestBody Map<String,String> params) throws IOException {
|
|
String startDate = params.get("startDate");
|
|
String direction = params.get("direction");
|
|
String periodType = params.get("periodType");
|
|
String fileUrl = params.get("fileUrl");
|
|
List<SectionTrafficRanking> list = new ArrayList<>();
|
|
List<Map<String, String>> dcStatisticsData = dcGantryStatisticsDataService.sectionTrafficRanking(startDate, direction, periodType);
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < dcStatisticsData.size(); i++) {
|
|
SectionTrafficRanking sectionTrafficRanking = new SectionTrafficRanking();
|
|
sectionTrafficRanking.setRank(i + UniversalEnum.ONE.getNumber());
|
|
sectionTrafficRanking.setFacilityName(dcStatisticsData.get(i).get("facilityName"));
|
|
sectionTrafficRanking.setNumber(String.valueOf(dcStatisticsData.get(i).get("trafficVolume")));
|
|
list.add(sectionTrafficRanking);
|
|
}
|
|
|
|
ExcelUtil<SectionTrafficRanking> util = new ExcelUtil<>(SectionTrafficRanking.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, UniversalEnum.SECTION_TRAFFIC_RANKING.getValue(),imageBytes,3,28);
|
|
|
|
}
|
|
|
|
/**
|
|
* sectionTrafficIndexAnalysis
|
|
*
|
|
* @param startDate 时间
|
|
* @param direction 方向
|
|
* @param periodType 时间粒子
|
|
* @param ranking 排名 1 饱和度 2拥挤度 3交通特征指数
|
|
*/
|
|
@ApiOperation("路段交通指标分析")
|
|
@GetMapping("/history/sectionTrafficIndexAnalysis")
|
|
public AjaxResult sectionTrafficIndexAnalysis(String startDate, String direction, String periodType, Long ranking) {
|
|
List<Map<String, Object>> mapList = dcGantryMetricsStatisticsDataService.sectionTrafficIndexAnalysis(startDate, direction, periodType, ranking);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(mapList);
|
|
}
|
|
|
|
@ApiOperation(value = "导出路段交通指标分析", tags = {"ECharts导出"})
|
|
@PostMapping("/history/exportSectionTrafficIndexAnalysis")
|
|
public void exportSectionTrafficIndexAnalysis(HttpServletResponse response,@RequestBody Map<String,Object> params) throws IOException {
|
|
String startDate = params.get("startDate").toString();
|
|
String direction = params.get("direction").toString();
|
|
String periodType = params.get("periodType").toString();
|
|
Long ranking = null;
|
|
if (params.containsKey("ranking")){
|
|
ranking = Long.valueOf(params.get("ranking").toString());
|
|
}
|
|
String fileUrl = params.get("fileUrl").toString();
|
|
|
|
List<SectionTrafficIndexAnalysis> list = new ArrayList<>();
|
|
|
|
String endDate = UniversalEnum.EMPTY_STRING.getValue();
|
|
if (UniversalEnum.FOUR.getValue().equals(periodType)) {
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue());
|
|
LocalDate inputDate = LocalDate.parse(startDate, formatter);
|
|
// 获取一年前的日期
|
|
LocalDate end = inputDate.minusYears(1);
|
|
endDate = end.format(formatter);
|
|
} else if (UniversalEnum.THREE.getValue().equals(periodType)) {
|
|
String[] parts = startDate.split(UniversalEnum.SHORT_BAR.getValue());
|
|
int year = Integer.parseInt(parts[UniversalEnum.ZERO.getNumber()]);
|
|
int month = Integer.parseInt(parts[UniversalEnum.ONE.getNumber()]);
|
|
|
|
// 计算一年前的年份和月份
|
|
year -= UniversalEnum.ONE.getNumber();
|
|
// 如果计算后月份为0,则调整为上一年的12月
|
|
if (month == UniversalEnum.ZERO.getNumber()) {
|
|
year -= UniversalEnum.ONE.getNumber();
|
|
month = UniversalEnum.TWELVE.getNumber();
|
|
}
|
|
endDate = String.format("%04d-%02d", year, month);
|
|
} else if (UniversalEnum.ONE.getValue().equals(periodType)) {
|
|
int year = Integer.parseInt(startDate) - UniversalEnum.ONE.getNumber();
|
|
endDate = String.valueOf(year);
|
|
}
|
|
List<Map<String, Object>> thisYearList = dcGantryMetricsStatisticsDataService.sectionTrafficIndexAnalysis(startDate, direction, periodType, ranking);
|
|
Map<String, List<Map<String, Object>>> thisYearData = thisYearList.stream().collect(Collectors.groupingBy(item -> item.get("groupName").toString()));
|
|
List<Map<String, Object>> lastYearList = dcGantryMetricsStatisticsDataService.sectionTrafficIndexAnalysis(endDate, direction, periodType, ranking);
|
|
Map<String, List<Map<String, Object>>> lastYearData = lastYearList.stream().collect(Collectors.groupingBy(item -> item.get("groupName").toString()));
|
|
|
|
for (StakeMarkRange value : StakeMarkRange.values()) {
|
|
String sectionName = value.getDescription();
|
|
SectionTrafficIndexAnalysis sectionTrafficIndexAnalysis = new SectionTrafficIndexAnalysis();
|
|
sectionTrafficIndexAnalysis.setName(value.getDescription());
|
|
if (thisYearData != null && thisYearData.containsKey(sectionName)) {
|
|
Map<String, Object> sectionData = thisYearData.get(sectionName).get(UniversalEnum.ZERO.getNumber());
|
|
sectionTrafficIndexAnalysis.setCrowdingRate(sectionData.get("crowdingRate").toString());
|
|
sectionTrafficIndexAnalysis.setSaturationRate(sectionData.get("saturationRate").toString());
|
|
sectionTrafficIndexAnalysis.setTrafficCompositionRate(sectionData.get("trafficCompositionRate").toString());
|
|
} else {
|
|
sectionTrafficIndexAnalysis.setCrowdingRate(UniversalEnum.ZERO.getValue());
|
|
sectionTrafficIndexAnalysis.setSaturationRate(UniversalEnum.ZERO.getValue());
|
|
sectionTrafficIndexAnalysis.setTrafficCompositionRate(UniversalEnum.ZERO.getValue());
|
|
}
|
|
|
|
if (lastYearData != null && lastYearData.containsKey(sectionName)) {
|
|
Map<String, Object> sectionData = lastYearData.get(sectionName).get(UniversalEnum.ZERO.getNumber());
|
|
sectionTrafficIndexAnalysis.setCrowdingRateLastYear(sectionData.get("crowdingRate").toString());
|
|
sectionTrafficIndexAnalysis.setSaturationRateLastYear(sectionData.get("saturationRate").toString());
|
|
sectionTrafficIndexAnalysis.setTrafficCompositionRateLastYear(sectionData.get("trafficCompositionRate").toString());
|
|
} else {
|
|
sectionTrafficIndexAnalysis.setCrowdingRateLastYear(UniversalEnum.ZERO.getValue());
|
|
sectionTrafficIndexAnalysis.setSaturationRateLastYear(UniversalEnum.ZERO.getValue());
|
|
sectionTrafficIndexAnalysis.setTrafficCompositionRateLastYear(UniversalEnum.ZERO.getValue());
|
|
}
|
|
list.add(sectionTrafficIndexAnalysis);
|
|
|
|
}
|
|
|
|
ExcelUtil<SectionTrafficIndexAnalysis> util = new ExcelUtil<>(SectionTrafficIndexAnalysis.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, UniversalEnum.SECTION_TRAFFIC_INDEX_ANALYSIS.getValue(),imageBytes,7,14);
|
|
// 将查询结果封装为成功响应并返回
|
|
}
|
|
|
|
@ApiOperation("通指标时间分布")
|
|
@GetMapping("/history/passIndicatorTimeDistribution")
|
|
public AjaxResult passIndicatorTimeDistribution(String startDate, String direction, String periodType) {
|
|
List<Map<String, Object>> mapList = dcGantryMetricsStatisticsDataService.passIndicatorTimeDistribution(startDate, direction, periodType);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(mapList);
|
|
}
|
|
|
|
@ApiOperation(value = "导出交通指标时间分布", tags = {"ECharts导出"})
|
|
@PostMapping("/history/exportPassIndicatorTimeDistribution")
|
|
public void exportPassIndicatorTimeDistribution(HttpServletResponse response, @RequestBody Map<String,String> params) throws IOException {
|
|
String startDate = params.get("startDate");
|
|
String direction = params.get("direction");
|
|
String periodType = params.get("periodType");
|
|
String fileUrl = params.get("fileUrl");
|
|
|
|
List<PassIndicatorTimeDistribution> list = new ArrayList<>();
|
|
|
|
String endDate = UniversalEnum.EMPTY_STRING.getValue();
|
|
if (UniversalEnum.FOUR.getValue().equals(periodType)) {
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue());
|
|
LocalDate inputDate = LocalDate.parse(startDate, formatter);
|
|
// 获取一年前的日期
|
|
LocalDate end = inputDate.minusYears(1);
|
|
endDate = end.format(formatter);
|
|
} else if (UniversalEnum.THREE.getValue().equals(periodType)) {
|
|
String[] parts = startDate.split(UniversalEnum.SHORT_BAR.getValue());
|
|
int year = Integer.parseInt(parts[UniversalEnum.ZERO.getNumber()]);
|
|
int month = Integer.parseInt(parts[UniversalEnum.ONE.getNumber()]);
|
|
|
|
// 计算一年前的年份和月份
|
|
year -= UniversalEnum.ONE.getNumber();
|
|
// 如果计算后月份为0,则调整为上一年的12月
|
|
if (month == UniversalEnum.ZERO.getNumber()) {
|
|
year -= UniversalEnum.ONE.getNumber();
|
|
month = UniversalEnum.TWELVE.getNumber();
|
|
}
|
|
endDate = String.format("%04d-%02d", year, month);
|
|
} else if (UniversalEnum.ONE.getValue().equals(periodType)) {
|
|
int year = Integer.parseInt(startDate) - UniversalEnum.ONE.getNumber();
|
|
endDate = String.valueOf(year);
|
|
}
|
|
List<Map<String, Object>> thisYearList = dcGantryMetricsStatisticsDataService.passIndicatorTimeDistribution(startDate, direction, periodType);
|
|
Map<String, List<Map<String, Object>>> thisYearData = new HashMap<>();
|
|
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm");
|
|
if (UniversalEnum.FOUR.getValue().equals(periodType)) {
|
|
thisYearData = thisYearList.stream().collect(Collectors.groupingBy(item -> {
|
|
LocalDateTime dateTime = LocalDateTime.parse(item.get("groupTime").toString(), inputFormatter);
|
|
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("HH时");
|
|
return outputFormatter.format(dateTime);
|
|
}));
|
|
} else if (UniversalEnum.THREE.getValue().equals(periodType)) {
|
|
thisYearData = thisYearList.stream().collect(Collectors.groupingBy(item -> {
|
|
LocalDateTime dateTime = LocalDateTime.parse(item.get("groupTime").toString(), inputFormatter);
|
|
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("M月d日");
|
|
return dateTime.format(outputFormatter);
|
|
}));
|
|
} else if (UniversalEnum.ONE.getValue().equals(periodType)) {
|
|
thisYearData = thisYearList.stream().collect(Collectors.groupingBy(item -> {
|
|
LocalDateTime dateTime = LocalDateTime.parse(item.get("groupTime").toString(), inputFormatter);
|
|
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("M月");
|
|
return dateTime.format(outputFormatter);
|
|
}));
|
|
}
|
|
List<Map<String, Object>> lastYearList = dcGantryMetricsStatisticsDataService.passIndicatorTimeDistribution(endDate, direction, periodType);
|
|
Map<String, List<Map<String, Object>>> lastYearData = lastYearList.stream().collect(Collectors.groupingBy(item -> item.get("groupTime").toString()));
|
|
|
|
Set<String> allKey = new HashSet<>();
|
|
if (thisYearData != null) {
|
|
allKey.addAll(thisYearData.keySet());
|
|
}
|
|
if (lastYearData != null) {
|
|
allKey.addAll(lastYearData.keySet());
|
|
}
|
|
|
|
List<String> keyList = new ArrayList<>(allKey);
|
|
Collections.sort(keyList);
|
|
|
|
for (String key : keyList) {
|
|
PassIndicatorTimeDistribution passIndicatorTimeDistribution = new PassIndicatorTimeDistribution();
|
|
passIndicatorTimeDistribution.setTime(key);
|
|
if (thisYearData != null && thisYearData.containsKey(key)) {
|
|
Map<String, Object> sectionData = thisYearData.get(key).get(UniversalEnum.ZERO.getNumber());
|
|
passIndicatorTimeDistribution.setCrowdingRate(sectionData.get("crowdingRate").toString());
|
|
|
|
if (sectionData.get("saturationRate") instanceof Double) {
|
|
double saturationRate = (Double) sectionData.get("saturationRate");
|
|
passIndicatorTimeDistribution.setSaturationRate(String.format("%.4f", saturationRate));
|
|
} else {
|
|
passIndicatorTimeDistribution.setSaturationRate("0");
|
|
}
|
|
// passIndicatorTimeDistribution.setSaturationRate(sectionData.get("saturationRate").toString());
|
|
passIndicatorTimeDistribution.setTrafficCompositionRate(sectionData.get("trafficCompositionRate").toString());
|
|
}
|
|
|
|
if (lastYearData != null && lastYearData.containsKey(key)) {
|
|
Map<String, Object> sectionData = lastYearData.get(key).get(UniversalEnum.ZERO.getNumber());
|
|
passIndicatorTimeDistribution.setCrowdingRateLastYear(sectionData.get("crowdingRate").toString());
|
|
// passIndicatorTimeDistribution.setSaturationRateLastYear(sectionData.get("saturationRate").toString());
|
|
if (sectionData.get("saturationRate") instanceof Double) {
|
|
double saturationRate = (Double) sectionData.get("saturationRate");
|
|
passIndicatorTimeDistribution.setSaturationRateLastYear(String.format("%.4f", saturationRate));
|
|
} else {
|
|
passIndicatorTimeDistribution.setSaturationRateLastYear("0");
|
|
}
|
|
passIndicatorTimeDistribution.setTrafficCompositionRateLastYear(sectionData.get("trafficCompositionRate").toString());
|
|
} else {
|
|
// 如果 lastYearData 不存在或者不包含 key,将所有字段设置为 "0"
|
|
passIndicatorTimeDistribution.setCrowdingRateLastYear("0");
|
|
passIndicatorTimeDistribution.setSaturationRateLastYear("0");
|
|
passIndicatorTimeDistribution.setTrafficCompositionRateLastYear("0");
|
|
}
|
|
list.add(passIndicatorTimeDistribution);
|
|
}
|
|
|
|
ExcelUtil<PassIndicatorTimeDistribution> util = new ExcelUtil<>(PassIndicatorTimeDistribution.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);
|
|
// 将查询结果封装为成功响应并返回
|
|
}
|
|
|
|
@ApiOperation("交通指标雷达图")
|
|
@GetMapping("/history/radarMapOfTrafficIndicators")
|
|
public AjaxResult radarMapOfTrafficIndicators(String startDate, String direction, String periodType) {
|
|
Map<String, Object> map = dcGantryMetricsStatisticsDataService.radarMapOfTrafficIndicators(startDate, direction, periodType);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(map);
|
|
}
|
|
|
|
@ApiOperation(value = "导出交通指标雷达图", tags = {"ECharts导出"})
|
|
@GetMapping("/history/exportRadarMapOfTrafficIndicators")
|
|
public void exportRadarMapOfTrafficIndicators(HttpServletResponse response, String startDate, String direction, String periodType, Long ranking) {
|
|
List<RadarMapOfTrafficIndicators> list = new ArrayList<>();
|
|
|
|
String endDate = UniversalEnum.EMPTY_STRING.getValue();
|
|
if (UniversalEnum.FOUR.getValue().equals(periodType)) {
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue());
|
|
LocalDate inputDate = LocalDate.parse(startDate, formatter);
|
|
// 获取一年前的日期
|
|
LocalDate end = inputDate.minusYears(1);
|
|
endDate = end.format(formatter);
|
|
} else if (UniversalEnum.THREE.getValue().equals(periodType)) {
|
|
String[] parts = startDate.split(UniversalEnum.SHORT_BAR.getValue());
|
|
int year = Integer.parseInt(parts[UniversalEnum.ZERO.getNumber()]);
|
|
int month = Integer.parseInt(parts[UniversalEnum.ONE.getNumber()]);
|
|
|
|
// 计算一年前的年份和月份
|
|
year -= UniversalEnum.ONE.getNumber();
|
|
// 如果计算后月份为0,则调整为上一年的12月
|
|
if (month == UniversalEnum.ZERO.getNumber()) {
|
|
year -= UniversalEnum.ONE.getNumber();
|
|
month = UniversalEnum.TWELVE.getNumber();
|
|
}
|
|
endDate = String.format("%04d-%02d", year, month);
|
|
} else if (UniversalEnum.ONE.getValue().equals(periodType)) {
|
|
int year = Integer.parseInt(startDate) - UniversalEnum.ONE.getNumber();
|
|
endDate = String.valueOf(year);
|
|
}
|
|
Map<String, Object> map = dcGantryMetricsStatisticsDataService.radarMapOfTrafficIndicators(startDate, direction, periodType);
|
|
Map<String, Object> mapLastYear = dcGantryMetricsStatisticsDataService.radarMapOfTrafficIndicators(endDate, direction, periodType);
|
|
|
|
RadarMapOfTrafficIndicators radarMapOfTrafficIndicators = new RadarMapOfTrafficIndicators();
|
|
radarMapOfTrafficIndicators.setName("拥挤度");
|
|
radarMapOfTrafficIndicators.setCurrentData(map.get("crowdingRate").toString());
|
|
radarMapOfTrafficIndicators.setContemporaneousData(mapLastYear.get("crowdingRate").toString());
|
|
list.add(radarMapOfTrafficIndicators);
|
|
|
|
radarMapOfTrafficIndicators = new RadarMapOfTrafficIndicators();
|
|
radarMapOfTrafficIndicators.setName("饱和度");
|
|
if (map.get("saturationRate") instanceof Double) {
|
|
double saturationRate = (Double) map.get("saturationRate");
|
|
radarMapOfTrafficIndicators.setCurrentData(String.format("%.4f", saturationRate));
|
|
} else {
|
|
radarMapOfTrafficIndicators.setCurrentData("0");
|
|
}
|
|
|
|
if (mapLastYear.get("saturationRate") instanceof Double) {
|
|
double saturationRate = (Double) mapLastYear.get("saturationRate");
|
|
radarMapOfTrafficIndicators.setContemporaneousData(String.format("%.4f", saturationRate));
|
|
} else {
|
|
radarMapOfTrafficIndicators.setContemporaneousData("0");
|
|
}
|
|
list.add(radarMapOfTrafficIndicators);
|
|
|
|
radarMapOfTrafficIndicators = new RadarMapOfTrafficIndicators();
|
|
radarMapOfTrafficIndicators.setName("交通特征组成指数");
|
|
radarMapOfTrafficIndicators.setCurrentData(map.get("trafficCompositionRate").toString());
|
|
radarMapOfTrafficIndicators.setContemporaneousData(mapLastYear.get("trafficCompositionRate").toString());
|
|
list.add(radarMapOfTrafficIndicators);
|
|
|
|
|
|
ExcelUtil<RadarMapOfTrafficIndicators> util = new ExcelUtil<>(RadarMapOfTrafficIndicators.class);
|
|
util.exportExcel(response, list, "交通指标雷达图");
|
|
}
|
|
|
|
@ApiOperation("综合指标查询")
|
|
@GetMapping("/history/comprehensiveIndexQuery")
|
|
public TableDataInfo comprehensiveIndexQuery(ComprehensiveIndexQuery comprehensiveIndexQuery) {
|
|
startPage();
|
|
List<ComprehensiveIndexQuery> mapList = dcGantryMetricsStatisticsDataService.comprehensiveIndexQuery(comprehensiveIndexQuery);
|
|
// 将查询结果封装为成功响应并返回
|
|
return getDataTable(mapList);
|
|
}
|
|
|
|
@ApiOperation("导出综合指标")
|
|
//@PreAuthorize("@ss.hasPermi('system:event:export')")
|
|
@Log(title = "导出综合指标", businessType = BusinessType.EXPORT)
|
|
@PostMapping("/export")
|
|
public void export(HttpServletResponse response, @RequestBody ComprehensiveIndexQuery comprehensiveIndexQuery) {
|
|
List<ComprehensiveIndexQuery> list = dcGantryMetricsStatisticsDataService.comprehensiveIndexQuery(comprehensiveIndexQuery);
|
|
ExcelUtil<ComprehensiveIndexQuery> util = new ExcelUtil<ComprehensiveIndexQuery>(ComprehensiveIndexQuery.class);
|
|
util.exportExcel(response, list, UniversalEnum.EVENT_INFORMATION_DATA.getValue());
|
|
}
|
|
|
|
/**
|
|
* 获取门架指标统计数据
|
|
*
|
|
* @param request 包含查询条件的请求对象,用于筛选历史门架指标统计数据
|
|
* @return 返回一个AjaxResult对象,其中包含了查询到的门架指标统计数据列表
|
|
*/
|
|
@ApiOperation("获取门架交通特指数数据")
|
|
@GetMapping("/history/gantry-metrics")
|
|
public AjaxResult historyGantryMetrics(DcGantryMetricsStatisticsData request) {
|
|
// 调用服务层方法,根据请求条件查询历史车门架数据
|
|
List<DcGantryMetricsStatisticsData> dcStatisticsData = dcGantryMetricsStatisticsDataService.gantryMetricsData(request);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(dcStatisticsData);
|
|
}
|
|
|
|
/********************************************* 智慧高速平接口 **************************************************/
|
|
|
|
|
|
/**
|
|
* 获取在途车辆流量(分车型)
|
|
* 该接口不接受任何参数,调用后返回在途车辆的统计数据,数据格式为JSONObject。
|
|
*
|
|
* @return AjaxResult 返回类型为AjaxResult,其中包含了操作结果和在途车辆统计数据的JSONObject。
|
|
*/
|
|
@ApiOperation("获取在途车辆流量(分车型)")
|
|
@GetMapping("/current/in-transit-vehicles")
|
|
public AjaxResult vehiclesInTransit() throws HttpException, IOException {
|
|
// 调用服务层方法,获取在途车辆的统计数据
|
|
JSONArray dcStatisticsData = dcTrafficStatisticsService.vehiclesInTransit();
|
|
return AjaxResult.success(dcStatisticsData);
|
|
}
|
|
|
|
@ApiOperation("获取在途车路段平均车速")
|
|
@GetMapping("/current/average-speed")
|
|
public AjaxResult currentAverageSpeed() throws HttpException, IOException {
|
|
// 调用服务层方法,获取在途车辆的统计数据
|
|
JSONArray dcStatisticsData = dcTrafficStatisticsService.currentAverageSpeed();
|
|
return AjaxResult.success(dcStatisticsData);
|
|
}
|
|
|
|
/**
|
|
* 获取当前拥堵事件信息(智慧高速平台)
|
|
*
|
|
* @return 返回一个AjaxResult对象,其中包含了查询结果。如果查询成功,则结果中封装了当前拥堵路段的数据列表。
|
|
*/
|
|
@ApiOperation("获取当前拥堵事件信息")
|
|
@GetMapping("/current/event-congested")
|
|
public AjaxResult currentEventCongested() throws HttpException, IOException {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
JSONArray jsonArray = dcTrafficStatisticsService.currentEventCongested();
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(jsonArray);
|
|
}
|
|
|
|
@ApiOperation("获取当前拥堵路段")
|
|
@GetMapping("/current/getTheCurrentCongestedSection")
|
|
public AjaxResult getTheCurrentCongestedSection() throws HttpException, IOException {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
JSONArray jsonArray = dcTrafficStatisticsService.getTheCurrentCongestedSection();
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(jsonArray);
|
|
}
|
|
|
|
/**
|
|
* 获取当前拥堵路段信息
|
|
*
|
|
* @return 返回一个AjaxResult对象,其中包含了查询结果。如果查询成功,则结果中封装了当前拥堵路段的数据列表。
|
|
*/
|
|
@ApiOperation("获取当前路段拥堵信息")
|
|
@GetMapping("/current/section-congested")
|
|
public AjaxResult currentSectionCongested() throws HttpException, IOException {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
List<DcRoadSectionCongestion> roadSectionCongestions = dcTrafficStatisticsService.currentSectionCongested();
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(roadSectionCongestions);
|
|
}
|
|
|
|
/**
|
|
* 获取车道占有率信息
|
|
*/
|
|
@ApiOperation("获取车道占有率信息")
|
|
@GetMapping("/history/lane-occupancy")
|
|
public AjaxResult laneOccupancy(String startDate, String endDate) throws HttpException, IOException {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
JSONArray jsonArray = dcTrafficStatisticsService.laneOccupancy(startDate, endDate);
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(jsonArray);
|
|
}
|
|
|
|
/**
|
|
* 断面小时车流量分车型
|
|
*/
|
|
@ApiOperation("断面小时车流量分车型")
|
|
@GetMapping("/history/sectionHourlyTrafficFlow")
|
|
public AjaxResult sectionHourlyTrafficFlow(String startDate, String endDate) throws HttpException, IOException {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
JSONArray jsonArray = dcTrafficStatisticsService.sectionHourlyTrafficFlow(startDate, endDate);
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(jsonArray);
|
|
|
|
}
|
|
|
|
/**
|
|
* 各收费站入口分车型车流量
|
|
*/
|
|
@ApiOperation("各收费站入口分车型小时车流量")
|
|
@GetMapping("/history/trafficFlowAtTollStationEntranceHour")
|
|
public AjaxResult trafficFlowAtTollStationEntranceHour(String startDate, String endDate, String stationType) throws HttpException, IOException {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
List<Map<String, String>> jsonArray = dcTrafficStatisticsService.trafficFlowAtTollStationEntrance(startDate, endDate, stationType);
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(jsonArray);
|
|
}
|
|
|
|
/**
|
|
* 各收费站入口分车型车流量
|
|
*/
|
|
@ApiOperation("收费站日累计车流辆")
|
|
@GetMapping("/history/trafficFlowAtToll")
|
|
public AjaxResult trafficFlowAtToll(String startDate) throws HttpException, IOException {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
int a = dcTrafficStatisticsService.trafficFlowAtToll(startDate);
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(a);
|
|
}
|
|
|
|
@ApiOperation("收费站昨日累计车流辆")
|
|
@GetMapping("/history/yesterdayTrafficFlowAtToll")
|
|
public AjaxResult yesterdayTrafficFlowAtToll(String startDate) throws HttpException, IOException {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
int a = dcTrafficStatisticsService.yesterdayTrafficFlowAtToll(startDate);
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(a);
|
|
}
|
|
|
|
/**
|
|
* 导出收费站出入口实时车流量
|
|
*/
|
|
@ApiOperation(value = "导出收费站出入口实时车流量", tags = {"ECharts导出"})
|
|
@PostMapping("/history/exportTrafficFlowAtTollStationEntranceHour")
|
|
public void exportTrafficFlowAtTollStationEntranceHour(HttpServletResponse response,@RequestBody Map<String,String> params) throws IOException, HttpException {
|
|
|
|
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);
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue());
|
|
LocalDate currentDate = LocalDate.now();
|
|
String now = currentDate.format(formatter);
|
|
|
|
// 获取一年前的日期
|
|
LocalDate oneYearAgo = currentDate.minusYears(UniversalEnum.ONE.getNumber());
|
|
String lastYear = oneYearAgo.format(formatter);
|
|
|
|
Set<String> stationList = new HashSet<>();
|
|
|
|
// 本期入口
|
|
List<Map<String, String>> thisYearEntrance = dcTrafficStatisticsService.trafficFlowAtTollStationEntrance(now, now, "1");
|
|
Map<String, List<Map<String, String>>> thisYearEntranceData = new HashMap<>();
|
|
if (thisYearEntrance != null && thisYearEntrance.size() > 0) {
|
|
thisYearEntranceData = thisYearEntrance.stream().collect(Collectors.groupingBy(item -> item.get("name")));
|
|
stationList.addAll(thisYearEntranceData.keySet());
|
|
}
|
|
|
|
// 本期出口
|
|
List<Map<String, String>> thisYearExport = dcTrafficStatisticsService.trafficFlowAtTollStationEntrance(now, now, "2");
|
|
Map<String, List<Map<String, String>>> thisYearExportData = new HashMap<>();
|
|
if (thisYearExport != null && thisYearExport.size() > 0) {
|
|
thisYearExportData = thisYearExport.stream().collect(Collectors.groupingBy(item -> item.get("name")));
|
|
stationList.addAll(thisYearExportData.keySet());
|
|
}
|
|
|
|
// 去年入口
|
|
List<Map<String, String>> lastYearEntrance = dcTrafficStatisticsService.trafficFlowAtTollStationEntrance(lastYear, lastYear, "1");
|
|
Map<String, List<Map<String, String>>> lastYearEntranceData = new HashMap<>();
|
|
if (lastYearEntrance != null && lastYearEntrance.size() > 0) {
|
|
lastYearEntranceData = lastYearEntrance.stream().collect(Collectors.groupingBy(item -> item.get("name")));
|
|
stationList.addAll(lastYearEntranceData.keySet());
|
|
}
|
|
|
|
// 去年出口
|
|
List<Map<String, String>> lastYearExport = dcTrafficStatisticsService.trafficFlowAtTollStationEntrance(lastYear, lastYear, "2");
|
|
Map<String, List<Map<String, String>>> lastYearExportData = new HashMap<>();
|
|
if (lastYearExport != null && lastYearExport.size() > 0) {
|
|
lastYearExportData = lastYearExport.stream().collect(Collectors.groupingBy(item -> item.get("name")));
|
|
stationList.addAll(lastYearExportData.keySet());
|
|
}
|
|
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);
|
|
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());
|
|
Cell cell = row.createCell(UniversalEnum.ZERO.getNumber());
|
|
cell.setCellValue(UniversalEnum.TOLL_STATION.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
cell = row.createCell(UniversalEnum.ONE.getNumber());
|
|
cell.setCellValue(UniversalEnum.ENTRANCE.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
cell = row.createCell(UniversalEnum.TWO.getNumber());
|
|
cell.setCellValue(UniversalEnum.EMPTY_STRING.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
;
|
|
cell = row.createCell(UniversalEnum.THREE.getNumber());
|
|
cell.setCellValue(UniversalEnum.EXIT.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
cell = row.createCell(UniversalEnum.FOUR.getNumber());
|
|
cell.setCellValue(UniversalEnum.EMPTY_STRING.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
// 添加第二层级表头(与第一层级对齐)
|
|
Row subHeaderRow1 = sheet.createRow(UniversalEnum.ONE.getNumber());
|
|
cell = subHeaderRow1.createCell(UniversalEnum.ZERO.getNumber());
|
|
cell.setCellValue(UniversalEnum.EMPTY_STRING.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
cell = subHeaderRow1.createCell(UniversalEnum.ONE.getNumber());
|
|
cell.setCellValue(UniversalEnum.CURRENT_TRAFFIC_FLOW.getValue() + "(辆)");
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
cell = subHeaderRow1.createCell(UniversalEnum.TWO.getNumber());
|
|
cell.setCellValue(UniversalEnum.THE_SAME_PERIOD_LAST_YEAR.getValue() + "(辆)");
|
|
cell.setCellStyle(headerStyle);
|
|
cell = subHeaderRow1.createCell(UniversalEnum.THREE.getNumber());
|
|
cell.setCellValue(UniversalEnum.CURRENT_TRAFFIC_FLOW.getValue() + "(辆)");
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
cell = subHeaderRow1.createCell(UniversalEnum.FOUR.getNumber());
|
|
cell.setCellValue(UniversalEnum.THE_SAME_PERIOD_LAST_YEAR.getValue() + "(辆)");
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
//合并单元格,参数依次为起始行,结束行,起始列,结束列 (从0开始)
|
|
//路段名称
|
|
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber()));
|
|
//济南方向
|
|
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.TWO.getNumber()));
|
|
//菏泽方向
|
|
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.THREE.getNumber(), UniversalEnum.FOUR.getNumber()));
|
|
|
|
int i = 2;
|
|
for (LocationEnum stationEnum : LocationEnum.values()) {
|
|
String station = stationEnum.getName();
|
|
Row subHeaderRow = sheet.createRow(i);
|
|
cell = subHeaderRow.createCell(UniversalEnum.ZERO.getNumber());
|
|
cell.setCellValue(station);
|
|
cell.setCellStyle(dataStyle);
|
|
|
|
if (thisYearEntranceData.containsKey(station)) {
|
|
cell = subHeaderRow.createCell(UniversalEnum.ONE.getNumber());
|
|
cell.setCellValue(thisYearEntranceData.get(station).get(0).get("value"));
|
|
cell.setCellStyle(dataStyle);
|
|
} else {
|
|
cell = subHeaderRow.createCell(UniversalEnum.ONE.getNumber());
|
|
cell.setCellValue("");
|
|
cell.setCellStyle(dataStyle);
|
|
}
|
|
|
|
if (lastYearEntranceData.containsKey(station)) {
|
|
cell = subHeaderRow.createCell(UniversalEnum.TWO.getNumber());
|
|
cell.setCellValue(lastYearEntranceData.get(station).get(0).get("value"));
|
|
cell.setCellStyle(dataStyle);
|
|
} else {
|
|
cell = subHeaderRow.createCell(UniversalEnum.TWO.getNumber());
|
|
cell.setCellValue("");
|
|
cell.setCellStyle(dataStyle);
|
|
}
|
|
|
|
if (thisYearExportData.containsKey(station)) {
|
|
cell = subHeaderRow.createCell(UniversalEnum.THREE.getNumber());
|
|
cell.setCellValue(thisYearExportData.get(station).get(0).get("value"));
|
|
cell.setCellStyle(dataStyle);
|
|
} else {
|
|
cell = subHeaderRow.createCell(UniversalEnum.THREE.getNumber());
|
|
cell.setCellValue("");
|
|
cell.setCellStyle(dataStyle);
|
|
}
|
|
|
|
if (lastYearExportData.containsKey(station)) {
|
|
cell = subHeaderRow.createCell(UniversalEnum.FOUR.getNumber());
|
|
cell.setCellValue(lastYearExportData.get(station).get(0).get("value"));
|
|
cell.setCellStyle(dataStyle);
|
|
} else {
|
|
cell = subHeaderRow.createCell(UniversalEnum.FOUR.getNumber());
|
|
cell.setCellValue("");
|
|
cell.setCellStyle(dataStyle);
|
|
}
|
|
i++;
|
|
}
|
|
|
|
// 写入文件
|
|
try (ServletOutputStream outputStream = response.getOutputStream()) {
|
|
String fileUrl = params.get("fileUrl");
|
|
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);
|
|
// 添加图片到工作簿并获取图片索引
|
|
int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG);
|
|
// 创建绘图对象
|
|
Drawing<?> drawing = sheet.createDrawingPatriarch();
|
|
// 设置图片位置
|
|
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, LocationEnum.values().length+3, 12, LocationEnum.values().length + 3 + 12);
|
|
Picture pict = drawing.createPicture(anchor, pictureIdx);
|
|
|
|
workbook.write(outputStream);
|
|
} finally {
|
|
workbook.close();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* 各收费站入口分车型小时车流量
|
|
*/
|
|
@ApiOperation("各收费站入口分车型车流量")
|
|
@GetMapping("/history/trafficFlowAtTollStationEntrance")
|
|
public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endDate, String stationType) throws HttpException, IOException {
|
|
// 调用服务层方法,获取当前交通指标数据
|
|
JSONArray jsonArray = dcTrafficStatisticsService.trafficFlowAtTollStationEntranceHour(startDate, endDate, stationType);
|
|
// 将获取到的交通指标数据封装为成功的结果并返回
|
|
return AjaxResult.success(jsonArray);
|
|
|
|
}
|
|
|
|
/**
|
|
* 全路段双向实时车流量
|
|
*/
|
|
@ApiOperation("全路段双向实时车流量")
|
|
@GetMapping("/history/realTimeTrafficFlowHour")
|
|
public AjaxResult realTimeTrafficFlowHour() throws HttpException, IOException {
|
|
Map<String, List<Map<String, Object>>> mapList = dcTrafficStatisticsService.realTimeTrafficFlowHour();
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(mapList);
|
|
}
|
|
|
|
@ApiOperation("按照桩号查询门架数据 ")
|
|
@GetMapping("/history/queryTheGantryDataByPileNumber")
|
|
public AjaxResult queryTheGantryDataByPileNumber(String startDate, String stakeMark) throws HttpException, IOException {
|
|
List<Map<String, Object>> mapList = dcTrafficStatisticsService.queryTheGantryDataByPileNumber(startDate, stakeMark);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(mapList);
|
|
}
|
|
|
|
/**
|
|
* 获取据库中 收费站统计数据
|
|
*
|
|
* @param startDate 时间
|
|
* @param accessType 出入口 1入 2出
|
|
* @param periodType 方向
|
|
*/
|
|
@ApiOperation("获取据库中收费站数数据")
|
|
@GetMapping("/history/TollBoothStatistics")
|
|
public AjaxResult TollBoothStatistics(String startDate, String accessType, String periodType) throws HttpException, IOException {
|
|
List<Map<String, String>> mapList = dcTollStationStatisticsDataService.TollBoothStatistics(startDate, accessType, periodType);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(mapList);
|
|
}
|
|
|
|
@ApiOperation("获取据库中收费站数数据")
|
|
@GetMapping("/history/TollBoothStatisticsList")
|
|
public AjaxResult TollBoothStatisticsList(String startDate, String accessType, String periodType) throws HttpException, IOException {
|
|
List<DcTollStationStatisticsDataMap> mapList = dcTollStationStatisticsDataService.TollBoothStatisticsList(startDate, accessType, periodType);
|
|
// 将查询结果封装为成功响应并返回
|
|
return AjaxResult.success(mapList);
|
|
}
|
|
|
|
/**
|
|
* 导出全路段双向实时车流量
|
|
*/
|
|
@ApiOperation(value = "导出全路段双向实时车流量", tags = {"ECharts导出"})
|
|
@PostMapping("/history/exportRealTimeTrafficFlowHour")
|
|
public void exportRealTimeTrafficFlowHour(HttpServletResponse response,@RequestBody Map<String,String> params) throws IOException, HttpException {
|
|
|
|
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 = UniversalEnum.REAL_TIME_TRAFFIC_FLOW_IN_BOTH_DIRECTIONS_XLSX.name();
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
|
|
|
|
Map<String, List<Map<String, Object>>> map = dcTrafficStatisticsService.realTimeTrafficFlowHour();
|
|
if (map != null) {
|
|
List<Map<String, Object>> thisYearHZ = map.get(UniversalEnum.ONE.getValue());
|
|
List<Map<String, Object>> thisYearJN = map.get(UniversalEnum.TWO.getValue());
|
|
List<Map<String, Object>> lastYearHZ = map.get(UniversalEnum.THREE.getValue());
|
|
List<Map<String, Object>> lastYearJN = map.get(UniversalEnum.FOUR.getValue());
|
|
|
|
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);
|
|
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());
|
|
Cell cell = row.createCell(UniversalEnum.ZERO.getNumber());
|
|
cell.setCellValue(UniversalEnum.ROAD_SECTION_NAME.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
cell = row.createCell(UniversalEnum.ONE.getNumber());
|
|
cell.setCellValue(UniversalEnum.DIRECTION_OF_JINAN.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
cell = row.createCell(UniversalEnum.TWO.getNumber());
|
|
cell.setCellValue(UniversalEnum.EMPTY_STRING.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
;
|
|
cell = row.createCell(UniversalEnum.THREE.getNumber());
|
|
cell.setCellValue(UniversalEnum.DIRECTION_OF_HEZE.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
cell = row.createCell(UniversalEnum.FOUR.getNumber());
|
|
cell.setCellValue(UniversalEnum.EMPTY_STRING.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
// 添加第二层级表头(与第一层级对齐)
|
|
Row subHeaderRow1 = sheet.createRow(UniversalEnum.ONE.getNumber());
|
|
cell = subHeaderRow1.createCell(UniversalEnum.ZERO.getNumber());
|
|
cell.setCellValue(UniversalEnum.EMPTY_STRING.getValue());
|
|
cell.setCellStyle(headerStyle);
|
|
cell = subHeaderRow1.createCell(UniversalEnum.ONE.getNumber());
|
|
cell.setCellValue(UniversalEnum.CURRENT_TRAFFIC_FLOW.getValue() + "(辆)");
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
cell = subHeaderRow1.createCell(UniversalEnum.TWO.getNumber());
|
|
cell.setCellValue(UniversalEnum.THE_SAME_PERIOD_LAST_YEAR.getValue() + "(辆)");
|
|
cell.setCellStyle(headerStyle);
|
|
cell = subHeaderRow1.createCell(UniversalEnum.THREE.getNumber());
|
|
cell.setCellValue(UniversalEnum.CURRENT_TRAFFIC_FLOW.getValue() + "(辆)");
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
cell = subHeaderRow1.createCell(UniversalEnum.FOUR.getNumber());
|
|
cell.setCellValue(UniversalEnum.THE_SAME_PERIOD_LAST_YEAR.getValue() + "(辆)");
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
//合并单元格,参数依次为起始行,结束行,起始列,结束列 (从0开始)
|
|
//路段名称
|
|
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber()));
|
|
//济南方向
|
|
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.TWO.getNumber()));
|
|
//菏泽方向
|
|
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.THREE.getNumber(), UniversalEnum.FOUR.getNumber()));
|
|
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < thisYearHZ.size(); i++) {
|
|
Row subHeaderRow = sheet.createRow(i + UniversalEnum.TWO.getNumber());
|
|
cell = subHeaderRow.createCell(UniversalEnum.ZERO.getNumber());
|
|
cell.setCellValue(thisYearJN.get(i).get("name").toString());
|
|
cell.setCellStyle(dataStyle);
|
|
cell = subHeaderRow.createCell(UniversalEnum.ONE.getNumber());
|
|
cell.setCellValue(thisYearJN.get(i).get("totalFlow").toString());
|
|
cell.setCellStyle(dataStyle);
|
|
cell = subHeaderRow.createCell(UniversalEnum.TWO.getNumber());
|
|
cell.setCellValue(lastYearJN.get(i).get("totalFlow").toString());
|
|
cell.setCellStyle(dataStyle);
|
|
cell = subHeaderRow.createCell(UniversalEnum.THREE.getNumber());
|
|
cell.setCellValue(thisYearHZ.get(i).get("totalFlow").toString());
|
|
cell.setCellStyle(dataStyle);
|
|
cell = subHeaderRow.createCell(UniversalEnum.FOUR.getNumber());
|
|
cell.setCellValue(lastYearHZ.get(i).get("totalFlow").toString());
|
|
cell.setCellStyle(dataStyle);
|
|
}
|
|
|
|
|
|
// 写入文件
|
|
try (ServletOutputStream outputStream = response.getOutputStream()) {
|
|
String fileUrl = params.get("fileUrl");
|
|
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);
|
|
// 添加图片到工作簿并获取图片索引
|
|
int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG);
|
|
// 创建绘图对象
|
|
Drawing<?> drawing = sheet.createDrawingPatriarch();
|
|
// 设置图片位置
|
|
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, thisYearHZ.size()+3, 12, thisYearHZ.size() + 3 + 12);
|
|
Picture pict = drawing.createPicture(anchor, pictureIdx);
|
|
|
|
workbook.write(outputStream);
|
|
} finally {
|
|
workbook.close();
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|