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
15decda0
authored
Dec 13, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix: 呼吸心率设备数据上报缓存问题
parent
79600242
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
30 deletions
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderRealTimeServiceImpl.java
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderRealTimeServiceImpl.java
View file @
15decda0
...
...
@@ -194,11 +194,6 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
Map
<
Object
,
Object
>
entries
=
redisTemplate
.
opsForHash
().
entries
(
DEVICE_BR_ANALYSIS
+
platDevice
.
getOriDeviceId
());
Collection
<
Object
>
values
=
entries
.
values
();
if
(
values
.
size
()
>=
sleepTimeActionDuration
)
{
Predicate
<
Object
>
predicate
=
entity
->
{
JSONObject
result
=
JSON
.
parseObject
(
entity
.
toString
());
Integer
bodymove
=
Integer
.
valueOf
(
result
.
getString
(
"bodymove"
));
return
bodymove
.
compareTo
(
sleepTimeActionThreshold
)
<=
0
;
};
int
count
=
0
;
for
(
Object
entity
:
values
)
{
JSONObject
result
=
JSON
.
parseObject
(
entity
.
toString
());
...
...
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
15decda0
...
...
@@ -153,42 +153,21 @@ public class PushCallback implements MqttCallback {
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
());
if
(
size
==
duration
)
{
redisTemplate
.
opsForHash
().
delete
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
currentSecond
-
duration
);
}
else
if
(
size
-
duration
>=
5
)
{
redisTemplate
.
delete
(
Objects
.
requireNonNull
(
redisTemplate
.
keys
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
())));
}
redisTemplate
.
opsForHash
().
put
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
currentSecond
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
expire
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
duration
+
3
,
TimeUnit
.
MINUTES
);
cacheBrDeviceData
(
device
,
currentSecond
);
redisTemplate
.
opsForValue
().
set
(
DEVICE_BR_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
5000
,
TimeUnit
.
MILLISECONDS
);
}
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
(),
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
(),
currentSecond
-
maxSize
);
}
cacheSpaceFallDeviceData
(
DEVICE_SPACE_TEMP_DATA
,
device
,
currentSecond
);
redisTemplate
.
opsForValue
().
set
(
DEVICE_SPACE_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
5000
,
TimeUnit
.
MILLISECONDS
);
}
if
(
REPORT_PROPERTY
.
equals
(
device
.
getMessageType
())
&&
headers
.
getProductName
().
contains
(
"跌倒"
))
{
long
maxSize
=
10L
;
Long
size
=
redisTemplate
.
opsForHash
().
size
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
());
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
(),
currentSecond
-
maxSize
);
}
cacheSpaceFallDeviceData
(
DEVICE_FALL_TEMP_DATA
,
device
,
currentSecond
);
redisTemplate
.
opsForValue
().
set
(
DEVICE_FALL_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
5000
,
TimeUnit
.
MILLISECONDS
);
...
...
@@ -251,6 +230,35 @@ public class PushCallback implements MqttCallback {
}
private
void
cacheSpaceFallDeviceData
(
String
deviceSpaceTempData
,
DeviceInfo
device
,
long
currentSecond
)
{
long
maxSize
=
10L
;
String
key
=
deviceSpaceTempData
+
device
.
getDeviceId
();
Long
size
=
redisTemplate
.
opsForHash
().
size
(
key
);
redisTemplate
.
opsForHash
().
put
(
key
,
currentSecond
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
expire
(
key
,
maxSize
+
1
,
TimeUnit
.
SECONDS
);
if
(
size
==
maxSize
)
{
redisTemplate
.
opsForHash
().
delete
(
key
,
currentSecond
-
maxSize
);
}
}
private
void
cacheBrDeviceData
(
DeviceInfo
device
,
long
currentSecond
)
{
// 缓存呼吸设备某段时间的数据,hash 最大长度 duration
String
key
=
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
();
long
duration
=
getSleepTimeActionDuration
();
long
size
=
redisTemplate
.
opsForHash
().
size
(
key
);
long
differenceValue
=
currentSecond
-
duration
;
if
(
size
==
duration
)
{
redisTemplate
.
opsForHash
().
delete
(
key
,
differenceValue
);
}
else
if
(
size
-
duration
>=
5
)
{
// 兼容设备上报数据时间不准确问题
for
(
long
i
=
differenceValue
;
i
<
differenceValue
-
10
;
i
--)
{
redisTemplate
.
opsForHash
().
delete
(
key
,
i
);
}
}
redisTemplate
.
opsForHash
().
put
(
key
,
currentSecond
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
expire
(
key
,
duration
+
3
,
TimeUnit
.
MINUTES
);
}
private
Long
getSleepTimeActionDuration
()
{
String
sleepTimeActionDuration
=
""
;
String
result
=
redisTemplate
.
opsForValue
().
get
(
SLEEP_ANALYSIS_KEY
);
...
...
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