Browse Source

交通流检测echarts导出

develop
lau572 5 months ago
parent
commit
53cf04bda4
  1. 179
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  2. 86
      zc-business/src/main/java/com/zc/business/domain/export/RealTimeTrafficFlow.java
  3. 62
      zc-business/src/main/java/com/zc/business/domain/export/SectionTrafficRanking.java
  4. 62
      zc-business/src/main/java/com/zc/business/domain/export/TrafficPeriodAnalysis.java

179
zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java

@ -6,8 +6,14 @@ 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.zc.business.domain.*;
import com.zc.business.domain.export.ManyTimesInterval;
import com.zc.business.domain.export.RealTimeTrafficFlow;
import com.zc.business.domain.export.SectionTrafficRanking;
import com.zc.business.domain.export.TrafficPeriodAnalysis;
import com.zc.business.request.DcTrafficMetricsDataRequest;
import com.zc.business.request.DcTrafficSectionDataRequest;
import com.zc.business.service.*;
@ -19,9 +25,10 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -203,6 +210,75 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
/**
* 导出全路段双向实时车流量
* @param startDate 时间
* @param direction 方向
* @param periodType 时间粒子
*/
@ApiOperation(value="导出全路段车流量状况分析",tags = {"ECharts导出"})
@GetMapping("/history/exportRealTimeTrafficFlow")
public AjaxResult exportRealTimeTrafficFlow(HttpServletResponse response,String startDate, String direction,String periodType ){
if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(direction) || StringUtils.isEmpty(periodType)){
return AjaxResult.error("参数错误");
}
String endDate = "";
if ("4".equals(periodType)){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate inputDate = LocalDate.parse(startDate, formatter);
// 获取一年前的日期
LocalDate end = inputDate.minusYears(1);
endDate = end.format(formatter);
} else if ("3".equals(periodType)){
String[] parts = startDate.split("-");
int year = Integer.parseInt(parts[0]);
int month = Integer.parseInt(parts[1]);
// 计算一年前的年份和月份
year -= 1;
// 如果计算后月份为0,则调整为上一年的12月
if (month == 0) {
year -= 1;
month = 12;
}
endDate = String.format("%04d-%02d", year, month);
} else if ("1".equals(periodType)){
int year = Integer.parseInt(startDate) - 1;
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);
util.exportExcel(response, list, "全路段双向实时车流量");
// 将查询结果封装为成功响应并返回
return AjaxResult.success("导出成功");
}
/**
* 车流量时段分析
* @param startDate 时间
@ -217,6 +293,75 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
return AjaxResult.success(mapList);
}
/**
* 导出车流量时段分析
* @param startDate 时间
* @param direction 方向
* @param periodType 时间粒子
*/
@ApiOperation(value="导出车流量时段分析",tags = {"ECharts导出"})
@GetMapping("/history/exportTrafficPeriodAnalysis")
public AjaxResult exportTrafficPeriodAnalysis(HttpServletResponse response,String startDate, String direction,String periodType ){
if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(direction) || StringUtils.isEmpty(periodType)){
return AjaxResult.error("参数错误");
}
String endDate = "";
if ("4".equals(periodType)){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate inputDate = LocalDate.parse(startDate, formatter);
// 获取一年前的日期
LocalDate end = inputDate.minusYears(1);
endDate = end.format(formatter);
} else if ("3".equals(periodType)){
String[] parts = startDate.split("-");
int year = Integer.parseInt(parts[0]);
int month = Integer.parseInt(parts[1]);
// 计算一年前的年份和月份
year -= 1;
// 如果计算后月份为0,则调整为上一年的12月
if (month == 0) {
year -= 1;
month = 12;
}
endDate = String.format("%04d-%02d", year, month);
} else if ("1".equals(periodType)){
int year = Integer.parseInt(startDate) - 1;
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() > 0){
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() > 0){
for (Map<String, String> item : lastList) {
lastData.put(item.get("statisticalHour"),item.get("trafficVolume"));
}
}
for (int i = 0; i < 24; i++) {
TrafficPeriodAnalysis trafficPeriodAnalysis = new TrafficPeriodAnalysis();
trafficPeriodAnalysis.setTime(i + "点至" + (i+1) + "点");
trafficPeriodAnalysis.setCurrentData(mapData.getOrDefault(String.valueOf(i), "0"));
trafficPeriodAnalysis.setContemporaneousData(lastData.getOrDefault(String.valueOf(i), "0"));
list.add(trafficPeriodAnalysis);
}
ExcelUtil<TrafficPeriodAnalysis> util = new ExcelUtil<>(TrafficPeriodAnalysis.class);
util.exportExcel(response, list, "车流量时段分析");
// 将查询结果封装为成功响应并返回
return AjaxResult.success("导出成功");
}
@ApiOperation("断面车流量排名")
@GetMapping("/history/sectionTrafficRanking")
public AjaxResult sectionTrafficRanking(String startDate, String direction,String periodType ){
@ -224,6 +369,34 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
// 将查询结果封装为成功响应并返回
return AjaxResult.success(dcStatisticsData);
}
/**
* 导出断面车流量排名
* @param startDate 时间
* @param direction 方向
* @param periodType 时间粒子
*/
@ApiOperation(value="导出断面车流量排名",tags = {"ECharts导出"})
@GetMapping("/history/exportSectionTrafficRanking")
public AjaxResult exportSectionTrafficRanking(HttpServletResponse response,String startDate, String direction,String periodType ){
List<SectionTrafficRanking> list = new ArrayList<>();
List<Map<String, String>> dcStatisticsData = dcGantryStatisticsDataService.sectionTrafficRanking(startDate,direction,periodType);
for (int i = 0; i < dcStatisticsData.size(); i++) {
SectionTrafficRanking sectionTrafficRanking = new SectionTrafficRanking();
sectionTrafficRanking.setRank(i + 1);
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);
util.exportExcel(response, list, "断面车流量排名");
// 将查询结果封装为成功响应并返回
return AjaxResult.success("导出成功");
}
/**
* sectionTrafficIndexAnalysis
* @param startDate 时间

86
zc-business/src/main/java/com/zc/business/domain/export/RealTimeTrafficFlow.java

@ -0,0 +1,86 @@
package com.zc.business.domain.export;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 导出全路段双向实时车流量对象
*
* @author ruoyi
* @date 2024-01-13
*/
public class RealTimeTrafficFlow extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 路段 */
@Excel(name = "路段")
private String name;
/** 客车 */
@Excel(name = "客车")
private String totalPassengerFlow;
/** 货车 */
@Excel(name = "货车")
private String typeTruckFlow;
/** 专项车 */
@Excel(name = "专项车")
private String typeSpecialVehicleFlow;
/** 去年同期 */
@Excel(name = "去年同期")
private String lastYearTotal;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTotalPassengerFlow() {
return totalPassengerFlow;
}
public void setTotalPassengerFlow(String totalPassengerFlow) {
this.totalPassengerFlow = totalPassengerFlow;
}
public String getTypeTruckFlow() {
return typeTruckFlow;
}
public void setTypeTruckFlow(String typeTruckFlow) {
this.typeTruckFlow = typeTruckFlow;
}
public String getTypeSpecialVehicleFlow() {
return typeSpecialVehicleFlow;
}
public void setTypeSpecialVehicleFlow(String typeSpecialVehicleFlow) {
this.typeSpecialVehicleFlow = typeSpecialVehicleFlow;
}
public String getLastYearTotal() {
return lastYearTotal;
}
public void setLastYearTotal(String lastYearTotal) {
this.lastYearTotal = lastYearTotal;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("name", getName())
.append("totalPassengerFlow", getTotalPassengerFlow())
.append("typeTruckFlow", getTypeTruckFlow())
.append("typeSpecialVehicleFlow", getTypeSpecialVehicleFlow())
.append("lastYearTotal", getLastYearTotal())
.toString();
}
}

