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
8e1c37cb
authored
Dec 07, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix: 实时监测状态问题
parent
212cf08f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
15 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 @
8e1c37cb
...
@@ -67,6 +67,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
...
@@ -67,6 +67,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
public
static
final
String
DEVICE_BR_DATA
=
"device:brhr:data:"
;
public
static
final
String
DEVICE_BR_DATA
=
"device:brhr:data:"
;
public
static
final
String
SLEEP_ANALYSIS_KEY
=
"saas:sleep:analysis"
;
public
static
final
String
DEVICE_SPACE_DATA
=
"device:space:data:"
;
public
static
final
String
DEVICE_SPACE_DATA
=
"device:space:data:"
;
public
static
final
String
DEVICE_FALL_DATA
=
"device:fall:data:"
;
public
static
final
String
DEVICE_FALL_DATA
=
"device:fall:data:"
;
...
@@ -76,6 +78,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
...
@@ -76,6 +78,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
public
static
final
String
DEVICE_SPACE_TEMP_DATA
=
"device:space:tempData:"
;
public
static
final
String
DEVICE_SPACE_TEMP_DATA
=
"device:space:tempData:"
;
public
static
final
String
DEVICE_FALL_TEMP_DATA
=
"device:fall:tempData:"
;
@Autowired
@Autowired
private
PlatElderService
platElderService
;
private
PlatElderService
platElderService
;
...
@@ -326,22 +330,12 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
...
@@ -326,22 +330,12 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
String
person
=
jsonObject
.
getString
(
"person"
);
String
person
=
jsonObject
.
getString
(
"person"
);
String
personState
=
jsonObject
.
getString
(
"personState"
);
String
personState
=
jsonObject
.
getString
(
"personState"
);
if
(
StringUtils
.
equals
(
person
,
"1"
))
{
if
(
StringUtils
.
equals
(
person
,
"1"
))
{
// 在床运动
if
(
StringUtils
.
equals
(
personState
,
"1"
))
{
log
.
info
(
"当前属于在床运动:"
+
platElderIdDTO
.
getElderId
());
platElderRealTimeNowVO
.
setStatus
(
PlatElderRealtimeReportEnum
.
NowStatus
.
SPORT
.
getValue
());
return
platElderRealTimeNowVO
;
}
// 在床静息
if
(
StringUtils
.
equals
(
personState
,
"2"
)
||
StringUtils
.
equals
(
personState
,
"3"
))
{
log
.
info
(
"当前属于在床静息:"
+
platElderIdDTO
.
getElderId
());
platElderRealTimeNowVO
.
setStatus
(
PlatElderRealtimeReportEnum
.
NowStatus
.
BED
.
getValue
());
return
platElderRealTimeNowVO
;
}
// 判断是否在床睡觉
// 判断是否在床睡觉
Integer
sleepTimeActionThreshold
=
getSleepTimeActionThreshold
();
Integer
sleepTimeActionThreshold
=
getSleepTimeActionThreshold
();
Long
sleepTimeActionDuration
=
getSleepTimeActionDuration
();
Map
<
Object
,
Object
>
entries
=
redisTemplate
.
opsForHash
().
entries
(
DEVICE_BR_ANALYSIS
+
platDevice
.
getOriDeviceId
());
Map
<
Object
,
Object
>
entries
=
redisTemplate
.
opsForHash
().
entries
(
DEVICE_BR_ANALYSIS
+
platDevice
.
getOriDeviceId
());
Collection
<
Object
>
values
=
entries
.
values
();
Collection
<
Object
>
values
=
entries
.
values
();
if
(
values
.
size
()
>=
sleepTimeActionDuration
*
60
)
{
Predicate
<
Object
>
predicate
=
entity
->
{
Predicate
<
Object
>
predicate
=
entity
->
{
JSONObject
result
=
JSON
.
parseObject
(
entity
.
toString
());
JSONObject
result
=
JSON
.
parseObject
(
entity
.
toString
());
Integer
bodymove
=
Integer
.
valueOf
(
result
.
getString
(
"bodymove"
));
Integer
bodymove
=
Integer
.
valueOf
(
result
.
getString
(
"bodymove"
));
...
@@ -354,6 +348,19 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
...
@@ -354,6 +348,19 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
return
platElderRealTimeNowVO
;
return
platElderRealTimeNowVO
;
}
}
}
}
// 在床运动
if
(
StringUtils
.
equals
(
personState
,
"1"
))
{
log
.
info
(
"当前属于在床运动:"
+
platElderIdDTO
.
getElderId
());
platElderRealTimeNowVO
.
setStatus
(
PlatElderRealtimeReportEnum
.
NowStatus
.
SPORT
.
getValue
());
return
platElderRealTimeNowVO
;
}
// 在床静息
if
(
StringUtils
.
equals
(
personState
,
"2"
)
||
StringUtils
.
equals
(
personState
,
"3"
))
{
log
.
info
(
"当前属于在床静息:"
+
platElderIdDTO
.
getElderId
());
platElderRealTimeNowVO
.
setStatus
(
PlatElderRealtimeReportEnum
.
NowStatus
.
BED
.
getValue
());
return
platElderRealTimeNowVO
;
}
}
}
}
List
<
PlatDevice
>
spaceDeviceList
=
getSpaceDevice
(
platElderIdDTO
.
getElderId
(),
platElderIdDTO
.
getDeviceId
());
List
<
PlatDevice
>
spaceDeviceList
=
getSpaceDevice
(
platElderIdDTO
.
getElderId
(),
platElderIdDTO
.
getDeviceId
());
List
<
PlatDevice
>
fallDeviceList
=
getFallDevice
(
platElderIdDTO
.
getElderId
(),
platElderIdDTO
.
getDeviceId
());
List
<
PlatDevice
>
fallDeviceList
=
getFallDevice
(
platElderIdDTO
.
getElderId
(),
platElderIdDTO
.
getDeviceId
());
...
@@ -405,7 +412,7 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
...
@@ -405,7 +412,7 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
}
}
for
(
PlatDevice
device
:
fallDeviceList
)
{
for
(
PlatDevice
device
:
fallDeviceList
)
{
// 无人
// 无人
Map
<
Object
,
Object
>
entries
=
redisTemplate
.
opsForHash
().
entries
(
DEVICE_FALL_DATA
+
device
.
getOriDeviceId
());
Map
<
Object
,
Object
>
entries
=
redisTemplate
.
opsForHash
().
entries
(
DEVICE_FALL_
TEMP_
DATA
+
device
.
getOriDeviceId
());
if
(
entries
.
isEmpty
())
{
if
(
entries
.
isEmpty
())
{
continue
;
continue
;
}
}
...
@@ -455,6 +462,22 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
...
@@ -455,6 +462,22 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
return
platElderRealTimeNowVO
;
return
platElderRealTimeNowVO
;
}
}
private
Long
getSleepTimeActionDuration
()
{
String
sleepTimeActionDuration
=
""
;
String
result
=
redisTemplate
.
opsForValue
().
get
(
SLEEP_ANALYSIS_KEY
);
if
(
result
!=
null
)
{
sleepTimeActionDuration
=
result
;
}
else
{
SaasSleepAnalysisModel
analysisModel
=
saasSleepAnalysisModelService
.
getOne
(
new
QueryWrapper
<
SaasSleepAnalysisModel
>().
lambda
()
.
orderByDesc
(
BaseEntity:
:
getCreateBy
)
.
last
(
"limit 1"
));
redisTemplate
.
opsForValue
().
set
(
SLEEP_ANALYSIS_KEY
,
analysisModel
.
getSleepTimeActionDuration
(),
1
,
TimeUnit
.
DAYS
);
sleepTimeActionDuration
=
analysisModel
.
getSleepTimeActionDuration
();
}
BigDecimal
s
=
new
BigDecimal
(
sleepTimeActionDuration
).
multiply
(
new
BigDecimal
(
60
));
return
s
.
longValue
();
}
private
Integer
getSleepTimeActionThreshold
()
{
private
Integer
getSleepTimeActionThreshold
()
{
Integer
sleepTimeActionThreshold
;
Integer
sleepTimeActionThreshold
;
String
result
=
redisTemplate
.
opsForValue
().
get
(
SLEEP_ANALYSIS_THRESHOLD_KEY
);
String
result
=
redisTemplate
.
opsForValue
().
get
(
SLEEP_ANALYSIS_THRESHOLD_KEY
);
...
...
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
8e1c37cb
...
@@ -118,8 +118,8 @@ public class PushCallback implements MqttCallback {
...
@@ -118,8 +118,8 @@ public class PushCallback implements MqttCallback {
// 缓存呼吸设备某段时间的数据,hash 最大长度 duration
// 缓存呼吸设备某段时间的数据,hash 最大长度 duration
Long
duration
=
getSleepTimeActionDuration
();
Long
duration
=
getSleepTimeActionDuration
();
Long
size
=
redisTemplate
.
opsForHash
().
size
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
());
Long
size
=
redisTemplate
.
opsForHash
().
size
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
());
if
(
size
.
equals
(
duration
))
{
if
(
size
.
equals
(
duration
*
60
))
{
redisTemplate
.
opsForHash
().
delete
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
timestamp
-
duration
);
redisTemplate
.
opsForHash
().
delete
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
timestamp
-
duration
*
60
);
}
}
redisTemplate
.
opsForHash
().
put
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
timestamp
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
opsForHash
().
put
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
timestamp
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
expire
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
duration
,
TimeUnit
.
MINUTES
);
redisTemplate
.
expire
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
duration
,
TimeUnit
.
MINUTES
);
...
...
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