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
de6cffc6
Commit
de6cffc6
authored
May 28, 2025
by
duwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
信号灯倒计时,加入下发控制,1秒1帧
parent
c30538f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
19 deletions
+59
-19
SignalStatusTask.java
...ce/src/main/java/net/wanji/utc/task/SignalStatusTask.java
+59
-19
No files found.
signal-utc-service/src/main/java/net/wanji/utc/task/SignalStatusTask.java
View file @
de6cffc6
...
...
@@ -128,7 +128,7 @@ public class SignalStatusTask {
/**
* 消费孪生灯态kafka数据
*/
@KafkaListener
(
topics
=
{
"WHSpatData"
},
groupId
=
"utc-whspat-consumer-0
5
"
)
@KafkaListener
(
topics
=
{
"WHSpatData"
},
groupId
=
"utc-whspat-consumer-0
8
"
)
public
void
consumeTwinSpat
(
ConsumerRecord
<
Object
,
Object
>
record
,
Acknowledgment
ack
)
{
try
{
String
lightStatusJson
=
String
.
valueOf
(
record
.
value
());
...
...
@@ -209,6 +209,16 @@ public class SignalStatusTask {
// 记录每个路口最后发送灯态的时间戳,单位毫秒
private
static
final
Map
<
String
,
Long
>
lastSentTimestampMap
=
new
ConcurrentHashMap
<>();
//map<路口id_方向_转向_灯色_倒计时, 1>
public
static
final
ExpiringMap
<
String
,
Integer
>
controlSendMap
=
ExpiringMap
.
builder
()
.
expiration
(
10
,
TimeUnit
.
SECONDS
)
.
maxSize
(
1000
)
.
variableExpiration
()
.
expirationPolicy
(
ExpirationPolicy
.
CREATED
)
//过期监听
.
asyncExpirationListener
((
rcuIdStr
,
value
)
->
{
}).
build
();
/**
* 保存灯态数据并发送
...
...
@@ -227,7 +237,7 @@ public class SignalStatusTask {
//2. 循环遍历灯态数据,并保存灯态数据到数据库,并发送灯态数据到websocket
for
(
LightsStatusVO
lightsStatusVO
:
lightsStatusVOS
)
{
if
(
Objects
.
nonNull
(
lightsStatusVO
)
&&
Objects
.
equals
(
lightsStatusVO
.
getCrossId
(),
crossId
)
)
{
//
calculateControlCountDown
(
crossId
,
lightsStatusVO
);
try
{
// 相同路口不同websocket统一发送灯态
...
...
@@ -235,14 +245,33 @@ public class SignalStatusTask {
if
(
CollectionUtil
.
isEmpty
(
listResult2
))
{
continue
;
}
//控制下发频率,条件:方向_转向_灯色_时间戳
String
key
=
crossId
+
"_"
+
listResult2
.
get
(
0
).
getDirLampGroupMapList
().
get
(
0
).
getDir
()
+
"_"
+
listResult2
.
get
(
0
).
getDirLampGroupMapList
().
get
(
0
).
getTurnList
().
get
(
0
).
getTurn
()
+
"_"
+
listResult2
.
get
(
0
).
getDirLampGroupMapList
().
get
(
0
).
getTurnList
().
get
(
0
).
getColor
()
+
"_"
+
listResult2
.
get
(
0
).
getDirLampGroupMapList
().
get
(
0
).
getTurnList
().
get
(
0
).
getCountDown
();
Integer
f
=
controlSendMap
.
get
(
key
);
if
(
f
!=
null
&&
f
==
1
)
{
continue
;
}
else
{
controlSendMap
.
put
(
key
,
1
);
}
String
json
=
mapper
.
writeValueAsString
(
listResult2
);
// 新增:判断是否达到1秒间隔
long
now
=
System
.
currentTimeMillis
();
long
lastSent
=
lastSentTimestampMap
.
getOrDefault
(
crossId
,
0L
);
if
(
now
-
lastSent
<
1000
)
{
// 不足1秒,跳过本次推送
return
;
while
(
true
)
{
long
lastSent
=
lastSentTimestampMap
.
getOrDefault
(
crossId
,
0L
);
if
(
now
-
lastSent
>
1000
)
{
// 更新最后发送时间
lastSentTimestampMap
.
put
(
crossId
,
now
);
// 不足1秒,跳过本次推送
break
;
}
Thread
.
sleep
(
100
);
now
=
System
.
currentTimeMillis
();
}
for
(
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>
socketEntry
:
value
)
{
...
...
@@ -252,9 +281,6 @@ public class SignalStatusTask {
webSocket
.
sendInfo
(
json
,
crossIdStr
);
}
// 更新最后发送时间
lastSentTimestampMap
.
put
(
crossId
,
now
);
insertIntoHist
(
crossId
,
json
);
produceListMap
.
put
(
crossId
,
listResult2
);
}
catch
(
Exception
e
)
{
...
...
@@ -355,19 +381,30 @@ public class SignalStatusTask {
}
//后两个参数是map<方向,倒计时>, 倒计时
Map
<
String
,
Object
>
dirLampGroupMap1
=
infoVo
.
getDirLampGroupMap
();
Map
<
String
,
Object
>
existDirLampGroupMap
=
infoVo
.
getDirLampGroupMap
();
Map
<
String
,
Object
>
dirLampGroupMap
=
getDirLampGroupMap
(
p
,
m
,
phaseMap
,
p
.
getLimitEndTime
());
if
(
dirLampGroupMap1
!=
null
)
{
if
(
dirLampGroupMap
!=
null
)
{
dirLampGroupMap1
.
putAll
(
dirLampGroupMap
);
}
}
else
{
if
(
dirLampGroupMap
!=
null
){
infoVo
.
setDirLampGroupMap
(
dirLampGroupMap
);
}
else
{
infoVo
.
setDirLampGroupMap
(
Maps
.
newHashMap
());
if
(
dirLampGroupMap
!=
null
)
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
dirLampGroupMap
.
entrySet
())
{
String
direction
=
entry
.
getKey
();
Map
<
Integer
,
String
>
turnColorMap
=
(
Map
<
Integer
,
String
>)
entry
.
getValue
();
if
(
existDirLampGroupMap
!=
null
)
{
if
(
existDirLampGroupMap
.
containsKey
(
direction
))
{
// 方向已存在,合并内部 Map
Map
<
Integer
,
String
>
existingTurnMap
=
(
Map
<
Integer
,
String
>)
existDirLampGroupMap
.
get
(
direction
);
existingTurnMap
.
putAll
(
turnColorMap
);
// 覆盖同 key 的值
}
else
{
// 方向不存在,直接放入
existDirLampGroupMap
.
put
(
direction
,
new
HashMap
<>(
turnColorMap
));
}
}
else
{
existDirLampGroupMap
=
new
HashMap
<>();
existDirLampGroupMap
.
put
(
direction
,
new
HashMap
<>(
turnColorMap
));
infoVo
.
setDirLampGroupMap
(
existDirLampGroupMap
);
}
}
}
}
infoVo
.
setTimeStamp
(
light
.
getTimestamp
()
+
""
);
infoVo
.
setSchemeStartTime
(
light
.
getTimestamp
()
+
""
);
...
...
@@ -396,6 +433,9 @@ public class SignalStatusTask {
String
color
=
transferLampGroup
(
light
);
//车道灯态适配
int
turn
=
phase
.
getTurn
();
int
turnDir
=
TurnDirectionMapper
.
mapToTargetValue
(
turn
);
//车道转向适配
// if (0 == turn || 2 == turn){
// System.out.println("无效的车道转向:" + turn);
// }
if
(
m
.
containsKey
(
dir
+
"-"
+
turnDir
+
"-"
+
color
)){
return
null
;
...
...
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