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
521bbf36
authored
Dec 18, 2023
by
汪志阳
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix:bug fix
parent
385c825c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
34 deletions
server-service/src/main/java/com/makeit/service/platform/alarm/alarmStrategy/OffBedAlarm.java
server-service/src/main/java/com/makeit/service/platform/alarm/alarmStrategy/OffBedAlarm.java
View file @
521bbf36
...
@@ -11,6 +11,7 @@ import com.makeit.entity.platform.elder.PlatElder;
...
@@ -11,6 +11,7 @@ import com.makeit.entity.platform.elder.PlatElder;
import
com.makeit.enums.CommonEnum
;
import
com.makeit.enums.CommonEnum
;
import
com.makeit.enums.platform.alarm.PlatAlarmConfigEnum
;
import
com.makeit.enums.platform.alarm.PlatAlarmConfigEnum
;
import
com.makeit.enums.redis.RedisConst
;
import
com.makeit.enums.redis.RedisConst
;
import
com.makeit.service.platform.alarm.PlatAlarmConfigService
;
import
com.makeit.service.platform.alarm.PlatAlarmRecordService
;
import
com.makeit.service.platform.alarm.PlatAlarmRecordService
;
import
com.makeit.utils.AlarmConfigCacheUtil
;
import
com.makeit.utils.AlarmConfigCacheUtil
;
import
com.makeit.utils.AlarmRedisDTO
;
import
com.makeit.utils.AlarmRedisDTO
;
...
@@ -19,6 +20,7 @@ import com.makeit.utils.redis.RedisUtil;
...
@@ -19,6 +20,7 @@ import com.makeit.utils.redis.RedisUtil;
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.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
...
@@ -36,6 +38,8 @@ public class OffBedAlarm implements IAlarm {
...
@@ -36,6 +38,8 @@ public class OffBedAlarm implements IAlarm {
private
final
PlatAlarmConfigEnum
.
AlarmTypeEnum
alarmTypeEnum
=
PlatAlarmConfigEnum
.
AlarmTypeEnum
.
OFF_BED
;
private
final
PlatAlarmConfigEnum
.
AlarmTypeEnum
alarmTypeEnum
=
PlatAlarmConfigEnum
.
AlarmTypeEnum
.
OFF_BED
;
@Resource
@Resource
private
AlarmConfigCacheUtil
alarmConfigCacheUtil
;
private
AlarmConfigCacheUtil
alarmConfigCacheUtil
;
@Autowired
private
PlatAlarmConfigService
platAlarmConfigService
;
@Override
@Override
public
boolean
support
(
String
alarmType
)
{
public
boolean
support
(
String
alarmType
)
{
...
@@ -48,7 +52,7 @@ public class OffBedAlarm implements IAlarm {
...
@@ -48,7 +52,7 @@ public class OffBedAlarm implements IAlarm {
* @param platAlarmCheckDTO
* @param platAlarmCheckDTO
*/
*/
@Override
@Override
public
synchronized
void
checkConfig
(
PlatAlarmCheckDTO
platAlarmCheckDTO
)
{
public
void
checkConfig
(
PlatAlarmCheckDTO
platAlarmCheckDTO
)
{
PlatDevice
platDevice
=
platAlarmCheckDTO
.
getPlatDevice
();
PlatDevice
platDevice
=
platAlarmCheckDTO
.
getPlatDevice
();
platAlarmRecordService
.
getElderListByDeviceId
(
platAlarmCheckDTO
);
platAlarmRecordService
.
getElderListByDeviceId
(
platAlarmCheckDTO
);
log
.
info
(
"执行离床checkConfig方法:"
);
log
.
info
(
"执行离床checkConfig方法:"
);
...
@@ -58,6 +62,13 @@ public class OffBedAlarm implements IAlarm {
...
@@ -58,6 +62,13 @@ public class OffBedAlarm implements IAlarm {
return
;
return
;
}
}
PlatAlarmConfig
config
=
alarmConfigCacheUtil
.
get
(
platDevice
.
getOrgId
(),
PlatAlarmConfigEnum
.
AlarmTypeEnum
.
OFF_BED
.
getValue
());
PlatAlarmConfig
config
=
alarmConfigCacheUtil
.
get
(
platDevice
.
getOrgId
(),
PlatAlarmConfigEnum
.
AlarmTypeEnum
.
OFF_BED
.
getValue
());
// PlatAlarmConfig platAlarmConfig = platAlarmCheckDTO.getPlatAlarmConfig();
log
.
info
(
"离床告警dto,org_config:{}"
,
config
.
getRuleConfig
());
offBedCheckAlarm
(
config
,
platAlarmCheckDTO
,
platDevice
);
}
private
void
offBedCheckAlarm
(
PlatAlarmConfig
config
,
PlatAlarmCheckDTO
platAlarmCheckDTO
,
PlatDevice
platDevice
)
{
if
(
config
==
null
||
StringUtils
.
isBlank
(
config
.
getRuleConfig
())
||
!
"5"
.
equals
(
config
.
getAlarmType
()))
{
if
(
config
==
null
||
StringUtils
.
isBlank
(
config
.
getRuleConfig
())
||
!
"5"
.
equals
(
config
.
getAlarmType
()))
{
// log.error("离床告警配置不存在,config:{}", JSONUtil.toJsonStr(config));
// log.error("离床告警配置不存在,config:{}", JSONUtil.toJsonStr(config));
return
;
return
;
...
@@ -128,14 +139,12 @@ public class OffBedAlarm implements IAlarm {
...
@@ -128,14 +139,12 @@ public class OffBedAlarm implements IAlarm {
}
else
{
}
else
{
handleUnCrossDay
(
alarmRedisDTO
,
ruleConfig
,
platAlarmCheckDTO
,
config
,
deviceId
);
handleUnCrossDay
(
alarmRedisDTO
,
ruleConfig
,
platAlarmCheckDTO
,
config
,
deviceId
);
}
}
}
}
}
}
/**
/**
* 处理跨天业务
* 处理跨天业务
*
* @param alarmRedisDTO
* @param alarmRedisDTO
* @param ruleConfig
* @param ruleConfig
* @param platAlarmCheckDTO
* @param platAlarmCheckDTO
...
@@ -146,25 +155,23 @@ public class OffBedAlarm implements IAlarm {
...
@@ -146,25 +155,23 @@ public class OffBedAlarm implements IAlarm {
PlatAlarmCheckDTO
platAlarmCheckDTO
,
PlatAlarmCheckDTO
platAlarmCheckDTO
,
PlatAlarmConfig
config
,
PlatAlarmConfig
config
,
String
deviceId
)
{
String
deviceId
)
{
log
.
info
(
"cross_config:{},第一次离床时间:{}"
,
config
.
getRuleConfig
(),
longToTime
(
alarmRedisDTO
.
getStartLong
()));
Integer
duration
=
ruleConfig
.
getDuration
();
Integer
duration
=
ruleConfig
.
getDuration
();
LocalTime
startTime
=
ruleConfig
.
getOffBedStart
();
LocalTime
startTime
=
ruleConfig
.
getOffBedStart
();
LocalTime
endTime
=
ruleConfig
.
getOffBedEnd
();
LocalTime
endTime
=
ruleConfig
.
getOffBedEnd
();
Long
firstOffBedLong
=
alarmRedisDTO
.
getStartLong
();
Long
firstOffBedLong
=
alarmRedisDTO
.
getStartLong
();
long
currentTimeMillis
=
System
.
currentTimeMillis
();
long
currentTimeMillis
=
currentLong
();
currentTimeMillis
=
currentLong
();
boolean
isOverTime
=
(
currentTimeMillis
-
firstOffBedLong
)
/
1000
>=
duration
*
60
;
boolean
isOverTime
=
(
currentTimeMillis
-
firstOffBedLong
)
/
1000
>=
duration
*
60
;
LocalDateTime
firstOffBedTime
=
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
firstOffBedLong
),
ZoneOffset
.
of
(
"+8"
));
LocalTime
firstTime
=
longToTime
(
firstOffBedLong
).
toLocalTime
();
LocalTime
firstTime
=
firstOffBedTime
.
toLocalTime
();
boolean
isInTime
=
firstTime
.
isAfter
(
startTime
)
||
firstTime
.
isBefore
(
endTime
);
boolean
isInTime
=
firstTime
.
isAfter
(
startTime
)
||
firstTime
.
isBefore
(
endTime
);
// LocalTime endTimeLimit = endTime.plusMinutes(-duration);
// LocalTime endTimeLimit = endTime.plusMinutes(-duration);
// 离床时间在范围内
// 离床时间在范围内
if
(
isInTime
&&
isOverTime
)
{
if
(
isInTime
&&
isOverTime
)
{
platAlarmCheckDTO
.
setAbnormalValue
(
String
.
valueOf
(
currentTimeMillis
-
firstOffBedLong
));
platAlarmCheckDTO
.
setAbnormalValue
(
String
.
valueOf
(
currentTimeMillis
-
firstOffBedLong
));
platAlarmCheckDTO
.
setPlatAlarmConfig
(
config
);
log
.
info
(
"cross离床告警离床时间在范围时间内,配置:{}"
,
config
.
getRuleConfig
());
log
.
info
(
"cross离床告警离床时间在范围时间内,配置:{}"
,
config
.
getRuleConfig
());
platAlarmCheckDTO
.
setPlatAlarmConfig
(
config
);
noticeAlarm
(
alarmRedisDTO
,
platAlarmCheckDTO
,
deviceId
);
noticeAlarm
(
alarmRedisDTO
,
platAlarmCheckDTO
,
deviceId
);
return
;
return
;
}
}
...
@@ -175,8 +182,8 @@ public class OffBedAlarm implements IAlarm {
...
@@ -175,8 +182,8 @@ public class OffBedAlarm implements IAlarm {
boolean
noInOverTime
=
mills
>=
duration
*
60
;
boolean
noInOverTime
=
mills
>=
duration
*
60
;
if
(
noInOverTime
)
{
if
(
noInOverTime
)
{
platAlarmCheckDTO
.
setAbnormalValue
(
String
.
valueOf
(
currentTimeMillis
-
firstOffBedLong
));
platAlarmCheckDTO
.
setAbnormalValue
(
String
.
valueOf
(
currentTimeMillis
-
firstOffBedLong
));
platAlarmCheckDTO
.
setPlatAlarmConfig
(
config
);
log
.
info
(
"cross离床告警第一次离床时间在范围前,配置:{}"
,
config
.
getRuleConfig
());
log
.
info
(
"cross离床告警第一次离床时间在范围前,配置:{}"
,
config
.
getRuleConfig
());
platAlarmCheckDTO
.
setPlatAlarmConfig
(
config
);
noticeAlarm
(
alarmRedisDTO
,
platAlarmCheckDTO
,
deviceId
);
noticeAlarm
(
alarmRedisDTO
,
platAlarmCheckDTO
,
deviceId
);
}
else
{
}
else
{
log
.
info
(
"cross离床告警,第一次离床时间在范围前,未预警,配置:{},时间持续:{},start:{}"
,
config
.
getRuleConfig
(),
mills
,
startLocalDteTime
);
log
.
info
(
"cross离床告警,第一次离床时间在范围前,未预警,配置:{},时间持续:{},start:{}"
,
config
.
getRuleConfig
(),
mills
,
startLocalDteTime
);
...
@@ -189,7 +196,8 @@ public class OffBedAlarm implements IAlarm {
...
@@ -189,7 +196,8 @@ public class OffBedAlarm implements IAlarm {
}
}
/**
/**
* 处理跨天业务
* 处理未跨天业务
*
* @param alarmRedisDTO
* @param alarmRedisDTO
* @param ruleConfig
* @param ruleConfig
* @param platAlarmCheckDTO
* @param platAlarmCheckDTO
...
@@ -200,7 +208,7 @@ public class OffBedAlarm implements IAlarm {
...
@@ -200,7 +208,7 @@ public class OffBedAlarm implements IAlarm {
PlatAlarmCheckDTO
platAlarmCheckDTO
,
PlatAlarmCheckDTO
platAlarmCheckDTO
,
PlatAlarmConfig
config
,
PlatAlarmConfig
config
,
String
deviceId
)
{
String
deviceId
)
{
log
.
info
(
"uncross_config:{},第一次离床时间:{}"
,
config
.
getRuleConfig
(),
longToTime
(
alarmRedisDTO
.
getStartLong
()));
Integer
duration
=
ruleConfig
.
getDuration
();
Integer
duration
=
ruleConfig
.
getDuration
();
LocalTime
startTime
=
ruleConfig
.
getOffBedStart
();
LocalTime
startTime
=
ruleConfig
.
getOffBedStart
();
LocalDateTime
startLocalDteTime
=
LocalDateTime
.
of
(
LocalDate
.
now
(),
startTime
);
LocalDateTime
startLocalDteTime
=
LocalDateTime
.
of
(
LocalDate
.
now
(),
startTime
);
...
@@ -210,18 +218,16 @@ public class OffBedAlarm implements IAlarm {
...
@@ -210,18 +218,16 @@ public class OffBedAlarm implements IAlarm {
Long
firstOffBedLong
=
alarmRedisDTO
.
getStartLong
();
Long
firstOffBedLong
=
alarmRedisDTO
.
getStartLong
();
long
currentTimeMillis
=
currentLong
();
long
currentTimeMillis
=
currentLong
();
boolean
isOverTime
=
(
currentTimeMillis
-
firstOffBedLong
)
/
1000
>=
duration
*
60
;
boolean
isOverTime
=
(
currentTimeMillis
-
firstOffBedLong
)
/
1000
>=
duration
*
60
;
LocalDateTime
firstOffBedTime
=
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
firstOffBedLong
),
ZoneOffset
.
of
(
"+8"
));
LocalTime
firstTime
=
longToTime
(
firstOffBedLong
).
toLocalTime
();
LocalTime
firstTime
=
firstOffBedTime
.
toLocalTime
();
boolean
isInTime
=
firstTime
.
isAfter
(
startTime
)
&&
firstTime
.
isBefore
(
endTime
);
boolean
isInTime
=
firstTime
.
isAfter
(
startTime
)
&&
firstTime
.
isBefore
(
endTime
);
LocalTime
endTimeLimit
=
endTime
.
plusMinutes
(-
duration
);
LocalTime
endTimeLimit
=
endTime
.
plusMinutes
(-
duration
);
// 离床时间在范围内
// 离床时间在范围内
if
(
isInTime
&&
isOverTime
)
{
if
(
isInTime
&&
isOverTime
)
{
if
(
firstTime
.
isAfter
(
endTimeLimit
))
{
//
if (firstTime.isAfter(endTimeLimit)) {
log
.
info
(
"handleUnCrossDay第一次离床时间,{}+持续时间:{}将超过范围,{}"
,
firstTime
,
duration
,
endTime
);
//
log.info("handleUnCrossDay第一次离床时间,{}+持续时间:{}将超过范围,{}", firstTime, duration, endTime);
return
;
//
return;
}
//
}
platAlarmCheckDTO
.
setAbnormalValue
(
String
.
valueOf
(
currentTimeMillis
-
firstOffBedLong
));
platAlarmCheckDTO
.
setAbnormalValue
(
String
.
valueOf
(
currentTimeMillis
-
firstOffBedLong
));
platAlarmCheckDTO
.
setPlatAlarmConfig
(
config
);
platAlarmCheckDTO
.
setPlatAlarmConfig
(
config
);
log
.
info
(
"uncross离床告警离床时间在范围时间内,配置:{}"
,
config
.
getRuleConfig
());
log
.
info
(
"uncross离床告警离床时间在范围时间内,配置:{}"
,
config
.
getRuleConfig
());
...
@@ -236,8 +242,8 @@ public class OffBedAlarm implements IAlarm {
...
@@ -236,8 +242,8 @@ public class OffBedAlarm implements IAlarm {
boolean
noInOverTime
=
mills
>=
duration
*
60
;
boolean
noInOverTime
=
mills
>=
duration
*
60
;
if
(
noInOverTime
)
{
if
(
noInOverTime
)
{
platAlarmCheckDTO
.
setAbnormalValue
(
String
.
valueOf
(
currentTimeMillis
-
firstOffBedLong
));
platAlarmCheckDTO
.
setAbnormalValue
(
String
.
valueOf
(
currentTimeMillis
-
firstOffBedLong
));
platAlarmCheckDTO
.
setPlatAlarmConfig
(
config
);
log
.
info
(
"uncross离床告警第一次离床时间在范围前,配置:{}"
,
config
.
getRuleConfig
());
log
.
info
(
"uncross离床告警第一次离床时间在范围前,配置:{}"
,
config
.
getRuleConfig
());
platAlarmCheckDTO
.
setPlatAlarmConfig
(
config
);
noticeAlarm
(
alarmRedisDTO
,
platAlarmCheckDTO
,
deviceId
);
noticeAlarm
(
alarmRedisDTO
,
platAlarmCheckDTO
,
deviceId
);
}
else
{
}
else
{
log
.
info
(
"uncross离床告警第一次离床时间在范围前,未预警,配置:{},时间持续:{},start:{}"
,
config
.
getRuleConfig
(),
mills
,
startLocalDteTime
);
log
.
info
(
"uncross离床告警第一次离床时间在范围前,未预警,配置:{},时间持续:{},start:{}"
,
config
.
getRuleConfig
(),
mills
,
startLocalDteTime
);
...
@@ -249,22 +255,15 @@ public class OffBedAlarm implements IAlarm {
...
@@ -249,22 +255,15 @@ public class OffBedAlarm implements IAlarm {
private
void
sendToRedis
(
AlarmRedisDTO
alarmRedisDTO
,
String
deviceId
)
{
private
void
sendToRedis
(
AlarmRedisDTO
alarmRedisDTO
,
String
deviceId
)
{
Date
now
=
toDate
();
Date
now
=
toDate
();
// Date now = new Date();
long
endLong
=
now
.
getTime
();
// 第一次上报
// 第一次上报
if
(
alarmRedisDTO
==
null
)
{
if
(
alarmRedisDTO
==
null
)
{
alarmRedisDTO
=
new
AlarmRedisDTO
();
alarmRedisDTO
=
new
AlarmRedisDTO
();
alarmRedisDTO
.
setAlarm
(
CommonEnum
.
NO
.
getValue
());
alarmRedisDTO
.
setAlarm
(
CommonEnum
.
NO
.
getValue
());
alarmRedisDTO
.
setStart
(
now
);
alarmRedisDTO
.
setStart
(
now
);
endLong
=
currentLong
();
alarmRedisDTO
.
setStartLong
(
currentLong
());
alarmRedisDTO
.
setStartLong
(
endLong
);
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_OFF_BED_ID
+
deviceId
,
alarmRedisDTO
);
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_OFF_BED_ID
+
deviceId
,
alarmRedisDTO
);
// log.info("离床告警 离床设备存储redis,第一次上报时间:{},开始上报时间:{},是否上报:{}",
// alarmRedisDTO.getStartLong(), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm());
}
else
{
}
else
{
alarmRedisDTO
.
setStart
(
now
);
alarmRedisDTO
.
setStart
(
now
);
// log.info("离床告警离床更新redis,第一次上报时间:{},更新时间:{},是否上报:{}",
// longToTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm());
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_OFF_BED_ID
+
deviceId
,
alarmRedisDTO
);
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_OFF_BED_ID
+
deviceId
,
alarmRedisDTO
);
}
}
}
}
...
@@ -278,8 +277,9 @@ public class OffBedAlarm implements IAlarm {
...
@@ -278,8 +277,9 @@ public class OffBedAlarm implements IAlarm {
alarmRedisDTO
.
setStart
(
new
Date
());
alarmRedisDTO
.
setStart
(
new
Date
());
alarmRedisDTO
.
setAlarm
(
CommonEnum
.
YES
.
getValue
());
alarmRedisDTO
.
setAlarm
(
CommonEnum
.
YES
.
getValue
());
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_OFF_BED_ID
+
deviceId
,
alarmRedisDTO
);
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_OFF_BED_ID
+
deviceId
,
alarmRedisDTO
);
log
.
info
(
"离床告警推送离床消息,第一次上报时间:{},开始上报时间:{},是否上报:{}"
,
log
.
info
(
"离床告警推送离床消息,第一次上报时间:{},开始上报时间:{},是否上报:{},上报的config:{}"
,
longToTime
(
alarmRedisDTO
.
getStartLong
()),
alarmRedisDTO
.
getStart
(),
alarmRedisDTO
.
getAlarm
());
longToTime
(
alarmRedisDTO
.
getStartLong
()),
alarmRedisDTO
.
getStart
(),
alarmRedisDTO
.
getAlarm
()
,
platAlarmConfig
.
getRuleConfig
());
}
}
@Override
@Override
...
@@ -321,15 +321,15 @@ public class OffBedAlarm implements IAlarm {
...
@@ -321,15 +321,15 @@ public class OffBedAlarm implements IAlarm {
}
}
private
LocalDateTime
currentTime
()
{
private
LocalDateTime
currentTime
()
{
return
LocalDateTime
.
now
().
plusHours
(
5
);
// return LocalDateTime.now().plusHours(3
);
//
return LocalDateTime.now();
return
LocalDateTime
.
now
();
}
}
private
LocalDateTime
longToTime
(
Long
longTime
)
{
private
LocalDateTime
longToTime
(
Long
longTime
)
{
return
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
longTime
),
ZoneOffset
.
of
(
"+8"
));
return
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
longTime
),
ZoneOffset
.
of
(
"+8"
));
}
}
private
Date
toDate
(){
private
Date
toDate
()
{
ZoneId
zoneId
=
ZoneId
.
systemDefault
();
ZoneId
zoneId
=
ZoneId
.
systemDefault
();
ZonedDateTime
zdt
=
currentTime
().
atZone
(
zoneId
);
ZonedDateTime
zdt
=
currentTime
().
atZone
(
zoneId
);
return
Date
.
from
(
zdt
.
toInstant
());
return
Date
.
from
(
zdt
.
toInstant
());
...
...
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