Commit bd07fa24 authored by duanruiming's avatar duanruiming

[update] 优化代码4,优化灯态定时任务程序可读性

parent 2f5ddba9
...@@ -192,39 +192,7 @@ public class SignalStatusTask { ...@@ -192,39 +192,7 @@ public class SignalStatusTask {
Map<Integer, String> turnColorMap = (Map<Integer, String>) groupEntry.getValue(); Map<Integer, String> turnColorMap = (Map<Integer, String>) groupEntry.getValue();
List<LightsStatusVO2.TurnInfo> turnList = new ArrayList<>(); List<LightsStatusVO2.TurnInfo> turnList = new ArrayList<>();
for (Map.Entry<Integer, String> turnEntry : turnColorMap.entrySet()) { for (Map.Entry<Integer, String> turnEntry : turnColorMap.entrySet()) {
Integer turn = null; setDirTurnInfo(phaseMap, dir, turnList, turnEntry);
if (turnEntry.getKey() instanceof Integer) {
turn = (Integer) turnEntry.getKey();
} else {
Object object = turnEntry.getKey();
turn = Integer.parseInt(String.valueOf(object));
}
String color = turnEntry.getValue();
LightsStatusVO2.TurnInfo turnInfo = new LightsStatusVO2.TurnInfo();
turnInfo.setTurn(String.valueOf(turn));
if (Objects.equals(turn, 20) && Objects.equals(color, "yellow")) { //行人黄灯时。绿闪
turnInfo.setColor("greenFlash");
} else {
turnInfo.setColor(color);
}
String key = dir.concat(Constants.SEPARATOR_UNDER_LINE).concat(String.valueOf(turn));
if (phaseMap.get(key) instanceof Map) {
Map<Integer, Integer> turnMap = (Map<Integer, Integer>) phaseMap.get(key);
if (Objects.nonNull(turnMap) && !turnMap.isEmpty()) {
Integer countDown = turnMap.get(turn);
turnInfo.setCountDown(countDown);
}
} else {
Integer countDown = null;
if (phaseMap.get(dir) instanceof Map) {
Map<Integer, Integer> turnMap = (Map<Integer, Integer>) phaseMap.get(dir);
countDown = turnMap.get(turn);
} else {
countDown = (Integer) phaseMap.get(key);
}
turnInfo.setCountDown(countDown);
}
turnList.add(turnInfo);
} }
dirInfo.setDir(dir); dirInfo.setDir(dir);
dirInfo.setTurnList(turnList); dirInfo.setTurnList(turnList);
...@@ -240,6 +208,70 @@ public class SignalStatusTask { ...@@ -240,6 +208,70 @@ public class SignalStatusTask {
return listResult; return listResult;
} }
/**
* 设置方向转向信息实体
* @param phaseMap
* @param dir
* @param turnList
* @param turnEntry
*/
private static void setDirTurnInfo(Map<String, Object> phaseMap, String dir, List<LightsStatusVO2.TurnInfo> turnList, Map.Entry<Integer, String> turnEntry) {
Integer turn = parseTurn(turnEntry);
String color = turnEntry.getValue();
LightsStatusVO2.TurnInfo turnInfo = new LightsStatusVO2.TurnInfo();
turnInfo.setTurn(String.valueOf(turn));
if (Objects.equals(turn, 20) && Objects.equals(color, "yellow")) { //行人黄灯时。绿闪
turnInfo.setColor("greenFlash");
} else {
turnInfo.setColor(color);
}
setTurnInfoCounDown(phaseMap, dir, turn, turnInfo);
turnList.add(turnInfo);
}
/**
* 转换转向参数
* @param turnEntry
* @return
*/
private static Integer parseTurn(Map.Entry<Integer, String> turnEntry) {
Integer turn = null;
if (turnEntry.getKey() instanceof Integer) {
turn = (Integer) turnEntry.getKey();
} else {
Object object = turnEntry.getKey();
turn = Integer.parseInt(String.valueOf(object));
}
return turn;
}
/**
* 设置方向转向倒计时时间
* @param phaseMap
* @param dir
* @param turn
* @param turnInfo
*/
private static void setTurnInfoCounDown(Map<String, Object> phaseMap, String dir, Integer turn, LightsStatusVO2.TurnInfo turnInfo) {
String key = dir.concat(Constants.SEPARATOR_UNDER_LINE).concat(String.valueOf(turn));
if (phaseMap.get(key) instanceof Map) {
Map<Integer, Integer> turnMap = (Map<Integer, Integer>) phaseMap.get(key);
if (Objects.nonNull(turnMap) && !turnMap.isEmpty()) {
Integer countDown = turnMap.get(turn);
turnInfo.setCountDown(countDown);
}
} else {
Integer countDown = null;
if (phaseMap.get(dir) instanceof Map) {
Map<Integer, Integer> turnMap = (Map<Integer, Integer>) phaseMap.get(dir);
countDown = turnMap.get(turn);
} else {
countDown = (Integer) phaseMap.get(key);
}
turnInfo.setCountDown(countDown);
}
}
/** /**
* 灯态数据发送kafka * 灯态数据发送kafka
*/ */
......
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