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; ...@@ -12,6 +12,7 @@ import java.util.Objects;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum OptStatusEnum { public enum OptStatusEnum {
ZERO(0, "未优化"),
ONE(1, "优化中"), ONE(1, "优化中"),
TWO(2, "优化完"); TWO(2, "优化完");
private Integer code; private Integer code;
...@@ -23,6 +24,6 @@ public enum OptStatusEnum { ...@@ -23,6 +24,6 @@ public enum OptStatusEnum {
return value.getDesc(); return value.getDesc();
} }
} }
return OptStatusEnum.ONE.getDesc(); return OptStatusEnum.ZERO.getDesc();
} }
} }
...@@ -90,14 +90,14 @@ public class CrossIndexController { ...@@ -90,14 +90,14 @@ public class CrossIndexController {
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON) produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/crossAIList") @GetMapping(value = "/crossAIList")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "OK", response = AddOrUpdateSceneDTO.class), @ApiResponse(code = 200, message = "OK", response = AIOptResultVO.class),
}) })
public JsonViewObject crossAIList() { public JsonViewObject crossAIList() {
List<AIOptResultVO> results = null; List<AIOptResultVO> results = null;
try { try {
results = crossIndexService.crossAIList(); results = crossIndexService.crossAIList();
} catch (Exception e) { } catch (Exception e) {
JsonViewObject.newInstance().fail("优化监测-AI路口"); JsonViewObject.newInstance().fail("优化监测-AI路口查询异常");
} }
return JsonViewObject.newInstance().success(results); return JsonViewObject.newInstance().success(results);
} }
......
...@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.po.trend.HoloEventInfoPO; import net.wanji.opt.po.trend.HoloEventInfoPO;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -12,10 +13,11 @@ import java.util.List; ...@@ -12,10 +13,11 @@ import java.util.List;
* @date 2023/01/31 18:32 * @date 2023/01/31 18:32
*/ */
@Repository @Repository
@DS("holo")
public interface HoloEventMapper extends BaseMapper<HoloEventInfoPO> { public interface HoloEventMapper extends BaseMapper<HoloEventInfoPO> {
Integer selectCrossEmergencyCount(String crossId, int startStamp, int endStamp); Integer selectCrossEmergencyCount(String crossId, int startStamp, int endStamp);
Integer selectEmergencyCountWithLaneIds(String crossId, int startStamp, int endStamp, List<String> laneIds); 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; ...@@ -3,9 +3,13 @@ package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.synthesis.pojo.StrategyCrossResultEntity; import net.wanji.opt.synthesis.pojo.StrategyCrossResultEntity;
import java.util.Date;
import java.util.List;
/** /**
* @author duanruiming * @author duanruiming
* @date 2024/12/01 14:23 * @date 2024/12/01 14:23
*/ */
public interface StrategyCrossResultMapper extends BaseMapper<StrategyCrossResultEntity> { public interface StrategyCrossResultMapper extends BaseMapper<StrategyCrossResultEntity> {
List<StrategyCrossResultEntity> selectAICrossList(Date date);
} }
...@@ -104,4 +104,6 @@ public class HoloEventInfoPO implements Serializable { ...@@ -104,4 +104,6 @@ public class HoloEventInfoPO implements Serializable {
private String remark; private String remark;
@ApiModelProperty(value = "拓展字段") @ApiModelProperty(value = "拓展字段")
private String extend; private String extend;
@ApiModelProperty(value = "拓展字段")
private Integer alarmStatus;
} }
\ No newline at end of file
...@@ -24,7 +24,7 @@ public interface CrossIndexService { ...@@ -24,7 +24,7 @@ public interface CrossIndexService {
List<CrossOptResult> crossOptResultList(CrossIdBO crossIdBO) throws Exception; List<CrossOptResult> crossOptResultList(CrossIdBO crossIdBO) throws Exception;
List<AIOptResultVO> crossAIList(); List<AIOptResultVO> crossAIList() throws Exception;
crossStatusCountVO crossStatusCount(String crossId); crossStatusCountVO crossStatusCount(String crossId);
} }
...@@ -13,6 +13,7 @@ import net.wanji.databus.po.TBaseCrossInfo; ...@@ -13,6 +13,7 @@ import net.wanji.databus.po.TBaseCrossInfo;
import net.wanji.opt.common.enums.CrossOptStrategyEnum; import net.wanji.opt.common.enums.CrossOptStrategyEnum;
import net.wanji.opt.common.enums.OptStatusEnum; import net.wanji.opt.common.enums.OptStatusEnum;
import net.wanji.opt.common.enums.StrategyControlEnum; 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.dao.mapper.StrategyCrossResultMapper;
import net.wanji.opt.service.CrossIndexService; import net.wanji.opt.service.CrossIndexService;
import net.wanji.opt.synthesis.pojo.StrategyCrossResultEntity; import net.wanji.opt.synthesis.pojo.StrategyCrossResultEntity;
...@@ -26,6 +27,7 @@ import javax.annotation.Resource; ...@@ -26,6 +27,7 @@ import javax.annotation.Resource;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -45,6 +47,8 @@ public class CrossIndexServiceImpl implements CrossIndexService { ...@@ -45,6 +47,8 @@ public class CrossIndexServiceImpl implements CrossIndexService {
private BaseCrossInfoMapper baseCrossInfoMapper; private BaseCrossInfoMapper baseCrossInfoMapper;
@Resource @Resource
private StrategyCrossResultMapper strategyCrossResultMapper; private StrategyCrossResultMapper strategyCrossResultMapper;
@Resource
private HoloEventMapper holoEventMapper;
@Override @Override
public Map<Integer, CrossDirDataRealtimePO> crossDirIndex(CrossIdBO crossIdBO) { public Map<Integer, CrossDirDataRealtimePO> crossDirIndex(CrossIdBO crossIdBO) {
...@@ -75,7 +79,7 @@ public class CrossIndexServiceImpl implements CrossIndexService { ...@@ -75,7 +79,7 @@ public class CrossIndexServiceImpl implements CrossIndexService {
} }
@Override @Override
public List<CrossOptResult> crossOptResultList(CrossIdBO crossIdBO) throws Exception{ public List<CrossOptResult> crossOptResultList(CrossIdBO crossIdBO) throws Exception {
LambdaQueryWrapper<StrategyCrossResultEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<StrategyCrossResultEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyCrossResultEntity::getCrossId, crossIdBO.getCrossId()); queryWrapper.eq(StrategyCrossResultEntity::getCrossId, crossIdBO.getCrossId());
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();
...@@ -88,7 +92,7 @@ public class CrossIndexServiceImpl implements CrossIndexService { ...@@ -88,7 +92,7 @@ public class CrossIndexServiceImpl implements CrossIndexService {
if (!CollectionUtils.isEmpty(list)) { if (!CollectionUtils.isEmpty(list)) {
for (StrategyCrossResultEntity entity : list) { for (StrategyCrossResultEntity entity : list) {
CrossOptResult crossOptResult = new CrossOptResult(); 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); crossOptResult.setTimeStamp(date);
String timingPlan = entity.getTimingPlan(); String timingPlan = entity.getTimingPlan();
Integer countDown = entity.getCountDown(); Integer countDown = entity.getCountDown();
...@@ -108,19 +112,14 @@ public class CrossIndexServiceImpl implements CrossIndexService { ...@@ -108,19 +112,14 @@ public class CrossIndexServiceImpl implements CrossIndexService {
@Override @Override
public List<AIOptResultVO> crossAIList() { public List<AIOptResultVO> crossAIList() {
List<AIOptResultVO> results = new ArrayList<>(); List<AIOptResultVO> results = new ArrayList<>();
try {
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT; LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime); LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime);
LambdaQueryWrapper<StrategyCrossResultEntity> queryWrapper = new LambdaQueryWrapper<>(); Date date = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
queryWrapper.ge(StrategyCrossResultEntity::getIssueTime, startOfDay); List<StrategyCrossResultEntity> list = strategyCrossResultMapper.selectAICrossList(date);
List<StrategyCrossResultEntity> list = strategyCrossResultMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(list)) { if (!CollectionUtils.isEmpty(list)) {
// 查询出表中当天最新数据 for (StrategyCrossResultEntity resultEntity : 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) {
AIOptResultVO aiOptResultVO = new AIOptResultVO(); AIOptResultVO aiOptResultVO = new AIOptResultVO();
aiOptResultVO.setId(resultEntity.getCrossId()); aiOptResultVO.setId(resultEntity.getCrossId());
aiOptResultVO.setName(resultEntity.getCrossName()); aiOptResultVO.setName(resultEntity.getCrossName());
...@@ -132,11 +131,18 @@ public class CrossIndexServiceImpl implements CrossIndexService { ...@@ -132,11 +131,18 @@ public class CrossIndexServiceImpl implements CrossIndexService {
Integer optStatus = Objects.equals(1, currentAlgo) ? OptStatusEnum.ONE.getCode() : OptStatusEnum.TWO.getCode(); Integer optStatus = Objects.equals(1, currentAlgo) ? OptStatusEnum.ONE.getCode() : OptStatusEnum.TWO.getCode();
aiOptResultVO.setOptStatus(optStatus); aiOptResultVO.setOptStatus(optStatus);
aiOptResultVO.setOptStatusName(Objects.equals(1, currentAlgo) ? OptStatusEnum.ONE.getDesc() : OptStatusEnum.TWO.getDesc()); 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); 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; return results;
} }
......
...@@ -20,9 +20,11 @@ import net.wanji.databus.po.BaseCrossInfoPO; ...@@ -20,9 +20,11 @@ import net.wanji.databus.po.BaseCrossInfoPO;
import net.wanji.databus.vo.AbnormalCrossListVO; import net.wanji.databus.vo.AbnormalCrossListVO;
import net.wanji.opt.cache.BaseCrossInfoCache; import net.wanji.opt.cache.BaseCrossInfoCache;
import net.wanji.opt.cache.GreenWaveInfoCache; import net.wanji.opt.cache.GreenWaveInfoCache;
import net.wanji.opt.common.enums.EventStatusEnum;
import net.wanji.opt.common.enums.StrategyControlEnum; import net.wanji.opt.common.enums.StrategyControlEnum;
import net.wanji.opt.dao.mapper.*; import net.wanji.opt.dao.mapper.*;
import net.wanji.opt.po.StrategyGreenOptHistEntity; 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.enums.StrategyCrossAlgoEnum;
import net.wanji.opt.synthesis.pojo.*; import net.wanji.opt.synthesis.pojo.*;
import net.wanji.opt.synthesis.pojo.vo.StrategyControlDataVO; import net.wanji.opt.synthesis.pojo.vo.StrategyControlDataVO;
...@@ -31,6 +33,7 @@ import net.wanji.opt.synthesis.pojo.vo.StrategyControlVO; ...@@ -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.pojo.vo.StrategyOptTimesVO;
import net.wanji.opt.synthesis.service.PushStrategyControlService; import net.wanji.opt.synthesis.service.PushStrategyControlService;
import net.wanji.opt.synthesis.service.StrategyControlService; import net.wanji.opt.synthesis.service.StrategyControlService;
import net.wanji.opt.vo.AIOptResultVO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -43,6 +46,7 @@ import java.text.SimpleDateFormat; ...@@ -43,6 +46,7 @@ import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -76,6 +80,8 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -76,6 +80,8 @@ public class StrategyControlServiceImpl implements StrategyControlService {
private BaseCrossInfoCache baseCrossInfoCache; private BaseCrossInfoCache baseCrossInfoCache;
@Resource @Resource
private CrossDataRealtimeMapper crossDataRealtimeMapper; private CrossDataRealtimeMapper crossDataRealtimeMapper;
@Resource
private HoloEventMapper holoEventMapper;
@Override @Override
...@@ -400,6 +406,98 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -400,6 +406,98 @@ public class StrategyControlServiceImpl implements StrategyControlService {
@Override @Override
public JsonViewObject crossOptInfoList(Integer type) throws Exception { 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(); JsonViewObject jsonViewObject = JsonViewObject.newInstance();
try { try {
List<StrategyControlDataEntity> currentStrateInfoList = getCurrentStrateInfoList(type); List<StrategyControlDataEntity> currentStrateInfoList = getCurrentStrateInfoList(type);
......
...@@ -33,4 +33,27 @@ ...@@ -33,4 +33,27 @@
</choose> </choose>
</select> </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> </mapper>
\ No newline at end of file
...@@ -5,4 +5,23 @@ ...@@ -5,4 +5,23 @@
<mapper namespace="net.wanji.opt.dao.mapper.StrategyCrossResultMapper"> <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> </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