Commit f6fed476 authored by duanruiming's avatar duanruiming

[add] 路网优化检测AI优化历史优化

parent 074627fc
...@@ -28,7 +28,7 @@ public class GreenBeltController { ...@@ -28,7 +28,7 @@ public class GreenBeltController {
@Resource @Resource
private GreenBeltInfoService greenBeltInfoService; private GreenBeltInfoService greenBeltInfoService;
@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)
@GetMapping(value = "/greenBeltCrossDetailHist") @GetMapping(value = "/greenBeltCrossDetailHist")
@ApiResponses({ @ApiResponses({
......
...@@ -31,15 +31,10 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService { ...@@ -31,15 +31,10 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService {
@Override @Override
public List<GreenBeltFlowStopTimeVO> greenBeltCrossDetailHist(Integer greenId) { public List<GreenBeltFlowStopTimeVO> greenBeltCrossDetailHist(Integer greenId) {
List<String> crossIds = greenwaveInfoMapper.selectCrossIdsById(greenId); List<String> crossIds = greenwaveInfoMapper.selectCrossIdsById(greenId);
LocalDate currentDate = LocalDate.now(); long currentTimeMillis = System.currentTimeMillis();
LocalTime startTime = LocalTime.MIDNIGHT; // 00:00 int startSecond = (int) (currentTimeMillis / 1000 - 3600);
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime); int endSecond = (int) (currentTimeMillis / 1000);
LocalDate nextDate = currentDate.plusDays(1); List<CrossDataHistPO> crossDataHistPOS = crossDataHistMapper.selectByCrossIdsAndTimestamp(crossIds, startSecond , endSecond);
LocalTime endTime = LocalTime.MIDNIGHT; // 00:00 of the next day
LocalDateTime endOfDay = LocalDateTime.of(nextDate, endTime);
long startSecond = startOfDay.toEpochSecond(ZoneOffset.of("+8")) + 5 * 600;
long endSecond = endOfDay.toEpochSecond(ZoneOffset.of("+8"));
List<CrossDataHistPO> crossDataHistPOS = crossDataHistMapper.selectByCrossIdsAndTimestamp(crossIds, (int) startSecond , (int) endSecond);
if (!CollectionUtils.isEmpty(crossDataHistPOS)) { if (!CollectionUtils.isEmpty(crossDataHistPOS)) {
List<GreenBeltFlowStopTimeVO> results = new ArrayList<>(); List<GreenBeltFlowStopTimeVO> results = new ArrayList<>();
Map<Date, List<CrossDataHistPO>> startTimeMap = crossDataHistPOS.stream().collect(Collectors.groupingBy(CrossDataHistPO::getStartTime)); Map<Date, List<CrossDataHistPO>> startTimeMap = crossDataHistPOS.stream().collect(Collectors.groupingBy(CrossDataHistPO::getStartTime));
...@@ -55,6 +50,8 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService { ...@@ -55,6 +50,8 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService {
flowStopTimeDetail.setFlow(crossDataHistPO.getFlow()); flowStopTimeDetail.setFlow(crossDataHistPO.getFlow());
flowStopTimeDetail.setStopTimes(crossDataHistPO.getStopTimes()); flowStopTimeDetail.setStopTimes(crossDataHistPO.getStopTimes());
flowStopTimeDetail.setCrossId(crossDataHistPO.getCrossId()); flowStopTimeDetail.setCrossId(crossDataHistPO.getCrossId());
// todo 先删除,后续通过路口距离/速度计算 距离通过卫博发送数据
flowStopTimeDetail.setTravelTime(0.0);
crossList.add(flowStopTimeDetail); crossList.add(flowStopTimeDetail);
} }
} }
......
...@@ -77,7 +77,18 @@ public class StrategyControlController { ...@@ -77,7 +77,18 @@ public class StrategyControlController {
} }
@ApiOperation(value = "路网优化监测", notes = "路网优化监测", @ApiOperation(value = "AI优化次数优化时长", notes = "路网优化检测-AI优化次数优化时长",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/strategyOptTimes")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = StrategyControlDataEntity.class),
})
public JsonViewObject strategyOptTimes() throws Exception {
return strategyControlService.strategyOptTimes();
}
@ApiOperation(value = "路网优化监测-接口干线列表", notes = "路网优化监测-AI路口-AI干线",
response = JsonViewObject.class, response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON) produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/crossOptInfoList") @GetMapping(value = "/crossOptInfoList")
......
...@@ -24,7 +24,7 @@ import java.util.List; ...@@ -24,7 +24,7 @@ import java.util.List;
* @date 2024/11/19 20:10 * @date 2024/11/19 20:10
* @description 神思推送绿波时序图 * @description 神思推送绿波时序图
*/ */
@Api(value = "StrategyGreenBeltController", description = "策略绿波带") @Api(value = "StrategyGreenBeltController", description = "策略绿波带弹窗")
@RequestMapping("/strategyBelt") @RequestMapping("/strategyBelt")
@RestController @RestController
public class StrategyGreenBeltController { public class StrategyGreenBeltController {
......
package net.wanji.opt.synthesis.pojo.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author duanruiming
* @date 2024/12/04 13:58
*/
@Data
@ApiModel("AI优化次数优化时长返回实体")
public class StrategyOptTimesVO {
@ApiModelProperty("优化次数")
private Integer count;
@ApiModelProperty("优化时长")
private Integer times;
}
...@@ -15,6 +15,7 @@ public interface StrategyControlService { ...@@ -15,6 +15,7 @@ public interface StrategyControlService {
JsonViewObject strategyInfoPageList(StrategyControlDataEntity entity) throws Exception; JsonViewObject strategyInfoPageList(StrategyControlDataEntity entity) throws Exception;
JsonViewObject crossStrategyInfoList(Integer type) throws Exception; JsonViewObject crossStrategyInfoList(Integer type) throws Exception;
JsonViewObject strategyOptTimes() throws Exception;
JsonViewObject crossStrategyHistList() throws Exception; JsonViewObject crossStrategyHistList() throws Exception;
JsonViewObject crossOptInfoList(Integer type) throws Exception; JsonViewObject crossOptInfoList(Integer type) throws Exception;
......
...@@ -16,6 +16,7 @@ import net.wanji.databus.dao.entity.GreenwaveInfoPO; ...@@ -16,6 +16,7 @@ import net.wanji.databus.dao.entity.GreenwaveInfoPO;
import net.wanji.databus.dao.mapper.BaseCrossInfoMapper; import net.wanji.databus.dao.mapper.BaseCrossInfoMapper;
import net.wanji.databus.dao.mapper.GreenwaveInfoMapper; import net.wanji.databus.dao.mapper.GreenwaveInfoMapper;
import net.wanji.databus.po.BaseCrossInfoPO; import net.wanji.databus.po.BaseCrossInfoPO;
import net.wanji.databus.po.TBaseCrossInfo;
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.dao.mapper.*; import net.wanji.opt.dao.mapper.*;
...@@ -25,6 +26,7 @@ import net.wanji.opt.synthesis.pojo.*; ...@@ -25,6 +26,7 @@ import net.wanji.opt.synthesis.pojo.*;
import net.wanji.opt.synthesis.pojo.vo.StrategyControlDataVO; import net.wanji.opt.synthesis.pojo.vo.StrategyControlDataVO;
import net.wanji.opt.synthesis.pojo.vo.StrategyControlHistVO; import net.wanji.opt.synthesis.pojo.vo.StrategyControlHistVO;
import net.wanji.opt.synthesis.pojo.vo.StrategyControlVO; 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.PushStrategyControlService;
import net.wanji.opt.synthesis.service.StrategyControlService; import net.wanji.opt.synthesis.service.StrategyControlService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -38,6 +40,7 @@ import java.text.ParseException; ...@@ -38,6 +40,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; 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.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -245,12 +248,15 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -245,12 +248,15 @@ public class StrategyControlServiceImpl implements StrategyControlService {
try { try {
List<StrategyControlDataEntity> results = new ArrayList<>(); List<StrategyControlDataEntity> results = new ArrayList<>();
List<StrategyControlDataEntity> entities = getCurrentStrateInfoList(type); List<StrategyControlDataEntity> entities = getCurrentStrateInfoList(type);
Map<String, StrategyControlDataEntity> map = entities.stream().collect(Collectors.toMap(StrategyControlDataEntity::getBizId, entity -> entity)); List<StrategyControlDataEntity> runList = entities.stream().filter(entity -> Objects.equals(1, entity.getStatus())).collect(Collectors.toList());
Map<String, StrategyControlDataEntity> map = runList.stream().collect(Collectors.toMap(StrategyControlDataEntity::getBizId, entity -> entity));
// 路口 // 路口
if (Objects.equals(0, type)) { if (Objects.equals(0, type)) {
List<BaseCrossInfoPO> baseCrossInfoPOS = baseCrossInfoMapper.selectAll(); LambdaQueryWrapper<TBaseCrossInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TBaseCrossInfo::getIsSignal, 1);
List<TBaseCrossInfo> baseCrossInfoPOS = baseCrossInfoMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(baseCrossInfoPOS)) { if (!CollectionUtils.isEmpty(baseCrossInfoPOS)) {
for (BaseCrossInfoPO baseCrossInfoPO : baseCrossInfoPOS) { for (TBaseCrossInfo baseCrossInfoPO : baseCrossInfoPOS) {
StrategyControlDataEntity strategyControlDataEntity = new StrategyControlDataEntity(); StrategyControlDataEntity strategyControlDataEntity = new StrategyControlDataEntity();
String crossId = baseCrossInfoPO.getId(); String crossId = baseCrossInfoPO.getId();
strategyControlDataEntity.setBizType(0); strategyControlDataEntity.setBizType(0);
...@@ -258,13 +264,13 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -258,13 +264,13 @@ public class StrategyControlServiceImpl implements StrategyControlService {
strategyControlDataEntity.setStrategy(null); strategyControlDataEntity.setStrategy(null);
strategyControlDataEntity.setTime(null); strategyControlDataEntity.setTime(null);
strategyControlDataEntity.setStatus(0); strategyControlDataEntity.setStatus(0);
if (map.containsKey(crossId)) {
strategyControlDataEntity = map.get(crossId);
}
strategyControlDataEntity.setCrossName(baseCrossInfoPO.getName()); strategyControlDataEntity.setCrossName(baseCrossInfoPO.getName());
String location = baseCrossInfoPO.getLocation(); String location = baseCrossInfoPO.getLocation();
location = location.replace("POINT(", "").replace(" ", ",").replace(")", ""); location = location.replace("POINT(", "").replace(" ", ",").replace(")", "");
strategyControlDataEntity.setWkt(location); strategyControlDataEntity.setWkt(location);
if (map.containsKey(crossId)) {
strategyControlDataEntity = map.get(crossId);
}
results.add(strategyControlDataEntity); results.add(strategyControlDataEntity);
} }
} }
...@@ -274,17 +280,17 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -274,17 +280,17 @@ public class StrategyControlServiceImpl implements StrategyControlService {
if (!CollectionUtils.isEmpty(greenwaveInfoPOS)) { if (!CollectionUtils.isEmpty(greenwaveInfoPOS)) {
for (GreenwaveInfoPO greenwaveInfoPO : greenwaveInfoPOS) { for (GreenwaveInfoPO greenwaveInfoPO : greenwaveInfoPOS) {
StrategyControlDataEntity strategyControlDataEntity = new StrategyControlDataEntity(); StrategyControlDataEntity strategyControlDataEntity = new StrategyControlDataEntity();
Integer greenId = greenwaveInfoPO.getId(); String greenId = String.valueOf(greenwaveInfoPO.getId());
strategyControlDataEntity.setBizType(1); strategyControlDataEntity.setBizType(1);
strategyControlDataEntity.setBizId(String.valueOf(greenId)); strategyControlDataEntity.setBizId(String.valueOf(greenId));
strategyControlDataEntity.setStrategy(null); strategyControlDataEntity.setStrategy(null);
strategyControlDataEntity.setTime(null); strategyControlDataEntity.setTime(null);
strategyControlDataEntity.setStatus(0); strategyControlDataEntity.setStatus(0);
strategyControlDataEntity.setCrossName(greenwaveInfoPO.getName());
strategyControlDataEntity.setWkt(greenwaveInfoPO.getWkt());
if (map.containsKey(greenId)) { if (map.containsKey(greenId)) {
strategyControlDataEntity = map.get(greenId); strategyControlDataEntity = map.get(greenId);
} }
strategyControlDataEntity.setCrossName(greenwaveInfoPO.getName());
strategyControlDataEntity.setWkt(greenwaveInfoPO.getWkt());
results.add(strategyControlDataEntity); results.add(strategyControlDataEntity);
} }
} }
...@@ -296,15 +302,50 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -296,15 +302,50 @@ public class StrategyControlServiceImpl implements StrategyControlService {
} }
} }
@Override
public JsonViewObject strategyOptTimes() throws Exception {
LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime);
LambdaQueryWrapper<StrategyGreenOptHistEntity> greenQuery = new LambdaQueryWrapper<>();
greenQuery.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay);
List<StrategyGreenOptHistEntity> greenOptList = strategyGreenOptHistMapper.selectList(greenQuery);
int totalTime = 0;
int totalCount = 0;
if (!CollectionUtils.isEmpty(greenOptList)) {
for (StrategyGreenOptHistEntity entity : greenOptList) {
Integer controlDuration = entity.getControlDuration();
totalTime += controlDuration;
totalCount += 1;
}
}
LambdaQueryWrapper<StrategyCrossResultEntity> crossQuery = new LambdaQueryWrapper<>();
crossQuery.ge(StrategyCrossResultEntity::getIssueTime, startOfDay);
List<StrategyCrossResultEntity> crossList = strategyCrossResultMapper.selectList(crossQuery);
if (!CollectionUtils.isEmpty(crossList)) {
for (StrategyCrossResultEntity entity : crossList) {
Integer countDown = entity.getCountDown();
if (Math.abs(countDown) > 1) {
totalTime += countDown;
totalCount += 1;
}
}
}
StrategyOptTimesVO strategyOptTimesVO = new StrategyOptTimesVO();
strategyOptTimesVO.setCount(totalCount);
strategyOptTimesVO.setTimes(totalTime / 3600);
return JsonViewObject.newInstance().success(strategyOptTimesVO);
}
private List<StrategyControlDataEntity> getCurrentStrateInfoList(Integer type) throws Exception { private List<StrategyControlDataEntity> getCurrentStrateInfoList(Integer type) throws Exception {
ObjectMapper instance = JacksonUtils.getInstance(); ObjectMapper instance = JacksonUtils.getInstance();
LambdaQueryWrapper<StrategyControlDataEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<StrategyControlDataEntity> queryWrapper = new LambdaQueryWrapper<>();
Date current = new Date();
queryWrapper.eq(StrategyControlDataEntity::getBizType, type); queryWrapper.eq(StrategyControlDataEntity::getBizType, type);
queryWrapper.ge(StrategyControlDataEntity::getScheduleStart, new Date()); queryWrapper.le(StrategyControlDataEntity::getScheduleStart, current);
queryWrapper.le(StrategyControlDataEntity::getScheduleEnd, new Date()); queryWrapper.ge(StrategyControlDataEntity::getScheduleEnd, current);
List<StrategyControlDataEntity> entities = strategyControlInfoMapper.selectList(queryWrapper); List<StrategyControlDataEntity> entities = strategyControlInfoMapper.selectList(queryWrapper);
List<StrategyControlDataEntity> results = new ArrayList<>(entities.size()); List<StrategyControlDataEntity> results = new ArrayList<>(entities.size());
Date current = new Date();
for (StrategyControlDataEntity entity : entities) { for (StrategyControlDataEntity entity : entities) {
StrategyControlDataEntity result = new StrategyControlDataEntity(); StrategyControlDataEntity result = new StrategyControlDataEntity();
BeanUtils.copyProperties(entity, result); BeanUtils.copyProperties(entity, result);
...@@ -317,7 +358,7 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -317,7 +358,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
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) { for (StrategyControlDataVO.TimeTable timeTable : timeTables) {
int currentWeek = DateUtil.thisDayOfWeek(); int currentWeek = DateUtil.thisDayOfWeek() - 1;
if (currentWeek != timeTable.getWeek()) { if (currentWeek != timeTable.getWeek()) {
result.setTime(""); result.setTime("");
} else { } else {
...@@ -328,14 +369,17 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -328,14 +369,17 @@ public class StrategyControlServiceImpl implements StrategyControlService {
String[] currentHour = hour.split("-"); String[] currentHour = hour.split("-");
String startHour = currentHour[0]; String startHour = currentHour[0];
String entHour = currentHour[1]; String entHour = currentHour[1];
if (StringUtils.equals("24:00", entHour)) {
entHour = "23:59";
}
String format = DateUtil.format(current, "HH:mm"); String format = DateUtil.format(current, "HH:mm");
DateTime currentTime = DateUtil.parse(format, "HH:mm"); DateTime currentTime = DateUtil.parse(format, "HH:mm");
DateTime startHourDate = DateUtil.parse(startHour, "HH:mm"); DateTime startHourDate = DateUtil.parse(startHour, "HH:mm");
DateTime endHourDate = DateUtil.parse(entHour, "HH:mm"); DateTime endHourDate = DateUtil.parse(entHour, "HH:mm");
if (currentTime.before(startHourDate) || currentTime.after(endHourDate)) { if (currentTime.after(startHourDate) && currentTime.before(endHourDate)) {
result.setTime(hour); result.setTime(hour);
result.setStatus(1); result.setStatus(1);
} } else {
// 如果有调度策略在执行,设置为开启,否则关闭,提供前端过滤配置和未配置 // 如果有调度策略在执行,设置为开启,否则关闭,提供前端过滤配置和未配置
result.setStatus(0); result.setStatus(0);
} }
...@@ -343,6 +387,7 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -343,6 +387,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
} }
} }
} }
}
if (type == 0) { if (type == 0) {
BaseCrossInfoPO baseCrossInfoPO = baseCrossInfoMapper.selectById(entity.getBizId()); BaseCrossInfoPO baseCrossInfoPO = baseCrossInfoMapper.selectById(entity.getBizId());
result.setCrossName(baseCrossInfoPO.getName()); result.setCrossName(baseCrossInfoPO.getName());
......
...@@ -86,6 +86,7 @@ public class StrategyGreenBeltServiceImpl implements StrategyGreenBeltService { ...@@ -86,6 +86,7 @@ public class StrategyGreenBeltServiceImpl implements StrategyGreenBeltService {
vo.setHourMinute(DateUtils.format(greenwaveHistPO.getStartTime(), "HH:mm")); vo.setHourMinute(DateUtils.format(greenwaveHistPO.getStartTime(), "HH:mm"));
vo.setStopTimes(greenwaveHistPO.getStopTimes()); vo.setStopTimes(greenwaveHistPO.getStopTimes());
vo.setCordQueueRatio(greenwaveHistPO.getCordQueueRatio() * 100); vo.setCordQueueRatio(greenwaveHistPO.getCordQueueRatio() * 100);
vo.setTravelTime(greenwaveHistPO.getTrvalTime());
results.add(vo); results.add(vo);
} }
} }
......
...@@ -29,5 +29,7 @@ public class GreenBeltFlowStopTimeVO { ...@@ -29,5 +29,7 @@ public class GreenBeltFlowStopTimeVO {
private Integer flow; private Integer flow;
@ApiModelProperty("停车次数") @ApiModelProperty("停车次数")
private Double stopTimes; private Double stopTimes;
@ApiModelProperty("行程时间")
private Double travelTime;
} }
} }
...@@ -27,4 +27,6 @@ public class GreenBeltStopTimesQueueLengthVO { ...@@ -27,4 +27,6 @@ public class GreenBeltStopTimesQueueLengthVO {
private Double stopTimes; private Double stopTimes;
@ApiModelProperty("空间占比") @ApiModelProperty("空间占比")
private Double cordQueueRatio; private Double cordQueueRatio;
@ApiModelProperty("行程时间")
private Integer travelTime;
} }
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