Commit 33ea7d79 authored by duanruiming's avatar duanruiming

[add] AI路口优化

parent 96fba4c9
package net.wanji.opt.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Objects;
/**
* @author duanruiming
* @date 2024/12/31 11:58
*/
@Getter
@AllArgsConstructor
public enum EventStatusEnum {
// 0未处理 1分析中 2优化中 3优化完 4已结束
ZERO(0, "未处理"),
ONE(1, "分析中"),
TWO(2, "优化中"),
THREE(3, "优化中"),
FOUR(4, "已结束");
private Integer code;
private String desc;
public static String getDesc(Integer code) {
for (EventStatusEnum value : EventStatusEnum.values()) {
if (Objects.equals(code, value.getCode())) {
return value.getDesc();
}
}
// 畅通为未优化
return "未优化";
}
}
......@@ -12,6 +12,7 @@ import java.util.Objects;
@Getter
@AllArgsConstructor
public enum OptStatusEnum {
ZERO(0, "未优化"),
ONE(1, "优化中"),
TWO(2, "优化完");
private Integer code;
......@@ -23,6 +24,6 @@ public enum OptStatusEnum {
return value.getDesc();
}
}
return OptStatusEnum.ONE.getDesc();
return OptStatusEnum.ZERO.getDesc();
}
}
......@@ -90,14 +90,14 @@ public class CrossIndexController {
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/crossAIList")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = AddOrUpdateSceneDTO.class),
@ApiResponse(code = 200, message = "OK", response = AIOptResultVO.class),
})
public JsonViewObject crossAIList() {
List<AIOptResultVO> results = null;
try {
results = crossIndexService.crossAIList();
} catch (Exception e) {
JsonViewObject.newInstance().fail("优化监测-AI路口");
JsonViewObject.newInstance().fail("优化监测-AI路口查询异常");
}
return JsonViewObject.newInstance().success(results);
}
......
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.po.trend.HoloEventInfoPO;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
/**
......@@ -12,10 +13,11 @@ import java.util.List;
* @date 2023/01/31 18:32
*/
@Repository
@DS("holo")
public interface HoloEventMapper extends BaseMapper<HoloEventInfoPO> {
Integer selectCrossEmergencyCount(String crossId, int startStamp, int endStamp);
Integer selectEmergencyCountWithLaneIds(String crossId, int startStamp, int endStamp, List<String> laneIds);
List<HoloEventInfoPO> selectAIList(Date startTime);
List<HoloEventInfoPO> selectAIGreenList(Date startTime);
}
......@@ -3,9 +3,13 @@ package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.synthesis.pojo.StrategyCrossResultEntity;
import java.util.Date;
import java.util.List;
/**
* @author duanruiming
* @date 2024/12/01 14:23
*/
public interface StrategyCrossResultMapper extends BaseMapper<StrategyCrossResultEntity> {
List<StrategyCrossResultEntity> selectAICrossList(Date date);
}
......@@ -104,4 +104,6 @@ public class HoloEventInfoPO implements Serializable {
private String remark;
@ApiModelProperty(value = "拓展字段")
private String extend;
@ApiModelProperty(value = "拓展字段")
private Integer alarmStatus;
}
\ No newline at end of file
......@@ -24,7 +24,7 @@ public interface CrossIndexService {
List<CrossOptResult> crossOptResultList(CrossIdBO crossIdBO) throws Exception;
List<AIOptResultVO> crossAIList();
List<AIOptResultVO> crossAIList() throws Exception;
crossStatusCountVO crossStatusCount(String crossId);
}
......@@ -13,6 +13,7 @@ import net.wanji.databus.po.TBaseCrossInfo;
import net.wanji.opt.common.enums.CrossOptStrategyEnum;
import net.wanji.opt.common.enums.OptStatusEnum;
import net.wanji.opt.common.enums.StrategyControlEnum;
import net.wanji.opt.dao.mapper.HoloEventMapper;
import net.wanji.opt.dao.mapper.StrategyCrossResultMapper;
import net.wanji.opt.service.CrossIndexService;
import net.wanji.opt.synthesis.pojo.StrategyCrossResultEntity;
......@@ -26,6 +27,7 @@ import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
......@@ -45,6 +47,8 @@ public class CrossIndexServiceImpl implements CrossIndexService {
private BaseCrossInfoMapper baseCrossInfoMapper;
@Resource
private StrategyCrossResultMapper strategyCrossResultMapper;
@Resource
private HoloEventMapper holoEventMapper;
@Override
public Map<Integer, CrossDirDataRealtimePO> crossDirIndex(CrossIdBO crossIdBO) {
......@@ -75,7 +79,7 @@ public class CrossIndexServiceImpl implements CrossIndexService {
}
@Override
public List<CrossOptResult> crossOptResultList(CrossIdBO crossIdBO) throws Exception{
public List<CrossOptResult> crossOptResultList(CrossIdBO crossIdBO) throws Exception {
LambdaQueryWrapper<StrategyCrossResultEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyCrossResultEntity::getCrossId, crossIdBO.getCrossId());
LocalDate currentDate = LocalDate.now();
......@@ -88,7 +92,7 @@ public class CrossIndexServiceImpl implements CrossIndexService {
if (!CollectionUtils.isEmpty(list)) {
for (StrategyCrossResultEntity entity : list) {
CrossOptResult crossOptResult = new CrossOptResult();
Date date =DateUtil.parse(entity.getIssueTime(), "yyyy-MM-dd HH:mm:ss");
Date date = DateUtil.parse(entity.getIssueTime(), "yyyy-MM-dd HH:mm:ss");
crossOptResult.setTimeStamp(date);
String timingPlan = entity.getTimingPlan();
Integer countDown = entity.getCountDown();
......@@ -108,19 +112,14 @@ public class CrossIndexServiceImpl implements CrossIndexService {
@Override
public List<AIOptResultVO> crossAIList() {
List<AIOptResultVO> results = new ArrayList<>();
LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime);
LambdaQueryWrapper<StrategyCrossResultEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.ge(StrategyCrossResultEntity::getIssueTime, startOfDay);
List<StrategyCrossResultEntity> list = strategyCrossResultMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(list)) {
// 查询出表中当天最新数据
Map<String, Optional<StrategyCrossResultEntity>> crossTimeMap = list.stream().collect(Collectors.groupingBy(StrategyCrossResultEntity::getCrossId,
Collectors.maxBy(Comparator.comparing(StrategyCrossResultEntity::getIssueTime))));
List<StrategyCrossResultEntity> crossMaxTimeList = crossTimeMap.values().stream().map(Optional::get).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(crossMaxTimeList)) {
for (StrategyCrossResultEntity resultEntity : crossMaxTimeList) {
try {
LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime);
Date date = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
List<StrategyCrossResultEntity> list = strategyCrossResultMapper.selectAICrossList(date);
if (!CollectionUtils.isEmpty(list)) {
for (StrategyCrossResultEntity resultEntity : list) {
AIOptResultVO aiOptResultVO = new AIOptResultVO();
aiOptResultVO.setId(resultEntity.getCrossId());
aiOptResultVO.setName(resultEntity.getCrossName());
......@@ -132,11 +131,18 @@ public class CrossIndexServiceImpl implements CrossIndexService {
Integer optStatus = Objects.equals(1, currentAlgo) ? OptStatusEnum.ONE.getCode() : OptStatusEnum.TWO.getCode();
aiOptResultVO.setOptStatus(optStatus);
aiOptResultVO.setOptStatusName(Objects.equals(1, currentAlgo) ? OptStatusEnum.ONE.getDesc() : OptStatusEnum.TWO.getDesc());
if (Objects.isNull(currentAlgo)) {
aiOptResultVO.setOptStatus(-1);
aiOptResultVO.setOptStatusName(OptStatusEnum.ZERO.getDesc());
}
results.add(aiOptResultVO);
}
}
} catch (Exception e) {
log.error("AI路口监测查询异常:", e);
throw new RuntimeException(e);
}
Collections.sort(results, Comparator.comparingInt(AIOptResultVO::getOptStatus));
Collections.sort(results, Comparator.comparingInt(AIOptResultVO::getOptStatus).reversed());
return results;
}
......
......@@ -20,9 +20,11 @@ import net.wanji.databus.po.BaseCrossInfoPO;
import net.wanji.databus.vo.AbnormalCrossListVO;
import net.wanji.opt.cache.BaseCrossInfoCache;
import net.wanji.opt.cache.GreenWaveInfoCache;
import net.wanji.opt.common.enums.EventStatusEnum;
import net.wanji.opt.common.enums.StrategyControlEnum;
import net.wanji.opt.dao.mapper.*;
import net.wanji.opt.po.StrategyGreenOptHistEntity;
import net.wanji.opt.po.trend.HoloEventInfoPO;
import net.wanji.opt.synthesis.enums.StrategyCrossAlgoEnum;
import net.wanji.opt.synthesis.pojo.*;
import net.wanji.opt.synthesis.pojo.vo.StrategyControlDataVO;
......@@ -31,6 +33,7 @@ import net.wanji.opt.synthesis.pojo.vo.StrategyControlVO;
import net.wanji.opt.synthesis.pojo.vo.StrategyOptTimesVO;
import net.wanji.opt.synthesis.service.PushStrategyControlService;
import net.wanji.opt.synthesis.service.StrategyControlService;
import net.wanji.opt.vo.AIOptResultVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
......@@ -43,6 +46,7 @@ import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
......@@ -76,6 +80,8 @@ public class StrategyControlServiceImpl implements StrategyControlService {
private BaseCrossInfoCache baseCrossInfoCache;
@Resource
private CrossDataRealtimeMapper crossDataRealtimeMapper;
@Resource
private HoloEventMapper holoEventMapper;
@Override
......@@ -400,6 +406,98 @@ public class StrategyControlServiceImpl implements StrategyControlService {
@Override
public JsonViewObject crossOptInfoList(Integer type) throws Exception {
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
try {
LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime);
Date date = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
List<StrategyControlDataExt> results = new ArrayList<>();
if (Objects.equals(0, type)) {
results = getCrossList(date);
}
if (Objects.equals(1, type)) {
results = getGreenList(date);
}
return jsonViewObject.success(results, "路网优化监测查询成功");
} catch (Exception e) {
log.error("AI路口查询异常:", e);
throw new RuntimeException(e);
}
}
private List<StrategyControlDataExt> getGreenList(Date date) {
List<StrategyControlDataExt> results = new ArrayList<>();
List<HoloEventInfoPO> holoEventInfoPOS = holoEventMapper.selectAIGreenList(date);
if (!CollectionUtils.isEmpty(holoEventInfoPOS)) {
for (HoloEventInfoPO holoEventInfoPO : holoEventInfoPOS) {
StrategyControlDataExt ext = new StrategyControlDataExt();
ext.setBizId(holoEventInfoPO.getCrossId());
ext.setCrossName(holoEventInfoPO.getRemark());
String location = holoEventInfoPO.getExtend();
ext.setWkt(location);
Integer alarmStatus = holoEventInfoPO.getAlarmStatus();
String optMethod = "效率提升";
if (Objects.isNull(alarmStatus)) {
ext.setStatus(-1);
} else {
ext.setStatus(alarmStatus);
}
ext.setOptMethod(optMethod);
String desc = EventStatusEnum.getDesc(alarmStatus);
ext.setOptStatus(desc);
String type = holoEventInfoPO.getType();
if (StringUtils.isBlank(type)) {
ext.setStrategyName("动态绿波");
}
if (StringUtils.equals("705", type)) {
ext.setStrategyName("干线-缓行");
}
if (StringUtils.equals("706", type)) {
ext.setStrategyName("干线-拥堵");
}
results.add(ext);
}
}
results.sort(Comparator.comparing(StrategyControlDataExt::getStatus).reversed());
return results;
}
private List<StrategyControlDataExt> getCrossList(Date date) {
List<StrategyControlDataExt> results = new ArrayList<>();
List<HoloEventInfoPO> holoEventInfoPOS = holoEventMapper.selectAIList(date);
if (!CollectionUtils.isEmpty(holoEventInfoPOS)) {
for (HoloEventInfoPO holoEventInfoPO : holoEventInfoPOS) {
StrategyControlDataExt ext = new StrategyControlDataExt();
ext.setBizId(holoEventInfoPO.getCrossId());
ext.setCrossName(holoEventInfoPO.getRemark());
String location = holoEventInfoPO.getExtend();
location = location.replace("POINT(", "").replace(" ", ",").replace(")", "");
ext.setWkt(location);
String eventType = holoEventInfoPO.getType();
Integer alarmStatus = holoEventInfoPO.getAlarmStatus();
String optMethod = "效率提升";
ext.setStatus(alarmStatus);
ext.setOptMethod(optMethod);
if (StringUtils.equals(eventType, "702")) {
ext.setOptMethod("均衡调控");
}
if (StringUtils.isBlank(eventType)) {
ext.setOptMethod("畅通");
ext.setStatus(-1);
}
String desc = EventStatusEnum.getDesc(alarmStatus);
ext.setOptStatus(desc);
results.add(ext);
}
}
results.sort(Comparator.comparing(StrategyControlDataExt::getStatus).reversed());
return results;
}
//@Override
public JsonViewObject crossOptInfoList1241(Integer type) throws Exception {
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
try {
List<StrategyControlDataEntity> currentStrateInfoList = getCurrentStrateInfoList(type);
......
......@@ -33,4 +33,27 @@
</choose>
</select>
<select id="selectAIList" resultType="net.wanji.opt.po.trend.HoloEventInfoPO">
select t1.id as crossId, t1.name as remark, t2.type, t2.alarm_status, t1.location as extend from t_base_cross_info t1 left join
(select cross_id, type, max(start_time), alarm_status
from t_event_info
where start_time > #{date}
and type in ('701', '702', '703', '704', '707')
group by cross_id
order by start_time) t2 on t1.id = t2.cross_id
where t1.is_signal = 1
order by t2.alarm_status desc
</select>
<select id="selectAIGreenList" resultType="net.wanji.opt.po.trend.HoloEventInfoPO">
select t1.id as crossId, t1.name as remark, t2.type, t2.alarm_status, t1.wkt as extend from t_greenwave_info t1 left join
(select green_id, type, max(start_time), alarm_status
from t_event_info
where start_time > #{date}
and type in ('705', '706')
group by green_id
order by start_time ) t2 on t1.id = t2.green_id
order by t2.alarm_status desc
</select>
</mapper>
\ No newline at end of file
......@@ -5,4 +5,23 @@
<mapper namespace="net.wanji.opt.dao.mapper.StrategyCrossResultMapper">
<select id="selectAICrossList" resultType="net.wanji.opt.synthesis.pojo.StrategyCrossResultEntity">
select t1.id as cross_id, t1.name as cross_name, t2.current_algo, t2.issue_time
from t_base_cross_info t1 left join
(
select cross_id, cross_name, max(issue_time) issue_time, current_algo
from t_strategy_cross_result
where issue_time > #{date} and response_code = 200
union
select cross_id, cross_name, max(issue_time) issue_time, current_algo
from t_strategy_cross_result
where issue_time > #{date} and response_code &lt; 0
group by cross_id
order by issue_time
) t2 on t1.id = t2.cross_id
where t1.is_signal = 1
order by t2.issue_time desc;
</select>
</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