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
aa3f63ea
authored
Dec 27, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
19fe1429
55e10402
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
318 additions
and
346 deletions
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderBreatheAnalysisServiceImpl.java
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderDayReportDayServiceImpl.java
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderBreatheAnalysisServiceImpl.java
View file @
aa3f63ea
...
...
@@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.makeit.common.entity.BaseEntity
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.platform.elder.PlatElder
;
...
...
@@ -21,8 +20,6 @@ import com.makeit.enums.report.ConditionTypeEnum;
import
com.makeit.mapper.platform.elder.PlatElderBreatheAnalysisMapper
;
import
com.makeit.module.iot.service.IotProductDeviceService
;
import
com.makeit.module.iot.vo.DeviceOperationLogEntity
;
import
com.makeit.module.iot.vo.analysis.AnalysisVO
;
import
com.makeit.module.iot.vo.analysis.BreatheAbnormalVO
;
import
com.makeit.module.iot.vo.analysis.DiseaseReportVO
;
import
com.makeit.module.iot.vo.analysis.EvaluateReportVO
;
import
com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe
;
...
...
@@ -37,21 +34,22 @@ import com.makeit.service.saas.SaasSleepAnalysisModelService;
import
com.makeit.utils.data.convert.JsonUtil
;
import
com.makeit.utils.data.convert.StreamUtil
;
import
com.makeit.utils.time.LocalDateTimeUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.math.BigDecimal
;
import
java.time.*
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -63,6 +61,7 @@ import java.util.stream.Collectors;
* @since 2023-09-15
*/
@Service
@Slf4j
public
class
PlatElderBreatheAnalysisServiceImpl
extends
ServiceImpl
<
PlatElderBreatheAnalysisMapper
,
PlatElderBreatheAnalysis
>
implements
PlatElderBreatheAnalysisService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PlatElderBreatheAnalysisServiceImpl
.
class
);
...
...
@@ -88,6 +87,311 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
private
static
final
DateTimeFormatter
DEFAULT_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm"
);
private
LocalDateTime
longToTime
(
Long
longTime
)
{
return
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
longTime
),
ZoneOffset
.
of
(
"+8"
));
}
private
PlatElderBreatheAnalysis
elderHeartAnalysis
(
PlatElder
platElder
,
Map
<
String
,
PlatElderBreatheDayStat
>
breatheDayStatMap
,
LocalDateTime
yesStart
,
SaasSleepAnalysisModel
analysisModel
,
SaasDiseaseModel
saasDiseaseModel
,
LocalDate
yesDate
,
Map
<
String
,
PlatElderBreatheAnalysis
>
analysisMap
,
SaasDiseaseEvaluateReport
saasDiseaseEvaluateReport
)
{
// 呼吸率
int
breatheThresholdMin
=
Integer
.
parseInt
(
analysisModel
.
getBreatheThresholdMin
());
int
breatheThresholdMax
=
Integer
.
parseInt
(
analysisModel
.
getBreatheThresholdMax
());
int
breatheDuration
=
Integer
.
parseInt
(
analysisModel
.
getBreatheDuration
());
// 心率
int
heartThresholdMin
=
Integer
.
parseInt
(
analysisModel
.
getHeartThresholdMin
());
int
heartThresholdMax
=
Integer
.
parseInt
(
analysisModel
.
getHeartThresholdMax
());
int
heartDuration
=
Integer
.
parseInt
(
analysisModel
.
getHeartDuration
());
PlatElderBreatheDayStat
elderBreatheDayStat
=
breatheDayStatMap
.
get
(
platElder
.
getId
());
if
(
elderBreatheDayStat
==
null
)
{
return
new
PlatElderBreatheAnalysis
();
}
PlatDevice
platDevice
=
platElderRealTimeService
.
getBreathDevice
(
platElder
.
getId
(),
null
);
if
(
platDevice
==
null
)
{
return
new
PlatElderBreatheAnalysis
();
}
List
<
String
>
dayHourRange
=
getLastDayHourRange
(
yesStart
);
// 呼吸暂停
AtomicInteger
brStopCount
=
new
AtomicInteger
(
0
);
AtomicLong
brStopSecond
=
new
AtomicLong
(
0
);
// 呼吸过速
AtomicInteger
brFastCount
=
new
AtomicInteger
(
0
);
;
AtomicLong
brFastSecond
=
new
AtomicLong
();
// 呼吸过缓
AtomicInteger
brSlowCount
=
new
AtomicInteger
(
0
);
AtomicLong
brSlowSecond
=
new
AtomicLong
();
// 心率过速
AtomicInteger
hrFastCount
=
new
AtomicInteger
(
0
);
AtomicLong
hrFastSecond
=
new
AtomicLong
();
// 心率过缓
AtomicInteger
hrSlowCount
=
new
AtomicInteger
(
0
);
AtomicLong
hrSlowSecond
=
new
AtomicLong
();
for
(
String
hourRange
:
dayHourRange
)
{
String
[]
hourRangeArray
=
hourRange
.
split
(
"~"
);
List
<
DeviceOperationLogEntity
>
deviceOperationLogEntities
=
productDeviceService
.
getDeviceLogByTimeRange
(
platDevice
.
getOriDeviceId
(),
"reportProperty"
,
5000
,
hourRangeArray
[
0
],
hourRangeArray
[
1
]);
if
(
CollectionUtils
.
isEmpty
(
deviceOperationLogEntities
))
{
continue
;
}
List
<
DeviceInfoContentBreathe
>
deviceInfoContentBreatheList
=
deviceOperationLogEntities
.
stream
()
.
filter
(
deviceOperationLogEntity
->
deviceOperationLogEntity
.
getType
().
contains
(
"reportProperty"
))
.
map
(
deviceOperationLogEntity
->
{
DeviceInfoContentBreathe
deviceInfoContentBreathe
=
JsonUtil
.
toObj
((
String
)
deviceOperationLogEntity
.
getContent
(),
DeviceInfoContentBreathe
.
class
);
assert
deviceInfoContentBreathe
!=
null
;
deviceInfoContentBreathe
.
setReportTime
(
formatLongTime
(
deviceInfoContentBreathe
.
getTimestamp
()));
return
deviceInfoContentBreathe
;
})
.
collect
(
Collectors
.
toList
());
AtomicBoolean
existHrFast
=
new
AtomicBoolean
(
false
);
AtomicBoolean
existHrSlow
=
new
AtomicBoolean
(
false
);
AtomicBoolean
existBrFast
=
new
AtomicBoolean
(
false
);
AtomicBoolean
existBrSlow
=
new
AtomicBoolean
(
false
);
AtomicBoolean
existBrStop
=
new
AtomicBoolean
(
false
);
deviceInfoContentBreatheList
.
forEach
(
deviceInfo
->
{
DeviceInfoContentBreathe
.
Properties
deviceProperties
=
deviceInfo
.
getProperties
();
int
br
=
deviceProperties
.
getBr
();
int
hr
=
deviceProperties
.
getHr
();
Integer
hasPerson
=
deviceProperties
.
getPerson
();
// 0无人,1有人
// 0和255设备误报直接跳过
if
(
hasPerson
==
0
||
hr
==
255
||
br
==
255
)
{
brStopSecond
.
set
(
0
);
brFastSecond
.
set
(
0
);
brSlowSecond
.
set
(
0
);
hrFastSecond
.
set
(
0
);
hrSlowSecond
.
set
(
0
);
existHrFast
.
set
(
false
);
existHrSlow
.
set
(
false
);
existBrFast
.
set
(
false
);
existBrSlow
.
set
(
false
);
existBrStop
.
set
(
false
);
return
;
}
Long
timestamp
=
deviceInfo
.
getTimestamp
();
// 判断呼吸暂停
if
(
br
==
0
)
{
long
firstStopSecond
=
brStopSecond
.
get
();
if
(
firstStopSecond
==
0
)
{
log
.
info
(
"第一次呼吸暂停的时间:{}"
,
longToTime
(
timestamp
));
brStopSecond
.
set
(
timestamp
);
}
if
(
firstStopSecond
!=
0
&&
(
timestamp
-
firstStopSecond
)
/
1000
>=
breatheDuration
)
{
// 避免每10s生成一次统计的方式,切换状态后重新计算
if
(!
existBrStop
.
get
())
{
log
.
info
(
"第一次呼吸暂停持续时间满足:{}:now:{}"
,
breatheDuration
,
longToTime
(
timestamp
));
brStopCount
.
getAndIncrement
();
existBrStop
.
set
(
true
);
}
}
brFastSecond
.
set
(
0
);
brSlowSecond
.
set
(
0
);
existBrFast
.
set
(
false
);
existBrSlow
.
set
(
false
);
}
else
if
(
breatheThresholdMax
<
br
)
{
//呼吸过快
long
firstFastBr
=
brFastSecond
.
get
();
if
(
firstFastBr
==
0
)
{
log
.
info
(
"第一次呼吸:{},fast大于阈值:{},的时间:{}"
,
br
,
breatheThresholdMax
,
longToTime
(
timestamp
));
brFastSecond
.
set
(
timestamp
);
}
if
(
firstFastBr
!=
0
&&
(
timestamp
-
firstFastBr
)
/
1000
>=
breatheDuration
)
{
if
(!
existBrFast
.
get
())
{
log
.
info
(
"第一次呼吸:{},fast持续时间满足:{}:now:{}"
,
br
,
breatheDuration
,
longToTime
(
timestamp
));
brFastCount
.
getAndIncrement
();
existBrFast
.
set
(
true
);
}
}
brSlowSecond
.
set
(
0
);
brStopSecond
.
set
(
0
);
existBrSlow
.
set
(
false
);
existBrStop
.
set
(
false
);
}
else
if
(
br
<
breatheThresholdMin
)
{
// 呼吸过慢
long
firstSlowBr
=
brSlowSecond
.
get
();
if
(
firstSlowBr
==
0
)
{
log
.
info
(
"第一次呼吸:{},slow小于阈值:{},的时间:{}"
,
br
,
breatheThresholdMin
,
longToTime
(
timestamp
));
brSlowSecond
.
set
(
timestamp
);
}
if
(
firstSlowBr
!=
0
&&
(
timestamp
-
firstSlowBr
)
/
1000
>=
breatheDuration
)
{
if
(!
existBrSlow
.
get
())
{
log
.
info
(
"第一次呼吸:{},slow持续时间满足:{}:now:{}"
,
br
,
breatheDuration
,
longToTime
(
timestamp
));
brSlowCount
.
getAndIncrement
();
}
}
brFastSecond
.
set
(
0
);
brStopSecond
.
set
(
0
);
existBrFast
.
set
(
false
);
existBrStop
.
set
(
false
);
}
else
{
brSlowSecond
.
set
(
0
);
brFastSecond
.
set
(
0
);
brStopSecond
.
set
(
0
);
existBrFast
.
set
(
false
);
existBrStop
.
set
(
false
);
existBrSlow
.
set
(
false
);
log
.
info
(
"呼吸正常:{},min:{},max:{},的时间:{}"
,
br
,
breatheThresholdMin
,
breatheThresholdMax
,
longToTime
(
timestamp
));
}
// 心率过快
if
(
heartThresholdMax
<
hr
)
{
long
firstHrMax
=
hrFastSecond
.
get
();
if
(
firstHrMax
==
0
)
{
log
.
info
(
"第一次心率:{},max大于阈值:{},的时间:{}"
,
hr
,
heartThresholdMax
,
longToTime
(
timestamp
));
hrFastSecond
.
set
(
timestamp
);
}
if
(
firstHrMax
!=
0
&&
(
timestamp
-
firstHrMax
)
/
1000
>=
heartDuration
)
{
if
(!
existHrFast
.
get
())
{
log
.
info
(
"第一次心率:{},max持续时间满足:{}:now:{}"
,
hr
,
heartDuration
,
longToTime
(
timestamp
));
hrFastCount
.
getAndIncrement
();
existHrFast
.
set
(
true
);
}
}
hrSlowSecond
.
set
(
0
);
existHrSlow
.
set
(
false
);
}
else
if
(
heartThresholdMin
>
hr
)
{
// 心率过慢
long
firstHrMin
=
hrSlowSecond
.
get
();
if
(
firstHrMin
==
0
)
{
log
.
info
(
"第一次心率:{},min小于阈值:{},的时间:{}"
,
hr
,
heartThresholdMin
,
longToTime
(
timestamp
));
hrSlowSecond
.
set
(
timestamp
);
}
if
(
firstHrMin
!=
0
&&
(
timestamp
-
firstHrMin
)
/
1000
>=
heartDuration
)
{
if
(!
existHrSlow
.
get
())
{
log
.
info
(
"第一次心率:{},min持续时间满足:{}:now:{}"
,
hr
,
heartDuration
,
longToTime
(
timestamp
));
hrSlowCount
.
getAndIncrement
();
existHrSlow
.
set
(
true
);
}
}
hrFastSecond
.
set
(
0
);
existHrFast
.
set
(
false
);
}
else
{
hrSlowSecond
.
set
(
0
);
existHrSlow
.
set
(
false
);
hrFastSecond
.
set
(
0
);
existHrFast
.
set
(
false
);
log
.
info
(
"心率正常:{},min:{},max:{},的时间:{}"
,
hr
,
heartThresholdMin
,
heartThresholdMax
,
longToTime
(
timestamp
));
}
});
}
// 呼吸暂停
int
apneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getApneaTime
());
int
apneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getApneaThreshold
());
// 呼吸过速
int
tachypneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachypneaTime
());
int
tachypneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachypneaThreshold
());
// 呼吸过缓
int
bradypneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradypneaTime
());
int
bradypneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradypneaThreshold
());
// 心率过缓
int
bradycardiaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradycardiaTime
());
int
bradycardiaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradycardiaThreshold
());
// 心率过速
int
tachycardiaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachycardiaTime
());
int
tachycardiaComparison
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachycardiaThreshold
());
boolean
brStopFlag
=
false
;
boolean
brFastFlag
=
false
;
boolean
brSlowFlag
=
false
;
boolean
hrFastFlag
=
false
;
boolean
hrSlowFlag
=
false
;
boolean
normalFlag
;
if
(
brStopCount
.
get
()
>
apneaThreshold
)
{
brStopFlag
=
true
;
}
if
(
brFastCount
.
get
()
>
tachypneaThreshold
)
{
brFastFlag
=
true
;
}
if
(
brSlowCount
.
get
()
>
bradypneaThreshold
)
{
brSlowFlag
=
true
;
}
if
(
hrFastCount
.
get
()
>
tachycardiaComparison
)
{
hrFastFlag
=
true
;
}
if
(
hrSlowCount
.
get
()
>
bradycardiaThreshold
)
{
hrSlowFlag
=
true
;
}
normalFlag
=
!(
hrFastFlag
||
brStopFlag
||
brFastFlag
||
brSlowFlag
||
hrSlowFlag
);
List
<
DiseaseReportVO
>
evaluateReportList
=
JSON
.
parseArray
(
saasDiseaseEvaluateReport
.
getResultContent
(),
DiseaseReportVO
.
class
);
DiseaseReportVO
finalReport
=
new
DiseaseReportVO
();
// 根据疾病标准配置的规则判断满足哪个区间范围
for
(
DiseaseReportVO
diseaseReportVO
:
evaluateReportList
)
{
List
<
DiseaseReportVO
.
Condition
>
conditionList
=
diseaseReportVO
.
getCondition
();
if
(
CollUtil
.
isEmpty
(
conditionList
))
{
continue
;
}
boolean
conditionFlag
=
true
;
for
(
DiseaseReportVO
.
Condition
condition
:
conditionList
)
{
String
resultRelational
=
condition
.
getResultRelational
();
String
resultCondition
=
condition
.
getResultCondition
();
if
(
"or"
.
equals
(
resultCondition
))
{
if
(
conditionFlag
)
{
break
;
}
}
else
{
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
NORMAL
.
getCode
()))
{
conditionFlag
=
normalFlag
&&
conditionFlag
;
}
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
BREATHE_STOP
.
getCode
()))
{
conditionFlag
=
brStopFlag
&&
conditionFlag
;
}
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
BREATHE_FAST
.
getCode
()))
{
conditionFlag
=
brFastFlag
&&
conditionFlag
;
}
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
BREATHE_SLOW
.
getCode
()))
{
conditionFlag
=
brSlowFlag
&&
conditionFlag
;
}
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
HEART_FAST
.
getCode
()))
{
conditionFlag
=
hrFastFlag
&&
conditionFlag
;
}
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
HEART_SLOW
.
getCode
()))
{
conditionFlag
=
hrSlowFlag
&&
conditionFlag
;
}
}
}
if
(
conditionFlag
)
{
finalReport
=
diseaseReportVO
;
}
}
long
scoreLong
=
Long
.
parseLong
(
finalReport
.
getScore
());
if
(
scoreLong
>
100
)
{
scoreLong
=
100
;
finalReport
.
setScore
(
"100"
);
}
EvaluateReportVO
diseaseReport
=
saasDiseaseReportService
.
getByScore
(
scoreLong
);
PlatElderBreatheAnalysis
platElderBreatheAnalysis
=
new
PlatElderBreatheAnalysis
();
platElderBreatheAnalysis
.
setElderId
(
platElder
.
getId
());
platElderBreatheAnalysis
.
setAvgBreatheRate
(
String
.
valueOf
(
elderBreatheDayStat
.
getRespiratoryRateAvg
()));
platElderBreatheAnalysis
.
setAvgHeartRate
(
String
.
valueOf
(
elderBreatheDayStat
.
getHeartRateAvg
()));
platElderBreatheAnalysis
.
setBreatheScore
(
finalReport
.
getScore
());
platElderBreatheAnalysis
.
setHappenDate
(
String
.
valueOf
(
yesDate
));
platElderBreatheAnalysis
.
setTenantId
(
platElder
.
getTenantId
());
platElderBreatheAnalysis
.
setBreatheEvaluate
(
diseaseReport
==
null
?
""
:
diseaseReport
.
getEvaluate
());
platElderBreatheAnalysis
.
setOriDeviceId
(
platDevice
.
getOriDeviceId
());
// 修复数据
PlatElderBreatheAnalysis
breatheAnalysis
=
analysisMap
.
get
(
platElder
.
getId
());
if
(
breatheAnalysis
!=
null
)
{
platElderBreatheAnalysis
.
setId
(
breatheAnalysis
.
getId
());
platElderBreatheAnalysisService
.
updateById
(
platElderBreatheAnalysis
);
}
else
{
platElderBreatheAnalysisService
.
save
(
platElderBreatheAnalysis
);
}
return
platElderBreatheAnalysis
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
List
<
PlatElderBreatheAnalysis
>
elderHeartRespiratoryAnalysisTask
(
Integer
month
,
Integer
day
)
{
...
...
@@ -126,349 +430,16 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
.
in
(
PlatElderBreatheAnalysis:
:
getElderId
,
elderIdList
)
.
eq
(
PlatElderBreatheAnalysis:
:
getHappenDate
,
yesDate
)),
PlatElderBreatheAnalysis:
:
getElderId
);
SaasDiseaseEvaluateReport
saasDiseaseEvaluateReport
=
saasDiseaseEvaluateReportService
.
getOne
(
new
QueryWrapper
<
SaasDiseaseEvaluateReport
>().
lambda
().
orderByDesc
(
BaseEntity:
:
getCreateBy
)
.
last
(
"limit 1"
));
// 呼吸率
int
breatheThresholdMin
=
Integer
.
parseInt
(
analysisModel
.
getBreatheThresholdMin
());
int
breatheThresholdMax
=
Integer
.
parseInt
(
analysisModel
.
getBreatheThresholdMax
());
int
breatheDuration
=
Integer
.
parseInt
(
analysisModel
.
getBreatheDuration
());
// 心率
int
heartThresholdMin
=
Integer
.
parseInt
(
analysisModel
.
getHeartThresholdMin
());
int
heartThresholdMax
=
Integer
.
parseInt
(
analysisModel
.
getHeartThresholdMax
());
int
heartDuration
=
Integer
.
parseInt
(
analysisModel
.
getHeartDuration
());
for
(
PlatElder
platElder
:
elderList
)
{
PlatElderBreatheDayStat
elderBreatheDayStat
=
breatheDayStatMap
.
get
(
platElder
.
getId
());
if
(
elderBreatheDayStat
==
null
)
{
continue
;
}
PlatDevice
platDevice
=
platElderRealTimeService
.
getBreathDevice
(
platElder
.
getId
(),
null
);
if
(
platDevice
==
null
)
{
continue
;
}
List
<
String
>
dayHourRange
=
getLastDayHourRange
(
yesStart
);
TreeMap
<
String
,
AnalysisVO
>
totalMap
=
new
TreeMap
<>();
String
reportStartTime
=
""
;
String
reportEndTime
=
""
;
for
(
String
hourRange
:
dayHourRange
)
{
String
[]
hourRangeArray
=
hourRange
.
split
(
"~"
);
List
<
DeviceOperationLogEntity
>
deviceOperationLogEntities
=
productDeviceService
.
getDeviceLogByTimeRange
(
platDevice
.
getOriDeviceId
(),
"reportProperty"
,
5000
,
hourRangeArray
[
0
],
hourRangeArray
[
1
]);
if
(
CollectionUtils
.
isEmpty
(
deviceOperationLogEntities
))
{
continue
;
}
List
<
DeviceInfoContentBreathe
>
deviceInfoContentBreatheList
=
deviceOperationLogEntities
.
stream
()
.
filter
(
deviceOperationLogEntity
->
deviceOperationLogEntity
.
getType
().
contains
(
"reportProperty"
))
.
map
(
deviceOperationLogEntity
->
{
DeviceInfoContentBreathe
deviceInfoContentBreathe
=
JsonUtil
.
toObj
((
String
)
deviceOperationLogEntity
.
getContent
(),
DeviceInfoContentBreathe
.
class
);
deviceInfoContentBreathe
.
setReportTime
(
formatLongTime
(
deviceInfoContentBreathe
.
getTimestamp
()));
return
deviceInfoContentBreathe
;
})
.
collect
(
Collectors
.
toList
());
Map
<
String
,
List
<
DeviceInfoContentBreathe
>>
minuteMap
=
StreamUtil
.
groupBy
(
deviceInfoContentBreatheList
,
DeviceInfoContentBreathe:
:
getReportTime
);
deviceOperationLogEntities
.
clear
();
// 统计每小时的体动和翻身
Map
<
String
,
AnalysisVO
>
statisticsMap
=
Maps
.
newHashMap
();
List
<
DeviceInfoContentBreathe
>
deviceInfoContentBreathes
;
for
(
Map
.
Entry
<
String
,
List
<
DeviceInfoContentBreathe
>>
entry
:
minuteMap
.
entrySet
())
{
if
(
StringUtils
.
isEmpty
(
reportStartTime
))
{
reportStartTime
=
entry
.
getKey
();
}
reportEndTime
=
entry
.
getKey
();
deviceInfoContentBreathes
=
entry
.
getValue
();
DeviceInfoContentBreathe
.
Properties
breatheProperties
;
// 呼吸暂停
int
brStopCount
=
0
;
int
brStopSecond
=
0
;
// 呼吸过速
int
brFastCount
=
0
;
int
brFastSecond
=
0
;
int
brFast
=
0
;
// 呼吸过缓
int
brSlowCount
=
0
;
int
brSlowSecond
=
0
;
int
brSlow
=
0
;
// 心率过速
int
hrFastCount
=
0
;
int
hrFast
=
0
;
int
hrFastSecond
=
0
;
// 心率过缓
int
hrSlowCount
=
0
;
int
hrSlowSecond
=
0
;
int
hrSlow
=
0
;
AnalysisVO
analysisVO
=
new
AnalysisVO
();
for
(
DeviceInfoContentBreathe
infoContentBreathe
:
deviceInfoContentBreathes
)
{
// 体动指数
breatheProperties
=
infoContentBreathe
.
getProperties
();
int
br
=
breatheProperties
.
getBr
();
int
hr
=
breatheProperties
.
getHr
();
Integer
hasPerson
=
breatheProperties
.
getPerson
();
// 0无人,1有人
if
(
hasPerson
==
0
)
{
continue
;
}
// 0和255设备误报直接跳过
if
(
hr
==
255
||
br
==
255
)
{
continue
;
}
// 判断呼吸暂停
if
(
br
==
0
)
{
brStopSecond
++;
if
(
brStopSecond
==
breatheDuration
)
{
brStopCount
++;
brStopSecond
=
0
;
}
}
else
{
brStopSecond
=
0
;
}
// 判断呼吸率阈值,记录发生时间和当前呼吸率
if
(
breatheThresholdMax
<
br
)
{
if
(
brFast
==
0
)
{
brFast
=
br
;
}
brFastSecond
++;
if
(
brFastSecond
==
breatheDuration
)
{
brFastCount
++;
brFastSecond
=
0
;
}
}
else
{
brFastSecond
=
0
;
}
if
(
br
<
breatheThresholdMin
)
{
if
(
brSlow
==
0
)
{
brSlow
=
br
;
}
brSlowSecond
++;
if
(
brSlowSecond
==
breatheDuration
)
{
brSlowCount
++;
brSlowSecond
=
0
;
}
}
else
{
brSlowSecond
=
0
;
}
if
(
heartThresholdMax
<
hr
)
{
if
(
hrFast
==
0
)
{
hrFast
=
br
;
}
hrFastSecond
++;
if
(
hrFastSecond
==
heartDuration
)
{
hrFastCount
++;
hrFastSecond
=
0
;
}
}
else
{
hrFastSecond
=
0
;
}
if
(
heartThresholdMin
>
hr
)
{
if
(
hrSlow
==
0
)
{
hrSlow
=
br
;
}
hrSlowSecond
++;
if
(
hrSlowSecond
==
heartDuration
)
{
hrSlowCount
++;
hrSlowSecond
=
0
;
}
}
else
{
hrSlowSecond
=
0
;
}
}
analysisVO
.
setBrStopThreshold
(
brStopCount
);
analysisVO
.
setBrFastThreshold
(
brFastCount
);
analysisVO
.
setBrSlowThreshold
(
brSlowCount
);
analysisVO
.
setHrFastThreshold
(
hrFastCount
);
analysisVO
.
setHrSlowThreshold
(
hrSlowCount
);
statisticsMap
.
put
(
entry
.
getKey
(),
analysisVO
);
}
TreeMap
<
String
,
AnalysisVO
>
treeMap
=
new
TreeMap
<>(
statisticsMap
);
totalMap
.
putAll
(
treeMap
);
statisticsMap
.
clear
();
treeMap
.
clear
();
}
if
(
totalMap
.
isEmpty
())
{
continue
;
}
// 呼吸暂停
int
apneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getApneaTime
());
int
apneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getApneaThreshold
());
BigDecimal
apneaRate
=
new
BigDecimal
(
apneaThreshold
);
// 呼吸过速
int
tachypneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachypneaTime
());
int
tachypneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachypneaThreshold
());
BigDecimal
tachypneaRate
=
new
BigDecimal
(
tachypneaThreshold
);
// 呼吸过缓
int
bradypneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradypneaTime
());
int
bradypneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradypneaThreshold
());
BigDecimal
bradypneaRate
=
new
BigDecimal
(
bradypneaThreshold
);
// 心率过缓
int
bradycardiaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradycardiaTime
());
int
bradycardiaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradycardiaThreshold
());
BigDecimal
bradycardiaRate
=
new
BigDecimal
(
bradycardiaThreshold
);
// 心率过速
int
tachycardiaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachycardiaTime
());
int
tachycardiaComparison
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachycardiaThreshold
());
BigDecimal
tachycardiaRate
=
new
BigDecimal
(
tachycardiaComparison
);
// 呼吸疾病报告
int
brStopCount
=
0
;
int
brFastCount
=
0
;
int
brSlowCount
=
0
;
int
hrFastCount
=
0
;
int
hrSlowCount
=
0
;
// 计算异常的信息,并且统计异常的次数
List
<
BreatheAbnormalVO
>
breatheAbnormalVOList
=
Lists
.
newArrayList
();
for
(
Map
.
Entry
<
String
,
AnalysisVO
>
entry
:
totalMap
.
entrySet
())
{
AnalysisVO
analysisVO
=
entry
.
getValue
();
if
(
analysisVO
.
getBrStopThreshold
()
>
0
)
{
brStopCount
+=
analysisVO
.
getBrStopThreshold
();
}
if
(
analysisVO
.
getBrSlowThreshold
()
>
0
)
{
brSlowCount
+=
analysisVO
.
getBrSlowThreshold
();
}
if
(
analysisVO
.
getBrFastThreshold
()
>
0
)
{
brFastCount
+=
analysisVO
.
getBrFastThreshold
();
}
if
(
analysisVO
.
getHrFastThreshold
()
>
0
)
{
hrFastCount
+=
analysisVO
.
getHrFastThreshold
();
}
if
(
analysisVO
.
getHrSlowThreshold
()
>
0
)
{
hrSlowCount
+=
analysisVO
.
getHrSlowThreshold
();
}
}
int
timeHourRange
=
24
;
if
(
StringUtils
.
isNotEmpty
(
reportStartTime
)
&&
StringUtils
.
isNotEmpty
(
reportEndTime
))
{
timeHourRange
=
Math
.
toIntExact
(
getDurationRange
(
reportStartTime
,
reportEndTime
));
}
// 判断是否满足配置的呼吸心率异常类型
BigDecimal
dayBrStopRate
=
new
BigDecimal
(
brStopCount
);
BigDecimal
dayBrSlowRate
=
new
BigDecimal
(
brSlowCount
);
BigDecimal
dayBrFastRate
=
new
BigDecimal
(
brFastCount
);
BigDecimal
dayHrFastRate
=
new
BigDecimal
(
hrFastCount
);
BigDecimal
dayHrSlowRate
=
new
BigDecimal
(
hrSlowCount
);
boolean
brStopFlag
=
false
;
boolean
brFastFlag
=
false
;
boolean
brSlowFlag
=
false
;
boolean
hrFastFlag
=
false
;
boolean
hrSlowFlag
=
false
;
boolean
normalFlag
;
if
(
dayBrStopRate
.
compareTo
(
apneaRate
)
>
0
)
{
brStopFlag
=
true
;
}
if
(
dayBrFastRate
.
compareTo
(
tachypneaRate
)
>
0
)
{
brFastFlag
=
true
;
}
if
(
dayBrSlowRate
.
compareTo
(
bradypneaRate
)
>
0
)
{
brSlowFlag
=
true
;
}
if
(
dayHrFastRate
.
compareTo
(
tachycardiaRate
)
>
0
)
{
hrFastFlag
=
true
;
}
if
(
dayHrSlowRate
.
compareTo
(
bradycardiaRate
)
>
0
)
{
hrSlowFlag
=
true
;
}
normalFlag
=
!(
hrFastFlag
||
brStopFlag
||
brFastFlag
||
brSlowFlag
||
hrSlowFlag
);
SaasDiseaseEvaluateReport
saasDiseaseEvaluateReport
=
saasDiseaseEvaluateReportService
.
getOne
(
new
QueryWrapper
<
SaasDiseaseEvaluateReport
>().
lambda
()
.
orderByDesc
(
BaseEntity:
:
getCreateBy
)
.
last
(
"limit 1"
));
String
resultContent
=
saasDiseaseEvaluateReport
.
getResultContent
();
List
<
DiseaseReportVO
>
evaluateReportList
=
JSON
.
parseArray
(
resultContent
,
DiseaseReportVO
.
class
);
DiseaseReportVO
finalReport
=
new
DiseaseReportVO
();
// 根据疾病标准配置的规则判断满足哪个区间范围
for
(
DiseaseReportVO
diseaseReportVO
:
evaluateReportList
)
{
List
<
DiseaseReportVO
.
Condition
>
conditionList
=
diseaseReportVO
.
getCondition
();
if
(
CollUtil
.
isEmpty
(
conditionList
))
{
return
result
;
}
boolean
conditionFlag
=
true
;
for
(
DiseaseReportVO
.
Condition
condition
:
conditionList
)
{
String
resultRelational
=
condition
.
getResultRelational
();
String
resultCondition
=
condition
.
getResultCondition
();
if
(
"or"
.
equals
(
resultCondition
))
{
if
(
conditionFlag
)
{
break
;
}
}
else
{
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
NORMAL
.
getCode
()))
{
conditionFlag
=
normalFlag
&&
conditionFlag
;
}
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
BREATHE_STOP
.
getCode
()))
{
conditionFlag
=
brStopFlag
&&
conditionFlag
;
}
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
BREATHE_FAST
.
getCode
()))
{
conditionFlag
=
brFastFlag
&&
conditionFlag
;
}
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
BREATHE_SLOW
.
getCode
()))
{
conditionFlag
=
brSlowFlag
&&
conditionFlag
;
}
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
HEART_FAST
.
getCode
()))
{
conditionFlag
=
hrFastFlag
&&
conditionFlag
;
}
if
(
resultCondition
.
equals
(
ConditionTypeEnum
.
HEART_SLOW
.
getCode
()))
{
conditionFlag
=
hrSlowFlag
&&
conditionFlag
;
}
}
}
if
(
conditionFlag
)
{
finalReport
=
diseaseReportVO
;
}
}
EvaluateReportVO
diseaseReport
=
saasDiseaseReportService
.
getByScore
(
Long
.
parseLong
(
finalReport
.
getScore
()));
PlatElderBreatheAnalysis
platElderBreatheAnalysis
=
new
PlatElderBreatheAnalysis
();
platElderBreatheAnalysis
.
setElderId
(
platElder
.
getId
());
platElderBreatheAnalysis
.
setAvgBreatheRate
(
String
.
valueOf
(
elderBreatheDayStat
.
getRespiratoryRateAvg
()));
platElderBreatheAnalysis
.
setAvgHeartRate
(
String
.
valueOf
(
elderBreatheDayStat
.
getHeartRateAvg
()));
platElderBreatheAnalysis
.
setBreatheScore
(
finalReport
.
getScore
());
platElderBreatheAnalysis
.
setHappenDate
(
String
.
valueOf
(
yesDate
));
platElderBreatheAnalysis
.
setTenantId
(
platElder
.
getTenantId
());
platElderBreatheAnalysis
.
setBreatheEvaluate
(
diseaseReport
==
null
?
""
:
diseaseReport
.
getEvaluate
());
platElderBreatheAnalysis
.
setOriDeviceId
(
platDevice
.
getOriDeviceId
());
// 修复数据
PlatElderBreatheAnalysis
breatheAnalysis
=
analysisMap
.
get
(
platElder
.
getId
());
if
(
breatheAnalysis
!=
null
)
{
platElderBreatheAnalysis
.
setId
(
breatheAnalysis
.
getId
());
platElderBreatheAnalysisService
.
updateById
(
platElderBreatheAnalysis
);
}
else
{
platElderBreatheAnalysisService
.
save
(
platElderBreatheAnalysis
);
}
result
.
add
(
platElderBreatheAnalysis
);
PlatElderBreatheAnalysis
platAnalysis
=
elderHeartAnalysis
(
platElder
,
breatheDayStatMap
,
yesStart
,
analysisModel
,
saasDiseaseModel
,
yesDate
,
analysisMap
,
saasDiseaseEvaluateReport
);
result
.
add
(
platAnalysis
);
}
return
result
;
}
public
Long
getDurationRange
(
String
startTime
,
String
endTime
)
{
...
...
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderDayReportDayServiceImpl.java
View file @
aa3f63ea
...
...
@@ -185,7 +185,8 @@ public class PlatElderDayReportDayServiceImpl implements PlatElderDayReportDaySe
score
.
updateAndGet
(
v
->
v
+
Long
.
parseLong
(
finalSleepScore
));
});
});
return
Long
.
parseLong
(
baseScore
)
+
score
.
get
();
Long
result
=
Long
.
parseLong
(
baseScore
)
+
score
.
get
();
return
result
.
compareTo
(
100L
)
>
0
?
100L
:
result
;
}
...
...
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