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
4ea26e5f
authored
Nov 03, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix:修复bug
parent
d4c2dc6e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
32 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 @
4ea26e5f
...
...
@@ -73,4 +73,6 @@ public interface PlatDeviceService extends IService<PlatDevice> {
PlatDeviceViewVO
viewByDeviceId
(
String
id
);
void
batchEditProperties
(
PlatDeviceAttrDTO
dto
);
void
updateDeviceStatus
(
String
messageType
,
String
deviceId
,
String
iot_tenantId
);
}
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
View file @
4ea26e5f
...
...
@@ -32,6 +32,7 @@ import com.makeit.enums.CodeMessageEnum;
import
com.makeit.enums.CommonEnum
;
import
com.makeit.enums.report.DeviceNameEnum
;
import
com.makeit.exception.BusinessException
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.mapper.platform.device.PlatDeviceMapper
;
import
com.makeit.module.iot.dto.UserServerInfo
;
import
com.makeit.module.iot.service.IotDevicePropertiesOperateService
;
...
...
@@ -603,4 +604,30 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
});
return
deviceMap
.
values
();
}
@Override
@TenantIdIgnore
public
void
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
.
isEmpty
(
deviceList
))
{
return
;
}
for
(
PlatDevice
platDevice
:
deviceList
)
{
platDevice
.
setStatus
(
messageType
.
toLowerCase
());
}
deviceCacheUtil
.
putAll
(
deviceList
);
}
}
catch
(
Exception
e
){
log
.
error
(
"更新设备状态:"
,
e
);
}
}
}
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
4ea26e5f
...
...
@@ -58,8 +58,6 @@ public class PushCallback implements MqttCallback {
@Autowired
private
PlatDeviceService
platDeviceService
;
@Autowired
private
PlatTenantService
platTenantService
;
@Autowired
private
StringRedisTemplate
redisTemplate
;
...
...
@@ -115,15 +113,15 @@ public class PushCallback implements MqttCallback {
redisTemplate
.
opsForValue
().
set
(
DEVICE_FALL_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
1000
,
TimeUnit
.
MILLISECONDS
);
}
String
deviceId
=
device
.
getDeviceId
();
String
messageType
=
device
.
getMessageType
();
//更新设备状态
platDeviceService
.
updateDeviceStatus
(
messageType
,
deviceId
,
""
);
for
(
HeaderInfo
.
Bind
binding
:
bindings
)
{
try
{
String
iot_tenantId
=
binding
.
getId
();
StopWatch
stopWatch
=
new
StopWatch
();
stopWatch
.
start
(
"checkAlarm-1"
);
String
deviceId
=
device
.
getDeviceId
();
String
messageType
=
device
.
getMessageType
();
//更新设备状态
updateDeviceStatus
(
messageType
,
deviceId
,
iot_tenantId
);
JSONObject
properties
=
device
.
getProperties
();
...
...
@@ -170,32 +168,6 @@ public class PushCallback implements MqttCallback {
}
@Transactional
@TenantIdIgnore
public
void
updateDeviceStatus
(
String
messageType
,
String
deviceId
,
String
iot_tenantId
)
{
try
{
if
(
StringUtils
.
equalsAnyIgnoreCase
(
messageType
,
DeviceState
.
offline
.
getValue
(),
DeviceState
.
online
.
getValue
()))
{
platDeviceService
.
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
=
platDeviceService
.
list
(
deviceLambdaQueryWrapper
);
if
(
CollectionUtils
.
isEmpty
(
deviceList
))
{
return
;
}
for
(
PlatDevice
platDevice
:
deviceList
)
{
platDevice
.
setStatus
(
messageType
.
toLowerCase
());
}
deviceCacheUtil
.
putAll
(
deviceList
);
}
}
catch
(
Exception
e
){
logger
.
error
(
"更新设备状态:"
,
e
);
}
}
}
...
...
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