Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gass-device-report
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
耿迪迪
gass-device-report
Commits
01d8b83c
Commit
01d8b83c
authored
Apr 06, 2023
by
耿迪迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
工业探测器接收数据格式修改
parent
aa113a98
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
147 deletions
+37
-147
FactoryDetectorUdpStart.java
...ehong/gassdevicereport/netty/FactoryDetectorUdpStart.java
+0
-56
NettyUDPStart.java
...java/com/zehong/gassdevicereport/netty/NettyUDPStart.java
+0
-61
FactoryDetectorUdpServerHandler.java
...report/netty/handler/FactoryDetectorUdpServerHandler.java
+31
-24
application-dev.yml
src/main/resources/application-dev.yml
+4
-4
application-test.yml
src/main/resources/application-test.yml
+2
-2
No files found.
src/main/java/com/zehong/gassdevicereport/netty/FactoryDetectorUdpStart.java
deleted
100644 → 0
View file @
aa113a98
package
com
.
zehong
.
gassdevicereport
.
netty
;
import
com.zehong.gassdevicereport.netty.handler.FactoryDetectorUdpServerHandler
;
import
io.netty.bootstrap.Bootstrap
;
import
io.netty.channel.ChannelFuture
;
import
io.netty.channel.ChannelOption
;
import
io.netty.channel.EventLoopGroup
;
import
io.netty.channel.nio.NioEventLoopGroup
;
import
io.netty.channel.socket.nio.NioDatagramChannel
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PreDestroy
;
import
javax.annotation.Resource
;
/**
* @author geng
* 工业探测器数据接收
*/
@Component
public
class
FactoryDetectorUdpStart
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
FactoryDetectorUdpStart
.
class
);
@Resource
private
FactoryDetectorUdpServerHandler
factoryDetectorUdpServerHandler
;
private
EventLoopGroup
bossGroup
=
new
NioEventLoopGroup
();
/**
* 启动netty服务
* @throws InterruptedException
*/
@PostConstruct
public
void
start
()
throws
InterruptedException
{
Bootstrap
b
=
new
Bootstrap
();
b
.
group
(
bossGroup
)
.
channel
(
NioDatagramChannel
.
class
)
.
option
(
ChannelOption
.
SO_BACKLOG
,
128
)
.
handler
(
factoryDetectorUdpServerHandler
);
//开启需要监听 的端口
ChannelFuture
future
=
b
.
bind
(
65012
).
sync
();
if
(
future
.
isSuccess
())
{
logger
.
info
(
"FactoryDetector UDP server启动 65012 成功"
);
}
}
/**
* 销毁
*/
@PreDestroy
public
void
destroy
()
{
bossGroup
.
shutdownGracefully
().
syncUninterruptibly
();
logger
.
info
(
"FactoryDetector UDP server关闭 Netty 成功"
);
}
}
src/main/java/com/zehong/gassdevicereport/netty/NettyUDPStart.java
deleted
100644 → 0
View file @
aa113a98
package
com
.
zehong
.
gassdevicereport
.
netty
;
import
com.zehong.gassdevicereport.netty.handler.UDPServerHandler
;
import
io.netty.bootstrap.Bootstrap
;
import
io.netty.channel.ChannelFuture
;
import
io.netty.channel.ChannelOption
;
import
io.netty.channel.EventLoopGroup
;
import
io.netty.channel.nio.NioEventLoopGroup
;
import
io.netty.channel.socket.nio.NioDatagramChannel
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PreDestroy
;
import
javax.annotation.Resource
;
/**
* 物联网 开启检测 并写入数据库
*/
@Component
public
class
NettyUDPStart
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
NettyUDPStart
.
class
);
@Resource
private
UDPServerHandler
UDPServerHandler
;
private
EventLoopGroup
bossGroup
=
new
NioEventLoopGroup
();
@Value
(
"${UDPNetty.ports}"
)
private
int
[]
ports
;
/**
* 启动netty服务
* @throws InterruptedException
*/
@PostConstruct
public
void
start
()
throws
InterruptedException
{
Bootstrap
b
=
new
Bootstrap
();
b
.
group
(
bossGroup
)
.
channel
(
NioDatagramChannel
.
class
)
.
option
(
ChannelOption
.
SO_BACKLOG
,
128
)
.
handler
(
UDPServerHandler
);
//开启需要监听 的端口
for
(
int
port
:
ports
){
ChannelFuture
future
=
b
.
bind
(
port
).
sync
();
if
(
future
.
isSuccess
())
{
logger
.
info
(
"UDP server启动 "
+
port
+
" 成功"
);
}
}
}
/**
* 销毁
*/
@PreDestroy
public
void
destroy
()
{
bossGroup
.
shutdownGracefully
().
syncUninterruptibly
();
logger
.
info
(
"UDP server关闭 Netty 成功"
);
}
}
src/main/java/com/zehong/gassdevicereport/netty/handler/FactoryDetectorUdpServerHandler.java
View file @
01d8b83c
package
com
.
zehong
.
gassdevicereport
.
netty
.
handler
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zehong.gassdevicereport.entity.TDeviceAlarm
;
import
com.zehong.gassdevicereport.entity.TRelationDeviceData
;
import
com.zehong.gassdevicereport.entity.TRelationDeviceInfo
;
...
...
@@ -23,6 +24,7 @@ import java.io.IOException;
import
java.math.BigDecimal
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author geng
...
...
@@ -52,8 +54,9 @@ public class FactoryDetectorUdpServerHandler extends SimpleChannelInboundHandler
ByteBuf
buf
=
msg
.
content
();
String
msgStr
=
convertByteBufToString
(
buf
);
logger
.
info
(
"FactoryDetectorUdp 入参:"
+
msgStr
);
//解析上传参数 参数实例:ZHGM130001801001/7/000
String
[]
msgInfo
=
msgStr
.
split
(
"/"
);
//解析上传参数 参数实例:{"number":"866384067166661","status":1,"nd":"0","time":1680768201}
//String[] msgInfo = msgStr.split("/");
Map
<
String
,
Object
>
msgInfo
=
JSONObject
.
parseObject
(
msgStr
,
Map
.
class
);
//保存上报数据
saveDeviceData
(
msgInfo
);
//根据设备状态报警
...
...
@@ -65,45 +68,49 @@ public class FactoryDetectorUdpServerHandler extends SimpleChannelInboundHandler
* 保存上报数据
* @param msgInfo 信息
*/
private
void
saveDeviceData
(
String
[]
msgInfo
)
{
private
void
saveDeviceData
(
Map
<
String
,
Object
>
msgInfo
)
{
//设备上报数据入库
TRelationDeviceData
tRelationDeviceData
=
new
TRelationDeviceData
();
tRelationDeviceData
.
setDeviceCode
(
msgInfo
[
0
]
);
tRelationDeviceData
.
setStatus
(
msgInfo
[
1
]
);
tRelationDeviceData
.
setPotency
(
new
BigDecimal
(
msgInfo
[
2
]
));
tRelationDeviceData
.
setDeviceCode
(
(
String
)
msgInfo
.
get
(
"number"
)
);
tRelationDeviceData
.
setStatus
(
String
.
valueOf
(
msgInfo
.
get
(
"status"
))
);
tRelationDeviceData
.
setPotency
(
new
BigDecimal
(
(
String
)
msgInfo
.
get
(
"nd"
)
));
itRelationDeviceDataService
.
insertTRelationDeviceData
(
tRelationDeviceData
);
}
private
void
judgeDeviceStatus
(
String
[]
msgInfo
)
{
List
<
TRelationDeviceInfo
>
relationDeviceInfos
=
itRelationDeviceInfoService
.
getDeviceInfoByDeviceCode
(
msgInfo
[
0
]);
TDeviceAlarm
alarm
=
itDeviceAlarmService
.
selectTDeviceAlarmByDeviceId
(
relationDeviceInfos
.
get
(
0
).
getDeviceId
());
if
(!
"0"
.
equals
(
msgInfo
[
1
])
&&
!
"1"
.
equals
(
msgInfo
[
1
])){
if
(
null
!=
relationDeviceInfos
){
/**
* 根据设备状态更新报警信息
* @param msgInfo 设备上报信息
*/
private
void
judgeDeviceStatus
(
Map
<
String
,
Object
>
msgInfo
)
{
List
<
TRelationDeviceInfo
>
relationDeviceInfos
=
itRelationDeviceInfoService
.
getDeviceInfoByDeviceCode
((
String
)
msgInfo
.
get
(
"number"
));
if
(
null
!=
relationDeviceInfos
&&
relationDeviceInfos
.
size
()>
0
){
TDeviceAlarm
alarm
=
itDeviceAlarmService
.
selectTDeviceAlarmByDeviceId
(
relationDeviceInfos
.
get
(
0
).
getDeviceId
());
if
(
0
!=
(
int
)
msgInfo
.
get
(
"status"
)
&&
1
!=
(
int
)
msgInfo
.
get
(
"status"
)){
if
(
null
!=
alarm
){
alarm
.
setCreateTime
(
DateUtils
.
getNowDate
());
alarm
.
setAlarmType
(
msgInfo
[
1
]
);
alarm
.
setAlarmValue
(
String
.
valueOf
(
Integer
.
parseInt
(
msgInfo
[
2
]
)));
alarm
.
setAlarmType
(
String
.
valueOf
(
msgInfo
.
get
(
"status"
))
);
alarm
.
setAlarmValue
(
String
.
valueOf
(
msgInfo
.
get
(
"nd"
)));
itDeviceAlarmService
.
updateTDeviceAlarm
(
alarm
);
return
;
}
TDeviceAlarm
tDeviceAlarm
=
new
TDeviceAlarm
();
tDeviceAlarm
.
setDeviceId
(
relationDeviceInfos
.
get
(
0
).
getDeviceId
());
tDeviceAlarm
.
setAlarmType
(
msgInfo
[
1
]
);
tDeviceAlarm
.
setAlarmType
(
String
.
valueOf
(
msgInfo
.
get
(
"status"
))
);
tDeviceAlarm
.
setDeviceType
(
relationDeviceInfos
.
get
(
0
).
getDeviceType
());
tDeviceAlarm
.
setStartTime
(
new
Date
());
tDeviceAlarm
.
setAlarmValue
(
String
.
valueOf
(
Integer
.
parseInt
(
msgInfo
[
2
]
)));
tDeviceAlarm
.
setAlarmValue
(
String
.
valueOf
(
msgInfo
.
get
(
"nd"
)));
itDeviceAlarmService
.
insertTDeviceAlarm
(
tDeviceAlarm
);
pushWedSocket
(
tDeviceAlarm
.
getAlarmId
());
}
}
else
{
if
(
null
!=
alarm
){
//手动消警的报警结束更新状态
if
(
"4"
.
equals
(
alarm
.
getDealStatus
())){
alarm
.
setDealStatus
(
""
);
}
else
{
if
(
null
!=
alarm
){
//手动消警的报警结束更新状态
if
(
"4"
.
equals
(
alarm
.
getDealStatus
())){
alarm
.
setDealStatus
(
""
);
}
alarm
.
setEndTime
(
DateUtils
.
getNowDate
());
itDeviceAlarmService
.
updateTDeviceAlarm
(
alarm
);
pushWedSocket
(
alarm
.
getAlarmId
());
}
alarm
.
setEndTime
(
DateUtils
.
getNowDate
());
itDeviceAlarmService
.
updateTDeviceAlarm
(
alarm
);
pushWedSocket
(
alarm
.
getAlarmId
());
}
}
}
...
...
src/main/resources/application-dev.yml
View file @
01d8b83c
...
...
@@ -3,12 +3,12 @@ spring:
datasource
:
username
:
root
password
:
zehong_/sjz!D
url
:
jdbc:mysql://36.148.23.59:33060/gas_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url
:
jdbc:mysql://36.148.23.59:33060/gas_db
_test
?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
driver-class-name
:
com.mysql.jdbc.Driver
# redis 配置
redis
:
# 地址
host
:
127.0.0.1
host
:
36.148.23.59
# 端口,默认为6379
port
:
6379
# 数据库索引
...
...
@@ -30,10 +30,10 @@ spring:
#webSocektUrl
webSocektUrl
:
http://36.148.
23.59:890
1/gassafety/websocket/send
webSocektUrl
:
http://36.148.
1.253:809
1/gassafety/websocket/send
TCPNetty
:
ports
:
2396
UDPNetty
:
ports
:
65011
\ No newline at end of file
ports
:
65011,65012
\ No newline at end of file
src/main/resources/application-test.yml
View file @
01d8b83c
...
...
@@ -30,10 +30,10 @@ spring:
#webSocektUrl
webSocektUrl
:
http://36.148.
23.59:890
1/gassafety/websocket/send
webSocektUrl
:
http://36.148.
1.253:809
1/gassafety/websocket/send
TCPNetty
:
ports
:
2396
UDPNetty
:
ports
:
65011
\ No newline at end of file
ports
:
65011,65012
\ No newline at end of file
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