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
85f584d0
authored
Oct 07, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix:呼吸心率接口
parent
a8424457
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
11 deletions
server-common/src/main/java/com/makeit/module/iot/service/IotCommonService.java
server-common/src/main/java/com/makeit/module/iot/service/IotProductDeviceService.java
server-common/src/main/java/com/makeit/module/iot/vo/analysis/AnalysisVO.java
server-module/src/main/java/com/makeit/module/controller/elder/PlatElderSleepController.java
server-service/src/main/java/com/makeit/service/platform/elder/PlatElderSleepService.java
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderSleepServiceImpl.java
server-common/src/main/java/com/makeit/module/iot/service/IotCommonService.java
View file @
85f584d0
...
@@ -83,9 +83,20 @@ public class IotCommonService {
...
@@ -83,9 +83,20 @@ public class IotCommonService {
* ]
* ]
* @return
* @return
*/
*/
public
static
IotQueryParam
buildQueryParam
(
int
pageSize
)
{
public
static
IotQueryParam
buildQueryParam
(
int
page
Index
,
int
page
Size
)
{
IotQueryParam
iotQueryParam
=
new
IotQueryParam
();
IotQueryParam
iotQueryParam
=
new
IotQueryParam
();
iotQueryParam
.
setPageIndex
(
0
);
iotQueryParam
.
setPageIndex
(
pageIndex
);
iotQueryParam
.
setPageSize
(
pageSize
);
iotQueryParam
.
setSorts
(
buildSort
(
"timestamp"
));
iotQueryParam
.
setTerms
(
Lists
.
newArrayList
());
return
iotQueryParam
;
}
public
static
IotQueryParam
buildQueryParamByPageIndex
(
int
pageIndex
,
int
pageSize
)
{
IotQueryParam
iotQueryParam
=
new
IotQueryParam
();
iotQueryParam
.
setPageIndex
(
pageIndex
);
iotQueryParam
.
setPageSize
(
pageSize
);
iotQueryParam
.
setPageSize
(
pageSize
);
iotQueryParam
.
setSorts
(
buildSort
(
"timestamp"
));
iotQueryParam
.
setSorts
(
buildSort
(
"timestamp"
));
...
...
server-common/src/main/java/com/makeit/module/iot/service/IotProductDeviceService.java
View file @
85f584d0
package
com
.
makeit
.
module
.
iot
.
service
;
package
com
.
makeit
.
module
.
iot
.
service
;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DateUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
...
@@ -20,14 +22,13 @@ import com.makeit.utils.data.convert.StreamUtil;
...
@@ -20,14 +22,13 @@ import com.makeit.utils.data.convert.StreamUtil;
import
com.makeit.utils.old.StringUtils
;
import
com.makeit.utils.old.StringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.RandomUtils
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.time.Duration
;
import
java.time.*
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
/**
* iot产品设备相关接口
* iot产品设备相关接口
...
@@ -40,6 +41,7 @@ public class IotProductDeviceService extends IotCommonService {
...
@@ -40,6 +41,7 @@ public class IotProductDeviceService extends IotCommonService {
public
static
final
String
REPORT_PROPERTY
=
"reportProperty"
;
public
static
final
String
REPORT_PROPERTY
=
"reportProperty"
;
private
static
final
DateTimeFormatter
DEFAULT_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm"
);
/**
/**
* 获取设备信息
* 获取设备信息
*/
*/
...
@@ -47,7 +49,7 @@ public class IotProductDeviceService extends IotCommonService {
...
@@ -47,7 +49,7 @@ public class IotProductDeviceService extends IotCommonService {
String
url
=
iotUrl
+
DEVICE_PREFIX_URL
+
"_query"
;
String
url
=
iotUrl
+
DEVICE_PREFIX_URL
+
"_query"
;
// 条件可以自己改
// 条件可以自己改
IotQueryParam
iotQueryParam
=
buildQueryParam
(
10
);
IotQueryParam
iotQueryParam
=
buildQueryParam
(
0
,
10
);
String
body
=
JsonUtil
.
toJson
(
iotQueryParam
);
String
body
=
JsonUtil
.
toJson
(
iotQueryParam
);
...
@@ -129,14 +131,68 @@ public class IotProductDeviceService extends IotCommonService {
...
@@ -129,14 +131,68 @@ public class IotProductDeviceService extends IotCommonService {
}
}
public
List
<
String
>
getLastDayHourRange
(
LocalDateTime
startDateTime
)
{
int
count
=
24
;
List
<
String
>
list
=
Lists
.
newArrayList
();
String
startTime
;
String
endTime
;
for
(
int
i
=
count
;
i
>
0
;
i
--)
{
startTime
=
DateUtil
.
format
(
startDateTime
.
minusHours
(
i
),
DatePattern
.
NORM_DATETIME_PATTERN
);
endTime
=
DateUtil
.
format
(
startDateTime
.
minusHours
(
i
-
1
),
DatePattern
.
NORM_DATETIME_PATTERN
);
list
.
add
(
startTime
+
"~"
+
endTime
);
}
return
list
;
}
public
List
<
DeviceInfoContentBreathe
>
getDeviceLogByTimeRangeBreathe
(
String
deviceId
,
int
pageSize
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
public
List
<
DeviceInfoContentBreathe
>
getDeviceLogByTimeRangeBreathe
(
String
deviceId
,
int
pageSize
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
DateTimeFormatter
dateTimeFormatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
List
<
String
>
lastDayHourRange
=
getLastDayHourRange
(
startTime
);
for
(
String
hour
:
lastDayHourRange
)
{
String
[]
hourRangeArray
=
hour
.
split
(
"~"
);
List
<
DeviceOperationLogEntity
>
deviceOperationLogEntities
=
getDeviceLogByTimeRange
(
deviceId
,
REPORT_PROPERTY
,
5000
,
hourRangeArray
[
0
],
hourRangeArray
[
1
]);
List
<
DeviceInfoContentBreathe
>
deviceInfoContentBreatheList
=
StreamUtil
.
map
(
deviceOperationLogEntities
,
e
->
JsonUtil
.
toObj
((
String
)
e
.
getContent
(),
DeviceInfoContentBreathe
.
class
));
}
long
minute
=
1440
;
List
<
DeviceInfoContentBreathe
>
breatheList
=
Lists
.
newArrayList
();
DeviceInfoContentBreathe
deviceInfoContentBreathe
;
for
(
long
i
=
1
;
i
<=
minute
;
i
++)
{
int
brRandomLong
=
RandomUtils
.
nextInt
(
11
,
28
);
int
hrRandomLong
=
RandomUtils
.
nextInt
(
55
,
125
);
int
movebodyRandomLong
=
RandomUtils
.
nextInt
(
40
,
90
);
deviceInfoContentBreathe
=
new
DeviceInfoContentBreathe
();
LocalDateTime
localDateTime
=
startTime
.
plusMinutes
(
i
);
long
timeStamp
=
localDateTime
.
toEpochSecond
(
ZoneOffset
.
ofHours
(
8
));
deviceInfoContentBreathe
.
setTimestamp
(
timeStamp
);
DeviceInfoContentBreathe
.
Properties
properties
=
new
DeviceInfoContentBreathe
.
Properties
();
properties
.
setBr
(
brRandomLong
);
properties
.
setHr
(
hrRandomLong
);
properties
.
setBodymove
(
movebodyRandomLong
);
deviceInfoContentBreathe
.
setProperties
(
properties
);
breatheList
.
add
(
deviceInfoContentBreathe
);
}
/*
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
List<DeviceOperationLogEntity> deviceOperationLogEntityList = getDeviceLogByTimeRange(deviceId, REPORT_PROPERTY, pageSize, dateTimeFormatter.format(startTime), dateTimeFormatter.format(endTime));
List<DeviceOperationLogEntity> deviceOperationLogEntityList = getDeviceLogByTimeRange(deviceId, REPORT_PROPERTY, pageSize, dateTimeFormatter.format(startTime), dateTimeFormatter.format(endTime));
List
<
DeviceInfoContentBreathe
>
deviceInfoContentBreatheList
=
StreamUtil
.
map
(
deviceOperationLogEntityList
,
e
->
JsonUtil
.
toObj
((
String
)
e
.
getContent
(),
DeviceInfoContentBreathe
.
class
));
List<DeviceInfoContentBreathe> deviceInfoContentBreatheList = deviceOperationLogEntityList.stream()
.filter(deviceOperationLogEntity -> deviceOperationLogEntity.getType().contains(REPORT_PROPERTY))
.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);
for (Map.Entry<String, List<DeviceInfoContentBreathe>> entry : minuteMap.entrySet()) {
}*/
return
breatheList
;
}
return
deviceInfoContentBreatheList
;
public
static
String
formatLongTime
(
long
time
)
{
return
DEFAULT_FORMATTER
.
format
(
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
time
),
ZoneId
.
systemDefault
()));
}
}
public
List
<
DeviceInfoContentSpace
>
getDeviceLogByTimeRangeSpace
(
String
deviceId
,
int
pageSize
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
public
List
<
DeviceInfoContentSpace
>
getDeviceLogByTimeRangeSpace
(
String
deviceId
,
int
pageSize
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
...
@@ -217,7 +273,7 @@ public class IotProductDeviceService extends IotCommonService {
...
@@ -217,7 +273,7 @@ public class IotProductDeviceService extends IotCommonService {
* @return
* @return
*/
*/
public
List
<
DeviceOperationLogEntity
>
getDeviceLogByTimeRange
(
String
deviceId
,
String
typeValue
,
int
pageSize
,
String
startTime
,
String
endTime
)
{
public
List
<
DeviceOperationLogEntity
>
getDeviceLogByTimeRange
(
String
deviceId
,
String
typeValue
,
int
pageSize
,
String
startTime
,
String
endTime
)
{
IotQueryParam
iotQueryParam
=
buildQueryParam
(
pageSize
);
IotQueryParam
iotQueryParam
=
buildQueryParam
(
0
,
pageSize
);
List
<
Term
>
terms
=
Lists
.
newArrayList
();
List
<
Term
>
terms
=
Lists
.
newArrayList
();
Term
term1
=
Term
.
builder
()
Term
term1
=
Term
.
builder
()
...
@@ -283,7 +339,7 @@ public class IotProductDeviceService extends IotCommonService {
...
@@ -283,7 +339,7 @@ public class IotProductDeviceService extends IotCommonService {
*/
*/
public
List
<
DeviceOperationLogEntity
>
getDeviceLog
(
String
deviceId
,
int
pageSize
,
String
typeValue
)
{
public
List
<
DeviceOperationLogEntity
>
getDeviceLog
(
String
deviceId
,
int
pageSize
,
String
typeValue
)
{
String
url
=
iotUrl
+
DEVICE_PREFIX_URL
+
deviceId
+
"/logs"
;
String
url
=
iotUrl
+
DEVICE_PREFIX_URL
+
deviceId
+
"/logs"
;
IotQueryParam
iotQueryParam
=
buildQueryParam
(
pageSize
);
IotQueryParam
iotQueryParam
=
buildQueryParam
(
0
,
pageSize
);
if
(
StringUtils
.
isNotEmpty
(
typeValue
))
{
if
(
StringUtils
.
isNotEmpty
(
typeValue
))
{
List
<
Term
>
terms
=
Lists
.
newArrayList
();
List
<
Term
>
terms
=
Lists
.
newArrayList
();
Term
term
=
Term
.
builder
()
Term
term
=
Term
.
builder
()
...
...
server-common/src/main/java/com/makeit/module/iot/vo/analysis/AnalysisVO.java
View file @
85f584d0
...
@@ -7,8 +7,12 @@ public class AnalysisVO {
...
@@ -7,8 +7,12 @@ public class AnalysisVO {
private
Integer
totalHr
;
private
Integer
totalHr
;
private
Integer
avgHr
;
private
Integer
avgHr
;
private
Integer
maxHr
;
private
Integer
minHr
;
private
Integer
totalBr
;
private
Integer
totalBr
;
private
Integer
avgBr
;
private
Integer
avgBr
;
private
Integer
maxBr
;
private
Integer
minBr
;
private
Integer
actionCount
=
0
;
// 体动次数
private
Integer
actionCount
=
0
;
// 体动次数
private
Integer
turnedCount
=
0
;
// 翻身次数
private
Integer
turnedCount
=
0
;
// 翻身次数
...
...
server-module/src/main/java/com/makeit/module/controller/elder/PlatElderSleepController.java
View file @
85f584d0
...
@@ -5,6 +5,7 @@ import com.makeit.common.response.ApiResponseEntity;
...
@@ -5,6 +5,7 @@ import com.makeit.common.response.ApiResponseEntity;
import
com.makeit.common.response.ApiResponseUtils
;
import
com.makeit.common.response.ApiResponseUtils
;
import
com.makeit.global.annotation.AuthIgnore
;
import
com.makeit.global.annotation.AuthIgnore
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.service.platform.elder.PlatElderSleepService
;
import
com.makeit.task.IotSyncTask
;
import
com.makeit.task.IotSyncTask
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
...
@@ -28,6 +29,8 @@ public class PlatElderSleepController {
...
@@ -28,6 +29,8 @@ public class PlatElderSleepController {
@Autowired
@Autowired
private
IotSyncTask
iotSyncTask
;
private
IotSyncTask
iotSyncTask
;
@Autowired
private
PlatElderSleepService
platElderSleepService
;
@ApiOperation
(
"测试"
)
@ApiOperation
(
"测试"
)
@PostMapping
(
"test"
)
@PostMapping
(
"test"
)
...
@@ -38,6 +41,15 @@ public class PlatElderSleepController {
...
@@ -38,6 +41,15 @@ public class PlatElderSleepController {
return
ApiResponseUtils
.
success
();
return
ApiResponseUtils
.
success
();
}
}
@ApiOperation
(
"测试"
)
@PostMapping
(
"test1"
)
@AuthIgnore
@TenantIdIgnore
public
ApiResponseEntity
<
Void
>
test1
()
{
platElderSleepService
.
test1
();
return
ApiResponseUtils
.
success
();
}
}
}
...
...
server-service/src/main/java/com/makeit/service/platform/elder/PlatElderSleepService.java
View file @
85f584d0
...
@@ -14,4 +14,6 @@ import com.makeit.entity.platform.elder.PlatElderSleep;
...
@@ -14,4 +14,6 @@ import com.makeit.entity.platform.elder.PlatElderSleep;
public
interface
PlatElderSleepService
extends
IService
<
PlatElderSleep
>
{
public
interface
PlatElderSleepService
extends
IService
<
PlatElderSleep
>
{
void
elderSleepSleepAnalysisTask
();
void
elderSleepSleepAnalysisTask
();
void
test1
();
}
}
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderSleepServiceImpl.java
View file @
85f584d0
This diff is collapsed.
Click to expand it.
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