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
73f86d35
authored
Oct 11, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix: 实时监测数据
parent
2ee7c12d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
170 additions
and
9 deletions
server-module/src/main/java/com/makeit/module/controller/children/space/PlatRegionSettingChildrenController.java
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderRealTimeServiceImpl.java
server-service/src/main/java/com/makeit/vo/platform/elder/realtime/PlatElderCoordinateVO.java
server-service/src/main/java/com/makeit/vo/platform/elder/realtime/PlatElderRealTimeHeartRespiratoryVO.java
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-web/src/main/resources/logback-spring-test.xml
server-module/src/main/java/com/makeit/module/controller/children/space/PlatRegionSettingChildrenController.java
0 → 100644
View file @
73f86d35
package
com
.
makeit
.
module
.
controller
.
children
.
space
;
import
com.makeit.common.response.ApiResponseEntity
;
import
com.makeit.common.response.ApiResponseUtils
;
import
com.makeit.dto.platform.space.PlatRegionSettingDTO
;
import
com.makeit.dto.platform.space.PlatRegionSettingListDTO
;
import
com.makeit.dto.platform.space.PlatRegionSettingLocateDTO
;
import
com.makeit.dto.platform.space.PlatRegionSettingQueryDTO
;
import
com.makeit.module.iot.vo.fall.DeviceInfoContentFall
;
import
com.makeit.module.iot.vo.space.DeviceInfoContentSpace
;
import
com.makeit.service.platform.space.PlatRegionSettingService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
* Controller
*
* @author zm
* @version 2023/9/11
*/
@Api
(
tags
=
"子女端小程序-区域设置"
)
@RestController
@RequestMapping
(
"/children/plat/region/setting"
)
public
class
PlatRegionSettingChildrenController
{
@Autowired
private
PlatRegionSettingService
platRegionSettingService
;
@ApiOperation
(
"列表"
)
@PostMapping
(
"list"
)
public
ApiResponseEntity
<
List
<
PlatRegionSettingDTO
>>
list
(
@RequestBody
PlatRegionSettingQueryDTO
dto
)
{
List
<
PlatRegionSettingDTO
>
data
=
platRegionSettingService
.
list
(
dto
);
return
ApiResponseUtils
.
success
(
data
);
}
@ApiOperation
(
"编辑"
)
@PostMapping
(
"edit"
)
public
ApiResponseEntity
<?>
edit
(
@RequestBody
PlatRegionSettingDTO
dto
)
{
platRegionSettingService
.
edit
(
dto
);
return
ApiResponseUtils
.
success
();
}
@ApiOperation
(
"批量编辑"
)
@PostMapping
(
"batchEdit"
)
public
ApiResponseEntity
<?>
batchEdit
(
@RequestBody
PlatRegionSettingListDTO
dto
)
{
platRegionSettingService
.
batchEdit
(
dto
.
getList
());
return
ApiResponseUtils
.
success
();
}
@ApiOperation
(
"定位(时间范围内定位)"
)
@PostMapping
(
"locate"
)
public
ApiResponseEntity
<
List
<
DeviceInfoContentSpace
.
Properties
>>
locate
(
@RequestBody
PlatRegionSettingLocateDTO
dto
)
{
List
<
DeviceInfoContentSpace
.
Properties
>
list
=
platRegionSettingService
.
locate
(
dto
);
return
ApiResponseUtils
.
success
(
list
);
}
@ApiOperation
(
"跌倒设备定位(时间范围内定位)"
)
@PostMapping
(
"fallDeviceLocate"
)
public
ApiResponseEntity
<
List
<
DeviceInfoContentFall
.
Properties
>>
fallDeviceLocate
(
@RequestBody
PlatRegionSettingLocateDTO
dto
)
{
List
<
DeviceInfoContentFall
.
Properties
>
list
=
platRegionSettingService
.
fallDeviceLocate
(
dto
);
return
ApiResponseUtils
.
success
(
list
);
}
@ApiOperation
(
"实时定位"
)
@PostMapping
(
"nowDataLocate"
)
public
ApiResponseEntity
<
DeviceInfoContentSpace
.
Properties
>
nowDataLocate
(
@RequestBody
PlatRegionSettingLocateDTO
dto
)
{
DeviceInfoContentSpace
.
Properties
vo
=
platRegionSettingService
.
nowDataLocate
(
dto
);
return
ApiResponseUtils
.
success
(
vo
);
}
@ApiOperation
(
"跌倒设备实时定位"
)
@PostMapping
(
"fallDeviceNowDataLocate"
)
public
ApiResponseEntity
<
DeviceInfoContentFall
.
Properties
>
fallDeviceNowDataLocate
(
@RequestBody
PlatRegionSettingLocateDTO
dto
)
{
DeviceInfoContentFall
.
Properties
vo
=
platRegionSettingService
.
fallDeviceNowDataLocate
(
dto
);
return
ApiResponseUtils
.
success
(
vo
);
}
}
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderRealTimeServiceImpl.java
View file @
73f86d35
package
com
.
makeit
.
service
.
platform
.
elder
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.makeit.common.entity.BaseEntity
;
import
com.makeit.dto.platform.elder.PlatElderIdDTO
;
...
...
@@ -62,6 +63,10 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
public
static
final
String
ELDER_BR_HR
=
"plat:elder:brHr:"
;
public
static
final
String
ELDER_MOVE
=
"plat:elder:move:"
;
public
static
final
String
DEVICE_BR_DATA
=
"device:brhr:data:"
;
public
static
final
String
DEVICE_SPACE_DATA
=
"device:space:data:"
;
public
static
final
String
DEVICE_FALL_DATA
=
"device:fall:data:"
;
@Autowired
private
PlatElderService
platElderService
;
...
...
@@ -319,18 +324,35 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
platElderRealTimeNowVO
.
setRespiratoryRate
(
deviceInfoContentBreathe
.
getProperties
().
getBr
());
platElderRealTimeNowVO
.
setBodyMove
(
deviceInfoContentBreathe
.
getProperties
().
getBodymove
());
RedisUtil
.
set
(
ELDER_STATUS
+
platElderIdDTO
.
getElderId
(),
JSON
.
toJSONString
(
platElderRealTimeNowVO
),
1
5
,
TimeUnit
.
SECONDS
);
RedisUtil
.
set
(
ELDER_STATUS
+
platElderIdDTO
.
getElderId
(),
JSON
.
toJSONString
(
platElderRealTimeNowVO
),
1
0
,
TimeUnit
.
SECONDS
);
return
platElderRealTimeNowVO
;
}
@Override
public
PlatElderRealTimeHeartRespiratoryVO
heartRespiratory
(
PlatElderIdDTO
platElderIdDTO
)
{
String
result
=
redisTemplate
.
opsForList
().
rightPop
(
ELDER_BR_HR
+
platElderIdDTO
.
getElderId
());
PlatElderRealTimeHeartRespiratoryVO
vo
=
new
PlatElderRealTimeHeartRespiratoryVO
();
PlatDevice
platDevice
=
getBreathDevice
(
platElderIdDTO
.
getElderId
(),
platElderIdDTO
.
getDeviceId
());
if
(
platDevice
==
null
)
{
vo
.
setTime
(
LocalDateTime
.
now
());
return
vo
;
}
String
result
=
redisTemplate
.
opsForValue
().
get
(
DEVICE_BR_DATA
+
platDevice
.
getOriDeviceId
());
if
(
result
!=
null
)
{
return
JSON
.
parseObject
(
result
,
PlatElderRealTimeHeartRespiratoryVO
.
class
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
result
);
vo
.
setTime
(
LocalDateTime
.
now
());
vo
.
setHeartRate
(
Integer
.
valueOf
(
jsonObject
.
getString
(
"hr"
)));
vo
.
setRespiratoryRate
(
Integer
.
valueOf
(
jsonObject
.
getString
(
"br"
)));
vo
.
setBody
(
Integer
.
valueOf
(
jsonObject
.
getString
(
"bodymove"
)));
return
vo
;
}
String
brResult
=
redisTemplate
.
opsForList
().
rightPop
(
ELDER_BR_HR
+
platElderIdDTO
.
getElderId
());
if
(
brResult
!=
null
)
{
return
JSON
.
parseObject
(
brResult
,
PlatElderRealTimeHeartRespiratoryVO
.
class
);
}
DeviceInfoContentBreathe
deviceInfoContentBreathe
=
getNowDataBreathe
(
platElderIdDTO
.
getElderId
(),
platElderIdDTO
.
getDeviceId
());
if
(
deviceInfoContentBreathe
==
null
)
{
return
new
PlatElderRealTimeHeartRespiratoryVO
();
...
...
@@ -338,12 +360,14 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
int
count
=
10
;
int
heartRate
=
deviceInfoContentBreathe
.
getProperties
().
getHr
();
int
respiratoryRate
=
deviceInfoContentBreathe
.
getProperties
().
getBr
();
int
body
=
deviceInfoContentBreathe
.
getProperties
().
getBodymove
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
PlatElderRealTimeHeartRespiratoryVO
platElderRealTimeHeartRespiratoryVO
=
new
PlatElderRealTimeHeartRespiratoryVO
();
platElderRealTimeHeartRespiratoryVO
.
setTime
(
LocalDateTime
.
now
().
plusSeconds
(
i
));
if
(
i
==
0
)
{
platElderRealTimeHeartRespiratoryVO
.
setHeartRate
(
heartRate
);
platElderRealTimeHeartRespiratoryVO
.
setRespiratoryRate
(
respiratoryRate
);
platElderRealTimeHeartRespiratoryVO
.
setBody
(
body
);
}
else
{
if
(
heartRate
==
0
)
{
platElderRealTimeHeartRespiratoryVO
.
setHeartRate
(
0
);
...
...
@@ -357,6 +381,12 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
int
brRange
=
RandomUtils
.
nextInt
(
1
,
7
)
-
3
;
platElderRealTimeHeartRespiratoryVO
.
setRespiratoryRate
(
Math
.
max
(
respiratoryRate
+
brRange
,
0
));
}
if
(
body
==
0
)
{
platElderRealTimeHeartRespiratoryVO
.
setBody
(
body
);
}
else
{
int
hrRange
=
RandomUtils
.
nextInt
(
1
,
11
)
-
5
;
platElderRealTimeHeartRespiratoryVO
.
setBody
(
Math
.
max
(
body
+
hrRange
,
0
));
}
}
redisTemplate
.
opsForList
().
leftPush
(
ELDER_BR_HR
+
platElderIdDTO
.
getElderId
(),
JSON
.
toJSONString
(
platElderRealTimeHeartRespiratoryVO
));
...
...
@@ -449,7 +479,33 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
List
<
PlatDevice
>
deviceListSpace
=
getSpaceDevice
(
platElderIdDTO
.
getElderId
(),
platElderIdDTO
.
getDeviceId
());
///List<PlatDevice> deviceListFall = getFallDevice(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
for
(
PlatDevice
platDevice
:
deviceListSpace
)
{
String
spaceResult
=
redisTemplate
.
opsForValue
().
get
(
DEVICE_SPACE_DATA
+
platDevice
.
getOriDeviceId
());
if
(
spaceResult
!=
null
)
{
PlatElderCoordinateVO
vo
=
new
PlatElderCoordinateVO
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
spaceResult
);
vo
.
setDeviceId
(
platDevice
.
getId
());
vo
.
setOriDeviceId
(
platDevice
.
getOriDeviceId
());
vo
.
setDistance
(
Integer
.
valueOf
(
jsonObject
.
getString
(
"distance"
)));
vo
.
setAngle
(
Integer
.
valueOf
(
jsonObject
.
getString
(
"angle"
)));
voList
.
add
(
vo
);
}
String
fallResult
=
redisTemplate
.
opsForValue
().
get
(
DEVICE_FALL_DATA
+
platDevice
.
getOriDeviceId
());
if
(
fallResult
!=
null
)
{
PlatElderCoordinateVO
vo
=
new
PlatElderCoordinateVO
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
spaceResult
);
vo
.
setDeviceId
(
platDevice
.
getId
());
vo
.
setOriDeviceId
(
platDevice
.
getOriDeviceId
());
vo
.
setTrack
((
List
<
Integer
>)
jsonObject
.
get
(
"track"
));
voList
.
add
(
vo
);
}
}
if
(
CollectionUtils
.
isNotEmpty
(
voList
))
{
return
voList
;
}
int
count
=
20
;
for
(
PlatDevice
platDevice
:
deviceListSpace
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
...
...
server-service/src/main/java/com/makeit/vo/platform/elder/realtime/PlatElderCoordinateVO.java
View file @
73f86d35
...
...
@@ -3,7 +3,6 @@ package com.makeit.vo.platform.elder.realtime;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.math.BigDecimal
;
import
java.util.List
;
@Data
...
...
server-service/src/main/java/com/makeit/vo/platform/elder/realtime/PlatElderRealTimeHeartRespiratoryVO.java
View file @
73f86d35
...
...
@@ -18,5 +18,7 @@ public class PlatElderRealTimeHeartRespiratoryVO {
@ApiModelProperty
(
"呼吸率"
)
private
Integer
respiratoryRate
;
@ApiModelProperty
(
"体动值"
)
private
Integer
body
;
}
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
73f86d35
...
...
@@ -28,6 +28,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -35,6 +36,7 @@ import org.springframework.util.StopWatch;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
...
...
@@ -42,6 +44,9 @@ import java.util.stream.Collectors;
public
class
PushCallback
implements
MqttCallback
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
MqttPushClient
.
class
);
public
static
final
String
DEVICE_BR_DATA
=
"device:brhr:data:"
;
public
static
final
String
DEVICE_SPACE_DATA
=
"device:space:data:"
;
public
static
final
String
DEVICE_FALL_DATA
=
"device:fall:data:"
;
@Autowired
private
MqttConfig
mqttConfig
;
...
...
@@ -58,6 +63,8 @@ public class PushCallback implements MqttCallback {
private
PlatDeviceService
platDeviceService
;
@Autowired
private
PlatTenantService
platTenantService
;
@Autowired
private
StringRedisTemplate
redisTemplate
;
@Override
...
...
@@ -73,13 +80,14 @@ public class PushCallback implements MqttCallback {
// 收到消息并设置返回字符串格式
String
payload
=
new
String
(
message
.
getPayload
(),
"UTF-8"
);
//
logger.info("接收消息主题:{}, 接收消息QoS:{}", topic, message.getQos());
//
logger.info("接收消息内容:payload格式:{}", payload);
logger
.
info
(
"接收消息主题:{}, 接收消息QoS:{}"
,
topic
,
message
.
getQos
());
logger
.
info
(
"接收消息内容:payload格式:{}"
,
payload
);
// 解析数据
DeviceInfo
device
=
JSON
.
parseObject
(
payload
,
DeviceInfo
.
class
);
// todo
checkAlarm
(
device
);
}
...
...
@@ -98,7 +106,19 @@ public class PushCallback implements MqttCallback {
public
void
checkAlarm
(
DeviceInfo
device
)
{
HeaderInfo
headers
=
device
.
getHeaders
();
List
<
HeaderInfo
.
Bind
>
bindings
=
headers
.
getBindings
();
// TODO 先这样判断
if
(
headers
.
getProductName
().
contains
(
"呼吸"
))
{
redisTemplate
.
opsForValue
().
set
(
DEVICE_BR_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
1
,
TimeUnit
.
SECONDS
);
}
if
(
headers
.
getProductName
().
contains
(
"空间"
))
{
redisTemplate
.
opsForValue
().
set
(
DEVICE_SPACE_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
1
,
TimeUnit
.
SECONDS
);
}
if
(
headers
.
getProductName
().
contains
(
"跌倒"
))
{
redisTemplate
.
opsForValue
().
set
(
DEVICE_FALL_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
1
,
TimeUnit
.
SECONDS
);
}
for
(
HeaderInfo
.
Bind
binding
:
bindings
)
{
try
{
String
iot_tenantId
=
binding
.
getId
();
...
...
server-web/src/main/resources/logback-spring-test.xml
View file @
73f86d35
...
...
@@ -78,7 +78,7 @@
<logger
name=
"com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate"
value=
"DEBUG"
/>
<!-- root级别 DEBUG -->
<root
level=
"
debug
"
>
<root
level=
"
INFO
"
>
<!-- 文件输出 -->
<appender-ref
ref=
"ERROR"
/>
<appender-ref
ref=
"INFO"
/>
...
...
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