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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
221 additions
and
249 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;
...
@@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.makeit.common.entity.BaseEntity
;
import
com.makeit.common.entity.BaseEntity
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.platform.elder.PlatElder
;
import
com.makeit.entity.platform.elder.PlatElder
;
...
@@ -21,8 +20,6 @@ import com.makeit.enums.report.ConditionTypeEnum;
...
@@ -21,8 +20,6 @@ import com.makeit.enums.report.ConditionTypeEnum;
import
com.makeit.mapper.platform.elder.PlatElderBreatheAnalysisMapper
;
import
com.makeit.mapper.platform.elder.PlatElderBreatheAnalysisMapper
;
import
com.makeit.module.iot.service.IotProductDeviceService
;
import
com.makeit.module.iot.service.IotProductDeviceService
;
import
com.makeit.module.iot.vo.DeviceOperationLogEntity
;
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.DiseaseReportVO
;
import
com.makeit.module.iot.vo.analysis.EvaluateReportVO
;
import
com.makeit.module.iot.vo.analysis.EvaluateReportVO
;
import
com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe
;
import
com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe
;
...
@@ -37,21 +34,22 @@ import com.makeit.service.saas.SaasSleepAnalysisModelService;
...
@@ -37,21 +34,22 @@ import com.makeit.service.saas.SaasSleepAnalysisModelService;
import
com.makeit.utils.data.convert.JsonUtil
;
import
com.makeit.utils.data.convert.JsonUtil
;
import
com.makeit.utils.data.convert.StreamUtil
;
import
com.makeit.utils.data.convert.StreamUtil
;
import
com.makeit.utils.time.LocalDateTimeUtils
;
import
com.makeit.utils.time.LocalDateTimeUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.math.BigDecimal
;
import
java.time.*
;
import
java.time.*
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
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
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -63,6 +61,7 @@ import java.util.stream.Collectors;
...
@@ -63,6 +61,7 @@ import java.util.stream.Collectors;
* @since 2023-09-15
* @since 2023-09-15
*/
*/
@Service
@Service
@Slf4j
public
class
PlatElderBreatheAnalysisServiceImpl
extends
ServiceImpl
<
PlatElderBreatheAnalysisMapper
,
PlatElderBreatheAnalysis
>
implements
PlatElderBreatheAnalysisService
{
public
class
PlatElderBreatheAnalysisServiceImpl
extends
ServiceImpl
<
PlatElderBreatheAnalysisMapper
,
PlatElderBreatheAnalysis
>
implements
PlatElderBreatheAnalysisService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PlatElderBreatheAnalysisServiceImpl
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PlatElderBreatheAnalysisServiceImpl
.
class
);
...
@@ -88,45 +87,15 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
...
@@ -88,45 +87,15 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
private
static
final
DateTimeFormatter
DEFAULT_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm"
);
private
static
final
DateTimeFormatter
DEFAULT_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm"
);
@Override
private
LocalDateTime
longToTime
(
Long
longTime
)
{
@Transactional
(
rollbackFor
=
Exception
.
class
)
return
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
longTime
),
ZoneOffset
.
of
(
"+8"
));
public
List
<
PlatElderBreatheAnalysis
>
elderHeartRespiratoryAnalysisTask
(
Integer
month
,
Integer
day
)
{
// 12-06,12-18 12-07、 12-12(70分)
LocalDate
nowDate
=
LocalDate
.
now
();
if
(
month
!=
null
&&
day
!=
null
)
{
nowDate
=
LocalDate
.
of
(
2023
,
month
,
day
);
}
LocalDate
yesDate
=
nowDate
.
minusDays
(
1
);
LocalDateTime
yesStart
=
LocalDateTimeUtils
.
getDayStart
(
yesDate
);
LocalDateTime
yesEnd
=
LocalDateTimeUtils
.
getDayEnd
(
yesDate
);
List
<
PlatElder
>
elderList
=
platElderService
.
list
(
new
QueryWrapper
<
PlatElder
>().
lambda
()
.
isNotNull
(
PlatElder:
:
getBedId
));
List
<
PlatElderBreatheAnalysis
>
result
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isEmpty
(
elderList
))
{
return
result
;
}
}
List
<
String
>
elderIdList
=
StreamUtil
.
map
(
elderList
,
BaseEntity:
:
getId
);
List
<
PlatElderBreatheDayStat
>
elderBreatheDayStatList
=
platElderBreatheDayStatService
.
list
(
new
QueryWrapper
<
PlatElderBreatheDayStat
>().
lambda
()
.
in
(
PlatElderBreatheDayStat:
:
getElderId
,
elderIdList
)
.
eq
(
PlatElderBreatheDayStat:
:
getDay
,
yesDate
));
Map
<
String
,
PlatElderBreatheDayStat
>
breatheDayStatMap
=
StreamUtil
.
toMapDep
(
elderBreatheDayStatList
,
PlatElderBreatheDayStat:
:
getElderId
);
SaasSleepAnalysisModel
analysisModel
=
saasSleepAnalysisModelService
.
getOne
(
new
QueryWrapper
<
SaasSleepAnalysisModel
>().
lambda
()
.
orderByDesc
(
BaseEntity:
:
getCreateBy
)
.
last
(
"limit 1"
));
SaasDiseaseModel
saasDiseaseModel
=
saasDiseaseModelService
.
getOne
(
new
QueryWrapper
<
SaasDiseaseModel
>().
lambda
()
.
orderByDesc
(
BaseEntity:
:
getCreateBy
)
.
last
(
"limit 1"
));
Map
<
String
,
PlatElderBreatheAnalysis
>
analysisMap
=
StreamUtil
.
toMapDep
(
platElderBreatheAnalysisService
.
list
(
Wrappers
.<
PlatElderBreatheAnalysis
>
lambdaQuery
()
.
in
(
PlatElderBreatheAnalysis:
:
getElderId
,
elderIdList
)
.
eq
(
PlatElderBreatheAnalysis:
:
getHappenDate
,
yesDate
)),
PlatElderBreatheAnalysis:
:
getElderId
);
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
breatheThresholdMin
=
Integer
.
parseInt
(
analysisModel
.
getBreatheThresholdMin
());
int
breatheThresholdMax
=
Integer
.
parseInt
(
analysisModel
.
getBreatheThresholdMax
());
int
breatheThresholdMax
=
Integer
.
parseInt
(
analysisModel
.
getBreatheThresholdMax
());
...
@@ -136,23 +105,36 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
...
@@ -136,23 +105,36 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
int
heartThresholdMin
=
Integer
.
parseInt
(
analysisModel
.
getHeartThresholdMin
());
int
heartThresholdMin
=
Integer
.
parseInt
(
analysisModel
.
getHeartThresholdMin
());
int
heartThresholdMax
=
Integer
.
parseInt
(
analysisModel
.
getHeartThresholdMax
());
int
heartThresholdMax
=
Integer
.
parseInt
(
analysisModel
.
getHeartThresholdMax
());
int
heartDuration
=
Integer
.
parseInt
(
analysisModel
.
getHeartDuration
());
int
heartDuration
=
Integer
.
parseInt
(
analysisModel
.
getHeartDuration
());
for
(
PlatElder
platElder
:
elderList
)
{
PlatElderBreatheDayStat
elderBreatheDayStat
=
breatheDayStatMap
.
get
(
platElder
.
getId
());
PlatElderBreatheDayStat
elderBreatheDayStat
=
breatheDayStatMap
.
get
(
platElder
.
getId
());
if
(
elderBreatheDayStat
==
null
)
{
if
(
elderBreatheDayStat
==
null
)
{
continue
;
return
new
PlatElderBreatheAnalysis
()
;
}
}
PlatDevice
platDevice
=
platElderRealTimeService
.
getBreathDevice
(
platElder
.
getId
(),
null
);
PlatDevice
platDevice
=
platElderRealTimeService
.
getBreathDevice
(
platElder
.
getId
(),
null
);
if
(
platDevice
==
null
)
{
if
(
platDevice
==
null
)
{
continue
;
return
new
PlatElderBreatheAnalysis
()
;
}
}
List
<
String
>
dayHourRange
=
getLastDayHourRange
(
yesStart
);
List
<
String
>
dayHourRange
=
getLastDayHourRange
(
yesStart
);
TreeMap
<
String
,
AnalysisVO
>
totalMap
=
new
TreeMap
<>();
// 呼吸暂停
String
reportStartTime
=
""
;
AtomicInteger
brStopCount
=
new
AtomicInteger
(
0
);
String
reportEndTime
=
""
;
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
)
{
for
(
String
hourRange
:
dayHourRange
)
{
String
[]
hourRangeArray
=
hourRange
.
split
(
"~"
);
String
[]
hourRangeArray
=
hourRange
.
split
(
"~"
);
List
<
DeviceOperationLogEntity
>
deviceOperationLogEntities
=
productDeviceService
.
getDeviceLogByTimeRange
(
platDevice
.
getOriDeviceId
(),
"reportProperty"
,
5000
,
hourRangeArray
[
0
],
hourRangeArray
[
1
]);
List
<
DeviceOperationLogEntity
>
deviceOperationLogEntities
=
productDeviceService
.
getDeviceLogByTimeRange
(
platDevice
.
getOriDeviceId
(),
"reportProperty"
,
5000
,
hourRangeArray
[
0
],
hourRangeArray
[
1
]);
if
(
CollectionUtils
.
isEmpty
(
deviceOperationLogEntities
))
{
if
(
CollectionUtils
.
isEmpty
(
deviceOperationLogEntities
))
{
continue
;
continue
;
}
}
...
@@ -160,217 +142,160 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
...
@@ -160,217 +142,160 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
.
filter
(
deviceOperationLogEntity
->
deviceOperationLogEntity
.
getType
().
contains
(
"reportProperty"
))
.
filter
(
deviceOperationLogEntity
->
deviceOperationLogEntity
.
getType
().
contains
(
"reportProperty"
))
.
map
(
deviceOperationLogEntity
->
{
.
map
(
deviceOperationLogEntity
->
{
DeviceInfoContentBreathe
deviceInfoContentBreathe
=
JsonUtil
.
toObj
((
String
)
deviceOperationLogEntity
.
getContent
(),
DeviceInfoContentBreathe
.
class
);
DeviceInfoContentBreathe
deviceInfoContentBreathe
=
JsonUtil
.
toObj
((
String
)
deviceOperationLogEntity
.
getContent
(),
DeviceInfoContentBreathe
.
class
);
assert
deviceInfoContentBreathe
!=
null
;
deviceInfoContentBreathe
.
setReportTime
(
formatLongTime
(
deviceInfoContentBreathe
.
getTimestamp
()));
deviceInfoContentBreathe
.
setReportTime
(
formatLongTime
(
deviceInfoContentBreathe
.
getTimestamp
()));
return
deviceInfoContentBreathe
;
return
deviceInfoContentBreathe
;
})
})
.
collect
(
Collectors
.
toList
());
.
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
;
// 呼吸过速
AtomicBoolean
existHrFast
=
new
AtomicBoolean
(
false
);
int
brFastCount
=
0
;
AtomicBoolean
existHrSlow
=
new
AtomicBoolean
(
false
);
int
brFastSecond
=
0
;
AtomicBoolean
existBrFast
=
new
AtomicBoolean
(
false
);
int
brFast
=
0
;
AtomicBoolean
existBrSlow
=
new
AtomicBoolean
(
false
);
AtomicBoolean
existBrStop
=
new
AtomicBoolean
(
false
);
// 呼吸过缓
int
brSlowCount
=
0
;
deviceInfoContentBreatheList
.
forEach
(
deviceInfo
->
{
int
brSlowSecond
=
0
;
DeviceInfoContentBreathe
.
Properties
deviceProperties
=
deviceInfo
.
getProperties
();
int
brSlow
=
0
;
int
br
=
deviceProperties
.
getBr
();
int
hr
=
deviceProperties
.
getHr
();
// 心率过速
Integer
hasPerson
=
deviceProperties
.
getPerson
();
// 0无人,1有人
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设备误报直接跳过
// 0和255设备误报直接跳过
if
(
hr
==
255
||
br
==
255
)
{
if
(
hasPerson
==
0
||
hr
==
255
||
br
==
255
)
{
continue
;
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
)
{
if
(
br
==
0
)
{
brStopSecond
++;
long
firstStopSecond
=
brStopSecond
.
get
();
if
(
brStopSecond
==
breatheDuration
)
{
if
(
firstStopSecond
==
0
)
{
brStopCount
++;
log
.
info
(
"第一次呼吸暂停的时间:{}"
,
longToTime
(
timestamp
));
brStopSecond
=
0
;
brStopSecond
.
set
(
timestamp
);
}
}
}
else
{
if
(
firstStopSecond
!=
0
&&
(
timestamp
-
firstStopSecond
)
/
1000
>=
breatheDuration
)
{
brStopSecond
=
0
;
// 避免每10s生成一次统计的方式,切换状态后重新计算
}
if
(!
existBrStop
.
get
())
{
log
.
info
(
"第一次呼吸暂停持续时间满足:{}:now:{}"
,
breatheDuration
,
longToTime
(
timestamp
));
// 判断呼吸率阈值,记录发生时间和当前呼吸率
brStopCount
.
getAndIncrement
();
if
(
breatheThresholdMax
<
br
)
{
existBrStop
.
set
(
true
);
if
(
brFast
==
0
)
{
}
brFast
=
br
;
}
}
brFastSecond
++;
brFastSecond
.
set
(
0
);
if
(
brFastSecond
==
breatheDuration
)
{
brSlowSecond
.
set
(
0
);
brFastCount
++;
existBrFast
.
set
(
false
);
brFastSecond
=
0
;
existBrSlow
.
set
(
false
);
}
}
else
if
(
breatheThresholdMax
<
br
)
{
}
else
{
//呼吸过快
brFastSecond
=
0
;
long
firstFastBr
=
brFastSecond
.
get
();
}
if
(
firstFastBr
==
0
)
{
log
.
info
(
"第一次呼吸:{},fast大于阈值:{},的时间:{}"
,
br
,
breatheThresholdMax
,
longToTime
(
timestamp
));
if
(
br
<
breatheThresholdMin
)
{
brFastSecond
.
set
(
timestamp
);
if
(
brSlow
==
0
)
{
}
brSlow
=
br
;
if
(
firstFastBr
!=
0
&&
(
timestamp
-
firstFastBr
)
/
1000
>=
breatheDuration
)
{
}
if
(!
existBrFast
.
get
())
{
brSlowSecond
++;
log
.
info
(
"第一次呼吸:{},fast持续时间满足:{}:now:{}"
,
br
,
breatheDuration
,
longToTime
(
timestamp
));
if
(
brSlowSecond
==
breatheDuration
)
{
brFastCount
.
getAndIncrement
();
brSlowCount
++;
existBrFast
.
set
(
true
);
brSlowSecond
=
0
;
}
}
}
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
{
}
else
{
brSlowSecond
=
0
;
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
)
{
if
(
heartThresholdMax
<
hr
)
{
if
(
hrFast
==
0
)
{
long
firstHrMax
=
hrFastSecond
.
get
();
hrFast
=
br
;
if
(
firstHrMax
==
0
)
{
}
log
.
info
(
"第一次心率:{},max大于阈值:{},的时间:{}"
,
hr
,
heartThresholdMax
,
longToTime
(
timestamp
));
hrFastSecond
++;
hrFastSecond
.
set
(
timestamp
);
if
(
hrFastSecond
==
heartDuration
)
{
}
hrFastCount
++;
if
(
firstHrMax
!=
0
&&
(
timestamp
-
firstHrMax
)
/
1000
>=
heartDuration
)
{
hrFastSecond
=
0
;
if
(!
existHrFast
.
get
())
{
}
log
.
info
(
"第一次心率:{},max持续时间满足:{}:now:{}"
,
hr
,
heartDuration
,
longToTime
(
timestamp
));
}
else
{
hrFastCount
.
getAndIncrement
();
hrFastSecond
=
0
;
existHrFast
.
set
(
true
);
}
}
}
if
(
heartThresholdMin
>
hr
)
{
hrSlowSecond
.
set
(
0
);
if
(
hrSlow
==
0
)
{
existHrSlow
.
set
(
false
);
hrSlow
=
br
;
}
else
if
(
heartThresholdMin
>
hr
)
{
}
// 心率过慢
hrSlowSecond
++;
long
firstHrMin
=
hrSlowSecond
.
get
();
if
(
hrSlowSecond
==
heartDuration
)
{
if
(
firstHrMin
==
0
)
{
hrSlowCount
++;
log
.
info
(
"第一次心率:{},min小于阈值:{},的时间:{}"
,
hr
,
heartThresholdMin
,
longToTime
(
timestamp
));
hrSlowSecond
=
0
;
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
));
}
});
}
}
}
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
apneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getApneaTime
());
int
apneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getApneaThreshold
());
int
apneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getApneaThreshold
());
BigDecimal
apneaRate
=
new
BigDecimal
(
apneaThreshold
);
// 呼吸过速
// 呼吸过速
int
tachypneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachypneaTime
());
int
tachypneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachypneaTime
());
int
tachypneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachypneaThreshold
());
int
tachypneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachypneaThreshold
());
BigDecimal
tachypneaRate
=
new
BigDecimal
(
tachypneaThreshold
);
// 呼吸过缓
// 呼吸过缓
int
bradypneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradypneaTime
());
int
bradypneaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradypneaTime
());
int
bradypneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradypneaThreshold
());
int
bradypneaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradypneaThreshold
());
BigDecimal
bradypneaRate
=
new
BigDecimal
(
bradypneaThreshold
);
// 心率过缓
// 心率过缓
int
bradycardiaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradycardiaTime
());
int
bradycardiaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradycardiaTime
());
int
bradycardiaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradycardiaThreshold
());
int
bradycardiaThreshold
=
Integer
.
parseInt
(
saasDiseaseModel
.
getBradycardiaThreshold
());
BigDecimal
bradycardiaRate
=
new
BigDecimal
(
bradycardiaThreshold
);
// 心率过速
// 心率过速
int
tachycardiaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachycardiaTime
());
int
tachycardiaTime
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachycardiaTime
());
int
tachycardiaComparison
=
Integer
.
parseInt
(
saasDiseaseModel
.
getTachycardiaThreshold
());
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
brStopFlag
=
false
;
boolean
brFastFlag
=
false
;
boolean
brFastFlag
=
false
;
boolean
brSlowFlag
=
false
;
boolean
brSlowFlag
=
false
;
...
@@ -378,36 +303,30 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
...
@@ -378,36 +303,30 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
boolean
hrSlowFlag
=
false
;
boolean
hrSlowFlag
=
false
;
boolean
normalFlag
;
boolean
normalFlag
;
if
(
dayBrStopRate
.
compareTo
(
apneaRate
)
>
0
)
{
if
(
brStopCount
.
get
()
>
apneaThreshold
)
{
brStopFlag
=
true
;
brStopFlag
=
true
;
}
}
if
(
dayBrFastRate
.
compareTo
(
tachypneaRate
)
>
0
)
{
if
(
brFastCount
.
get
()
>
tachypneaThreshold
)
{
brFastFlag
=
true
;
brFastFlag
=
true
;
}
}
if
(
dayBrSlowRate
.
compareTo
(
bradypneaRate
)
>
0
)
{
if
(
brSlowCount
.
get
()
>
bradypneaThreshold
)
{
brSlowFlag
=
true
;
brSlowFlag
=
true
;
}
}
if
(
dayHrFastRate
.
compareTo
(
tachycardiaRate
)
>
0
)
{
if
(
hrFastCount
.
get
()
>
tachycardiaComparison
)
{
hrFastFlag
=
true
;
hrFastFlag
=
true
;
}
}
if
(
dayHrSlowRate
.
compareTo
(
bradycardiaRate
)
>
0
)
{
if
(
hrSlowCount
.
get
()
>
bradycardiaThreshold
)
{
hrSlowFlag
=
true
;
hrSlowFlag
=
true
;
}
}
normalFlag
=
!(
hrFastFlag
||
brStopFlag
||
brFastFlag
||
brSlowFlag
||
hrSlowFlag
);
normalFlag
=
!(
hrFastFlag
||
brStopFlag
||
brFastFlag
||
brSlowFlag
||
hrSlowFlag
);
SaasDiseaseEvaluateReport
saasDiseaseEvaluateReport
=
saasDiseaseEvaluateReportService
.
getOne
(
new
QueryWrapper
<
SaasDiseaseEvaluateReport
>().
lambda
()
List
<
DiseaseReportVO
>
evaluateReportList
=
JSON
.
parseArray
(
saasDiseaseEvaluateReport
.
getResultContent
(),
DiseaseReportVO
.
class
);
.
orderByDesc
(
BaseEntity:
:
getCreateBy
)
.
last
(
"limit 1"
));
String
resultContent
=
saasDiseaseEvaluateReport
.
getResultContent
();
List
<
DiseaseReportVO
>
evaluateReportList
=
JSON
.
parseArray
(
resultContent
,
DiseaseReportVO
.
class
);
DiseaseReportVO
finalReport
=
new
DiseaseReportVO
();
DiseaseReportVO
finalReport
=
new
DiseaseReportVO
();
// 根据疾病标准配置的规则判断满足哪个区间范围
// 根据疾病标准配置的规则判断满足哪个区间范围
for
(
DiseaseReportVO
diseaseReportVO
:
evaluateReportList
)
{
for
(
DiseaseReportVO
diseaseReportVO
:
evaluateReportList
)
{
List
<
DiseaseReportVO
.
Condition
>
conditionList
=
diseaseReportVO
.
getCondition
();
List
<
DiseaseReportVO
.
Condition
>
conditionList
=
diseaseReportVO
.
getCondition
();
if
(
CollUtil
.
isEmpty
(
conditionList
))
{
if
(
CollUtil
.
isEmpty
(
conditionList
))
{
return
result
;
continue
;
}
}
boolean
conditionFlag
=
true
;
boolean
conditionFlag
=
true
;
...
@@ -443,8 +362,13 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
...
@@ -443,8 +362,13 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
finalReport
=
diseaseReportVO
;
finalReport
=
diseaseReportVO
;
}
}
}
}
long
scoreLong
=
Long
.
parseLong
(
finalReport
.
getScore
());
if
(
scoreLong
>
100
)
{
scoreLong
=
100
;
finalReport
.
setScore
(
"100"
);
}
EvaluateReportVO
diseaseReport
=
saasDiseaseReportService
.
getByScore
(
Long
.
parseLong
(
finalReport
.
getScore
())
);
EvaluateReportVO
diseaseReport
=
saasDiseaseReportService
.
getByScore
(
scoreLong
);
PlatElderBreatheAnalysis
platElderBreatheAnalysis
=
new
PlatElderBreatheAnalysis
();
PlatElderBreatheAnalysis
platElderBreatheAnalysis
=
new
PlatElderBreatheAnalysis
();
platElderBreatheAnalysis
.
setElderId
(
platElder
.
getId
());
platElderBreatheAnalysis
.
setElderId
(
platElder
.
getId
());
...
@@ -464,11 +388,58 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
...
@@ -464,11 +388,58 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
}
else
{
}
else
{
platElderBreatheAnalysisService
.
save
(
platElderBreatheAnalysis
);
platElderBreatheAnalysisService
.
save
(
platElderBreatheAnalysis
);
}
}
result
.
add
(
platElderBreatheAnalysis
)
;
return
platElderBreatheAnalysis
;
}
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
List
<
PlatElderBreatheAnalysis
>
elderHeartRespiratoryAnalysisTask
(
Integer
month
,
Integer
day
)
{
// 12-06,12-18 12-07、 12-12(70分)
LocalDate
nowDate
=
LocalDate
.
now
();
if
(
month
!=
null
&&
day
!=
null
)
{
nowDate
=
LocalDate
.
of
(
2023
,
month
,
day
);
}
LocalDate
yesDate
=
nowDate
.
minusDays
(
1
);
LocalDateTime
yesStart
=
LocalDateTimeUtils
.
getDayStart
(
yesDate
);
LocalDateTime
yesEnd
=
LocalDateTimeUtils
.
getDayEnd
(
yesDate
);
List
<
PlatElder
>
elderList
=
platElderService
.
list
(
new
QueryWrapper
<
PlatElder
>().
lambda
()
.
isNotNull
(
PlatElder:
:
getBedId
));
List
<
PlatElderBreatheAnalysis
>
result
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isEmpty
(
elderList
))
{
return
result
;
return
result
;
}
List
<
String
>
elderIdList
=
StreamUtil
.
map
(
elderList
,
BaseEntity:
:
getId
);
List
<
PlatElderBreatheDayStat
>
elderBreatheDayStatList
=
platElderBreatheDayStatService
.
list
(
new
QueryWrapper
<
PlatElderBreatheDayStat
>().
lambda
()
.
in
(
PlatElderBreatheDayStat:
:
getElderId
,
elderIdList
)
.
eq
(
PlatElderBreatheDayStat:
:
getDay
,
yesDate
));
Map
<
String
,
PlatElderBreatheDayStat
>
breatheDayStatMap
=
StreamUtil
.
toMapDep
(
elderBreatheDayStatList
,
PlatElderBreatheDayStat:
:
getElderId
);
SaasSleepAnalysisModel
analysisModel
=
saasSleepAnalysisModelService
.
getOne
(
new
QueryWrapper
<
SaasSleepAnalysisModel
>().
lambda
()
.
orderByDesc
(
BaseEntity:
:
getCreateBy
)
.
last
(
"limit 1"
));
SaasDiseaseModel
saasDiseaseModel
=
saasDiseaseModelService
.
getOne
(
new
QueryWrapper
<
SaasDiseaseModel
>().
lambda
()
.
orderByDesc
(
BaseEntity:
:
getCreateBy
)
.
last
(
"limit 1"
));
Map
<
String
,
PlatElderBreatheAnalysis
>
analysisMap
=
StreamUtil
.
toMapDep
(
platElderBreatheAnalysisService
.
list
(
Wrappers
.<
PlatElderBreatheAnalysis
>
lambdaQuery
()
.
in
(
PlatElderBreatheAnalysis:
:
getElderId
,
elderIdList
)
.
eq
(
PlatElderBreatheAnalysis:
:
getHappenDate
,
yesDate
)),
PlatElderBreatheAnalysis:
:
getElderId
);
SaasDiseaseEvaluateReport
saasDiseaseEvaluateReport
=
saasDiseaseEvaluateReportService
.
getOne
(
new
QueryWrapper
<
SaasDiseaseEvaluateReport
>().
lambda
().
orderByDesc
(
BaseEntity:
:
getCreateBy
)
.
last
(
"limit 1"
));
for
(
PlatElder
platElder
:
elderList
)
{
PlatElderBreatheAnalysis
platAnalysis
=
elderHeartAnalysis
(
platElder
,
breatheDayStatMap
,
yesStart
,
analysisModel
,
saasDiseaseModel
,
yesDate
,
analysisMap
,
saasDiseaseEvaluateReport
);
result
.
add
(
platAnalysis
);
}
return
result
;
}
}
public
Long
getDurationRange
(
String
startTime
,
String
endTime
)
{
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
...
@@ -185,7 +185,8 @@ public class PlatElderDayReportDayServiceImpl implements PlatElderDayReportDaySe
score
.
updateAndGet
(
v
->
v
+
Long
.
parseLong
(
finalSleepScore
));
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