Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
traffic-signal-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
signal
traffic-signal-platform
Commits
bb3e1e56
Commit
bb3e1e56
authored
Oct 12, 2023
by
duanruiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] 优化海信灯态车道灯态问题2
parent
d159c659
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
63 deletions
+96
-63
SignalDataCache.java
...ain/java/net/wanji/utc/hisense/cache/SignalDataCache.java
+0
-1
SignalStatusServiceImpl.java
...nji/utc/hisense/service/impl/SignalStatusServiceImpl.java
+2
-3
HisensePhaseCountDownTask.java
...net/wanji/utc/hisense/task/HisensePhaseCountDownTask.java
+94
-59
No files found.
signal-utc-hisense-service/src/main/java/net/wanji/utc/hisense/cache/SignalDataCache.java
View file @
bb3e1e56
...
...
@@ -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
<>();
}
signal-utc-hisense-service/src/main/java/net/wanji/utc/hisense/service/impl/SignalStatusServiceImpl.java
View file @
bb3e1e56
...
...
@@ -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
;
...
...
signal-utc-hisense-service/src/main/java/net/wanji/utc/hisense/task/HisensePhaseCountDownTask.java
View file @
bb3e1e56
...
...
@@ -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,35 +46,34 @@ 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
());
if
(
StringUtils
.
equalsIgnoreCase
(
schemeStartTime
,
currentTime
))
{
crossSchemePO
=
crossSchemeMapper
.
selectByCrossIdAndSchemeNo
(
crossId
,
Integer
.
valueOf
(
nextSectionSchemeNo
));
executeNextSectionScheme
(
crossId
,
lightsStatusVO
,
crossSchemePO
);
lightsStatusVO
.
setCycleLen
(
crossSchemePO
.
getCycle
());
}
else
{
executeNextPeriod
(
crossId
,
lightsStatusVO
,
phaseId
,
crossSchemePO
);
}
// 当前方案下一周期
setDirLampGroupMap
(
lightsStatusVO
);
runningStateInfoCache
.
put
(
crossId
,
lightsStatusVO
);
}
else
{
// 如果是相同5秒时间内,直接时间相减,不需要计算灯态相位倒计时
// 通过时段表,切换方案 凌晨00:00 如果切换下一个日期方案,可能RefreshCacheTask还没执行
String
nextSectionSchemeNo
=
CrossRunSchemeCache
.
currentRunSchemeNoCache
.
get
(
crossId
);
String
currentTime
=
String
.
valueOf
(
new
Date
().
getTime
());
if
(
StringUtils
.
equalsIgnoreCase
(
schemeStartTime
,
currentTime
))
{
crossSchemePO
=
crossSchemeMapper
.
selectByCrossIdAndSchemeNo
(
crossId
,
Integer
.
valueOf
(
nextSectionSchemeNo
));
executeNextSectionScheme
(
crossId
,
lightsStatusVO
,
crossSchemePO
);
lightsStatusVO
.
setCycleLen
(
crossSchemePO
.
getCycle
());
}
else
{
executeNextPeriod
(
crossId
,
lightsStatusVO
,
phaseId
,
crossSchemePO
);
}
// 当前方案下一周期
setDirLampGroupMap
(
lightsStatusVO
);
if
(
Objects
.
nonNull
(
lightsStatusVO
.
getDirLampGroupMap
()))
{
runningStateInfoCache
.
put
(
crossId
,
lightsStatusVO
);
}
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,42 +149,7 @@ public class HisensePhaseCountDownTask {
Integer
redTime
=
phaseCountDownDTO
.
getRedTime
();
Map
<
Integer
,
List
<
CrossLightsPO
>>
dirTurnMap
=
phaseDirTurnPojo
.
getDirTurnMap
();
if
(!
dirTurnMap
.
isEmpty
())
{
for
(
Map
.
Entry
<
Integer
,
List
<
CrossLightsPO
>>
dirEntry
:
dirTurnMap
.
entrySet
())
{
Integer
dir
=
dirEntry
.
getKey
();
List
<
CrossLightsPO
>
lightsList
=
dirEntry
.
getValue
();
if
(
CollectionUtils
.
isEmpty
(
lightsList
))
{
continue
;
}
Map
<
String
,
String
>
turnColor
=
new
HashMap
<>();
Integer
type
=
2
;
// 灯组类型:1箭头;2圆饼;3行人;
String
color
=
null
;
for
(
CrossLightsPO
crossLightsPO
:
lightsList
)
{
type
=
crossLightsPO
.
getType
();
Integer
turn
=
crossLightsPO
.
getTurn
();
String
turnStr
=
String
.
valueOf
(
turn
);
if
(
cyclePhaseCountDown
>
yellowTime
+
redTime
)
{
color
=
"green"
;
if
(
turn
==
20
)
{
turnColor
.
put
(
turnStr
,
"red"
);
}
}
if
(
cyclePhaseCountDown
<=
yellowTime
+
redTime
&&
cyclePhaseCountDown
>
redTime
)
{
color
=
"yellow"
;
if
(
turn
==
20
)
{
turnColor
.
put
(
turnStr
,
"red"
);
}
}
if
(
cyclePhaseCountDown
<
redTime
)
{
color
=
"red"
;
if
(
turn
==
20
)
{
turnColor
.
put
(
turnStr
,
"green"
);
}
}
turnColor
.
put
(
turnStr
,
color
);
}
setAllTurnColor
(
turnColor
,
type
,
color
);
dirLampGroupMap
.
put
(
String
.
valueOf
(
dir
),
turnColor
);
}
setDirTurnColor
(
cyclePhaseCountDown
,
dirLampGroupMap
,
yellowTime
,
redTime
,
dirTurnMap
);
}
lightsStatusVO
.
setDirLampGroupMap
(
dirLampGroupMap
);
}
...
...
@@ -194,6 +157,78 @@ public class HisensePhaseCountDownTask {
}
}
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
();
if
(
CollectionUtils
.
isEmpty
(
lightsList
))
{
continue
;
}
Map
<
String
,
String
>
turnColor
=
new
HashMap
<>();
Integer
type
=
2
;
// 灯组类型:1箭头;2圆饼;3行人;
String
color
=
null
;
for
(
CrossLightsPO
crossLightsPO
:
lightsList
)
{
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
)
{
turnColor
.
put
(
turnStr
,
"red"
);
}
}
if
(
cyclePhaseCountDown
<=
yellowTime
+
redTime
&&
cyclePhaseCountDown
>
redTime
)
{
color
=
"yellow"
;
if
(
turn
==
20
)
{
turnColor
.
put
(
turnStr
,
"red"
);
}
}
if
(
cyclePhaseCountDown
<
redTime
)
{
color
=
"red"
;
if
(
turn
==
20
)
{
turnColor
.
put
(
turnStr
,
"green"
);
}
}
return
color
;
}
/**
* 两秒倒计时,全场红
* @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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment