Commit bd07fa24 authored by duanruiming's avatar duanruiming

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

parent 2f5ddba9
...@@ -192,13 +192,31 @@ public class SignalStatusTask { ...@@ -192,13 +192,31 @@ 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(); dirInfo.setDir(dir);
} else { dirInfo.setTurnList(turnList);
Object object = turnEntry.getKey(); dirList.add(dirInfo);
turn = Integer.parseInt(String.valueOf(object));
} }
lightsStatusVO2.setDirLampGroupMapList(dirList);
listResult.add(lightsStatusVO2);
}
} catch (Exception e) {
log.error("灯态推送转换V2异常:", e);
throw new Exception(e);
}
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(); String color = turnEntry.getValue();
LightsStatusVO2.TurnInfo turnInfo = new LightsStatusVO2.TurnInfo(); LightsStatusVO2.TurnInfo turnInfo = new LightsStatusVO2.TurnInfo();
turnInfo.setTurn(String.valueOf(turn)); turnInfo.setTurn(String.valueOf(turn));
...@@ -207,6 +225,34 @@ public class SignalStatusTask { ...@@ -207,6 +225,34 @@ public class SignalStatusTask {
} else { } else {
turnInfo.setColor(color); 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)); String key = dir.concat(Constants.SEPARATOR_UNDER_LINE).concat(String.valueOf(turn));
if (phaseMap.get(key) instanceof Map) { if (phaseMap.get(key) instanceof Map) {
Map<Integer, Integer> turnMap = (Map<Integer, Integer>) phaseMap.get(key); Map<Integer, Integer> turnMap = (Map<Integer, Integer>) phaseMap.get(key);
...@@ -224,20 +270,6 @@ public class SignalStatusTask { ...@@ -224,20 +270,6 @@ public class SignalStatusTask {
} }
turnInfo.setCountDown(countDown); turnInfo.setCountDown(countDown);
} }
turnList.add(turnInfo);
}
dirInfo.setDir(dir);
dirInfo.setTurnList(turnList);
dirList.add(dirInfo);
}
lightsStatusVO2.setDirLampGroupMapList(dirList);
listResult.add(lightsStatusVO2);
}
} catch (Exception e) {
log.error("灯态推送转换V2异常:", e);
throw new Exception(e);
}
return listResult;
} }
/** /**
......
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