Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
device-new-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
device-new-platform
Commits
57e45695
Commit
57e45695
authored
Dec 13, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决设备下发消息
parent
f4a43c8a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
46 deletions
+63
-46
device-manager/src/main/java/com/mortals/xhx/base/framework/listener/DirectDynamicListener.java
...ls/xhx/base/framework/listener/DirectDynamicListener.java
+1
-1
device-manager/src/main/java/com/mortals/xhx/busiz/web/DeviceApiController.java
...n/java/com/mortals/xhx/busiz/web/DeviceApiController.java
+14
-12
device-manager/src/main/java/com/mortals/xhx/thread/DeviceDownMsgThread.java
...main/java/com/mortals/xhx/thread/DeviceDownMsgThread.java
+48
-33
No files found.
device-manager/src/main/java/com/mortals/xhx/base/framework/listener/DirectDynamicListener.java
View file @
57e45695
...
@@ -113,7 +113,7 @@ public class DirectDynamicListener implements MessageListener {
...
@@ -113,7 +113,7 @@ public class DirectDynamicListener implements MessageListener {
bizLogPdu
.
setLogTime
(
new
Date
());
bizLogPdu
.
setLogTime
(
new
Date
());
messageProducer
.
syncBizSend
(
bizLogPdu
);
messageProducer
.
syncBizSend
(
bizLogPdu
);
}
}
log
.
info
(
"id:{},deviceCode:{} deviceStatus:{}==>上线 "
,
deviceEntity
.
getId
(),
deviceEntity
.
getDeviceCode
(),
deviceEntity
.
getDeviceStatus
());
//
log.info("id:{},deviceCode:{} deviceStatus:{}==>上线 ", deviceEntity.getId(), deviceEntity.getDeviceCode(), deviceEntity.getDeviceStatus());
}
}
if
(!
Constant
.
MESSAGETYPE_HEARTBEAT
.
equalsIgnoreCase
(
messageType
))
{
if
(!
Constant
.
MESSAGETYPE_HEARTBEAT
.
equalsIgnoreCase
(
messageType
))
{
DeviceLogEntity
deviceLogEntity
=
new
DeviceLogEntity
();
DeviceLogEntity
deviceLogEntity
=
new
DeviceLogEntity
();
...
...
device-manager/src/main/java/com/mortals/xhx/busiz/web/DeviceApiController.java
View file @
57e45695
...
@@ -77,6 +77,7 @@ import java.util.stream.Collectors;
...
@@ -77,6 +77,7 @@ import java.util.stream.Collectors;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
Constant
.*;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
Constant
.*;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.*;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.*;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
RedisKey
.
KEY_DEVICE_DOWN_MSG_QUEUE
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
RedisKey
.
KEY_TOKEN_API_CACHE
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
RedisKey
.
KEY_TOKEN_API_CACHE
;
/**
/**
...
@@ -185,7 +186,7 @@ public class DeviceApiController {
...
@@ -185,7 +186,7 @@ public class DeviceApiController {
ProductEntity
productEntity
=
productService
.
getCache
(
deviceEntity
.
getProductId
().
toString
());
ProductEntity
productEntity
=
productService
.
getCache
(
deviceEntity
.
getProductId
().
toString
());
if
(
ObjectUtils
.
isEmpty
(
productEntity
))
{
if
(
ObjectUtils
.
isEmpty
(
productEntity
))
{
throw
new
AppException
(
PRODUCT_IS_EMPTY
,
PRODUCT_IS_EMPTY_CONTENT
+
"productId:"
+
deviceEntity
.
getProductId
());
throw
new
AppException
(
PRODUCT_IS_EMPTY
,
PRODUCT_IS_EMPTY_CONTENT
+
"productId:"
+
deviceEntity
.
getProductId
());
}
}
if
(
ObjectUtils
.
isEmpty
(
productEntity
.
getPlatformId
()))
{
if
(
ObjectUtils
.
isEmpty
(
productEntity
.
getPlatformId
()))
{
...
@@ -440,7 +441,7 @@ public class DeviceApiController {
...
@@ -440,7 +441,7 @@ public class DeviceApiController {
updateDevice
(
req
,
platformEntity
,
productEntity
,
deviceEntity
);
updateDevice
(
req
,
platformEntity
,
productEntity
,
deviceEntity
);
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceEntity
.
setUpdateUserId
(
1L
);
cacheService
.
lpush
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
deviceEntity
);
cacheService
.
lpush
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
deviceEntity
);
//deviceService.update(deviceEntity, null);
//deviceService.update(deviceEntity, null);
}
}
...
@@ -667,12 +668,13 @@ public class DeviceApiController {
...
@@ -667,12 +668,13 @@ public class DeviceApiController {
rsp
.
setMsg
(
ApiRespCodeEnum
.
SUCCESS
.
getLabel
());
rsp
.
setMsg
(
ApiRespCodeEnum
.
SUCCESS
.
getLabel
());
rsp
.
setCode
(
ApiRespCodeEnum
.
SUCCESS
.
getValue
());
rsp
.
setCode
(
ApiRespCodeEnum
.
SUCCESS
.
getValue
());
try
{
try
{
List
<
DeviceMsgReq
>
collect
=
list
.
stream
().
sorted
(
Comparator
.
comparing
(
DeviceMsgReq:
:
getTimestamp
)).
collect
(
Collectors
.
toList
());
list
.
stream
()
/* collect.forEach(item->{
.
sorted
(
Comparator
.
comparing
(
DeviceMsgReq:
:
getTimestamp
))
cacheService.lpush(KEY_DEVICE_DOWN_MSG_QUEUE,item);
.
forEach
(
item
->
{
});*/
cacheService
.
lpush
(
KEY_DEVICE_DOWN_MSG_QUEUE
,
item
);
DownMsgTask
downMsgTask
=
new
DownMsgTask
(
list
,
platformService
,
productService
,
deviceService
,
deviceLogService
,
messageProducer
);
});
sendTaskThreadPool
.
execute
(
downMsgTask
);
/* DownMsgTask downMsgTask = new DownMsgTask(list, platformService, productService, deviceService, deviceLogService, messageProducer);
sendTaskThreadPool.execute(downMsgTask);*/
}
catch
(
AppException
e
)
{
}
catch
(
AppException
e
)
{
log
.
error
(
"接收数据失败"
,
e
);
log
.
error
(
"接收数据失败"
,
e
);
rsp
.
setCode
(
e
.
getCode
());
rsp
.
setCode
(
e
.
getCode
());
...
@@ -928,7 +930,7 @@ public class DeviceApiController {
...
@@ -928,7 +930,7 @@ public class DeviceApiController {
deviceEntity
.
setDeviceInFloor
(
req
.
getDeviceInFloor
());
deviceEntity
.
setDeviceInFloor
(
req
.
getDeviceInFloor
());
deviceEntity
.
setDeviceInBuilding
(
req
.
getDeviceInBuilding
());
deviceEntity
.
setDeviceInBuilding
(
req
.
getDeviceInBuilding
());
cacheService
.
lpush
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
deviceEntity
);
cacheService
.
lpush
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
deviceEntity
);
//deviceService.update(deviceEntity);
//deviceService.update(deviceEntity);
}
}
...
@@ -953,7 +955,7 @@ public class DeviceApiController {
...
@@ -953,7 +955,7 @@ public class DeviceApiController {
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceEntity
.
setUpdateUserId
(
1L
);
deviceEntity
.
setSwitchSend
(
false
);
deviceEntity
.
setSwitchSend
(
false
);
cacheService
.
lpush
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
deviceEntity
);
cacheService
.
lpush
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
deviceEntity
);
//deviceService.update(deviceEntity);
//deviceService.update(deviceEntity);
}
}
...
@@ -968,7 +970,7 @@ public class DeviceApiController {
...
@@ -968,7 +970,7 @@ public class DeviceApiController {
deviceEntity
.
setSwitchSend
(
false
);
deviceEntity
.
setSwitchSend
(
false
);
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceEntity
.
setUpdateUserId
(
1L
);
cacheService
.
lpush
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
deviceEntity
);
cacheService
.
lpush
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
deviceEntity
);
//deviceService.update(deviceEntity);
//deviceService.update(deviceEntity);
}
}
...
@@ -981,7 +983,7 @@ public class DeviceApiController {
...
@@ -981,7 +983,7 @@ public class DeviceApiController {
deviceEntity
.
setSwitchSend
(
false
);
deviceEntity
.
setSwitchSend
(
false
);
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceEntity
.
setUpdateUserId
(
1L
);
cacheService
.
lpush
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
deviceEntity
);
cacheService
.
lpush
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
deviceEntity
);
//deviceService.update(deviceEntity);
//deviceService.update(deviceEntity);
}
}
...
...
device-manager/src/main/java/com/mortals/xhx/thread/DeviceDownMsgThread.java
View file @
57e45695
...
@@ -25,7 +25,9 @@ import org.springframework.core.annotation.Order;
...
@@ -25,7 +25,9 @@ import org.springframework.core.annotation.Order;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
RedisKey
.
KEY_DEVICE_DOWN_MSG_QUEUE
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
RedisKey
.
KEY_DEVICE_DOWN_MSG_QUEUE
;
...
@@ -58,23 +60,35 @@ public class DeviceDownMsgThread extends AbstractThread {
...
@@ -58,23 +60,35 @@ public class DeviceDownMsgThread extends AbstractThread {
@Override
@Override
protected
void
process
()
{
protected
void
process
()
{
log
.
info
(
"DeviceDownMsgThread process"
);
log
.
info
(
"DeviceDownMsgThread process"
);
List
<
DeviceMsgReq
>
deviceMsgReqs
=
new
ArrayList
<>();
while
(
true
)
{
DeviceMsgReq
deviceMsgReq
=
cacheService
.
blpop
(
KEY_DEVICE_DOWN_MSG_QUEUE
,
10
,
DeviceMsgReq
.
class
);
DeviceMsgReq
deviceMsgReq
=
cacheService
.
blpop
(
KEY_DEVICE_DOWN_MSG_QUEUE
,
10
,
DeviceMsgReq
.
class
);
if
(!
ObjectUtils
.
isEmpty
(
deviceMsgReq
))
{
if
(
ObjectUtils
.
isEmpty
(
deviceMsgReq
))
{
log
.
info
(
"下发消息:{}"
,
deviceMsgReq
.
getDeviceCode
());
log
.
info
(
"deviceMsgReq:{}"
,
deviceMsgReq
==
null
);
break
;
}
else
{
deviceMsgReqs
.
add
(
deviceMsgReq
);
}
}
if
(!
ObjectUtils
.
isEmpty
(
deviceMsgReqs
))
{
log
.
info
(
"消息下发数量:{}"
,
deviceMsgReqs
.
size
());
for
(
DeviceMsgReq
item
:
deviceMsgReqs
)
{
//根据设备编码查询设备
//根据设备编码查询设备
DeviceEntity
deviceEntity
=
null
;
DeviceEntity
deviceEntity
=
null
;
try
{
try
{
deviceEntity
=
deviceService
.
getExtCache
(
deviceMsgReq
.
getDeviceCode
());
deviceEntity
=
deviceService
.
getExtCache
(
item
.
getDeviceCode
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
info
(
"deviceCode:{}"
,
item
.
getDeviceCode
());
log
.
error
(
"redis 获取设备异常!"
,
e
);
log
.
error
(
"redis 获取设备异常!"
,
e
);
continue
;
}
}
if
(!
ObjectUtils
.
isEmpty
(
deviceEntity
))
{
if
(!
ObjectUtils
.
isEmpty
(
deviceEntity
))
{
TbQueueMsgHeaders
header
=
new
DefaultTbQueueMsgHeaders
();
TbQueueMsgHeaders
header
=
new
DefaultTbQueueMsgHeaders
();
header
.
put
(
MessageHeader
.
MESSAGETYPE
,
deviceMsgReq
.
getMessageType
());
header
.
put
(
MessageHeader
.
MESSAGETYPE
,
item
.
getMessageType
());
header
.
put
(
MessageHeader
.
DEVICECODE
,
deviceMsgReq
.
getDeviceCode
());
header
.
put
(
MessageHeader
.
DEVICECODE
,
item
.
getDeviceCode
());
header
.
put
(
MessageHeader
.
TIMESTAMP
,
deviceMsgReq
.
getTimestamp
().
toString
());
header
.
put
(
MessageHeader
.
TIMESTAMP
,
item
.
getTimestamp
().
toString
());
TbQueueMsg
queueMsg
=
new
DefaultTbQueueMsg
(
IdUtil
.
fastUUID
(),
deviceMsgReq
.
getData
(),
header
);
TbQueueMsg
queueMsg
=
new
DefaultTbQueueMsg
(
IdUtil
.
fastUUID
(),
item
.
getData
(),
header
);
messageProducer
.
sendMsg
(
QueueKey
.
DEFAULT_EXCHANGE
,
Constant
.
DOWN_TOPIC
+
deviceEntity
.
getDeviceCode
(),
JSON
.
toJSONString
(
queueMsg
));
messageProducer
.
sendMsg
(
QueueKey
.
DEFAULT_EXCHANGE
,
Constant
.
DOWN_TOPIC
+
deviceEntity
.
getDeviceCode
(),
JSON
.
toJSONString
(
queueMsg
));
DeviceLogEntity
deviceLogEntity
=
new
DeviceLogEntity
();
DeviceLogEntity
deviceLogEntity
=
new
DeviceLogEntity
();
...
@@ -84,14 +98,15 @@ public class DeviceDownMsgThread extends AbstractThread {
...
@@ -84,14 +98,15 @@ public class DeviceDownMsgThread extends AbstractThread {
deviceLogEntity
.
setDeviceId
(
deviceEntity
.
getId
());
deviceLogEntity
.
setDeviceId
(
deviceEntity
.
getId
());
deviceLogEntity
.
setDeviceName
(
deviceEntity
.
getDeviceName
());
deviceLogEntity
.
setDeviceName
(
deviceEntity
.
getDeviceName
());
deviceLogEntity
.
setDeviceCode
(
deviceEntity
.
getDeviceCode
());
deviceLogEntity
.
setDeviceCode
(
deviceEntity
.
getDeviceCode
());
deviceLogEntity
.
setMessageHead
(
deviceMsgReq
.
getMessageType
());
deviceLogEntity
.
setMessageHead
(
item
.
getMessageType
());
deviceLogEntity
.
setContent
(
deviceMsgReq
.
getData
());
deviceLogEntity
.
setContent
(
item
.
getData
());
deviceLogEntity
.
setLogType
(
LogTypeEnum
.
下发服务
.
getValue
());
deviceLogEntity
.
setLogType
(
LogTypeEnum
.
下发服务
.
getValue
());
deviceLogEntity
.
setCreateUserId
(
1L
);
deviceLogEntity
.
setCreateUserId
(
1L
);
deviceLogEntity
.
setCreateTime
(
new
Date
());
deviceLogEntity
.
setCreateTime
(
new
Date
());
deviceLogService
.
save
(
deviceLogEntity
,
null
);
deviceLogService
.
save
(
deviceLogEntity
,
null
);
}
else
{
}
else
{
log
.
info
(
"未找到设备,deviceCode:{}"
,
deviceMsgReq
.
getDeviceCode
());
log
.
info
(
"未找到设备,deviceCode:{}"
,
item
.
getDeviceCode
());
}
}
}
}
}
}
}
...
...
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