Commit af51fec2 authored by duanruiming's avatar duanruiming

[add] 调优平台v2-雷达图;路口列表查询优化;

parent 016742f7
...@@ -16,7 +16,8 @@ public enum EventInfoTypeEnum { ...@@ -16,7 +16,8 @@ public enum EventInfoTypeEnum {
PHASE_EMPTY(5, "701","相位空放"), PHASE_EMPTY(5, "701","相位空放"),
CROSS_UNBALANCE(1, "702","路口失衡"), CROSS_UNBALANCE(1, "702","路口失衡"),
CROSS_OVERFLOW(3, "703","路口溢出"), CROSS_OVERFLOW(3, "703","路口溢出"),
CROSS_DEADLOCK(4, "704","路口死锁"), // 当前没有
//CROSS_DEADLOCK(4, "704","路口死锁"),
GREEN_SLOW(6, "705","干线-缓行"), GREEN_SLOW(6, "705","干线-缓行"),
GREEN_CONGEST(7, "706","干线-拥堵"), GREEN_CONGEST(7, "706","干线-拥堵"),
CROSS_CONGEST(2, "707","路口拥堵"); CROSS_CONGEST(2, "707","路口拥堵");
......
package net.wanji.opt.servicev2.implv2; package net.wanji.opt.servicev2.implv2;
import com.alibaba.nacos.api.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.databus.dao.mapper.CrossDataHistMapper;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.opt.common.enums.EventInfoTypeEnum;
import net.wanji.opt.dao.mapper.HoloEventMapper; import net.wanji.opt.dao.mapper.HoloEventMapper;
import net.wanji.opt.dao.mapper.StrategyCrossResultMapper; import net.wanji.opt.dao.mapper.StrategyCrossResultMapper;
import net.wanji.opt.servicev2.TrendServiceV2; import net.wanji.opt.servicev2.TrendServiceV2;
...@@ -11,7 +16,12 @@ import org.springframework.stereotype.Service; ...@@ -11,7 +16,12 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* @author duanruiming * @author duanruiming
...@@ -25,10 +35,26 @@ public class TrendServiceV2Impl implements TrendServiceV2 { ...@@ -25,10 +35,26 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
private HoloEventMapper holoEventMapper; private HoloEventMapper holoEventMapper;
@Resource @Resource
private StrategyCrossResultMapper strategyCrossResultMapper; private StrategyCrossResultMapper strategyCrossResultMapper;
@Resource
private CrossDataHistMapper crossDataHistMapper;
@Override @Override
public List<CrossGreenStatusTimeRateVO> crossGreenStatusTimeRate() { public List<CrossGreenStatusTimeRateVO> crossGreenStatusTimeRate() {
return holoEventMapper.selectCrossGreenStatusTimeRate(); List<CrossGreenStatusTimeRateVO> crossGreenStatusTimeRateVOS = holoEventMapper.selectCrossGreenStatusTimeRate();
if (!CollectionUtils.isEmpty(crossGreenStatusTimeRateVOS)) {
Map<String, CrossGreenStatusTimeRateVO> map = crossGreenStatusTimeRateVOS.stream().collect(Collectors.toMap(CrossGreenStatusTimeRateVO::getType, crossGreenStatusTimeRateVO -> crossGreenStatusTimeRateVO));
for (EventInfoTypeEnum typeEnum : EventInfoTypeEnum.values()) {
String eventType = typeEnum.getEventType();
if (!map.containsKey(eventType)) {
CrossGreenStatusTimeRateVO vo = new CrossGreenStatusTimeRateVO();
vo.setType(eventType);
vo.setCount(0);
crossGreenStatusTimeRateVOS.add(vo);
}
}
}
return crossGreenStatusTimeRateVOS;
} }
@Override @Override
...@@ -37,38 +63,44 @@ public class TrendServiceV2Impl implements TrendServiceV2 { ...@@ -37,38 +63,44 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
try { try {
results = new ArrayList<>(); results = new ArrayList<>();
List<CrossOptInfoVO> resultList = strategyCrossResultMapper.selectAICrossListV2(); List<CrossOptInfoVO> resultList = strategyCrossResultMapper.selectAICrossListV2();
LocalDateTime now = LocalDateTime.now();
LocalDateTime lastWeekNow = now.minusDays(7);
Instant instant = lastWeekNow.atZone(ZoneId.systemDefault()).toInstant();
long start = instant.getEpochSecond();
long end = start + 5 * 60;
LambdaQueryWrapper<CrossDataHistPO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.between(CrossDataHistPO::getBatchTime, start, end);
List<CrossDataHistPO> crossDataHistPOS = crossDataHistMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(resultList)) { if (!CollectionUtils.isEmpty(resultList)) {
for (CrossOptInfoVO entity : resultList) { for (CrossOptInfoVO entity : resultList) {
CrossOptInfoVO result = new CrossOptInfoVO(); CrossOptInfoVO result = new CrossOptInfoVO();
String crossId = entity.getCrossId();
Double trafficIndex = entity.getTrafficIndex();
Integer queueLength = entity.getQueueLength();
String location = entity.getLocation();
location = location.replace("POINT(", "").replace(" ", ",").replace(")", "");
BeanUtils.copyProperties(entity, result); BeanUtils.copyProperties(entity, result);
Integer currentAlgo = entity.getCurrentAlgo(); result.setLocation(location);
Date issueTime = entity.getIssueTime(); for (CrossDataHistPO crossDataHistPO : crossDataHistPOS) {
Date current = new Date(); String lastWeekCrossId = crossDataHistPO.getCrossId();
Integer duration = Objects.nonNull(entity.getDuration()) ? entity.getDuration() : 0; Double lastWeekTrafficIndex = crossDataHistPO.getTrafficIndex();
// 计算结束时间 Double lastWeekQueueLength = crossDataHistPO.getQueueLength();
if (Objects.nonNull(issueTime)) { if (StringUtils.equals(crossId, lastWeekCrossId)) {
if (Objects.equals(2, currentAlgo) && current.getTime() - issueTime.getTime() <= duration * 1000) { if (trafficIndex > lastWeekTrafficIndex) {
result.setOptStatus("优化中"); result.setTrafficIndexUpDown(1);
result.setOptMethod("均衡调控"); } else {
} else if (current.getTime() - issueTime.getTime() > 10 * 1000) { result.setTrafficIndexUpDown(0);
currentAlgo = null;
}
} }
if (queueLength > lastWeekQueueLength) {
// 0无策略 result.setQueueLengthUpDown(1);
if (Objects.isNull(currentAlgo) || Objects.equals(0, currentAlgo)) {
result.setOptStatus("正常");
result.setOptMethod("畅通");
} else if (Objects.equals(2, currentAlgo)) {
result.setOptStatus("优化中");
result.setOptMethod("均衡调控");
} else { } else {
result.setOptStatus("优化中"); result.setQueueLengthUpDown(0);
result.setOptMethod("效率提升");
} }
results.add(result); results.add(result);
} }
} }
}
}
} catch (Exception e) { } catch (Exception e) {
log.error("态势监测-区域体检-雷达图-查询失败:{}", e); log.error("态势监测-区域体检-雷达图-查询失败:{}", e);
throw new Exception(e); throw new Exception(e);
......
...@@ -25,8 +25,8 @@ public class CrossOptInfoVO { ...@@ -25,8 +25,8 @@ public class CrossOptInfoVO {
private Integer currentAlgo; private Integer currentAlgo;
@ApiModelProperty(value = "响应编码") @ApiModelProperty(value = "响应编码")
private Integer responseCode; private Integer responseCode;
@ApiModelProperty(value = "响应状态") @ApiModelProperty(value = "经纬度")
private String responseContent; private String location;
@ApiModelProperty(value = "持续时长") @ApiModelProperty(value = "持续时长")
private Integer duration; private Integer duration;
private String strategyName; private String strategyName;
...@@ -38,5 +38,9 @@ public class CrossOptInfoVO { ...@@ -38,5 +38,9 @@ public class CrossOptInfoVO {
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class) @JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double trafficIndex; private Double trafficIndex;
@ApiModelProperty(value = "排队长度") @ApiModelProperty(value = "排队长度")
private int queueLength; private Integer queueLength;
@ApiModelProperty(value = "同比交通指数,0-向下, 1向上")
private Integer trafficIndexUpDown;
@ApiModelProperty(value = "同比排队长度,0-向下, 1向上")
private Integer queueLengthUpDown;
} }
\ No newline at end of file
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
TIMESTAMPDIFF(SECOND, start_time, ifnull(end_time,now())) duration, TIMESTAMPDIFF(SECOND, start_time, ifnull(end_time,now())) duration,
TIMESTAMPDIFF(SECOND, DATE_FORMAT(start_time, '%Y-%m-%d 00:00:00'), now()) as totalTime TIMESTAMPDIFF(SECOND, DATE_FORMAT(start_time, '%Y-%m-%d 00:00:00'), now()) as totalTime
from t_event_info from t_event_info
where type in ('701', '702', '703', '704', '705', '706', '707') and start_time > curdate() where type in ('701', '702', '703', '705', '706', '707') and start_time > curdate()
) t1 group by t1.type ) t1 group by t1.type
</select> </select>
......
...@@ -19,9 +19,17 @@ ...@@ -19,9 +19,17 @@
<select id="selectAICrossListV2" resultType="net.wanji.opt.vo2.CrossOptInfoVO"> <select id="selectAICrossListV2" resultType="net.wanji.opt.vo2.CrossOptInfoVO">
select t1.id crossId, t1.name crossName, t2.issue_time issueTime, t2.current_algo currentAlgo, select t1.id crossId, t1.name crossName, t2.issue_time issueTime,
t2.response_code responseCode, t1.location as responseContent, t2.duration, case
t3.queue_length queueLength, t3.traffic_index trafficIndex from when t2.current_algo = 2 then '效率提升'
else '均衡调控'
end as strategyName,
t2.response_code responseCode,
t1.location as location,
ifnull(t2.duration, 0) duration,
t3.queue_length queueLength,
t3.traffic_index trafficIndex
from
(select id, name, location from t_base_cross_info where is_signal = 1) t1 (select id, name, location from t_base_cross_info where is_signal = 1) t1
left join (select t1.cross_id, t1.issue_time, t1.current_algo, t1.response_code, t1.duration from t_strategy_cross_result t1 left join (select t1.cross_id, t1.issue_time, t1.current_algo, t1.response_code, t1.duration from t_strategy_cross_result t1
inner join (select cross_id, max(issue_time) issue_time from t_strategy_cross_result where issue_time > CURDATE() group by cross_id) t3 inner join (select cross_id, max(issue_time) issue_time from t_strategy_cross_result where issue_time > CURDATE() group by cross_id) t3
...@@ -29,7 +37,7 @@ ...@@ -29,7 +37,7 @@
on t1.id = t2.cross_id on t1.id = t2.cross_id
and t2.issue_time > CURDATE() and t2.issue_time > CURDATE()
left join t_cross_data_realtime t3 on t1.id = t3.cross_id left join t_cross_data_realtime t3 on t1.id = t3.cross_id
order by t2.issue_time desc order by t3.traffic_index desc
</select> </select>
</mapper> </mapper>
\ No newline at end of file
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