Commit 81425054 authored by duanruiming's avatar duanruiming

[add] 干线交通状态比例图

parent 5b09156f
...@@ -278,6 +278,18 @@ public class TrendController { ...@@ -278,6 +278,18 @@ public class TrendController {
} }
@ApiOperation(value = "干线交通状态", notes = "干线交通状态", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/greenStatusTimeRate")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = CrossStatusTimeRateVO.class),
})
public JsonViewObject greenStatusTimeRate(Integer greenId) throws Exception {
GreenStatusTimeRateVO crossStatusTimeRateVO = trendService.greenStatusTimeRate(greenId);
return JsonViewObject.newInstance().success(crossStatusTimeRateVO);
}
@ApiOperation(value = "车道交通指标", notes = "车道交通指标", response = JsonViewObject.class, @ApiOperation(value = "车道交通指标", notes = "车道交通指标", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON) produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/laneTrafficIndex", @PostMapping(value = "/laneTrafficIndex",
......
...@@ -59,6 +59,7 @@ public interface TrendService { ...@@ -59,6 +59,7 @@ public interface TrendService {
List<Top5IndexVO> top5Flow() throws Exception; List<Top5IndexVO> top5Flow() throws Exception;
CrossStatusTimeRateVO crossStatusTimeRate(CommonCrossIdVO commonCrossIdVO) throws Exception; CrossStatusTimeRateVO crossStatusTimeRate(CommonCrossIdVO commonCrossIdVO) throws Exception;
GreenStatusTimeRateVO greenStatusTimeRate(Integer greenId) throws Exception;
List<TableQueryVO.CycleDataElement> laneTrafficIndex(CommonCrossIdDateTimeVO crossIdDateTimeVO) throws Exception; List<TableQueryVO.CycleDataElement> laneTrafficIndex(CommonCrossIdDateTimeVO crossIdDateTimeVO) throws Exception;
......
...@@ -1948,6 +1948,60 @@ public class TrendServiceImpl implements TrendService { ...@@ -1948,6 +1948,60 @@ public class TrendServiceImpl implements TrendService {
return hotspotCrossVOS; return hotspotCrossVOS;
} }
@Override
public GreenStatusTimeRateVO greenStatusTimeRate(Integer greenId) throws Exception {
try {
GreenStatusTimeRateVO greenStatusTimeRateVO = new GreenStatusTimeRateVO();
Date date = new Date();
long time = date.getTime() / 1000;
Instant instant = Instant.ofEpochSecond(time);
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("+8"));
// 00:00
LocalDateTime startOfDay = localDateTime.withHour(0).withMinute(0).withSecond(0);
int startBatchTime = Long.valueOf(Date.from(startOfDay.atZone(ZoneId.of("+8")).toInstant()).getTime() / 1000).intValue();
// 23:59
LocalDateTime endOfDay = startOfDay.plus(1, ChronoUnit.DAYS).minus(1, ChronoUnit.SECONDS);
int endBatchTime = Long.valueOf(Date.from(endOfDay.atZone(ZoneId.of("+8")).toInstant()).getTime() / 1000).intValue();
LambdaQueryWrapper<GreenwaveHistPO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(GreenwaveHistPO::getGreenId, greenId);
queryWrapper.ge(GreenwaveHistPO::getBatchTime, startBatchTime);
queryWrapper.le(GreenwaveHistPO::getBatchTime, endBatchTime);
List<GreenwaveHistPO> greenwaveHistPOS = greenwaveHistMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(greenwaveHistPOS)) {
int size = greenwaveHistPOS.size();
int unblockedTimeRate = 0;
int slowTimeRate = 0;
int congestionTimeRate = 0;
for (GreenwaveHistPO greenwaveHistPO : greenwaveHistPOS) {
Integer status = greenwaveHistPO.getStatus();
if (status == 1 || status == 5) {
unblockedTimeRate += 1;
}
if (status == 2) {
slowTimeRate += 1;
}
if (status == 3 || status == 4) {
congestionTimeRate += 1;
}
}
greenStatusTimeRateVO.setUnblockedTimeRate(getRate(unblockedTimeRate, size));
greenStatusTimeRateVO.setSlowTimeRate(getRate(slowTimeRate, size));
greenStatusTimeRateVO.setCongestionTimeRate(getRate(congestionTimeRate, size));
}
return greenStatusTimeRateVO;
} catch (Exception e) {
log.error("干线运行状态监测异常: ", e);
throw new RuntimeException(e);
}
}
private int getRate(int count, int size) {
float temp = count / (float) size * 100;
temp = temp < 1 ? 0 : temp;
int rate = Math.round(temp);
return rate;
}
@Override @Override
public CrossStatusTimeRateVO crossStatusTimeRate(CommonCrossIdVO commonCrossIdVO) throws Exception { public CrossStatusTimeRateVO crossStatusTimeRate(CommonCrossIdVO commonCrossIdVO) throws Exception {
......
package net.wanji.opt.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author duanruiming
* @date 2024/12/09 15:00
*/
@Data
@NoArgsConstructor
@ApiModel(value = "GreenStatusTimeRateVO")
public class GreenStatusTimeRateVO {
@ApiModelProperty(value = "干线ID")
private Integer greenId;
@ApiModelProperty(value = "干线拥堵")
private int congestionTimeRate;
@ApiModelProperty(value = "干线缓行")
private int slowTimeRate;
@ApiModelProperty(value = "干线畅通")
private int unblockedTimeRate;
}
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