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
098dcc25
authored
Dec 07, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix: 数据保存
parent
78d4dbe3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
098dcc25
...
...
@@ -112,16 +112,17 @@ public class PushCallback implements MqttCallback {
List
<
HeaderInfo
.
Bind
>
bindings
=
headers
.
getBindings
();
Long
timestamp
=
device
.
getTimestamp
();
long
currentSecond
=
timestamp
/
1000
;
// TODO 先这样判断
if
(
REPORT_PROPERTY
.
equals
(
device
.
getMessageType
())
&&
headers
.
getProductName
().
contains
(
"呼吸"
))
{
// 缓存呼吸设备某段时间的数据,hash 最大长度 duration
long
duration
=
getSleepTimeActionDuration
();
Long
size
=
redisTemplate
.
opsForHash
().
size
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
());
redisTemplate
.
opsForHash
().
put
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
timestamp
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
opsForHash
().
put
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
currentSecond
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
expire
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
duration
,
TimeUnit
.
MINUTES
);
if
(
size
>
duration
*
60
)
{
redisTemplate
.
opsForHash
().
delete
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
timestamp
-
duration
*
60
);
redisTemplate
.
opsForHash
().
delete
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
currentSecond
-
duration
*
60
);
}
redisTemplate
.
opsForValue
().
set
(
DEVICE_BR_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
5000
,
TimeUnit
.
MILLISECONDS
);
...
...
@@ -129,22 +130,22 @@ public class PushCallback implements MqttCallback {
if
(
REPORT_PROPERTY
.
equals
(
device
.
getMessageType
())
&&
headers
.
getProductName
().
contains
(
"空间"
))
{
long
maxSize
=
10L
;
Long
size
=
redisTemplate
.
opsForHash
().
size
(
DEVICE_SPACE_TEMP_DATA
+
device
.
getDeviceId
());
redisTemplate
.
opsForHash
().
put
(
DEVICE_SPACE_TEMP_DATA
+
device
.
getDeviceId
(),
timestamp
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
opsForHash
().
put
(
DEVICE_SPACE_TEMP_DATA
+
device
.
getDeviceId
(),
currentSecond
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
expire
(
DEVICE_SPACE_TEMP_DATA
+
device
.
getDeviceId
(),
maxSize
+
1
,
TimeUnit
.
SECONDS
);
if
(
size
>
maxSize
)
{
redisTemplate
.
opsForHash
().
delete
(
DEVICE_SPACE_TEMP_DATA
+
device
.
getDeviceId
(),
timestamp
-
maxSize
);
redisTemplate
.
opsForHash
().
delete
(
DEVICE_SPACE_TEMP_DATA
+
device
.
getDeviceId
(),
currentSecond
-
maxSize
);
}
redisTemplate
.
opsForValue
().
set
(
DEVICE_SPACE_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
5000
,
TimeUnit
.
MILLISECONDS
);
}
if
(
REPORT_PROPERTY
.
equals
(
device
.
getMessageType
())
&&
headers
.
getProductName
().
contains
(
"跌倒"
))
{
L
ong
maxSize
=
10L
;
l
ong
maxSize
=
10L
;
Long
size
=
redisTemplate
.
opsForHash
().
size
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
());
redisTemplate
.
opsForHash
().
put
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
(),
timestamp
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
opsForHash
().
put
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
(),
currentSecond
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
expire
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
(),
maxSize
+
1
,
TimeUnit
.
SECONDS
);
if
(
size
>
maxSize
)
{
redisTemplate
.
opsForHash
().
delete
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
(),
timestamp
-
maxSize
);
redisTemplate
.
opsForHash
().
delete
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
(),
currentSecond
-
maxSize
);
}
redisTemplate
.
opsForValue
().
set
(
DEVICE_FALL_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
...
...
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