Commit 7ee9a099 authored by duanruiming's avatar duanruiming

[add] AI路口优化

parent 03350324
......@@ -12,6 +12,7 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
......@@ -74,7 +75,8 @@ public class BaseCrossInfoCache implements CommandLineRunner {
public void init() {
List<BaseCrossInfoPO> baseCrossInfoPOS = baseCrossInfoMapper.selectAll(new CrossInfoVO());
if (!CollectionUtils.isEmpty(baseCrossInfoPOS)) {
crossInfoList.addAll(baseCrossInfoPOS);
List<BaseCrossInfoPO> collect = baseCrossInfoPOS.stream().filter(po -> Objects.equals(po.getIsSignal(), 1)).collect(Collectors.toList());
crossInfoList.addAll(collect);
}
}
}
......@@ -19,7 +19,6 @@ import net.wanji.databus.po.BaseCrossInfoPO;
import net.wanji.databus.po.TBaseCrossInfo;
import net.wanji.opt.cache.BaseCrossInfoCache;
import net.wanji.opt.cache.GreenWaveInfoCache;
import net.wanji.opt.common.enums.CrossOptStrategyEnum;
import net.wanji.opt.common.enums.StrategyControlEnum;
import net.wanji.opt.dao.mapper.*;
import net.wanji.opt.po.StrategyGreenOptHistEntity;
......@@ -72,6 +71,8 @@ public class StrategyControlServiceImpl implements StrategyControlService {
private StrategyGreenOptHistMapper strategyGreenOptHistMapper;
@Resource
private StrategyCrossResultMapper strategyCrossResultMapper;
@Resource
private BaseCrossInfoCache baseCrossInfoCache;
@Override
......@@ -352,9 +353,9 @@ public class StrategyControlServiceImpl implements StrategyControlService {
StrategyControlDataEntity result = new StrategyControlDataEntity();
BeanUtils.copyProperties(entity, result);
String time = entity.getTime();
List<StrategyControlDataVO.TimeTable> timeTables = instance.readValue(time, new TypeReference<List<StrategyControlDataVO.TimeTable>>() {});
List<StrategyControlDataVO.TimeTable> timeTables = instance.readValue(time, new TypeReference<List<StrategyControlDataVO.TimeTable>>() {
});
for (StrategyControlDataVO.TimeTable timeTable : timeTables) {
int currentWeek = DateUtil.thisDayOfWeek() - 1;
String[] timeList = timeTable.getTimeList();
for (String s : timeList) {
String[] hours = s.split(",");
......@@ -380,17 +381,13 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
}
}
if (type == 0) {
BaseCrossInfoPO baseCrossInfoPO = baseCrossInfoMapper.selectById(entity.getBizId());
result.setCrossName(baseCrossInfoPO.getName());
String location = baseCrossInfoPO.getLocation();
location = location.replace("POINT(", "").replace(" ", ",").replace(")", "");
result.setWkt(location);
}
if (type == 1) {
GreenwaveInfoPO greenwaveInfoPO = greenwaveInfoMapper.selectById(Integer.valueOf(entity.getBizId()));
result.setCrossName(greenwaveInfoPO.getName());
result.setWkt(greenwaveInfoPO.getWkt());
Map<Integer, GreenwaveInfoPO> greenWaveMap = GreenWaveInfoCache.greenWaveMap;
if (!greenWaveMap.isEmpty()) {
GreenwaveInfoPO greenwaveInfoPO = greenWaveMap.get(Integer.valueOf(entity.getBizId()));
result.setCrossName(greenwaveInfoPO.getName());
result.setWkt(greenwaveInfoPO.getWkt());
}
}
results.add(result);
}
......@@ -403,19 +400,43 @@ public class StrategyControlServiceImpl implements StrategyControlService {
try {
List<StrategyControlDataEntity> currentStrateInfoList = getCurrentStrateInfoList(type);
List<StrategyControlDataExt> strategyControlDataExts = new ArrayList<>();
List<StrategyControlDataExt> results = new ArrayList<>();
for (StrategyControlDataEntity strategyControlDataEntity : currentStrateInfoList) {
Integer strategy = strategyControlDataEntity.getStrategy();
StrategyControlDataExt strategyControlDataExt = new StrategyControlDataExt();
BeanUtils.copyProperties(strategyControlDataEntity, strategyControlDataExt);
strategyControlDataExt.setStrategyName(StrategyControlEnum.getDesc(strategy));
strategyControlDataExt.setOptStatus("未执行");
if (StringUtils.isNotBlank(strategyControlDataEntity.getTime())) {
strategyControlDataExt.setOptStatus("优化中");
strategyControlDataExts.add(strategyControlDataExt);
}
strategyControlDataExts.add(strategyControlDataExt);
}
strategyControlDataExts.sort(Comparator.comparing(StrategyControlDataExt::getOptStatus));
return jsonViewObject.success(strategyControlDataExts, "路网优化监测查询成功");
if (Objects.equals(0, type)) {
List<BaseCrossInfoPO> crossInfoCache = baseCrossInfoCache.getCrossInfoCache();
if (!CollectionUtils.isEmpty(crossInfoCache)) {
for (BaseCrossInfoPO baseCrossInfoPO : crossInfoCache) {
StrategyControlDataExt ext = new StrategyControlDataExt();
ext.setBizId(baseCrossInfoPO.getId());
ext.setStrategyName("无策略");
ext.setOptStatus("未优化");
ext.setStatus(0);
for (StrategyControlDataExt strategyControlDataExt : strategyControlDataExts) {
if (StringUtils.equals(baseCrossInfoPO.getId(), strategyControlDataExt.getBizId())) {
ext = strategyControlDataExt;
}
}
String location = baseCrossInfoPO.getLocation();
location = location.replace("POINT(", "").replace(" ", ",").replace(")", "");
ext.setWkt(location);
results.add(ext);
}
}
}
if (Objects.equals(1, type)) {
results.addAll(strategyControlDataExts);
}
results.sort(Comparator.comparing(StrategyControlDataExt::getOptStatus));
return jsonViewObject.success(results, "路网优化监测查询成功");
} catch (Exception e) {
log.error("路网优化监测查询失败: {}", e);
return jsonViewObject.fail("路网优化监测查询失败");
......
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