Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄嘉阳
/
iot-platform-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
20e6891c
authored
Nov 03, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix:设备上下线报错问题
parent
2d65945b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
5 deletions
server-service/src/main/java/com/makeit/service/platform/device/PlatDeviceService.java
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-service/src/main/java/com/makeit/service/platform/device/PlatDeviceService.java
View file @
20e6891c
...
@@ -70,4 +70,7 @@ public interface PlatDeviceService extends IService<PlatDevice> {
...
@@ -70,4 +70,7 @@ public interface PlatDeviceService extends IService<PlatDevice> {
void
savePlatDevice
();
void
savePlatDevice
();
PlatDeviceViewVO
viewByDeviceId
(
String
id
);
PlatDeviceViewVO
viewByDeviceId
(
String
id
);
boolean
updateDeviceStatus
(
String
messageType
,
String
deviceId
,
String
iot_tenantId
);
}
}
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
View file @
20e6891c
...
@@ -34,6 +34,7 @@ import com.makeit.enums.CommonEnum;
...
@@ -34,6 +34,7 @@ import com.makeit.enums.CommonEnum;
import
com.makeit.enums.HeaderConst
;
import
com.makeit.enums.HeaderConst
;
import
com.makeit.enums.report.DeviceNameEnum
;
import
com.makeit.enums.report.DeviceNameEnum
;
import
com.makeit.exception.BusinessException
;
import
com.makeit.exception.BusinessException
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.mapper.platform.device.PlatDeviceMapper
;
import
com.makeit.mapper.platform.device.PlatDeviceMapper
;
import
com.makeit.module.iot.service.IotDevicePropertiesOperateService
;
import
com.makeit.module.iot.service.IotDevicePropertiesOperateService
;
import
com.makeit.module.iot.service.IotOrgService
;
import
com.makeit.module.iot.service.IotOrgService
;
...
@@ -535,4 +536,31 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
...
@@ -535,4 +536,31 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
});
});
return
deviceMap
.
values
();
return
deviceMap
.
values
();
}
}
@Override
@TenantIdIgnore
public
boolean
updateDeviceStatus
(
String
messageType
,
String
deviceId
,
String
iot_tenantId
)
{
try
{
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
equalsAnyIgnoreCase
(
messageType
,
com
.
makeit
.
module
.
iot
.
enums
.
DeviceState
.
offline
.
getValue
(),
com
.
makeit
.
module
.
iot
.
enums
.
DeviceState
.
online
.
getValue
()))
{
update
(
new
UpdateWrapper
<
PlatDevice
>().
lambda
()
.
set
(
PlatDevice:
:
getStatus
,
messageType
.
toLowerCase
())
.
eq
(
PlatDevice:
:
getOriDeviceId
,
deviceId
));
LambdaQueryWrapper
<
PlatDevice
>
deviceLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
deviceLambdaQueryWrapper
.
eq
(
PlatDevice:
:
getOriDeviceId
,
deviceId
);
List
<
PlatDevice
>
deviceList
=
list
(
deviceLambdaQueryWrapper
);
if
(
CollectionUtils
.
isNotEmpty
(
deviceList
))
{
for
(
PlatDevice
platDevice
:
deviceList
)
{
platDevice
.
setStatus
(
messageType
.
toLowerCase
());
}
deviceCacheUtil
.
putAll
(
deviceList
);
}
return
true
;
}
}
catch
(
Exception
e
){
log
.
error
(
"更新设备状态:"
,
e
);
}
return
false
;
}
}
}
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
20e6891c
...
@@ -120,16 +120,18 @@ public class PushCallback implements MqttCallback {
...
@@ -120,16 +120,18 @@ public class PushCallback implements MqttCallback {
redisTemplate
.
opsForValue
().
set
(
DEVICE_FALL_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
redisTemplate
.
opsForValue
().
set
(
DEVICE_FALL_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
1000
,
TimeUnit
.
MILLISECONDS
);
1000
,
TimeUnit
.
MILLISECONDS
);
}
}
String
deviceId
=
device
.
getDeviceId
();
String
messageType
=
device
.
getMessageType
();
//更新设备状态
boolean
statusFlag
=
platDeviceService
.
updateDeviceStatus
(
messageType
,
deviceId
,
""
);
if
(
statusFlag
)
{
return
;
}
for
(
HeaderInfo
.
Bind
binding
:
bindings
)
{
for
(
HeaderInfo
.
Bind
binding
:
bindings
)
{
try
{
try
{
String
iot_tenantId
=
binding
.
getId
();
String
iot_tenantId
=
binding
.
getId
();
StopWatch
stopWatch
=
new
StopWatch
();
StopWatch
stopWatch
=
new
StopWatch
();
stopWatch
.
start
(
"checkAlarm-1"
);
stopWatch
.
start
(
"checkAlarm-1"
);
String
deviceId
=
device
.
getDeviceId
();
String
messageType
=
device
.
getMessageType
();
//更新设备状态
updateDeviceStatus
(
messageType
,
deviceId
,
iot_tenantId
);
JSONObject
properties
=
device
.
getProperties
();
JSONObject
properties
=
device
.
getProperties
();
//iot设备id
//iot设备id
...
...
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