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
fc6176f2
authored
Dec 06, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix: 实时监控状态
parent
54b0bd29
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
7 deletions
server-common/src/main/java/com/makeit/utils/StandardDeviationUtil.java
server-service/src/main/java/com/makeit/enums/platform/elder/PlatElderRealtimeReportEnum.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-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-common/src/main/java/com/makeit/utils/StandardDeviationUtil.java
View file @
fc6176f2
...
@@ -10,7 +10,7 @@ public class StandardDeviationUtil {
...
@@ -10,7 +10,7 @@ public class StandardDeviationUtil {
* @param x
* @param x
* @return 平均值
* @return 平均值
*/
*/
public
static
double
average
(
d
ouble
[]
x
)
{
public
static
double
average
(
D
ouble
[]
x
)
{
int
n
=
x
.
length
;
//数列元素个数
int
n
=
x
.
length
;
//数列元素个数
double
sum
=
0
;
double
sum
=
0
;
for
(
double
i
:
x
)
{
//求和
for
(
double
i
:
x
)
{
//求和
...
@@ -35,7 +35,7 @@ public class StandardDeviationUtil {
...
@@ -35,7 +35,7 @@ public class StandardDeviationUtil {
* @param x 要计算的数列
* @param x 要计算的数列
* @return 方差
* @return 方差
*/
*/
public
static
double
variance
(
d
ouble
[]
x
)
{
public
static
double
variance
(
D
ouble
[]
x
)
{
int
n
=
x
.
length
;
//数列元素个数
int
n
=
x
.
length
;
//数列元素个数
double
avg
=
average
(
x
);
//求平均值
double
avg
=
average
(
x
);
//求平均值
double
var
=
0
;
double
var
=
0
;
...
@@ -62,7 +62,7 @@ public class StandardDeviationUtil {
...
@@ -62,7 +62,7 @@ public class StandardDeviationUtil {
* @param x 要计算的数列
* @param x 要计算的数列
* @return 标准差
* @return 标准差
*/
*/
public
static
double
standardDeviation
(
d
ouble
[]
x
)
{
public
static
double
standardDeviation
(
D
ouble
[]
x
)
{
return
Math
.
sqrt
(
variance
(
x
));
return
Math
.
sqrt
(
variance
(
x
));
}
}
...
...
server-service/src/main/java/com/makeit/enums/platform/elder/PlatElderRealtimeReportEnum.java
View file @
fc6176f2
...
@@ -6,10 +6,11 @@ import com.makeit.utils.sys.SysDictUtil;
...
@@ -6,10 +6,11 @@ import com.makeit.utils.sys.SysDictUtil;
public
class
PlatElderRealtimeReportEnum
{
public
class
PlatElderRealtimeReportEnum
{
public
enum
NowStatus
implements
BaseEnum
{
public
enum
NowStatus
implements
BaseEnum
{
OUT
(
"elder.realtime.now.status.out"
),
OUT
(
"elder.realtime.now.status.out"
),
RUN
(
"elder.realtime.now.status.run"
),
RUN
(
"elder.realtime.now.status.noBed.run"
),
REST
(
"elder.realtime.now.status.rest"
),
REST
(
"elder.realtime.now.status.noBen.rest"
),
BED
(
"elder.realtime.now.status.bed"
),
BED
(
"elder.realtime.now.status.bed.rest"
),
SLEEP
(
"elder.realtime.now.status.sleep"
);
SLEEP
(
"elder.realtime.now.status.bed.sleep"
),
SPORT
(
"elder.realtime.now.status.bed.sport"
);
private
String
code
;
private
String
code
;
...
...
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderRealTimeServiceImpl.java
View file @
fc6176f2
This diff is collapsed.
Click to expand it.
server-service/src/main/java/com/makeit/vo/platform/elder/realtime/PlatElderCoordinateVO.java
View file @
fc6176f2
...
@@ -3,6 +3,7 @@ package com.makeit.vo.platform.elder.realtime;
...
@@ -3,6 +3,7 @@ package com.makeit.vo.platform.elder.realtime;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.Data
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.List
;
@Data
@Data
...
@@ -31,5 +32,9 @@ public class PlatElderCoordinateVO {
...
@@ -31,5 +32,9 @@ public class PlatElderCoordinateVO {
@ApiModelProperty
(
"跌倒设备轨迹"
)
@ApiModelProperty
(
"跌倒设备轨迹"
)
private
List
<
Integer
>
track
;
private
List
<
Integer
>
track
;
@ApiModelProperty
(
"x"
)
private
BigDecimal
x
;
@ApiModelProperty
(
"y"
)
private
BigDecimal
y
;
}
}
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
fc6176f2
...
@@ -2,15 +2,19 @@ package com.makeit.mqtt;
...
@@ -2,15 +2,19 @@ package com.makeit.mqtt;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.makeit.common.entity.BaseEntity
;
import
com.makeit.dto.platform.alarm.PlatAlarmCheckDTO
;
import
com.makeit.dto.platform.alarm.PlatAlarmCheckDTO
;
import
com.makeit.entity.platform.alarm.PlatAlarmConfig
;
import
com.makeit.entity.platform.alarm.PlatAlarmConfig
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.saas.analysis.SaasSleepAnalysisModel
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.module.iot.enums.DeviceState
;
import
com.makeit.module.iot.enums.DeviceState
;
import
com.makeit.module.iot.vo.DeviceInfo
;
import
com.makeit.module.iot.vo.DeviceInfo
;
import
com.makeit.module.iot.vo.HeaderInfo
;
import
com.makeit.module.iot.vo.HeaderInfo
;
import
com.makeit.service.platform.alarm.alarmStrategy.IAlarm
;
import
com.makeit.service.platform.alarm.alarmStrategy.IAlarm
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.service.saas.SaasSleepAnalysisModelService
;
import
com.makeit.utils.AlarmConfigCacheUtil
;
import
com.makeit.utils.AlarmConfigCacheUtil
;
import
com.makeit.utils.DeviceCacheUtil
;
import
com.makeit.utils.DeviceCacheUtil
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
...
@@ -39,6 +43,12 @@ public class PushCallback implements MqttCallback {
...
@@ -39,6 +43,12 @@ public class PushCallback implements MqttCallback {
public
static
final
String
DEVICE_SPACE_DATA
=
"device:space:data:"
;
public
static
final
String
DEVICE_SPACE_DATA
=
"device:space:data:"
;
public
static
final
String
DEVICE_FALL_DATA
=
"device:fall:data:"
;
public
static
final
String
DEVICE_FALL_DATA
=
"device:fall:data:"
;
public
static
final
String
SLEEP_ANALYSIS_KEY
=
"saas:sleep:analysis"
;
public
static
final
String
DEVICE_BR_ANALYSIS
=
"device:brhr:analysis:"
;
public
static
final
String
DEVICE_SPACE_TEMP_DATA
=
"device:space:tempData:"
;
public
static
final
String
DEVICE_FALL_TEMP_DATA
=
"device:fall:tempData:"
;
public
static
final
String
REPORT_PROPERTY
=
"REPORT_PROPERTY"
;
public
static
final
String
REPORT_PROPERTY
=
"REPORT_PROPERTY"
;
@Autowired
@Autowired
private
MqttConfig
mqttConfig
;
private
MqttConfig
mqttConfig
;
...
@@ -56,6 +66,8 @@ public class PushCallback implements MqttCallback {
...
@@ -56,6 +66,8 @@ public class PushCallback implements MqttCallback {
private
PlatDeviceService
platDeviceService
;
private
PlatDeviceService
platDeviceService
;
@Autowired
@Autowired
private
StringRedisTemplate
redisTemplate
;
private
StringRedisTemplate
redisTemplate
;
@Autowired
private
SaasSleepAnalysisModelService
saasSleepAnalysisModelService
;
@Override
@Override
...
@@ -97,16 +109,45 @@ public class PushCallback implements MqttCallback {
...
@@ -97,16 +109,45 @@ public class PushCallback implements MqttCallback {
public
void
checkAlarm
(
DeviceInfo
device
)
{
public
void
checkAlarm
(
DeviceInfo
device
)
{
HeaderInfo
headers
=
device
.
getHeaders
();
HeaderInfo
headers
=
device
.
getHeaders
();
List
<
HeaderInfo
.
Bind
>
bindings
=
headers
.
getBindings
();
List
<
HeaderInfo
.
Bind
>
bindings
=
headers
.
getBindings
();
Long
timestamp
=
device
.
getTimestamp
();
// TODO 先这样判断
// TODO 先这样判断
if
(
REPORT_PROPERTY
.
equals
(
device
.
getMessageType
())
&&
headers
.
getProductName
().
contains
(
"呼吸"
))
{
if
(
REPORT_PROPERTY
.
equals
(
device
.
getMessageType
())
&&
headers
.
getProductName
().
contains
(
"呼吸"
))
{
// 缓存呼吸设备某段时间的数据,hash 最大长度 duration
Long
duration
=
getSleepTimeActionDuration
();
Long
size
=
redisTemplate
.
opsForHash
().
size
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
());
if
(
size
.
equals
(
duration
))
{
redisTemplate
.
opsForHash
().
delete
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
timestamp
-
duration
);
}
redisTemplate
.
opsForHash
().
put
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
timestamp
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
expire
(
DEVICE_BR_ANALYSIS
+
device
.
getDeviceId
(),
duration
,
TimeUnit
.
MINUTES
);
redisTemplate
.
opsForValue
().
set
(
DEVICE_BR_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
redisTemplate
.
opsForValue
().
set
(
DEVICE_BR_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
5000
,
TimeUnit
.
MILLISECONDS
);
5000
,
TimeUnit
.
MILLISECONDS
);
}
}
if
(
REPORT_PROPERTY
.
equals
(
device
.
getMessageType
())
&&
headers
.
getProductName
().
contains
(
"空间"
))
{
if
(
REPORT_PROPERTY
.
equals
(
device
.
getMessageType
())
&&
headers
.
getProductName
().
contains
(
"空间"
))
{
Long
maxSize
=
10L
;
Long
size
=
redisTemplate
.
opsForHash
().
size
(
DEVICE_SPACE_TEMP_DATA
+
device
.
getDeviceId
());
if
(
size
.
equals
(
maxSize
))
{
redisTemplate
.
opsForHash
().
delete
(
DEVICE_SPACE_TEMP_DATA
+
device
.
getDeviceId
(),
timestamp
-
maxSize
);
}
redisTemplate
.
opsForHash
().
put
(
DEVICE_SPACE_TEMP_DATA
+
device
.
getDeviceId
(),
timestamp
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
expire
(
DEVICE_SPACE_TEMP_DATA
+
device
.
getDeviceId
(),
maxSize
+
1
,
TimeUnit
.
SECONDS
);
redisTemplate
.
opsForValue
().
set
(
DEVICE_SPACE_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
redisTemplate
.
opsForValue
().
set
(
DEVICE_SPACE_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
5000
,
TimeUnit
.
MILLISECONDS
);
5000
,
TimeUnit
.
MILLISECONDS
);
}
}
if
(
REPORT_PROPERTY
.
equals
(
device
.
getMessageType
())
&&
headers
.
getProductName
().
contains
(
"跌倒"
))
{
if
(
REPORT_PROPERTY
.
equals
(
device
.
getMessageType
())
&&
headers
.
getProductName
().
contains
(
"跌倒"
))
{
Long
maxSize
=
10L
;
Long
size
=
redisTemplate
.
opsForHash
().
size
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
());
if
(
size
.
equals
(
maxSize
))
{
redisTemplate
.
opsForHash
().
delete
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
(),
timestamp
-
maxSize
);
}
redisTemplate
.
opsForHash
().
put
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
(),
timestamp
,
JSON
.
toJSONString
(
device
.
getProperties
()));
redisTemplate
.
expire
(
DEVICE_FALL_TEMP_DATA
+
device
.
getDeviceId
(),
maxSize
+
1
,
TimeUnit
.
SECONDS
);
redisTemplate
.
opsForValue
().
set
(
DEVICE_FALL_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
redisTemplate
.
opsForValue
().
set
(
DEVICE_FALL_DATA
+
device
.
getDeviceId
(),
JSON
.
toJSONString
(
device
.
getProperties
()),
5000
,
TimeUnit
.
MILLISECONDS
);
5000
,
TimeUnit
.
MILLISECONDS
);
}
}
...
@@ -168,6 +209,20 @@ public class PushCallback implements MqttCallback {
...
@@ -168,6 +209,20 @@ public class PushCallback implements MqttCallback {
}
}
private
Long
getSleepTimeActionDuration
()
{
String
sleepTimeActionDuration
=
""
;
String
result
=
redisTemplate
.
opsForValue
().
get
(
SLEEP_ANALYSIS_KEY
);
if
(
result
!=
null
)
{
sleepTimeActionDuration
=
result
;
}
else
{
SaasSleepAnalysisModel
analysisModel
=
saasSleepAnalysisModelService
.
getOne
(
new
QueryWrapper
<
SaasSleepAnalysisModel
>().
lambda
()
.
orderByDesc
(
BaseEntity:
:
getCreateBy
)
.
last
(
"limit 1"
));
redisTemplate
.
opsForValue
().
set
(
SLEEP_ANALYSIS_KEY
,
analysisModel
.
getSleepTimeActionDuration
(),
1
,
TimeUnit
.
DAYS
);
sleepTimeActionDuration
=
analysisModel
.
getSleepTimeActionDuration
();
}
return
Long
.
parseLong
(
sleepTimeActionDuration
)
*
60
;
}
}
}
...
...
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