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
2f5ddba9
Commit
2f5ddba9
authored
Feb 20, 2024
by
duanruiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] 优化代码3,优化灯态定时任务程序可读性
parent
90ef44c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
43 deletions
+79
-43
SignalStatusTask.java
...ce/src/main/java/net/wanji/utc/task/SignalStatusTask.java
+79
-43
No files found.
signal-utc-service/src/main/java/net/wanji/utc/task/SignalStatusTask.java
View file @
2f5ddba9
...
@@ -11,7 +11,6 @@ import net.wanji.databus.dao.mapper.CrossLightsStatusHistMapper;
...
@@ -11,7 +11,6 @@ import net.wanji.databus.dao.mapper.CrossLightsStatusHistMapper;
import
net.wanji.databus.dao.mapper.ManufacturerInfoMapper
;
import
net.wanji.databus.dao.mapper.ManufacturerInfoMapper
;
import
net.wanji.databus.po.CrossInfoPO
;
import
net.wanji.databus.po.CrossInfoPO
;
import
net.wanji.databus.po.ManufacturerInfoPO
;
import
net.wanji.databus.po.ManufacturerInfoPO
;
import
net.wanji.databus.po.SignalStatusLogPO
;
import
net.wanji.databus.vo.LightsStatusVO
;
import
net.wanji.databus.vo.LightsStatusVO
;
import
net.wanji.databus.vo.LightsStatusVO2
;
import
net.wanji.databus.vo.LightsStatusVO2
;
import
net.wanji.feign.service.UtcDTFeignClients
;
import
net.wanji.feign.service.UtcDTFeignClients
;
...
@@ -75,7 +74,7 @@ public class SignalStatusTask {
...
@@ -75,7 +74,7 @@ public class SignalStatusTask {
// 运行状态、告警,1分钟一次
// 运行状态、告警,1分钟一次
@Scheduled
(
fixedRate
=
60
*
1000
)
@Scheduled
(
fixedRate
=
60
*
1000
)
public
void
runningStatusAlarm
()
throws
Exception
{
public
void
runningStatusAlarm
()
throws
Exception
{
List
<
SignalStatusLogPO
>
signalStatusLogPOS
=
signalStatusService
.
runningStatusAlarm
();
signalStatusService
.
runningStatusAlarm
();
}
}
// 灯态,每秒一次
// 灯态,每秒一次
...
@@ -89,60 +88,92 @@ public class SignalStatusTask {
...
@@ -89,60 +88,92 @@ public class SignalStatusTask {
//commonThreadPoolExecutor.execute(() -> {
//commonThreadPoolExecutor.execute(() -> {
ObjectMapper
mapper
=
JacksonUtils
.
getInstance
();
ObjectMapper
mapper
=
JacksonUtils
.
getInstance
();
String
crossId
=
entry
.
getKey
();
String
crossId
=
entry
.
getKey
();
List
<
LightsStatusVO
>
lightsStatusVOS
=
null
;
CrossInfoPO
crossInfoPO
=
crossInfoMapper
.
selectByPrimaryKey
(
crossId
);
CrossInfoPO
crossInfoPO
=
crossInfoMapper
.
selectByPrimaryKey
(
crossId
);
if
(
Objects
.
isNull
(
crossInfoPO
))
{
if
(
Objects
.
isNull
(
crossInfoPO
))
{
continue
;
continue
;
}
}
ManufacturerInfoPO
manufacturerInfoPO
=
manufacturerInfoMapper
.
selectById
(
crossInfoPO
.
getManufacturerId
());
List
<
LightsStatusVO
>
lightsStatusVOS
=
getLightsStatusVOS
(
mapper
,
crossId
,
crossInfoPO
);
saveAndSendLightsStatus
(
mapper
,
crossId
,
lightsStatusVOS
,
entry
);
//});
}
sendKafka
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
"实时推送灯态数据失败"
,
e
);
}
}
/**
* 保存灯态数据并发送
*
* @param mapper
* @param crossId
* @param lightsStatusVOS
*/
private
void
saveAndSendLightsStatus
(
ObjectMapper
mapper
,
String
crossId
,
List
<
LightsStatusVO
>
lightsStatusVOS
,
Map
.
Entry
<
String
,
List
<
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>>>
entry
)
{
List
<
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>>
value
=
entry
.
getValue
();
if
(!
CollectionUtils
.
isEmpty
(
lightsStatusVOS
))
{
for
(
LightsStatusVO
lightsStatusVO
:
lightsStatusVOS
)
{
if
(
Objects
.
nonNull
(
lightsStatusVO
)
&&
Objects
.
equals
(
lightsStatusVO
.
getCrossId
(),
crossId
))
{
calculateControlCountDown
(
crossId
,
lightsStatusVO
);
try
{
try
{
if
(
StringUtils
.
equals
(
BasicEnum
.
ManufacturerEnum
.
HK
.
getCode
(),
manufacturerInfoPO
.
getCode
()))
{
// 相同路口不同websocket统一发送灯态
lightsStatusVOS
=
hkLightsStatusService
.
getHkLightsStatus
(
crossId
);
List
<
LightsStatusVO2
>
listResult
=
lightsStatusVOCopy
(
lightsStatusVOS
);
}
else
if
(
StringUtils
.
equals
(
BasicEnum
.
ManufacturerEnum
.
DT
.
getCode
(),
manufacturerInfoPO
.
getCode
()))
{
String
json
=
mapper
.
writeValueAsString
(
listResult
);
JsonViewObject
jsonViewObject
=
utcDTFeignClients
.
lightStatus
(
crossId
);
for
(
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>
socketEntry
:
value
)
{
lightsStatusVOS
=
mapper
.
convertValue
(
jsonViewObject
.
getContent
(),
new
TypeReference
<
List
<
LightsStatusVO
>>()
{});
String
crossIdStr
=
socketEntry
.
getKey
();
}
else
if
(
StringUtils
.
endsWithIgnoreCase
(
BasicEnum
.
ManufacturerEnum
.
HISENSE
.
getCode
(),
manufacturerInfoPO
.
getCode
()))
{
RealTimeDataWebSocket
webSocket
=
socketEntry
.
getValue
();
JsonViewObject
jsonViewObject
=
utcHisenseFeignClients
.
lightStatus
(
crossId
);
webSocket
.
sendInfo
(
json
,
crossIdStr
);
lightsStatusVOS
=
mapper
.
convertValue
(
jsonViewObject
.
getContent
(),
new
TypeReference
<
List
<
LightsStatusVO
>>()
{});
}
else
if
(
StringUtils
.
endsWithIgnoreCase
(
"STATIC"
,
manufacturerInfoPO
.
getCode
()))
{
LightsStatusVO
lightsStatusVO
=
SignalStatus4StaticSchemeTask
.
currentCrossLightStatusCache
.
get
(
crossId
);
if
(
Objects
.
nonNull
(
lightsStatusVO
))
{
lightsStatusVOS
=
new
ArrayList
<>();
lightsStatusVOS
.
add
(
lightsStatusVO
);
}
}
}
insertIntoHist
(
crossId
,
json
);
produceListMap
.
put
(
crossId
,
lightsStatusVOS
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"
获取厂商灯态异常
"
,
e
);
log
.
error
(
"
RealTimeDataWebSocket发送异常,异常信息:
"
,
e
);
}
}
}
produceListMap
.
remove
(
crossId
);
List
<
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>>
value
=
entry
.
getValue
();
}
if
(!
CollectionUtils
.
isEmpty
(
lightsStatusVOS
))
{
}
for
(
LightsStatusVO
lightsStatusVO
:
lightsStatusVOS
)
{
}
if
(
Objects
.
nonNull
(
lightsStatusVO
)
&&
Objects
.
equals
(
lightsStatusVO
.
getCrossId
(),
crossId
))
{
calculateControlCountDown
(
crossId
,
lightsStatusVO
);
/**
try
{
// 相同路口不同websocket统一发送灯态
* 获取不同厂商的灯态列表
List
<
LightsStatusVO2
>
listResult
=
lightsStatusVOCopy
(
lightsStatusVOS
);
*
String
json
=
mapper
.
writeValueAsString
(
listResult
);
* @param mapper
for
(
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>
socketEntry
:
value
)
{
* @param crossId
String
crossIdStr
=
socketEntry
.
getKey
();
* @param manufacturerInfoPO
RealTimeDataWebSocket
webSocket
=
socketEntry
.
getValue
();
* @return
webSocket
.
sendInfo
(
json
,
crossIdStr
);
*/
}
private
List
<
LightsStatusVO
>
getLightsStatusVOS
(
ObjectMapper
mapper
,
String
crossId
,
CrossInfoPO
crossInfoPO
)
{
insertIntoHist
(
crossId
,
json
);
try
{
produceListMap
.
put
(
crossId
,
lightsStatusVOS
);
ManufacturerInfoPO
manufacturerInfoPO
=
manufacturerInfoMapper
.
selectById
(
crossInfoPO
.
getManufacturerId
());
}
catch
(
Exception
e
)
{
if
(
StringUtils
.
equals
(
BasicEnum
.
ManufacturerEnum
.
HK
.
getCode
(),
manufacturerInfoPO
.
getCode
()))
{
log
.
error
(
"RealTimeDataWebSocket发送异常,异常信息:"
,
e
);
return
hkLightsStatusService
.
getHkLightsStatus
(
crossId
);
}
}
}
if
(
StringUtils
.
equals
(
BasicEnum
.
ManufacturerEnum
.
DT
.
getCode
(),
manufacturerInfoPO
.
getCode
()))
{
}
JsonViewObject
jsonViewObject
=
utcDTFeignClients
.
lightStatus
(
crossId
);
}
return
mapper
.
convertValue
(
jsonViewObject
.
getContent
(),
new
TypeReference
<
List
<
LightsStatusVO
>>()
{});
//});
}
if
(
StringUtils
.
endsWithIgnoreCase
(
BasicEnum
.
ManufacturerEnum
.
HISENSE
.
getCode
(),
manufacturerInfoPO
.
getCode
()))
{
JsonViewObject
jsonViewObject
=
utcHisenseFeignClients
.
lightStatus
(
crossId
);
return
mapper
.
convertValue
(
jsonViewObject
.
getContent
(),
new
TypeReference
<
List
<
LightsStatusVO
>>()
{});
}
if
(
StringUtils
.
endsWithIgnoreCase
(
"STATIC"
,
manufacturerInfoPO
.
getCode
()))
{
LightsStatusVO
lightsStatusVO
=
SignalStatus4StaticSchemeTask
.
currentCrossLightStatusCache
.
get
(
crossId
);
List
<
LightsStatusVO
>
lightsStatusVOS
=
new
ArrayList
<>();
if
(
Objects
.
nonNull
(
lightsStatusVO
))
{
lightsStatusVOS
.
add
(
lightsStatusVO
);
}
}
sendKafka
()
;
return
lightsStatusVOS
;
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"
实时推送灯态数据失败"
,
e
);
log
.
error
(
"
获取当前厂商路口编号[{}]灯态异常"
,
crossId
,
e
);
}
}
return
Collections
.
emptyList
();
}
}
private
static
List
<
LightsStatusVO2
>
lightsStatusVOCopy
(
List
<
LightsStatusVO
>
lightsStatusVOS
)
throws
Exception
{
private
static
List
<
LightsStatusVO2
>
lightsStatusVOCopy
(
List
<
LightsStatusVO
>
lightsStatusVOS
)
throws
Exception
{
...
@@ -245,6 +276,11 @@ public class SignalStatusTask {
...
@@ -245,6 +276,11 @@ public class SignalStatusTask {
Constants
.
controlModeMap
.
put
(
crossId
,
lightsStatusVO
.
getRunMode
());
Constants
.
controlModeMap
.
put
(
crossId
,
lightsStatusVO
.
getRunMode
());
}
}
/**
* 不同系统获取统一路口灯态,统一处理
* @param evenWarnWebSocketMap
* @return
*/
private
static
Map
<
String
,
List
<
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>>>
getCrossEntryMap
(
ConcurrentHashMap
<
String
,
RealTimeDataWebSocket
>
evenWarnWebSocketMap
)
{
private
static
Map
<
String
,
List
<
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>>>
getCrossEntryMap
(
ConcurrentHashMap
<
String
,
RealTimeDataWebSocket
>
evenWarnWebSocketMap
)
{
Map
<
String
,
List
<
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>>>
tempMap
=
new
ConcurrentHashMap
<>();
Map
<
String
,
List
<
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>>>
tempMap
=
new
ConcurrentHashMap
<>();
for
(
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>
item
:
evenWarnWebSocketMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
RealTimeDataWebSocket
>
item
:
evenWarnWebSocketMap
.
entrySet
())
{
...
...
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