Commit bdf0aae0 authored by duanruiming's avatar duanruiming

[update] 微观大数据平台-优化转向数据导出逻辑

parent 430c9b7f
package net.wanji.opt.po.trend;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
......@@ -23,86 +22,66 @@ public class AnalysisRidTurnIndicators implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键", hidden = true)
@ExcelProperty("唯一ID")
private Integer oid;
@ApiModelProperty(value = "路口id")
@ExcelProperty("路口编号")
private String crossId;
@ApiModelProperty(name = "fRid", value = "进口rid")
@JsonProperty("fRid")
@ExcelProperty("进口编号")
private String fRid;
@ApiModelProperty(name = "fRidDir", value = "进口道方向 1北;2东北;3东;4东南;5南;6西南;7西;8西北")
@JsonProperty("fRidDir")
@ExcelProperty("进口方向")
private Integer fRidDir;
@ApiModelProperty(value = "出口rid", hidden = true)
@JsonProperty("tRid")
@ExcelProperty("出口编号")
private String tRid;
@ApiModelProperty(value = "转向类型 根据进入、出口路段转向计算 1 左转 2 直行3右转 4 掉头")
@ExcelProperty("转向类型")
private Integer turnDirNo;
@ApiModelProperty(value = "交通流量")
@ExcelProperty("交通流量")
private Integer flow;
@ApiModelProperty(value = "平均速度")
@ExcelProperty("平均速度")
private BigDecimal speed;
@ApiModelProperty(value = "排队长度")
@ExcelProperty("排队长度")
private Integer queueLength;
@ApiModelProperty(value = "绿灯有效利用率")
//@ExcelProperty("绿灯有效利用率%")
private BigDecimal greenUsageRate;
@ApiModelProperty(value = "平均停车次数")
@ExcelProperty("平均停车次数")
private BigDecimal stopNum;
@ApiModelProperty(value = "一次停车率")
@ExcelProperty("一次停车率%")
@JsonFormat()
private BigDecimal onceStopRate;
@ApiModelProperty(value = "二次停车率")
@ExcelProperty("二次停车率%")
private BigDecimal secondStopRate;
@ApiModelProperty(value = "三次停车率")
@ExcelProperty("三次停车率%")
private BigDecimal threeStopRate;
@ApiModelProperty(value = "不停车通过率")
@ExcelProperty("不停车通过率%")
private BigDecimal noStopRate;
@ApiModelProperty(value = "交通状态")
@ExcelProperty("交通状态")
private String trafficState;
@ApiModelProperty(value = "分析粒度【5m:五分钟 10m:10分钟 30m:30分钟 1h:一小时】", hidden = true)
@ExcelProperty("时间粒度")
private String granularity;
@JSONField(format = "yyyy-MM-dd HH:mm:ss.SSS")
@ExcelProperty("开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
private Date windowStartTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss.SSS")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
@ExcelProperty("结束时间")
private Date windowEndTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
@ExcelProperty("结束时间")
private Date ruksj;
}
\ No newline at end of file
......@@ -2056,31 +2056,98 @@ public class TrendServiceImpl implements TrendService {
@Override
public void periodTurnExcel(LanePeriodTurnVO lanePeriodTurnVO, HttpServletResponse response) throws Exception {
String crossId = lanePeriodTurnVO.getCrossId();
Date startDate = lanePeriodTurnVO.getStart();
Date endDate = lanePeriodTurnVO.getEnd();
String startStr = DateUtil.format(startDate, DateStyle.YYYY_MM_DD_HH_MM.getValue());
String endStr = DateUtil.format(endDate, DateStyle.MM_DD_HH_MM.getValue());
String startStr = null;
String endStr = null;
List<TurnDataIndexExcelVO> result = null;
try {
String crossId = lanePeriodTurnVO.getCrossId();
Date startDate = lanePeriodTurnVO.getStart();
Date endDate = lanePeriodTurnVO.getEnd();
startStr = DateUtil.format(startDate, DateStyle.YYYY_MM_DD_HH_MM.getValue());
endStr = DateUtil.format(endDate, DateStyle.MM_DD_HH_MM.getValue());
LambdaQueryWrapper<AnalysisRidTurnIndicators> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AnalysisRidTurnIndicators::getCrossId, crossId);
queryWrapper.between(AnalysisRidTurnIndicators::getWindowStartTime, startDate, endDate);
queryWrapper.orderByDesc(AnalysisRidTurnIndicators::getWindowStartTime);
List<AnalysisRidTurnIndicators> dataList = ridTurnIndicatorsMapper.selectList(queryWrapper);
result = new ArrayList<>();
Map<Date, List<AnalysisRidTurnIndicators>> timeMap = dataList.stream().collect(Collectors.groupingBy(AnalysisRidTurnIndicators::getWindowStartTime));
for (Map.Entry<Date, List<AnalysisRidTurnIndicators>> dateListEntry : timeMap.entrySet()) {
Date time = dateListEntry.getKey();
List<AnalysisRidTurnIndicators> dateValueList = dateListEntry.getValue();
Map<Integer, List<AnalysisRidTurnIndicators>> dirList = dateValueList.stream().collect(Collectors.groupingBy(AnalysisRidTurnIndicators::getFRidDir));
for (Map.Entry<Integer, List<AnalysisRidTurnIndicators>> entry : dirList.entrySet()) {
Integer dir = entry.getKey();
List<AnalysisRidTurnIndicators> turnList = entry.getValue();
if (!CollectionUtils.isEmpty(turnList)) {
int allFlow = 0;
int leftFlow = 0;
int straightFlow = 0;
int rightFlow = 0;
int left = 0;
int straight = 0;
int right = 0;
BigDecimal leftSpeed = new BigDecimal(0);
BigDecimal straightSpeed = new BigDecimal(0);
BigDecimal rightSpeed = new BigDecimal(0);
TurnDataIndexExcelVO turnDataIndexExcelVO = new TurnDataIndexExcelVO();
for (AnalysisRidTurnIndicators analysisRidTurnIndicators : turnList) {
Integer turnDirNo = analysisRidTurnIndicators.getTurnDirNo();
time = analysisRidTurnIndicators.getWindowStartTime();
if (turnDirNo == 1) {
leftFlow += analysisRidTurnIndicators.getFlow();
leftSpeed = leftSpeed.add(analysisRidTurnIndicators.getSpeed());
++left;
}
if (turnDirNo == 2) {
straightFlow += analysisRidTurnIndicators.getFlow();
straightSpeed = straightSpeed.add(analysisRidTurnIndicators.getSpeed());
++straight;
}
if (turnDirNo == 3) {
rightFlow += analysisRidTurnIndicators.getFlow();
rightSpeed = straightSpeed.add(analysisRidTurnIndicators.getSpeed());
++right;
}
}
allFlow = leftFlow + straightFlow + rightFlow;
turnDataIndexExcelVO.setTime(time);
turnDataIndexExcelVO.setDir(BaseEnum.SignalDirectionEnum.getNameByCode(dir));
turnDataIndexExcelVO.setFlow(allFlow);
turnDataIndexExcelVO.setLeftFlow(leftFlow);
BigDecimal leftAverage = leftSpeed.divide(new BigDecimal(left), 2, RoundingMode.HALF_UP);
turnDataIndexExcelVO.setLeftSpeed(leftAverage);
if (leftFlow == 0) {
turnDataIndexExcelVO.setLeftSpeed(new BigDecimal(0));
}
turnDataIndexExcelVO.setStraightFlow(straightFlow);
BigDecimal straightAverage = straightSpeed.divide(new BigDecimal(straight), 2, RoundingMode.HALF_UP);
turnDataIndexExcelVO.setStraightSpeed(straightAverage);
if (straightFlow == 0) {
turnDataIndexExcelVO.setStraightSpeed(new BigDecimal(0));
}
turnDataIndexExcelVO.setRightFlow(rightFlow);
BigDecimal rightAverage = rightSpeed.divide(new BigDecimal(right), 2, RoundingMode.HALF_UP);
turnDataIndexExcelVO.setRightSpeed(rightAverage);
if (rightFlow == 0) {
turnDataIndexExcelVO.setRightSpeed(new BigDecimal(0));
}
turnDataIndexExcelVO.setSpeed(leftAverage.add(straightAverage).add(rightAverage).divide(BigDecimal.valueOf(3), 2, RoundingMode.HALF_UP));
result.add(turnDataIndexExcelVO);
}
}
}
} catch (Exception e) {
log.error("导出转向数据异常:", e);
throw new RuntimeException(e);
}
LambdaQueryWrapper<AnalysisRidTurnIndicators> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AnalysisRidTurnIndicators::getCrossId, crossId);
queryWrapper.between(AnalysisRidTurnIndicators::getWindowStartTime, startDate, endDate);
queryWrapper.orderByDesc(AnalysisRidTurnIndicators::getWindowStartTime);
List<AnalysisRidTurnIndicators> dataList = ridTurnIndicatorsMapper.selectList(queryWrapper);
// 部分数据*100
BigDecimal offset = new BigDecimal("100");
List<AnalysisRidTurnIndicators> result = dataList.stream()
.map(item -> {
// 假设有一个名为value的字段需要乘以100
item.setGreenUsageRate(item.getGreenUsageRate().multiply(offset));
item.setOnceStopRate(item.getOnceStopRate().multiply(offset));
item.setSecondStopRate(item.getSecondStopRate().multiply(offset));
item.setThreeStopRate(item.getThreeStopRate().multiply(offset));
item.setNoStopRate(item.getNoStopRate().multiply(offset));
return item;
}).collect(Collectors.toList());
ExcelExportUtils.exportExcel(response, startStr, endStr, result, "周期转向数据", AnalysisRidTurnIndicators.class);
ExcelExportUtils.exportExcel(response, startStr, endStr, result, "周期转向数据", TurnDataIndexExcelVO.class);
}
@Override
......
......@@ -42,7 +42,6 @@ public class TableQueryVO {
private String laneSort;
@ApiModelProperty(value = "车道编号")
@ExcelProperty("车道编号")
private String laneId;
@ApiModelProperty(value = "排队长度")
......@@ -66,11 +65,10 @@ public class TableQueryVO {
private int carNums;
@ApiModelProperty(value = "空间密度车辆负荷比")
@ExcelProperty("空间密度负荷比")
private double vehicleNumsRatio;
@ApiModelProperty(value = "空间密度(长度占比)")
@ExcelProperty("空间密度长度占比")
@ExcelProperty("车辆分布情况")
private double vehicleLengthRatio;
@ApiModelProperty(value = "平均速度")
......@@ -94,7 +92,7 @@ public class TableQueryVO {
private double teamTailDistance;
@ApiModelProperty(value = "车头间距方差>车道内空间占有率")
@ExcelProperty("车道内空间占有率")
@ExcelProperty("空间占有率")
private double stdSpaceHeadway;
}
......@@ -111,7 +109,6 @@ public class TableQueryVO {
private Integer dir;
@ApiModelProperty(value = "车道转向:1左转;2直行;3右转;4掉头;5直左;6直右;7左直右;8左右;9左转掉头;10直行掉头;11右转掉头;12左直掉头;13直右掉头;14左直右掉头;15左右掉头',\n")
@ExcelProperty("转向")
private Integer turn;
@ApiModelProperty(value = "车道,从左车道开始编号11、12、13...")
......@@ -143,11 +140,10 @@ public class TableQueryVO {
private Integer vehheadTime;
@ApiModelProperty(value = "平均车头间距")
@ExcelProperty("平均车间距")
@ExcelProperty("平均车间距")
private Double vehheadDist;
@ApiModelProperty(value = "时间占有率")
@ExcelProperty("时间占有率")
private Integer timeOccupancy;
@ApiModelProperty(value = "空间占有率")
......
package net.wanji.opt.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author duanruiming
* @date 2024/06/19 15:52
*/
@Data
@NoArgsConstructor
@ApiModel(value = "TurnDataIndexExcelVO", description = "转向数据导出实体")
public class TurnDataIndexExcelVO {
@ApiModelProperty(value = "时间 格式 yyyy-MM-dd HH:mm:ss")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ExcelProperty("时间")
private Date time;
@ApiModelProperty(value = "方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北")
@ExcelProperty("方向")
private String dir;
@ApiModelProperty(value = "总流量")
@ExcelProperty("总流量")
private Integer flow;
@ApiModelProperty(value = "平均速度")
@ExcelProperty("平均速度")
private BigDecimal speed;
@ApiModelProperty(value = "左转流量")
@ExcelProperty("左转流量")
private Integer leftFlow;
@ApiModelProperty(value = "左转平均速度")
@ExcelProperty("左转平均速度")
private BigDecimal leftSpeed;
@ApiModelProperty(value = "直行流量")
@ExcelProperty("直行流量")
private Integer straightFlow;
@ApiModelProperty(value = "直行平均速度")
@ExcelProperty("直行平均速度")
private BigDecimal straightSpeed;
@ApiModelProperty(value = "右转平均流量")
@ExcelProperty("右转平均流量")
private Integer rightFlow;
@ApiModelProperty(value = "右转速度")
@ExcelProperty("右转速度")
private BigDecimal rightSpeed;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment