Commit ccaceaa0 authored by duanruiming's avatar duanruiming

[add] 干线列表查询优化

parent 310e5878
......@@ -8,16 +8,14 @@ import net.wanji.common.framework.rest.JsonViewObject;
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.dto.strategy.AddOrUpdateSceneDTO;
import net.wanji.opt.service.CrossIndexService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
......@@ -32,6 +30,17 @@ public class CrossIndexController {
@Resource
private CrossIndexService crossIndexService;
@ApiOperation(value = "路口信息查询", notes = "路口信息查询", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/crossInfoList")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = TBaseCrossInfo.class),
})
public JsonViewObject crossInfoList() {
List<TBaseCrossInfo> baseCrossInfoPOS = crossIndexService.crossInfoList();
return JsonViewObject.newInstance().success(baseCrossInfoPOS);
}
@ApiOperation(value = "路口方向指标", notes = "路口方向指标", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/crossDirIndex",
......
package net.wanji.opt.controller.signalopt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.dto.strategy.AddOrUpdateSceneDTO;
import net.wanji.opt.service.signalopt.GreenBeltInfoService;
import net.wanji.opt.vo.GreenBeltFlowStopTimeVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;
import java.util.List;
/**
* @author duanruiming
* @date 2024/11/28 16:03
*/
@Api(value = "CrossIndexController", description = "路口指标控制器")
@RequestMapping("/crossIndex")
@RequestMapping("/greenBelt")
@RestController
public class GreenBeltController {
@Resource
private GreenBeltInfoService greenBeltInfoService;
@ApiOperation(value = "绿波协调方向流量停车次数", notes = "绿波协调方向流量停车次数", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/greenBeltCrossDetailHist")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = AddOrUpdateSceneDTO.class),
})
public JsonViewObject greenBeltCrossDetailHist(Integer greenId) {
List<GreenBeltFlowStopTimeVO> greenBeltFlowStopTimeVOS = greenBeltInfoService.greenBeltCrossDetailHist(greenId);
return JsonViewObject.newInstance().success(greenBeltFlowStopTimeVOS);
}
}
......@@ -3,7 +3,9 @@ package net.wanji.opt.service;
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 java.util.List;
import java.util.Map;
/**
......@@ -12,5 +14,8 @@ import java.util.Map;
*/
public interface CrossIndexService {
Map<Integer, CrossDirDataRealtimePO> crossDirIndex(CrossIdBO crossIdBO);
CrossDataRealtimePO crossIndex(CrossIdBO crossIdBO);
List<TBaseCrossInfo> crossInfoList();
}
package net.wanji.opt.service;
import net.wanji.opt.vo.GreenBeltInfoVO;
/**
* @author duanruiming
* @date 2024/11/19 18:07
*/
public interface GreenBeltInfoService {
/**
* 数据转换
* @param message
* @return
* @throws Exception
*/
GreenBeltInfoVO convertData(String message) throws Exception;
/**
* 存储
* @param infoVO
* @throws Exception
*/
void save(GreenBeltInfoVO infoVO) throws Exception;
}
package net.wanji.opt.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.databus.bo.CrossIdBO;
import net.wanji.databus.dao.mapper.BaseCrossInfoMapper;
import net.wanji.databus.dao.mapper.CrossDataRealtimeMapper;
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.service.CrossIndexService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
......@@ -27,6 +30,8 @@ public class CrossIndexServiceImpl implements CrossIndexService {
private CrossDirDataRealtimeMapper crossDirDataRealtimeMapper;
@Resource
private CrossDataRealtimeMapper crossDataRealtimeMapper;
@Resource
private BaseCrossInfoMapper baseCrossInfoMapper;
@Override
public Map<Integer, CrossDirDataRealtimePO> crossDirIndex(CrossIdBO crossIdBO) {
......@@ -46,4 +51,13 @@ public class CrossIndexServiceImpl implements CrossIndexService {
CrossDataRealtimePO crossDataRealtimePO = crossDataRealtimeMapper.selectByCrossId(crossIdBO.getCrossId());
return crossDataRealtimePO;
}
@Override
public List<TBaseCrossInfo> crossInfoList() {
LambdaQueryWrapper<TBaseCrossInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TBaseCrossInfo::getIsSignal, 1);
List<TBaseCrossInfo> baseCrossInfoPOS = baseCrossInfoMapper.selectList(queryWrapper);
return baseCrossInfoPOS;
}
}
package net.wanji.opt.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.opt.common.Constants;
import net.wanji.opt.dao.mapper.StrategyGreenOptHistMapper;
import net.wanji.opt.dto.GreenBeltKafkaDTO;
import net.wanji.opt.po.StrategyGreenOptHistEntity;
import net.wanji.opt.service.GreenBeltInfoService;
import net.wanji.opt.vo.GreenBeltInfoVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* @author duanruiming
* @date 2024/11/19 19:04
*/
@Service
public class GreenBeltInfoServiceImpl implements GreenBeltInfoService {
@Resource
private StrategyGreenOptHistMapper strategyGreenOptHistMapper;
public static void main(String[] args) throws Exception {
String message = greenBeltInfoData;
ObjectMapper mapper = JacksonUtils.getInstance();
GreenBeltKafkaDTO kafkaDTO = mapper.readValue(message, GreenBeltKafkaDTO.class);
// 正反绿波容器
List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails = new ArrayList<>();
// 构建正向绿波
setForward(kafkaDTO, dirGreenDetails);
// 反向绿波
setBackward(kafkaDTO, dirGreenDetails);
// 返回绿波实体
GreenBeltInfoVO greenBeltInfoVO = new GreenBeltInfoVO();
greenBeltInfoVO.setGreenId(kafkaDTO.getGreenbeltId());
greenBeltInfoVO.setLength(kafkaDTO.getGreenbeltLength());
greenBeltInfoVO.setCycle(kafkaDTO.getMaxCycle());
greenBeltInfoVO.setControlTime(kafkaDTO.getControlTime());
greenBeltInfoVO.setControlDuration(kafkaDTO.getControlDuration());
greenBeltInfoVO.setType(kafkaDTO.getGreenbeltType());
greenBeltInfoVO.setDynamic(kafkaDTO.getDynamic());
greenBeltInfoVO.setControlMethod(kafkaDTO.getControlMethod());
greenBeltInfoVO.setDirGreenDetails(dirGreenDetails);
System.err.println(mapper.writeValueAsString(greenBeltInfoVO));
}
@Override
public GreenBeltInfoVO convertData(String message) throws Exception {
ObjectMapper mapper = JacksonUtils.getInstance();
GreenBeltKafkaDTO kafkaDTO = mapper.readValue(greenBeltInfoData, GreenBeltKafkaDTO.class);
// 正反绿波容器
List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails = new ArrayList<>();
// 构建正向绿波
setForward(kafkaDTO, dirGreenDetails);
// 反向绿波
setBackward(kafkaDTO, dirGreenDetails);
// 返回绿波实体
GreenBeltInfoVO greenBeltInfoVO = new GreenBeltInfoVO();
greenBeltInfoVO.setGreenId(kafkaDTO.getGreenbeltId());
greenBeltInfoVO.setLength(kafkaDTO.getGreenbeltLength());
greenBeltInfoVO.setCycle(kafkaDTO.getMaxCycle());
greenBeltInfoVO.setControlTime(kafkaDTO.getControlTime());
greenBeltInfoVO.setControlDuration(kafkaDTO.getControlDuration());
greenBeltInfoVO.setType(kafkaDTO.getGreenbeltType());
greenBeltInfoVO.setDynamic(kafkaDTO.getDynamic());
greenBeltInfoVO.setControlMethod(kafkaDTO.getControlMethod());
greenBeltInfoVO.setDirGreenDetails(dirGreenDetails);
return greenBeltInfoVO;
}
@Override
public void save(GreenBeltInfoVO infoVO) throws Exception {
if (Objects.nonNull(infoVO)) {
List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails = infoVO.getDirGreenDetails();
if (!CollectionUtils.isEmpty(dirGreenDetails)) {
for (GreenBeltInfoVO.DirGreenDetail dirGreenDetail : dirGreenDetails) {
StrategyGreenOptHistEntity entity = new StrategyGreenOptHistEntity();
entity.setGreenId(infoVO.getGreenId());
entity.setLength(infoVO.getLength());
entity.setCycle(infoVO.getCycle());
entity.setControlTime(infoVO.getControlTime());
entity.setControlDuration(infoVO.getControlDuration());
entity.setControlMethod(infoVO.getControlMethod());
entity.setType(infoVO.getType());
entity.setDynamic(infoVO.getDynamic());
entity.setDirType(dirGreenDetail.getDirType());
entity.setDir(dirGreenDetail.getDir());
entity.setMaxSpeed(dirGreenDetail.getMaxSpeed());
entity.setMinSpeed(dirGreenDetail.getMinSpeed());
entity.setGreenWidthTime(dirGreenDetail.getGreenWidthTime());
entity.setCrossGreenDetail(JacksonUtils.getInstance().writeValueAsString(dirGreenDetail.getCrossGreenDetailList()));
strategyGreenOptHistMapper.insert(entity);
String key = Constants.GREEN_ID_OPT_KEY.concat(String.valueOf(infoVO.getGreenId()));
}
}
}
}
private static void setBackward(GreenBeltKafkaDTO kafkaDTO, List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails) {
// 反向绿波路口列表
List<GreenBeltInfoVO.CrossGreenDetail> crossGreenDetails = new ArrayList<>();
Map<String, Double> phaseStartBackward = kafkaDTO.getPhaseStartBackward();
for (Map.Entry<String, Double> backEntry : phaseStartBackward.entrySet()) {
String crossId = backEntry.getKey();
Double phaseStartTime = backEntry.getValue();
GreenBeltInfoVO.CrossGreenDetail crossGreenDetail = new GreenBeltInfoVO.CrossGreenDetail();
crossGreenDetail.setCrossId(crossId);
crossGreenDetail.setPhaseStartTime(phaseStartTime);
Double phaseEndTime = kafkaDTO.getPhaseEndBackward().get(crossId);
crossGreenDetail.setPhaseEndTime(phaseEndTime);
Double greenStartTime = kafkaDTO.getBeltStartBackward().get(crossId);
crossGreenDetail.setGreenStartTime(greenStartTime);
Double speed = kafkaDTO.getSpeedBackward().get(crossId);
crossGreenDetail.setSpeed(speed);
Double offset = kafkaDTO.getOffset().get(crossId);
crossGreenDetail.setOffset(offset);
Double distance = kafkaDTO.getDistanceBackward().get(crossId);
crossGreenDetail.setDistance(distance);
Double travelTime = kafkaDTO.getTravelTimeBackward().get(crossId);
crossGreenDetail.setTravelTime(travelTime);
crossGreenDetails.add(crossGreenDetail);
}
// 反向绿波
// 反向绿波实体
GreenBeltInfoVO.DirGreenDetail dirGreenDetail = new GreenBeltInfoVO.DirGreenDetail();
dirGreenDetail.setDirType(0);
String forwardDirection = kafkaDTO.getBackwardDirection();
dirGreenDetail.setDir(forwardDirection);
double maxSpeedForward = kafkaDTO.getMaxSpeedBackward();
dirGreenDetail.setMaxSpeed(maxSpeedForward);
double minSpeedForward = kafkaDTO.getMinSpeedBackward();
dirGreenDetail.setMinSpeed(minSpeedForward);
double greenWidthForward = kafkaDTO.getGreenWidthBackward();
dirGreenDetail.setGreenWidthTime(greenWidthForward);
dirGreenDetail.setCrossGreenDetailList(crossGreenDetails);
dirGreenDetails.add(dirGreenDetail);
}
private static void setForward(GreenBeltKafkaDTO kafkaDTO, List<GreenBeltInfoVO.DirGreenDetail> dirGreenDetails) {
// 正向绿波路口列表
List<GreenBeltInfoVO.CrossGreenDetail> crossGreenDetails = new ArrayList<>();
Map<String, Double> phaseStartForward = kafkaDTO.getPhaseStartForward();
for (Map.Entry<String, Double> forwardEntry : phaseStartForward.entrySet()) {
String crossId = forwardEntry.getKey();
Double phaseStartTime = forwardEntry.getValue();
GreenBeltInfoVO.CrossGreenDetail crossGreenDetail = new GreenBeltInfoVO.CrossGreenDetail();
crossGreenDetail.setCrossId(crossId);
crossGreenDetail.setPhaseStartTime(phaseStartTime);
Double phaseEndTime = kafkaDTO.getPhaseEndForward().get(crossId);
crossGreenDetail.setPhaseEndTime(phaseEndTime);
Double greenStartTime = kafkaDTO.getBeltStartForward().get(crossId);
crossGreenDetail.setGreenStartTime(greenStartTime);
Double speed = kafkaDTO.getSpeedForward().get(crossId);
crossGreenDetail.setSpeed(speed);
Double offset = kafkaDTO.getOffset().get(crossId);
crossGreenDetail.setOffset(offset);
Double distance = kafkaDTO.getDistanceForward().get(crossId);
crossGreenDetail.setDistance(distance);
Double travelTime = kafkaDTO.getTravelTimeForward().get(crossId);
crossGreenDetail.setTravelTime(travelTime);
crossGreenDetails.add(crossGreenDetail);
}
// 正向绿波
// 正向绿波实体
GreenBeltInfoVO.DirGreenDetail dirGreenDetail = new GreenBeltInfoVO.DirGreenDetail();
dirGreenDetail.setDirType(1);
String forwardDirection = kafkaDTO.getForwardDirection();
dirGreenDetail.setDir(forwardDirection);
double maxSpeedForward = kafkaDTO.getMaxSpeedForward();
dirGreenDetail.setMaxSpeed(maxSpeedForward);
double minSpeedForward = kafkaDTO.getMinSpeedForward();
dirGreenDetail.setMinSpeed(minSpeedForward);
double greenWidthForward = kafkaDTO.getGreenWidthForward();
dirGreenDetail.setGreenWidthTime(greenWidthForward);
dirGreenDetail.setCrossGreenDetailList(crossGreenDetails);
dirGreenDetails.add(dirGreenDetail);
}
public static String greenBeltInfoData = "{\n" +
"\t\"backward_direction\": \"e2w\",\n" +
"\t\"belt_start_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": 0.0,\n" +
"\t\t\"13MQJ0B5SI0\": 91.0,\n" +
"\t\t\"13MS20B5SI0\": 25.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 45.0,\n" +
"\t\t\"13N200B5SH0\": 0.0\n" +
"\t},\n" +
"\t\"belt_start_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 0.0,\n" +
"\t\t\"13MQJ0B5SI0\": 91.0,\n" +
"\t\t\"13MS20B5SI0\": 25.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 45.0,\n" +
"\t\t\"13N200B5SH0\": 0.0\n" +
"\t},\n" +
"\t\"control_duration\": 10,\n" +
"\t\"control_method\": 1,\n" +
"\t\"control_time\": \"2024-11-20T18:15:31\",\n" +
"\t\"cycle\": {\n" +
"\t\t\"13MOD0B5SI0\": 220.0,\n" +
"\t\t\"13MQJ0B5SI0\": 220.0,\n" +
"\t\t\"13MS20B5SI0\": 220.0,\n" +
"\t\t\"13MUK0B5SH0\": 220.0,\n" +
"\t\t\"13N0F0B5SH0\": 220.0,\n" +
"\t\t\"13N200B5SH0\": 220.0\n" +
"\t},\n" +
"\t\"distance_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": -1.0,\n" +
"\t\t\"13MQJ0B5SI0\": 637.5,\n" +
"\t\t\"13MS20B5SI0\": 412.49999999999994,\n" +
"\t\t\"13MUK0B5SH0\": 725.0,\n" +
"\t\t\"13N0F0B5SH0\": 525.0,\n" +
"\t\t\"13N200B5SH0\": 450.0\n" +
"\t},\n" +
"\t\"distance_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 637.5,\n" +
"\t\t\"13MQJ0B5SI0\": 412.49999999999994,\n" +
"\t\t\"13MS20B5SI0\": 725.0,\n" +
"\t\t\"13MUK0B5SH0\": 525.0,\n" +
"\t\t\"13N0F0B5SH0\": 450.0,\n" +
"\t\t\"13N200B5SH0\": -1.0\n" +
"\t},\n" +
"\t\"dynamic\": 1,\n" +
"\t\"forward_direction\": \"w2e\",\n" +
"\t\"green_width_backward\": 42.0,\n" +
"\t\"green_width_forward\": 41.0,\n" +
"\t\"greenbelt_direction\": 2,\n" +
"\t\"greenbelt_id\": \"road1\",\n" +
"\t\"greenbelt_length\": 2757.0,\n" +
"\t\"greenbelt_type\": 2,\n" +
"\t\"max_cycle\": 220,\n" +
"\t\"max_speed_backward\": 50.0,\n" +
"\t\"max_speed_forward\": 50.0,\n" +
"\t\"min_speed_backward\": 40.0,\n" +
"\t\"min_speed_forward\": 40.0,\n" +
"\t\"offset\": {\n" +
"\t\t\"13MOD0B5SI0\": 0.0,\n" +
"\t\t\"13MQJ0B5SI0\": 87.0,\n" +
"\t\t\"13MS20B5SI0\": 117.0,\n" +
"\t\t\"13MUK0B5SH0\": 119.0,\n" +
"\t\t\"13N0F0B5SH0\": 0.0,\n" +
"\t\t\"13N200B5SH0\": 0.0\n" +
"\t},\n" +
"\t\"phase_end_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": 142.0,\n" +
"\t\t\"13MQJ0B5SI0\": 175.0,\n" +
"\t\t\"13MS20B5SI0\": 158.0,\n" +
"\t\t\"13MUK0B5SH0\": 125.0,\n" +
"\t\t\"13N0F0B5SH0\": 175.0,\n" +
"\t\t\"13N200B5SH0\": 145.0\n" +
"\t},\n" +
"\t\"phase_end_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 142.0,\n" +
"\t\t\"13MQJ0B5SI0\": 175.0,\n" +
"\t\t\"13MS20B5SI0\": 158.0,\n" +
"\t\t\"13MUK0B5SH0\": 125.0,\n" +
"\t\t\"13N0F0B5SH0\": 175.0,\n" +
"\t\t\"13N200B5SH0\": 145.0\n" +
"\t},\n" +
"\t\"phase_start_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": 39.0,\n" +
"\t\t\"13MQJ0B5SI0\": 42.0,\n" +
"\t\t\"13MS20B5SI0\": 45.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 42.0,\n" +
"\t\t\"13N200B5SH0\": 40.0\n" +
"\t},\n" +
"\t\"phase_start_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 39.0,\n" +
"\t\t\"13MQJ0B5SI0\": 42.0,\n" +
"\t\t\"13MS20B5SI0\": 45.0,\n" +
"\t\t\"13MUK0B5SH0\": 0.0,\n" +
"\t\t\"13N0F0B5SH0\": 42.0,\n" +
"\t\t\"13N200B5SH0\": 40.0\n" +
"\t},\n" +
"\t\"speed_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": -1.0,\n" +
"\t\t\"13MQJ0B5SI0\": 45.0,\n" +
"\t\t\"13MS20B5SI0\": 44.99999999999999,\n" +
"\t\t\"13MUK0B5SH0\": 45.0,\n" +
"\t\t\"13N0F0B5SH0\": 45.0,\n" +
"\t\t\"13N200B5SH0\": 45.0\n" +
"\t},\n" +
"\t\"speed_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 45.0,\n" +
"\t\t\"13MQJ0B5SI0\": 44.99999999999999,\n" +
"\t\t\"13MS20B5SI0\": 45.0,\n" +
"\t\t\"13MUK0B5SH0\": 45.0,\n" +
"\t\t\"13N0F0B5SH0\": 45.0,\n" +
"\t\t\"13N200B5SH0\": -1.0\n" +
"\t},\n" +
"\t\"travel_time_backward\": {\n" +
"\t\t\"13MOD0B5SI0\": -1.0,\n" +
"\t\t\"13MQJ0B5SI0\": 51.0,\n" +
"\t\t\"13MS20B5SI0\": 33.0,\n" +
"\t\t\"13MUK0B5SH0\": 58.0,\n" +
"\t\t\"13N0F0B5SH0\": 42.0,\n" +
"\t\t\"13N200B5SH0\": 36.0\n" +
"\t},\n" +
"\t\"travel_time_forward\": {\n" +
"\t\t\"13MOD0B5SI0\": 51.0,\n" +
"\t\t\"13MQJ0B5SI0\": 33.0,\n" +
"\t\t\"13MS20B5SI0\": 58.0,\n" +
"\t\t\"13MUK0B5SH0\": 42.0,\n" +
"\t\t\"13N0F0B5SH0\": 36.0,\n" +
"\t\t\"13N200B5SH0\": -1.0\n" +
"\t}\n" +
"}";
}
......@@ -490,7 +490,7 @@ public class RunningEvaluateServiceImpl implements RunningEvaluateService {
crossMetrics.setDelayTime(delayTimeSum / size);
crossMetrics.setEffusionRate(effusionRateSum / size);
crossMetrics.setEmptyPhase(emptyPhaseSum);
Date currentDate = dtoList.get(0).getStartTime();
Date currentDate = dtoList.get(dtoList.size() - 1).getStartTime();
Calendar instance = Calendar.getInstance();
instance.setTime(currentDate);
instance.set(Calendar.HOUR_OF_DAY, Integer.parseInt(section.substring(0, 2)));
......
......@@ -208,11 +208,13 @@ public class TrendServiceImpl implements TrendService {
Double speed = 0.0;
Double trafficIndex = 1.0;
int travelTime = 0;
Integer stopTimes = 0;
GreenwaveListVO wDirVo = new GreenwaveListVO();
for (GreenwaveListVO greenwaveListVO : value) {
speed += greenwaveListVO.getSpeed() == null ? 0.0 : greenwaveListVO.getSpeed();
trafficIndex += greenwaveListVO.getTrafficIndex() == null ? 0.0 : greenwaveListVO.getTrafficIndex();
travelTime += greenwaveListVO.getTravelTime();
stopTimes += greenwaveListVO.getStopTimes() == null ? 0 : greenwaveListVO.getStopTimes();
wDirVo.setId(greenId);
wDirVo.setName(greenwaveListVO.getName());
wDirVo.setWkt(greenwaveListVO.getWkt());
......@@ -222,6 +224,7 @@ public class TrendServiceImpl implements TrendService {
wDirVo.setInfoStatus(greenwaveListVO.getInfoStatus());
}
wDirVo.setSpeed(speed / 2);
wDirVo.setStopTimes(stopTimes / 2);
wDirVo.setTrafficIndex(trafficIndex / 2 < 1 ? 1 : trafficIndex / 2);
wDirVo.setTravelTime(travelTime / 2);
greenwaveListVOList.add(wDirVo);
......@@ -1756,7 +1759,7 @@ public class TrendServiceImpl implements TrendService {
AbnormalCrossListVO abnormalCrossListVO = new AbnormalCrossListVO();
// 如果路口编号为空,态势监测页面默认展示拥堵指数第一的路口排队长度数据
if (StringUtils.isBlank(crossId)) {
Optional<AbnormalCrossListVO> max = signalCrossRealTimeList.stream().max(Comparator.comparingDouble(AbnormalCrossListVO::getCongestionIndex));
Optional<AbnormalCrossListVO> max = signalCrossRealTimeList.stream().max(Comparator.comparingDouble(AbnormalCrossListVO::getTrafficIndex));
if (max.isPresent()) {
abnormalCrossListVO = max.get();
}
......@@ -1769,7 +1772,7 @@ public class TrendServiceImpl implements TrendService {
// 查询当前拥堵指数最大,历史表中一个小时以内数据
LambdaQueryWrapper<CrossDirDataHistPO> histQuery = new LambdaQueryWrapper<>();
histQuery.eq(CrossDirDataHistPO::getCrossId, abnormalCrossListVO.getId())
.between(CrossDirDataHistPO::getBatchTime, abnormalCrossListVO.getBatchTime() - 86400, abnormalCrossListVO.getBatchTime());
.between(CrossDirDataHistPO::getBatchTime, abnormalCrossListVO.getBatchTime() - 3600 * 2, abnormalCrossListVO.getBatchTime());
List<CrossDirDataHistPO> histPOS = crossDirDataHistMapper.selectList(histQuery);
if (!CollectionUtils.isEmpty(histPOS)) {
Map<Integer, List<CrossDirDataHistPO>> map = histPOS.stream().collect(Collectors.groupingBy(CrossDirDataHistPO::getBatchTime));
......
package net.wanji.opt.service.signalopt;
import net.wanji.opt.vo.GreenBeltFlowStopTimeVO;
import java.util.List;
/**
* @author duanruiming
* @date 2024/11/19 18:07
*/
public interface GreenBeltInfoService {
List<GreenBeltFlowStopTimeVO> greenBeltCrossDetailHist(Integer greenId);
}
package net.wanji.opt.service.signalopt.impl;
import net.wanji.databus.dao.mapper.CrossDataHistMapper;
import net.wanji.databus.dao.mapper.GreenwaveInfoMapper;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.opt.service.signalopt.GreenBeltInfoService;
import net.wanji.opt.vo.GreenBeltFlowStopTimeVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author duanruiming
* @date 2024/12/02 13:42
*/
@Service
public class GreenBeltServiceImpl implements GreenBeltInfoService {
@Resource
private GreenwaveInfoMapper greenwaveInfoMapper;
@Resource
private CrossDataHistMapper crossDataHistMapper;
@Override
public List<GreenBeltFlowStopTimeVO> greenBeltCrossDetailHist(Integer greenId) {
List<String> crossIds = greenwaveInfoMapper.selectCrossIdsById(greenId);
LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT; // 00:00
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime);
LocalDate nextDate = currentDate.plusDays(1);
LocalTime endTime = LocalTime.MIDNIGHT; // 00:00 of the next day
LocalDateTime endOfDay = LocalDateTime.of(nextDate, endTime);
long startSecond = startOfDay.toEpochSecond(ZoneOffset.of("+8"));
long endSecond = endOfDay.toEpochSecond(ZoneOffset.of("+8"));
List<CrossDataHistPO> crossDataHistPOS = crossDataHistMapper.selectByCrossIdsAndTimestamp(crossIds, (int) startSecond, (int) endSecond);
if (!CollectionUtils.isEmpty(crossDataHistPOS)) {
List<GreenBeltFlowStopTimeVO> results = new ArrayList<>();
Map<Date, List<CrossDataHistPO>> startTimeMap = crossDataHistPOS.stream().collect(Collectors.groupingBy(CrossDataHistPO::getStartTime));
GreenBeltFlowStopTimeVO greenBeltFlowStopTimeVO = new GreenBeltFlowStopTimeVO();
for (Map.Entry<Date, List<CrossDataHistPO>> entry : startTimeMap.entrySet()) {
Date startDate = entry.getKey();
List<GreenBeltFlowStopTimeVO.FlowStopTimeDetail> crossList = new ArrayList<>();
greenBeltFlowStopTimeVO.setStartTime(startDate);
List<CrossDataHistPO> value = entry.getValue();
if (!CollectionUtils.isEmpty(value)) {
for (CrossDataHistPO crossDataHistPO : value) {
GreenBeltFlowStopTimeVO.FlowStopTimeDetail flowStopTimeDetail = new GreenBeltFlowStopTimeVO.FlowStopTimeDetail();
flowStopTimeDetail.setFlow(crossDataHistPO.getFlow());
flowStopTimeDetail.setStopTimes(crossDataHistPO.getStopTimes());
flowStopTimeDetail.setCrossId(crossDataHistPO.getCrossId());
crossList.add(flowStopTimeDetail);
}
}
greenBeltFlowStopTimeVO.setDetailList(crossList);
results.add(greenBeltFlowStopTimeVO);
}
return results;
}
return Collections.EMPTY_LIST;
}
}
......@@ -30,8 +30,6 @@ public class StrategyControlController {
@Resource
private StrategyControlService strategyControlService;
@Resource
SynthesisOptimizeLogInfoMapper synthesisOptimizeLogInfoMapper;
@ApiOperation(value = "策略控制信息操作", notes = "策略控制信息操作",
response = JsonViewObject.class,
......
......@@ -174,7 +174,8 @@ public class StrategyControlServiceImpl implements StrategyControlService {
// 查询当前绿波历史记录
setGreenOptHist(results, midnight, format);
setCrossOptHist(results, midnight);
return JsonViewObject.newInstance().success(results);
List<StrategyControlHistVO> sorted = results.stream().sorted(Comparator.comparing(StrategyControlHistVO::getOptTime).reversed()).collect(Collectors.toList());
return JsonViewObject.newInstance().success(sorted);
}
private void setCrossOptHist(List<StrategyControlHistVO> results, LocalDateTime midnight) {
......
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;
import java.util.List;
/**
* @author duanruiming
* @date 2024/12/02 13:47
*/
@Data
@ApiModel(value = "绿波带历史流量停车次数")
public class GreenBeltFlowStopTimeVO {
@ApiModelProperty("时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "GMT+8")
private Date startTime;
@ApiModelProperty("流量停车次数列表")
private List<FlowStopTimeDetail> detailList;
@Data
public static class FlowStopTimeDetail {
@ApiModelProperty("路口编号")
private String crossId;
@ApiModelProperty("流量")
private Integer flow;
@ApiModelProperty("停车次数")
private Double stopTimes;
}
}
package net.wanji.databus.dao.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -9,10 +11,13 @@ import lombok.Data;
*/
@Data
@TableName("t_greenwave_hist")
public class GreenwaveHistPO extends GreenwaveRealtimePO{
@ApiModelProperty(value = "绿波名称")
@TableField(exist = false)
private String greenwaveName;
@ApiModelProperty(value = "协调方向:0正向;1反向;2双向")
@TableField(exist = false)
private Integer dir;
}
package net.wanji.databus.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.databus.dao.entity.GreenwaveHistPO;
import net.wanji.databus.dao.entity.GreenwaveHistPOExt;
import org.apache.ibatis.annotations.Param;
......@@ -13,7 +14,7 @@ import java.util.List;
* @date 2022/10/31 11:03
*/
@Repository
public interface GreenwaveHistMapper {
public interface GreenwaveHistMapper extends BaseMapper<GreenwaveHistPO> {
List<GreenwaveHistPOExt> selectRunMonitor(Date nowTime);
List<GreenwaveHistPO> selectByTimeSection(String startTimeStr, String endTimeStr);
......
......@@ -50,6 +50,8 @@ public class AbnormalCrossListVO {
private Integer isSpillover;
@ApiModelProperty(value = "是否拥堵:0否;1是")
private Integer isCongestion;
@ApiModelProperty(value = "交通指数")
private Double trafficIndex;
@ApiModelProperty(value = "拥堵指数")
private Double congestionIndex;
@ApiModelProperty(value = "失衡指数")
......
......@@ -42,6 +42,8 @@ public class GreenwaveListVO {
@ApiModelProperty(value = "行程速度")
@JsonSerialize(using = DoubleToTwoDecimalPlacesSerializer.class)
private Double speed;
@ApiModelProperty(value = "停车次数")
private Integer stopTimes;
@ApiModelProperty(value = "路口列表")
private List<CrossListElement> crossList;
......
......@@ -84,7 +84,7 @@
select
t2.id, t2.name, t2.is_signal, t1.unbalance_dirs, t1.congestion_dirs, t1.spillover_dirs, t1.status as realtimeStatus,
t1.start_time, t1.duration, t2.location as locationStr, t1.is_unbalance, t1.is_spillover, t1.is_congestion,
t1.congestion_index, t1.unbalance_index, t1.spillover_index, t1.batch_time
t1.congestion_index, t1.unbalance_index, t1.spillover_index, t1.batch_time, t1.traffic_index
from t_cross_data_realtime t1 JOIN t_base_cross_info t2
on t1.cross_id = t2.id
<where>
......
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