Commit bb3e1e56 authored by duanruiming's avatar duanruiming

[update] 优化海信灯态车道灯态问题2

parent d159c659
......@@ -24,5 +24,4 @@ public class SignalDataCache {
public static final Map<String, RunningLightsStatusPojo> runningStateInfoCacheUdp = new HashMap<>();
public static final Map<String, LightsStatusVO> runningStateInfoCache = new HashMap<>();
public static final Map<String, Long> runningStatusStampMap = new HashMap<>();
public static final Map<String, Integer> currentCrossPhaseNoRunPhaseTimeMap = new HashMap<>();
}
......@@ -153,8 +153,8 @@ public class SignalStatusServiceImpl implements SignalStatusService {
}
Date date = new Date();
Long time = date.getTime();
int offsetTime = (int) ((time - signalMachineStamp) / 1000);
int cycleCountDown = content.getCycleCountDown() - offsetTime;
int offsetTime = (int) ((time - signalMachineStamp) / 1000) - 6; //37.12.182.29服务器比北京时间快6秒
int cycleCountDown = content.getCycleCountDown() - Math.max(offsetTime, 0);
int hiControlMode = content.getControlMode();
int period = content.getPeriod();
int runTime = period - cycleCountDown;
......@@ -204,7 +204,6 @@ public class SignalStatusServiceImpl implements SignalStatusService {
Integer changePhaseTime = phaseCountDownDTO.getChangePhaseTime();
if (lastPhaseCountTime <= runTime && runTime < changePhaseTime) {
phaseTimeCountDown = changePhaseTime - runTime;
SignalDataCache.currentCrossPhaseNoRunPhaseTimeMap.put(crossId, phaseTimeCountDown);
break;
}
lastPhaseCountTime = changePhaseTime;
......
......@@ -38,7 +38,6 @@ public class HisensePhaseCountDownTask {
@Scheduled(fixedRate = 1000, initialDelay = 1000)
public void phaseTimeCountDown() {
Map<String, LightsStatusVO> runningStateInfoCache = SignalDataCache.runningStateInfoCache;
Map<String, Long> runningStatusStampMap = SignalDataCache.runningStatusStampMap;
if (!runningStateInfoCache.isEmpty()) {
for (Map.Entry<String, LightsStatusVO> entry : runningStateInfoCache.entrySet()) {
String crossId = entry.getKey();
......@@ -47,10 +46,8 @@ public class HisensePhaseCountDownTask {
String phaseId = lightsStatusVO.getPhaseId();
String schemeId = lightsStatusVO.getSchemeId();
Integer cyclePhaseCountDown = lightsStatusVO.getCyclePhaseCountDown();
Integer phaseCycleTime = SignalDataCache.currentCrossPhaseNoRunPhaseTimeMap.get(crossId);
CrossSchemePO crossSchemePO = crossSchemeMapper.selectByCrossIdAndSchemeNo(crossId, Integer.valueOf(schemeId));
// 切换相位号或者相位运行第一次
if (cyclePhaseCountDown <= 5 || cyclePhaseCountDown >= phaseCycleTime - 5) {
// 通过时段表,切换方案 凌晨00:00 如果切换下一个日期方案,可能RefreshCacheTask还没执行
String nextSectionSchemeNo = CrossRunSchemeCache.currentRunSchemeNoCache.get(crossId);
String currentTime = String.valueOf(new Date().getTime());
......@@ -63,19 +60,20 @@ public class HisensePhaseCountDownTask {
}
// 当前方案下一周期
setDirLampGroupMap(lightsStatusVO);
if (Objects.nonNull(lightsStatusVO.getDirLampGroupMap())) {
runningStateInfoCache.put(crossId, lightsStatusVO);
} else { // 如果是相同5秒时间内,直接时间相减,不需要计算灯态相位倒计时
executeNextPeriod(crossId, lightsStatusVO, phaseId, crossSchemePO);
} else {
log.error("当前灯态为空,为啥呢:{}", lightsStatusVO);
}
}
}
}
/**
* @description 通过日计划缓存,切换下一个时段方案
* @param crossId
* @param lightsStatusVO
* @param crossSchemePO
* @description 通过日计划缓存,切换下一个时段方案
*/
private void executeNextSectionScheme(String crossId, LightsStatusVO lightsStatusVO, CrossSchemePO crossSchemePO) {
if (Objects.nonNull(crossSchemePO)) {
......@@ -96,14 +94,14 @@ public class HisensePhaseCountDownTask {
}
/**
* @description 切换下一方案周期
* @param crossId
* @param lightsStatusVO
* @param phaseId
* @param crossSchemePO
* @description 切换下一方案周期
*/
private void executeNextPeriod(String crossId, LightsStatusVO lightsStatusVO, String phaseId, CrossSchemePO crossSchemePO) {
if (lightsStatusVO.getCyclePhaseCountDown() == 0 && Objects.nonNull(crossSchemePO)) {
if (lightsStatusVO.getCyclePhaseCountDown() <= 1 && Objects.nonNull(crossSchemePO)) {
List<CrossPhasePO> crossPhasePOS = crossPhaseMapper.selectByCrossIdAndPlanId(crossId, String.valueOf(crossSchemePO.getId()));
Integer nextPhaseTime = 0;
String nextPhaseId = "0";
......@@ -128,8 +126,8 @@ public class HisensePhaseCountDownTask {
}
/**
* @description 通过当前周期倒计时方案相位灯态
* @param lightsStatusVO
* @description 通过当前周期倒计时方案相位灯态
*/
public void setDirLampGroupMap(LightsStatusVO lightsStatusVO) {
String crossId = lightsStatusVO.getCrossId();
......@@ -151,6 +149,15 @@ public class HisensePhaseCountDownTask {
Integer redTime = phaseCountDownDTO.getRedTime();
Map<Integer, List<CrossLightsPO>> dirTurnMap = phaseDirTurnPojo.getDirTurnMap();
if (!dirTurnMap.isEmpty()) {
setDirTurnColor(cyclePhaseCountDown, dirLampGroupMap, yellowTime, redTime, dirTurnMap);
}
lightsStatusVO.setDirLampGroupMap(dirLampGroupMap);
}
}
}
}
private static void setDirTurnColor(Integer cyclePhaseCountDown, Map<String, Object> dirLampGroupMap, Integer yellowTime, Integer redTime, Map<Integer, List<CrossLightsPO>> dirTurnMap) {
for (Map.Entry<Integer, List<CrossLightsPO>> dirEntry : dirTurnMap.entrySet()) {
Integer dir = dirEntry.getKey();
List<CrossLightsPO> lightsList = dirEntry.getValue();
......@@ -164,6 +171,19 @@ public class HisensePhaseCountDownTask {
type = crossLightsPO.getType();
Integer turn = crossLightsPO.getTurn();
String turnStr = String.valueOf(turn);
color = setTurnColor(cyclePhaseCountDown, yellowTime, redTime, turnColor, color, turn, turnStr);
turnColor.put(turnStr, color);
}
if (cyclePhaseCountDown <= 2) {
setAllTurnColorRed(turnColor, type, color);
} else {
setAllTurnColor(turnColor, type, color);
}
dirLampGroupMap.put(String.valueOf(dir), turnColor);
}
}
private static String setTurnColor(Integer cyclePhaseCountDown, Integer yellowTime, Integer redTime, Map<String, String> turnColor, String color, Integer turn, String turnStr) {
if (cyclePhaseCountDown > yellowTime + redTime) {
color = "green";
if (turn == 20) {
......@@ -182,18 +202,33 @@ public class HisensePhaseCountDownTask {
turnColor.put(turnStr, "green");
}
}
turnColor.put(turnStr, color);
}
setAllTurnColor(turnColor, type, color);
dirLampGroupMap.put(String.valueOf(dir), turnColor);
}
return color;
}
lightsStatusVO.setDirLampGroupMap(dirLampGroupMap);
/**
* 两秒倒计时,全场红
* @param turnColor
* @param type
* @param color
*/
private static void setAllTurnColorRed(Map<String, String> turnColor, Integer type, String color) {
List<String> allTurn = Arrays.asList("1", "2", "3");
for (String turnStr : allTurn) {
if (!turnColor.containsKey(turnStr)) {
turnColor.put(turnStr, "red");
}
}
for (Map.Entry<String, String> entry : turnColor.entrySet()) {
entry.setValue("red");
}
}
/**
* 设置所有转向灯色
* @param turnColor
* @param type
* @param color
*/
private static void setAllTurnColor(Map<String, String> turnColor, Integer type, String color) {
List<String> allTurn = Arrays.asList("1", "2", "3");
for (String turn : allTurn) {
......@@ -212,11 +247,11 @@ public class HisensePhaseCountDownTask {
}
/**
* @description 获取路口方案相位倒计时
* @param crossId
* @param schemeNo
* @param phaseNo
* @return
* @description 获取路口方案相位倒计时
*/
private PhaseCountDownDTO getPhaseCountDownDTO(String crossId, String schemeNo, String phaseNo) {
List<CrossSchemePhaseCountDownDTO> crossSchemePhaseCountDownList = CrossSchemePhaseTimeCountCache.crossSchemePhaseCountDownList;
......
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