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
a6e745b1
Commit
a6e745b1
authored
Nov 02, 2023
by
duanruiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] 修改红灯倒计时
parent
fe214c17
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
132 additions
and
57 deletions
+132
-57
HisensePhaseCountDownTask.java
...net/wanji/utc/hisense/task/HisensePhaseCountDownTask.java
+132
-57
No files found.
signal-utc-hisense-service/src/main/java/net/wanji/utc/hisense/task/HisensePhaseCountDownTask.java
View file @
a6e745b1
...
...
@@ -22,6 +22,7 @@ import org.springframework.util.CollectionUtils;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* @author duanruiming
...
...
@@ -91,42 +92,94 @@ public class HisensePhaseCountDownTask {
}
}
private
void
getRedCountDown
(
String
crossId
,
LightsStatusVO
lightsStatusVO
,
String
schemeId
)
{
private
static
void
getRedCountDown
(
String
crossId
,
LightsStatusVO
lightsStatusVO
,
String
schemeId
)
{
Map
<
String
,
Object
>
phaseMap
=
new
HashMap
<>();
List
<
CrossPhaseDirTurnPojo
>
crossPhaseDirTurnCache
=
CrossPhaseDirTurnCache
.
getCrossPhaseDirTurnCache
(
crossId
);
List
<
PhaseCountDownDTO
>
phaseCountDownList
=
getPhaseCountDownList
(
crossId
,
schemeId
);
if
(!
CollectionUtils
.
isEmpty
(
phaseCountDownList
))
{
for
(
PhaseCountDownDTO
phaseCountDownDTO
:
phaseCountDownList
)
{
String
phaseNo
=
phaseCountDownDTO
.
getPhaseNo
();
Integer
changePhaseTime
=
phaseCountDownDTO
.
getChangePhaseTime
();
Integer
cycleLen
=
lightsStatusVO
.
getCycleLen
();
Integer
cycleCountDown
=
lightsStatusVO
.
getCycleCountDown
();
String
currenPhaseId
=
lightsStatusVO
.
getPhaseId
();
int
runtime
=
cycleLen
-
cycleCountDown
;
int
redCountDown
=
0
;
if
(!
CollectionUtils
.
isEmpty
(
crossPhaseDirTurnCache
))
{
for
(
CrossPhaseDirTurnPojo
dirTurnPojo
:
crossPhaseDirTurnCache
)
{
if
(
StringUtils
.
equalsIgnoreCase
(
schemeId
,
String
.
valueOf
(
dirTurnPojo
.
getSchemeNo
()))
&&
StringUtils
.
equalsIgnoreCase
(
phaseNo
,
String
.
valueOf
(
dirTurnPojo
.
getPhaseNo
())))
{
Map
<
Integer
,
List
<
CrossLightsPO
>>
dirTurnMap
=
dirTurnPojo
.
getDirTurnMap
();
for
(
Map
.
Entry
<
Integer
,
List
<
CrossLightsPO
>>
dirEntry
:
dirTurnMap
.
entrySet
())
{
List
<
CrossLightsPO
>
lightsPOS
=
dirEntry
.
getValue
();
if
(!
CollectionUtils
.
isEmpty
(
lightsPOS
))
{
for
(
CrossLightsPO
lightsPO
:
lightsPOS
)
{
Integer
dir
=
lightsPO
.
getDir
();
Integer
turn
=
lightsPO
.
getTurn
();
if
(
turn
==
20
)
{
if
(
StringUtils
.
equalsIgnoreCase
(
schemeId
,
String
.
valueOf
(
dirTurnPojo
.
getSchemeNo
())))
{
if
(!
StringUtils
.
equalsIgnoreCase
(
currenPhaseId
,
String
.
valueOf
(
dirTurnPojo
.
getPhaseNo
())))
{
Map
<
Integer
,
List
<
CrossLightsPO
>>
dirTurnMap
=
dirTurnPojo
.
getDirTurnMap
();
for
(
Map
.
Entry
<
Integer
,
List
<
CrossLightsPO
>>
dirEntry
:
dirTurnMap
.
entrySet
())
{
Integer
dir
=
dirEntry
.
getKey
();
Map
<
Integer
,
Integer
>
turnCountDown
=
new
HashMap
<>();
List
<
CrossLightsPO
>
lightsPOS
=
dirEntry
.
getValue
();
if
(!
CollectionUtils
.
isEmpty
(
lightsPOS
))
{
// 忽略行人
List
<
CrossLightsPO
>
person
=
lightsPOS
.
stream
().
filter
(
po
->
po
.
getTurn
()
==
20
).
collect
(
Collectors
.
toList
());
if
(
person
.
size
()
==
lightsPOS
.
size
())
{
continue
;
}
String
key
=
String
.
valueOf
(
dir
).
concat
(
"-"
).
concat
(
String
.
valueOf
(
turn
)
);
Integer
type
=
lightsPOS
.
get
(
0
).
getType
(
);
redCountDown
=
changePhaseTime
-
runtime
;
if
(
redCountDown
<
0
)
{
redCountDown
=
cycleLen
+
redCountDown
;
}
phaseMap
.
put
(
key
,
redCountDown
);
if
(
type
==
2
)
{
// 圆饼灯
List
<
Integer
>
dirList
=
Arrays
.
asList
(
1
,
2
,
3
);
for
(
Integer
commonTurn
:
dirList
)
{
turnCountDown
.
put
(
commonTurn
,
redCountDown
);
}
}
else
{
Map
<
Integer
,
List
<
CrossLightsPO
>>
turnMap
=
lightsPOS
.
stream
().
collect
(
Collectors
.
groupingBy
(
CrossLightsPO:
:
getTurn
));
for
(
Map
.
Entry
<
Integer
,
List
<
CrossLightsPO
>>
turnEntry
:
turnMap
.
entrySet
())
{
Integer
turn
=
turnEntry
.
getKey
();
List
<
CrossLightsPO
>
value
=
turnEntry
.
getValue
();
for
(
CrossLightsPO
lightsPO
:
value
)
{
if
(
lightsPO
.
getTurn
()
!=
20
)
{
turnCountDown
.
put
(
turn
,
redCountDown
);
}
}
}
}
}
phaseMap
.
put
(
String
.
valueOf
(
dir
),
turnCountDown
);
}
}
else
{
Integer
cyclePhaseCountDown
=
lightsStatusVO
.
getCyclePhaseCountDown
();
Map
<
Integer
,
List
<
CrossLightsPO
>>
dirTurnMap
=
dirTurnPojo
.
getDirTurnMap
();
for
(
Map
.
Entry
<
Integer
,
List
<
CrossLightsPO
>>
dirEntry
:
dirTurnMap
.
entrySet
())
{
Integer
dir
=
dirEntry
.
getKey
();
Map
<
Integer
,
Integer
>
turnCountDown
=
new
HashMap
<>();
List
<
CrossLightsPO
>
lightsPOS
=
dirEntry
.
getValue
();
if
(!
CollectionUtils
.
isEmpty
(
lightsPOS
))
{
// 忽略行人
List
<
CrossLightsPO
>
person
=
lightsPOS
.
stream
().
filter
(
po
->
po
.
getTurn
()
==
20
).
collect
(
Collectors
.
toList
());
if
(
person
.
size
()
==
lightsPOS
.
size
())
{
continue
;
}
Integer
type
=
lightsPOS
.
get
(
0
).
getType
();
redCountDown
=
cyclePhaseCountDown
;
if
(
type
==
2
)
{
// 圆饼灯
List
<
Integer
>
dirList
=
Arrays
.
asList
(
1
,
2
,
3
);
for
(
Integer
commonTurn
:
dirList
)
{
turnCountDown
.
put
(
commonTurn
,
redCountDown
);
}
}
else
{
Map
<
Integer
,
List
<
CrossLightsPO
>>
turnMap
=
lightsPOS
.
stream
().
collect
(
Collectors
.
groupingBy
(
CrossLightsPO:
:
getTurn
));
for
(
Map
.
Entry
<
Integer
,
List
<
CrossLightsPO
>>
turnEntry
:
turnMap
.
entrySet
())
{
Integer
turn
=
turnEntry
.
getKey
();
List
<
CrossLightsPO
>
value
=
turnEntry
.
getValue
();
for
(
CrossLightsPO
lightsPO
:
value
)
{
if
(
lightsPO
.
getTurn
()
!=
20
)
{
turnCountDown
.
put
(
turn
,
redCountDown
);
}
}
}
}
}
phaseMap
.
put
(
String
.
valueOf
(
dir
),
turnCountDown
);
}
}
}
}
}
...
...
@@ -206,16 +259,46 @@ public class HisensePhaseCountDownTask {
for
(
CrossPhaseDirTurnPojo
phaseDirTurnPojo
:
crossPhaseDirTurnCache
)
{
String
schemeNo
=
String
.
valueOf
(
phaseDirTurnPojo
.
getSchemeNo
());
String
phaseNo
=
String
.
valueOf
(
phaseDirTurnPojo
.
getPhaseNo
());
if
(
StringUtils
.
equalsIgnoreCase
(
schemeNo
,
currentSchemeNo
)
&&
StringUtils
.
equalsIgnoreCase
(
currentPhaseNo
,
String
.
valueOf
(
phaseNo
)))
{
PhaseCountDownDTO
phaseCountDownDTO
=
getPhaseCountDownDTO
(
crossId
,
schemeNo
,
phaseNo
);
if
(
Objects
.
isNull
(
phaseCountDownDTO
))
{
continue
;
}
Integer
yellowTime
=
phaseCountDownDTO
.
getYellowTime
();
Integer
redTime
=
phaseCountDownDTO
.
getRedTime
();
Map
<
Integer
,
List
<
CrossLightsPO
>>
dirTurnMap
=
phaseDirTurnPojo
.
getDirTurnMap
();
if
(!
dirTurnMap
.
isEmpty
())
{
setDirTurnColor
(
cyclePhaseCountDown
,
dirLampGroupMap
,
yellowTime
,
redTime
,
dirTurnMap
);
if
(
StringUtils
.
equalsIgnoreCase
(
schemeNo
,
currentSchemeNo
))
{
if
(!
StringUtils
.
equalsIgnoreCase
(
currentPhaseNo
,
String
.
valueOf
(
phaseNo
)))
{
// 相位红灯
Map
<
Integer
,
List
<
CrossLightsPO
>>
dirTurnMap
=
phaseDirTurnPojo
.
getDirTurnMap
();
if
(!
dirTurnMap
.
isEmpty
())
{
for
(
Map
.
Entry
<
Integer
,
List
<
CrossLightsPO
>>
entry
:
dirTurnMap
.
entrySet
())
{
String
dir
=
String
.
valueOf
(
entry
.
getKey
());
Map
<
Integer
,
String
>
turnColor
=
null
;
if
(!
dirLampGroupMap
.
containsKey
(
dir
))
{
turnColor
=
new
HashMap
<>();
}
else
{
turnColor
=
(
Map
<
Integer
,
String
>)
dirLampGroupMap
.
get
(
dir
);
}
List
<
CrossLightsPO
>
value
=
entry
.
getValue
();
for
(
CrossLightsPO
crossLightsPO
:
value
)
{
Integer
turn
=
crossLightsPO
.
getTurn
();
// 搭接相位跳过绿灯变红灯
if
(
turnColor
.
containsKey
(
turn
)
&&
turnColor
.
get
(
turn
).
equals
(
"green"
))
{
continue
;
}
turnColor
.
put
(
turn
,
"red"
);
}
turnColor
.
put
(
3
,
"green"
);
dirLampGroupMap
.
put
(
dir
,
turnColor
);
}
}
}
else
{
// 相位绿灯
PhaseCountDownDTO
phaseCountDownDTO
=
getPhaseCountDownDTO
(
crossId
,
schemeNo
,
phaseNo
);
if
(
Objects
.
isNull
(
phaseCountDownDTO
))
{
continue
;
}
Integer
yellowTime
=
phaseCountDownDTO
.
getYellowTime
();
Integer
redTime
=
phaseCountDownDTO
.
getRedTime
();
Map
<
Integer
,
List
<
CrossLightsPO
>>
dirTurnMap
=
phaseDirTurnPojo
.
getDirTurnMap
();
if
(!
dirTurnMap
.
isEmpty
())
{
setDirTurnColor
(
cyclePhaseCountDown
,
dirLampGroupMap
,
yellowTime
,
redTime
,
dirTurnMap
);
}
lightsStatusVO
.
setDirLampGroupMap
(
dirLampGroupMap
);
}
lightsStatusVO
.
setDirLampGroupMap
(
dirLampGroupMap
);
}
...
...
@@ -224,52 +307,52 @@ public class HisensePhaseCountDownTask {
}
private
static
void
setDirTurnColor
(
Integer
cyclePhaseCountDown
,
Map
<
String
,
Object
>
dirLampGroupMap
,
Integer
yellowTime
,
Integer
redTime
,
Map
<
Integer
,
List
<
CrossLightsPO
>>
dirTurnMap
)
throws
Exception
{
Integer
yellowTime
,
Integer
redTime
,
Map
<
Integer
,
List
<
CrossLightsPO
>>
dirTurnMap
)
throws
Exception
{
for
(
Map
.
Entry
<
Integer
,
List
<
CrossLightsPO
>>
dirEntry
:
dirTurnMap
.
entrySet
())
{
Integer
dir
=
dirEntry
.
getKey
(
);
String
dir
=
String
.
valueOf
(
dirEntry
.
getKey
()
);
List
<
CrossLightsPO
>
lightsList
=
dirEntry
.
getValue
();
if
(
CollectionUtils
.
isEmpty
(
lightsList
))
{
continue
;
}
Map
<
String
,
String
>
turnColor
=
new
HashMap
<>();
Map
<
Integer
,
String
>
turnColor
=
null
;
if
(!
dirLampGroupMap
.
containsKey
(
dir
))
{
turnColor
=
new
HashMap
<>();
}
else
{
turnColor
=
(
Map
<
Integer
,
String
>)
dirLampGroupMap
.
get
(
dir
);
}
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
);
color
=
setTurnColor
(
cyclePhaseCountDown
,
yellowTime
,
redTime
,
turnColor
,
color
,
turn
);
turnColor
.
put
(
turn
,
color
);
}
if
(
cyclePhaseCountDown
<=
redTime
)
{
setAllTurnColorRed
(
turnColor
,
type
,
color
);
}
else
{
setAllTurnColor
(
turnColor
,
type
,
color
);
if
(
type
==
2
)
{
setAllTurnColor
(
turnColor
,
color
);
}
dirLampGroupMap
.
put
(
String
.
valueOf
(
dir
)
,
turnColor
);
dirLampGroupMap
.
put
(
dir
,
turnColor
);
}
}
private
static
String
setTurnColor
(
Integer
cyclePhaseCountDown
,
Integer
yellowTime
,
Integer
redTime
,
Map
<
String
,
String
>
turnColor
,
String
color
,
Integer
turn
,
String
turnStr
)
throws
Exception
{
Map
<
Integer
,
String
>
turnColor
,
String
color
,
Integer
turn
)
throws
Exception
{
if
(
cyclePhaseCountDown
>
yellowTime
+
redTime
)
{
color
=
"green"
;
if
(
turn
==
20
)
{
turnColor
.
put
(
turn
Str
,
"red"
);
turnColor
.
put
(
turn
,
"red"
);
}
}
if
(
cyclePhaseCountDown
<=
yellowTime
+
redTime
&&
cyclePhaseCountDown
>
redTime
)
{
color
=
"yellow"
;
if
(
turn
==
20
)
{
turnColor
.
put
(
turn
Str
,
"red"
);
turnColor
.
put
(
turn
,
"red"
);
}
}
if
(
cyclePhaseCountDown
<
redTime
)
{
color
=
"red"
;
if
(
turn
==
20
)
{
turnColor
.
put
(
turn
Str
,
"green"
);
turnColor
.
put
(
turn
,
"green"
);
}
}
return
color
;
...
...
@@ -295,27 +378,19 @@ public class HisensePhaseCountDownTask {
}
/**
*
设置所有转
向灯色
*
圆饼灯设置所有方
向灯色
*
* @param turnColor
* @param type
* @param color
*/
private
static
void
setAllTurnColor
(
Map
<
String
,
String
>
turnColor
,
Integer
type
,
String
color
)
throws
Exception
{
List
<
String
>
allTurn
=
Arrays
.
asList
(
"1"
,
"2"
,
"3"
);
for
(
String
turn
:
allTurn
)
{
private
static
void
setAllTurnColor
(
Map
<
Integer
,
String
>
turnColor
,
String
color
)
throws
Exception
{
List
<
Integer
>
allTurn
=
Arrays
.
asList
(
1
,
2
);
for
(
Integer
turn
:
allTurn
)
{
if
(!
turnColor
.
containsKey
(
turn
))
{
if
(
Objects
.
equals
(
type
,
2
))
{
// 圆饼灯 相同颜色
turnColor
.
put
(
turn
,
color
);
}
else
{
if
(
"red"
.
equals
(
color
))
{
// 箭头灯 相反
turnColor
.
put
(
turn
,
"green"
);
}
else
{
// green yellow 都是黄色
turnColor
.
put
(
turn
,
"red"
);
}
}
turnColor
.
put
(
turn
,
color
);
}
}
turnColor
.
put
(
3
,
"green"
);
// 右转常绿
}
/**
...
...
@@ -344,7 +419,7 @@ public class HisensePhaseCountDownTask {
return
null
;
}
private
List
<
PhaseCountDownDTO
>
getPhaseCountDownList
(
String
crossId
,
String
schemeNo
)
{
private
static
List
<
PhaseCountDownDTO
>
getPhaseCountDownList
(
String
crossId
,
String
schemeNo
)
{
List
<
CrossSchemePhaseCountDownDTO
>
crossSchemePhaseCountDownList
=
CrossSchemePhaseTimeCountCache
.
crossSchemePhaseCountDownList
;
if
(!
CollectionUtils
.
isEmpty
(
crossSchemePhaseCountDownList
))
{
for
(
CrossSchemePhaseCountDownDTO
dto
:
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