Commit 38f53bd4 authored by duanruiming's avatar duanruiming

[add] 路口优化检测接口

parent 704eacde
package net.wanji.opt.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author duanruiming
* @date 2024/12/05 15:20
*/
@Getter
@AllArgsConstructor
public enum CrossOptStrategyEnum {
ZERO(0, "无策略"),
ONE(1, "绿灯空放"),
TWO(2, "失衡"),
THREE(3, "溢出");
private int code;
private String desc;
public static String getDesc(int code) {
for (CrossOptStrategyEnum value : CrossOptStrategyEnum.values()) {
if (code == value.code) {
return value.getDesc();
}
}
return "无策略";
}
}
......@@ -11,6 +11,7 @@ import net.wanji.databus.po.CrossDirDataRealtimePO;
import net.wanji.databus.po.TBaseCrossInfo;
import net.wanji.opt.dto.strategy.AddOrUpdateSceneDTO;
import net.wanji.opt.service.CrossIndexService;
import net.wanji.opt.vo.CrossOptResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
......@@ -65,4 +66,21 @@ public class CrossIndexController {
return JsonViewObject.newInstance().success(crossDataRealtimePO);
}
@ApiOperation(value = "方案优化曲线", notes = "优化监测-方案优化曲线", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/crossOptResultList",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = AddOrUpdateSceneDTO.class),
})
public JsonViewObject crossOptResultList(@RequestBody CrossIdBO crossIdBO) {
List<CrossOptResult> results = null;
try {
results = crossIndexService.crossOptResultList(crossIdBO);
} catch (Exception e) {
JsonViewObject.newInstance().fail("方案优化曲线查询异常");
}
return JsonViewObject.newInstance().success(results);
}
}
......@@ -4,6 +4,7 @@ import net.wanji.databus.bo.CrossIdBO;
import net.wanji.databus.po.CrossDataRealtimePO;
import net.wanji.databus.po.CrossDirDataRealtimePO;
import net.wanji.databus.po.TBaseCrossInfo;
import net.wanji.opt.vo.CrossOptResult;
import java.util.List;
import java.util.Map;
......@@ -18,4 +19,6 @@ public interface CrossIndexService {
CrossDataRealtimePO crossIndex(CrossIdBO crossIdBO);
List<TBaseCrossInfo> crossInfoList();
List<CrossOptResult> crossOptResultList(CrossIdBO crossIdBO) throws Exception;
}
......@@ -2,6 +2,7 @@ package net.wanji.opt.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.DateUtil;
import net.wanji.databus.bo.CrossIdBO;
import net.wanji.databus.dao.mapper.BaseCrossInfoMapper;
import net.wanji.databus.dao.mapper.CrossDataRealtimeMapper;
......@@ -9,14 +10,21 @@ import net.wanji.databus.dao.mapper.CrossDirDataRealtimeMapper;
import net.wanji.databus.po.CrossDataRealtimePO;
import net.wanji.databus.po.CrossDirDataRealtimePO;
import net.wanji.databus.po.TBaseCrossInfo;
import net.wanji.opt.common.enums.CrossOptStrategyEnum;
import net.wanji.opt.dao.mapper.StrategyCrossResultMapper;
import net.wanji.opt.service.CrossIndexService;
import net.wanji.opt.synthesis.pojo.StrategyCrossResultEntity;
import net.wanji.opt.vo.CrossOptResult;
import org.drools.core.util.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author duanruiming
......@@ -32,6 +40,8 @@ public class CrossIndexServiceImpl implements CrossIndexService {
private CrossDataRealtimeMapper crossDataRealtimeMapper;
@Resource
private BaseCrossInfoMapper baseCrossInfoMapper;
@Resource
private StrategyCrossResultMapper strategyCrossResultMapper;
@Override
public Map<Integer, CrossDirDataRealtimePO> crossDirIndex(CrossIdBO crossIdBO) {
......@@ -60,4 +70,35 @@ public class CrossIndexServiceImpl implements CrossIndexService {
List<TBaseCrossInfo> baseCrossInfoPOS = baseCrossInfoMapper.selectList(queryWrapper);
return baseCrossInfoPOS;
}
@Override
public List<CrossOptResult> crossOptResultList(CrossIdBO crossIdBO) throws Exception{
LambdaQueryWrapper<StrategyCrossResultEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyCrossResultEntity::getCrossId, crossIdBO.getCrossId());
LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime);
queryWrapper.eq(StrategyCrossResultEntity::getCrossId, crossIdBO.getCrossId());
queryWrapper.ge(StrategyCrossResultEntity::getIssueTime, startOfDay);
List<StrategyCrossResultEntity> list = strategyCrossResultMapper.selectList(queryWrapper);
List<CrossOptResult> crossOptResults = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
for (StrategyCrossResultEntity entity : list) {
CrossOptResult crossOptResult = new CrossOptResult();
Date date =DateUtil.parse(entity.getIssueTime(), "yyyy-MM-dd HH:mm:ss");
crossOptResult.setTimeStamp(date);
String timingPlan = entity.getTimingPlan();
Integer countDown = entity.getCountDown();
if (entity.getCurrentAlgo() == 2) {
countDown = 5;
}
crossOptResult.setCountDown(countDown);
Integer currentAlgo = entity.getCurrentAlgo();
crossOptResult.setStrategy(currentAlgo);
crossOptResult.setStrategyName(CrossOptStrategyEnum.getDesc(currentAlgo));
crossOptResults.add(crossOptResult);
}
}
return crossOptResults;
}
}
......@@ -349,19 +349,11 @@ public class StrategyControlServiceImpl implements StrategyControlService {
for (StrategyControlDataEntity entity : entities) {
StrategyControlDataEntity result = new StrategyControlDataEntity();
BeanUtils.copyProperties(entity, result);
Date start = entity.getScheduleStart();
Date end = entity.getScheduleEnd();
if (current.before(start) || current.after(end)) {
result.setTime("");
} else {
String time = entity.getTime();
List<StrategyControlDataVO.TimeTable> timeTables = instance.readValue(time, new TypeReference<List<StrategyControlDataVO.TimeTable>>() {
});
for (StrategyControlDataVO.TimeTable timeTable : timeTables) {
int currentWeek = DateUtil.thisDayOfWeek() - 1;
if (currentWeek != timeTable.getWeek()) {
result.setTime("");
} else {
String[] timeList = timeTable.getTimeList();
for (String s : timeList) {
String[] hours = s.split(",");
......@@ -386,8 +378,6 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
}
}
}
}
if (type == 0) {
BaseCrossInfoPO baseCrossInfoPO = baseCrossInfoMapper.selectById(entity.getBizId());
result.setCrossName(baseCrossInfoPO.getName());
......
......@@ -55,7 +55,7 @@ public class StrategyGreenBeltServiceImpl implements StrategyGreenBeltService {
GreenBeltAreaIndexVO.DirDetail dirDetail = new GreenBeltAreaIndexVO.DirDetail();
String roadDirection = realtimePO.getRoadDirection();
dirDetail.setDirName(GreenBeltDirEnum.getDesc(roadDirection));
dirDetail.setTravelTime(realtimePO.getTrvalTime());
dirDetail.setTravelTime(realtimePO.getTrvalTime() / 60);
dirDetail.setStopTimes(realtimePO.getStopTimes());
status = status >= realtimePO.getStatus() ? status : realtimePO.getStatus();
dirDetails.add(dirDetail);
......
package net.wanji.opt.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author duanruiming
* @date 2024/12/05 11:29
* @description 路口优化结果当前时间优化场景节约时间
*/
@Data
@ApiModel("路口优化曲线实体")
public class CrossOptResult {
@ApiModelProperty("策略")
private Integer strategy;
@ApiModelProperty("策略名称")
private String strategyName;
@ApiModelProperty("节约时间")
private Integer countDown;
@ApiModelProperty("时间戳")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "GMT+8")
private Date timeStamp;
}
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