62
zc-business/src/main/java/com/zc/business/domain/export/SectionTrafficRanking.java

@ -0,0 +1,62 @@
package com.zc.business.domain.export;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 导出断面车流量排名对象
*
* @author ruoyi
* @date 2024-01-13
*/
public class SectionTrafficRanking extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 排名 */
@Excel(name = "排名")
private Integer rank;
/** 路段名称 */
@Excel(name = "路段名称")
private String facilityName;
/** 车流量 */
@Excel(name = "车流量")
private String number;
public Integer getRank() {
return rank;
}
public void setRank(Integer rank) {
this.rank = rank;
}
public String getFacilityName() {
return facilityName;
}
public void setFacilityName(String facilityName) {
this.facilityName = facilityName;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("rank", getRank())
.append("facilityName", getFacilityName())
.append("number", getNumber())
.toString();
}
}

62
zc-business/src/main/java/com/zc/business/domain/export/TrafficPeriodAnalysis.java

@ -0,0 +1,62 @@
package com.zc.business.domain.export;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 导出车流量时段分析对象
*
* @author ruoyi
* @date 2024-01-13
*/
public class TrafficPeriodAnalysis extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 时段 */
@Excel(name = "时段")
private String time;
/** 本期车流量 */
@Excel(name = "本期车流量")
private String currentData;
/** 去年同期 */
@Excel(name = "去年同期")
private String contemporaneousData;
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getCurrentData() {
return currentData;
}
public void setCurrentData(String currentData) {
this.currentData = currentData;
}
public String getContemporaneousData() {
return contemporaneousData;
}
public void setContemporaneousData(String contemporaneousData) {
this.contemporaneousData = contemporaneousData;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("time", getTime())
.append("currentData", getCurrentData())
.append("contemporaneousData", getContemporaneousData())
.toString();
}
}
Loading…
Cancel
Save