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
4a60f7d1
Commit
4a60f7d1
authored
Apr 10, 2023
by
duanruiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] 信号服务优化
parent
be18693d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
23 deletions
+23
-23
SystemServiceStatusTask.java
...main/java/net/wanji/web/task/SystemServiceStatusTask.java
+22
-22
WebSocketServer.java
...rc/main/java/net/wanji/web/websocket/WebSocketServer.java
+1
-1
No files found.
signal-control-service/src/main/java/net/wanji/web/task/SystemServiceStatusTask.java
View file @
4a60f7d1
...
@@ -10,13 +10,11 @@ import net.wanji.web.common.util.date.DateStyle;
...
@@ -10,13 +10,11 @@ import net.wanji.web.common.util.date.DateStyle;
import
net.wanji.web.websocket.WebSocketServer
;
import
net.wanji.web.websocket.WebSocketServer
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -37,26 +35,28 @@ public class SystemServiceStatusTask {
...
@@ -37,26 +35,28 @@ public class SystemServiceStatusTask {
@Scheduled
(
fixedRate
=
1
*
60
*
1000
)
@Scheduled
(
fixedRate
=
1
*
60
*
1000
)
public
void
telnetStatus
()
throws
Exception
{
public
void
telnetStatus
()
throws
Exception
{
Set
<
WebSocketServer
>
webSocketSet
=
WebSocketServer
.
getWebSocketSet
(
Constant
.
WEBSOCKET_TOPIC_SYS_SERVICE_STATUS
);
for
(
SystemServiceStatusDTO
dto
:
sysList
)
{
if
(!
CollectionUtils
.
isEmpty
(
webSocketSet
))
{
String
ip
=
dto
.
getIp
();
for
(
SystemServiceStatusDTO
dto
:
sysList
)
{
int
port
=
dto
.
getPort
();
String
ip
=
dto
.
getIp
();
int
timeout
=
dto
.
getTimeout
();
int
port
=
dto
.
getPort
();
int
lastStatus
=
dto
.
getStatus
();
int
timeout
=
dto
.
getTimeout
();
int
currentStatus
=
SocketUtil
.
telnet
(
ip
,
port
,
timeout
)
==
true
?
0
:
1
;
int
lastStatus
=
dto
.
getStatus
();
if
(
currentStatus
!=
lastStatus
)
{
int
currentStatus
=
SocketUtil
.
telnet
(
ip
,
port
,
timeout
)
==
true
?
0
:
1
;
dto
.
setStatus
(
currentStatus
);
if
(
currentStatus
!=
lastStatus
)
{
}
dto
.
setStatus
(
currentStatus
);
// 如果正常 每分钟更新状态; 异常 更新异常初始状态
}
if
(
StringUtils
.
isBlank
(
dto
.
getStartTime
())
||
dto
.
getStatus
()
==
0
)
{
// 如果正常 每分钟更新状态; 异常 更新异常初始状态
LocalDateTime
now
=
LocalDateTime
.
now
();
if
(
StringUtils
.
isBlank
(
dto
.
getStartTime
())
||
dto
.
getStatus
()
==
0
)
{
String
format
=
now
.
format
(
DateTimeFormatter
.
ofPattern
(
DateStyle
.
YYYY_MM_DD_HH_MM_SS
.
getValue
()));
LocalDateTime
now
=
LocalDateTime
.
now
();
dto
.
setStartTime
(
format
);
String
format
=
now
.
format
(
DateTimeFormatter
.
ofPattern
(
DateStyle
.
YYYY_MM_DD_HH_MM_SS
.
getValue
()));
dto
.
setStartDate
(
new
Date
());
dto
.
setStartTime
(
format
);
dto
.
setStartDate
(
new
Date
());
}
}
}
List
<
SystemServiceStatusDTO
>
sort
=
sysList
.
stream
().
sorted
(
Comparator
.
comparing
(
SystemServiceStatusDTO:
:
getStartDate
)).
collect
(
Collectors
.
toList
());
WebSocketServer
.
sendTopicInfo2All
(
JSON
.
toJSONString
(
sort
),
Constant
.
WEBSOCKET_TOPIC_SYS_SERVICE_STATUS
);
}
}
List
<
SystemServiceStatusDTO
>
sort
=
sysList
.
stream
().
sorted
(
Comparator
.
comparing
(
SystemServiceStatusDTO:
:
getStartDate
)).
collect
(
Collectors
.
toList
());
WebSocketServer
.
sendInfo2All
(
JSON
.
toJSONString
(
sort
),
Constant
.
WEBSOCKET_TOPIC_SYS_SERVICE_STATUS
);
}
}
}
}
signal-control-service/src/main/java/net/wanji/web/websocket/WebSocketServer.java
View file @
4a60f7d1
...
@@ -170,7 +170,7 @@ public class WebSocketServer {
...
@@ -170,7 +170,7 @@ public class WebSocketServer {
* @param topic
* @param topic
* @throws IOException
* @throws IOException
*/
*/
public
static
void
sendInfo2All
(
String
message
,
String
topic
)
throws
IOException
{
public
static
void
send
Topic
Info2All
(
String
message
,
String
topic
)
throws
IOException
{
if
(
StringUtils
.
isNotBlank
(
topic
)
&&
webSocketMap
.
containsKey
(
topic
))
{
if
(
StringUtils
.
isNotBlank
(
topic
)
&&
webSocketMap
.
containsKey
(
topic
))
{
try
{
try
{
Set
<
WebSocketServer
>
socketSets
=
webSocketMap
.
get
(
topic
);
Set
<
WebSocketServer
>
socketSets
=
webSocketMap
.
get
(
topic
);
...
...
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