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
bb3ec1af
authored
Jan 31, 2024
by
汪志阳
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix:bug fix
parent
068b485f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
32 deletions
server-service/src/main/java/com/makeit/service/platform/elder/DeviceLogService.java
server-service/src/main/java/com/makeit/service/platform/elder/impl/DeviceLogServiceImpl.java
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderSleepServiceImpl.java
server-service/src/main/java/com/makeit/service/platform/elder/DeviceLogService.java
View file @
bb3ec1af
package
com
.
makeit
.
service
.
platform
.
elder
;
import
com.makeit.module.iot.vo.DeviceOperationLogEntity
;
import
com.makeit.module.iot.vo.analysis.AnalysisVO
;
import
com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
/**
...
...
@@ -14,7 +13,7 @@ import java.util.TreeMap;
*/
public
interface
DeviceLogService
{
void
save
(
Map
<
String
,
List
<
DeviceInfoContentBreathe
>>
minuteMap
);
void
save
(
List
<
DeviceOperationLogEntity
>
list
);
void
saveEntity
(
TreeMap
<
String
,
AnalysisVO
>
statisticsMap
,
String
id
);
...
...
server-service/src/main/java/com/makeit/service/platform/elder/impl/DeviceLogServiceImpl.java
View file @
bb3ec1af
...
...
@@ -7,17 +7,23 @@ import com.google.common.collect.Lists;
import
com.makeit.dto.SaveLogDTO
;
import
com.makeit.exception.BusinessException
;
import
com.makeit.mapper.platform.auth.PlatOrgMapper
;
import
com.makeit.module.iot.vo.DeviceOperationLogEntity
;
import
com.makeit.module.iot.vo.analysis.AnalysisVO
;
import
com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe
;
import
com.makeit.service.platform.elder.DeviceLogService
;
import
com.makeit.utils.data.convert.JsonUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.ZoneOffset
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.TreeMap
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -33,32 +39,45 @@ public class DeviceLogServiceImpl implements DeviceLogService {
@Override
public
void
save
(
Map
<
String
,
List
<
DeviceInfoContentBreathe
>>
minuteMap
)
{
if
(
CollUtil
.
isEmpty
(
minuteMap
))
{
public
void
save
(
List
<
DeviceOperationLogEntity
>
list
)
{
if
(
CollUtil
.
isEmpty
(
list
))
{
return
;
}
DateTimeFormatter
fmt
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm"
);
List
<
SaveLogDTO
>
saveList
=
new
ArrayList
<>();
minuteMap
.
forEach
((
k
,
v
)
->
{
v
.
forEach
(
value
->
{
SaveLogDTO
saveLogDTO
=
new
SaveLogDTO
();
saveLogDTO
.
setReportTime
(
LocalDateTime
.
parse
(
k
,
fmt
));
saveLogDTO
.
setCreatedTime
(
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
value
.
getTimestamp
()),
ZoneId
.
systemDefault
()));
DeviceInfoContentBreathe
.
Properties
properties
=
value
.
getProperties
();
saveLogDTO
.
setBodyMove
(
properties
.
getBodymove
());
saveLogDTO
.
setBr
(
properties
.
getBr
());
saveLogDTO
.
setDeviceId
(
value
.
getDeviceId
());
saveLogDTO
.
setHr
(
properties
.
getHr
());
saveLogDTO
.
setPerson
(
properties
.
getPerson
());
saveLogDTO
.
setMessageType
(
value
.
getMessageType
());
saveLogDTO
.
setPersonState
(
properties
.
getPersonState
());
saveList
.
add
(
saveLogDTO
);
});
list
.
forEach
(
l
->
{
SaveLogDTO
saveLogDTO
=
new
SaveLogDTO
();
long
timestamp
=
l
.
getTimestamp
();
String
time
=
formatLongTime
(
timestamp
);
saveLogDTO
.
setReportTime
(
LocalDateTime
.
parse
(
time
,
fmt
));
saveLogDTO
.
setCreatedTime
(
longToTime
(
timestamp
));
DeviceInfoContentBreathe
deviceInfoContentBreathe
=
JsonUtil
.
toObj
((
String
)
l
.
getContent
(),
DeviceInfoContentBreathe
.
class
);
DeviceInfoContentBreathe
.
Properties
properties
=
deviceInfoContentBreathe
.
getProperties
();
saveLogDTO
.
setBodyMove
(
properties
.
getBodymove
());
saveLogDTO
.
setBr
(
properties
.
getBr
());
saveLogDTO
.
setDeviceId
(
deviceInfoContentBreathe
.
getDeviceId
());
saveLogDTO
.
setHr
(
properties
.
getHr
());
saveLogDTO
.
setPerson
(
properties
.
getPerson
());
saveLogDTO
.
setMessageType
(
deviceInfoContentBreathe
.
getMessageType
());
saveLogDTO
.
setPersonState
(
properties
.
getPersonState
());
saveList
.
add
(
saveLogDTO
);
});
platOrgMapper
.
insertBatch
(
saveList
);
}
private
static
final
DateTimeFormatter
DEFAULT_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm"
);
public
static
String
formatLongTime
(
long
time
)
{
return
DEFAULT_FORMATTER
.
format
(
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
time
),
ZoneId
.
systemDefault
()));
}
private
LocalDateTime
longToTime
(
Long
longTime
)
{
return
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
longTime
),
ZoneOffset
.
of
(
"+8"
));
}
@Override
public
void
saveEntity
(
TreeMap
<
String
,
AnalysisVO
>
statisticsMap
,
String
id
)
{
List
<
AnalysisVO
>
list
=
new
ArrayList
<>();
...
...
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderSleepServiceImpl.java
View file @
bb3ec1af
...
...
@@ -47,7 +47,10 @@ import org.springframework.transaction.annotation.Transactional;
import
javax.annotation.Resource
;
import
java.time.*
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.stream.Collectors
;
...
...
@@ -117,6 +120,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
// 清醒每分钟体动是否满足要求 (每分钟体动值大于60或无人)
boolean
awakeMinuteActionFlag
=
false
;
int
noPersonCount
=
0
;
// 无人跳过计数
boolean
isLive
=
false
;
for
(
DeviceInfoContentBreathe
infoContentBreathe
:
deviceInfoContentBreathes
)
{
// 体动指数
breatheProperties
=
infoContentBreathe
.
getProperties
();
...
...
@@ -124,12 +128,19 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
int
br
=
breatheProperties
.
getBr
();
int
hr
=
breatheProperties
.
getHr
();
Integer
hasPerson
=
breatheProperties
.
getPerson
();
// 0无人,1有人
if
(
hasPerson
==
0
)
{
if
(
hasPerson
==
0
&&
!
isLive
)
{
noPersonCount
++;
isMoveBed
=
true
;
awakeMinuteActionFlag
=
true
;
// continue;
}
if
(
hasPerson
==
1
)
{
totalBr
+=
br
;
totalHr
+=
hr
;
hrBrCount
++;
isMoveBed
=
false
;
isLive
=
true
;
}
// 0和255直接跳过
if
(
breatheProperties
.
getHr
()
==
255
||
breatheProperties
.
getHr
()
==
0
)
{
noPersonCount
++;
...
...
@@ -173,11 +184,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
}
else
if
(
hr
<
minHr
)
{
minHr
=
hr
;
}
if
(
hasPerson
==
1
)
{
totalBr
+=
br
;
totalHr
+=
hr
;
hrBrCount
++;
}
}
// if (reportSize == noPersonCount) {
// // continue;
...
...
@@ -879,15 +886,17 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
PlatElder
elder
=
platElderService
.
getOne
(
new
QueryWrapper
<
PlatElder
>().
lambda
()
.
eq
(
PlatElder:
:
getBedId
,
bedId
));
// || !"1712648603580764161".equals(elder.getId())
if
(
elder
==
null
)
{
if
(
elder
==
null
||
!
"1712648603580764161"
.
equals
(
elder
.
getId
())
)
{
continue
;
}
PlatDevice
platDevice
=
platDeviceService
.
getById
(
platRoomBedDevice
.
getDeviceId
());
// || !"218A00XE2669104".equals(platDevice.getOriDeviceId())
if
(
platDevice
==
null
)
{
if
(
platDevice
==
null
||
!
"218A00XE2669104"
.
equals
(
platDevice
.
getOriDeviceId
())
)
{
continue
;
}
String
tenantId
=
elder
.
getTenantId
();
// dayHourRangeList = Lists.newArrayList("2024-01-30 09:45:00~2024-01-30 09:45:10");
for
(
String
hourRange
:
dayHourRangeList
)
{
String
[]
hourRangeArray
=
hourRange
.
split
(
"~"
);
List
<
DeviceOperationLogEntity
>
deviceOperationLogEntities
=
productDeviceService
.
getDeviceLogByTimeRange
(
platDevice
.
getOriDeviceId
(),
"reportProperty"
,
5000
,
hourRangeArray
[
0
],
hourRangeArray
[
1
]);
...
...
@@ -903,6 +912,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
return
deviceInfoContentBreathe
;
}).
collect
(
Collectors
.
toList
());
Map
<
String
,
List
<
DeviceInfoContentBreathe
>>
minuteMap
=
StreamUtil
.
groupBy
(
deviceInfoContentBreatheList
,
DeviceInfoContentBreathe:
:
getReportTime
);
deviceLogService
.
save
(
deviceOperationLogEntities
);
deviceOperationLogEntities
.
clear
();
TreeMap
<
String
,
AnalysisVO
>
statisticsMap
=
getPerMinuteData
(
minuteMap
,
analysisModel
);
if
(
CollUtil
.
isNotEmpty
(
statisticsMap
))
{
...
...
@@ -1002,7 +1012,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
return
DEFAULT_FORMATTER
.
format
(
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
time
),
ZoneId
.
systemDefault
()));
}
public
List
<
String
>
getLastDayHourRange
(
Integer
month
,
Integer
day
)
{
public
static
List
<
String
>
getLastDayHourRange
(
Integer
month
,
Integer
day
)
{
int
count
=
24
;
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
if
(
month
!=
null
&&
day
!=
null
)
{
...
...
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