Commit f708007b authored by duanruiming's avatar duanruiming

[add] 干线列表查询优化

parent 21927e5b
......@@ -193,7 +193,43 @@ public class TrendServiceImpl implements TrendService {
Integer status = greenwaveListDTO.getStatus();
String name = greenwaveListDTO.getName();
Integer type = greenwaveListDTO.getType();
List<GreenwaveListVO> greenwaveListVOList = greenwaveInfoMapper.listGreenwave(status, name, type);
List<GreenwaveListVO> greenDirList = greenwaveInfoMapper.listGreenwave(status, name, type);
// 数据库中包含正反绿波 转化成双向
List<GreenwaveListVO> greenwaveListVOList = new ArrayList<>();
if (!CollectionUtils.isEmpty(greenDirList)) {
Map<Integer, List<GreenwaveListVO>> greenMap = greenDirList.stream().collect(Collectors.groupingBy(GreenwaveListVO::getId));
for (Map.Entry<Integer, List<GreenwaveListVO>> entry : greenMap.entrySet()) {
Integer greenId = entry.getKey();
List<GreenwaveListVO> value = entry.getValue();
if (Objects.equals(1, value.size())) {
greenwaveListVOList.addAll(value);
}
if (Objects.equals(2, value.size())) {
Double speed = 0.0;
Double trafficIndex = 1.0;
int travelTime = 0;
GreenwaveListVO wDirVo = new GreenwaveListVO();
for (GreenwaveListVO greenwaveListVO : value) {
speed += greenwaveListVO.getSpeed() == null ? 0.0 : greenwaveListVO.getSpeed();
trafficIndex += greenwaveListVO.getTrafficIndex() == null ? 0.0 : greenwaveListVO.getTrafficIndex();
travelTime += greenwaveListVO.getTravelTime();
wDirVo.setId(greenId);
wDirVo.setName(greenwaveListVO.getName());
wDirVo.setWkt(greenwaveListVO.getWkt());
wDirVo.setDuration(greenwaveListVO.getDuration());
wDirVo.setStartTime(greenwaveListVO.getStartTime());
wDirVo.setRealtimeStatus(greenwaveListVO.getRealtimeStatus());
wDirVo.setInfoStatus(greenwaveListVO.getInfoStatus());
}
wDirVo.setSpeed(speed / 2);
wDirVo.setTrafficIndex(trafficIndex / 2 < 1 ? 1 : trafficIndex / 2);
wDirVo.setTravelTime(travelTime / 2);
greenwaveListVOList.add(wDirVo);
}
}
}
// 3、4都算拥堵
if (status != null && status == 3) {
List<GreenwaveListVO> extraList = greenwaveInfoMapper.listGreenwave(4, name, type);
......
......@@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import net.wanji.opt.config.DoubleToTwoDecimalPlacesSerializer;
import net.wanji.databus.config.DoubleToTwoDecimalPlacesSerializer;
import java.util.List;
......
package net.wanji.opt.config;
package net.wanji.databus.config;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
......@@ -9,7 +9,7 @@ import java.text.DecimalFormat;
/**
* @author duanruiming
* @date 2024/11/20 19:00
* @date 2024/12/01 16:17
*/
public class DoubleToTwoDecimalPlacesSerializer extends JsonSerializer<Double> {
private static final DecimalFormat df = new DecimalFormat("#.00");
......@@ -23,4 +23,4 @@ public class DoubleToTwoDecimalPlacesSerializer extends JsonSerializer<Double> {
gen.writeNull();
}
}
}
\ No newline at end of file
}
package net.wanji.databus.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import net.wanji.databus.config.DoubleToTwoDecimalPlacesSerializer;
import java.util.Date;
import java.util.List;
......@@ -22,6 +25,7 @@ public class GreenwaveListVO {
@ApiModelProperty(value = "路口状态:1畅通;2缓行;3拥堵;5未知")
private Integer realtimeStatus;
@ApiModelProperty(value = "拥堵指数")
@JsonSerialize(using = DoubleToTwoDecimalPlacesSerializer.class)
private Double trafficIndex;
@ApiModelProperty(value = "开始时间 格式 08:20:23")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss", timezone = "GMT+8")
......@@ -36,6 +40,7 @@ public class GreenwaveListVO {
@ApiModelProperty(value = "行程时间")
private int travelTime;
@ApiModelProperty(value = "行程速度")
@JsonSerialize(using = DoubleToTwoDecimalPlacesSerializer.class)
private Double speed;
@ApiModelProperty(value = "路口列表")
private List<CrossListElement> crossList;
......
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