Commit 521bbf36 by 汪志阳

fix:bug fix

parent 385c825c
......@@ -11,6 +11,7 @@ import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.redis.RedisConst;
import com.makeit.service.platform.alarm.PlatAlarmConfigService;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.AlarmConfigCacheUtil;
import com.makeit.utils.AlarmRedisDTO;
......@@ -19,6 +20,7 @@ import com.makeit.utils.redis.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
......@@ -36,6 +38,8 @@ public class OffBedAlarm implements IAlarm {
private final PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.OFF_BED;
@Resource
private AlarmConfigCacheUtil alarmConfigCacheUtil;
@Autowired
private PlatAlarmConfigService platAlarmConfigService;
@Override
public boolean support(String alarmType) {
......@@ -48,7 +52,7 @@ public class OffBedAlarm implements IAlarm {
* @param platAlarmCheckDTO
*/
@Override
public synchronized void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
log.info("执行离床checkConfig方法:");
......@@ -58,6 +62,13 @@ public class OffBedAlarm implements IAlarm {
return;
}
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())) {
// log.error("离床告警配置不存在,config:{}", JSONUtil.toJsonStr(config));
return;
......@@ -128,14 +139,12 @@ public class OffBedAlarm implements IAlarm {
} else {
handleUnCrossDay(alarmRedisDTO, ruleConfig, platAlarmCheckDTO, config, deviceId);
}
}
}
/**
* 处理跨天业务
*
* @param alarmRedisDTO
* @param ruleConfig
* @param platAlarmCheckDTO
......@@ -146,25 +155,23 @@ public class OffBedAlarm implements IAlarm {
PlatAlarmCheckDTO platAlarmCheckDTO,
PlatAlarmConfig config,
String deviceId) {
log.info("cross_config:{},第一次离床时间:{}", config.getRuleConfig(), longToTime(alarmRedisDTO.getStartLong()));
Integer duration = ruleConfig.getDuration();
LocalTime startTime = ruleConfig.getOffBedStart();
LocalTime endTime = ruleConfig.getOffBedEnd();
Long firstOffBedLong = alarmRedisDTO.getStartLong();
long currentTimeMillis = System.currentTimeMillis();
currentTimeMillis = currentLong();
long currentTimeMillis = currentLong();
boolean isOverTime = (currentTimeMillis - firstOffBedLong) / 1000 >= duration * 60;
LocalDateTime firstOffBedTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(firstOffBedLong), ZoneOffset.of("+8"));
LocalTime firstTime = firstOffBedTime.toLocalTime();
LocalTime firstTime = longToTime(firstOffBedLong).toLocalTime();
boolean isInTime = firstTime.isAfter(startTime) || firstTime.isBefore(endTime);
// LocalTime endTimeLimit = endTime.plusMinutes(-duration);
// 离床时间在范围内
if (isInTime && isOverTime) {
platAlarmCheckDTO.setAbnormalValue(String.valueOf(currentTimeMillis - firstOffBedLong));
platAlarmCheckDTO.setPlatAlarmConfig(config);
log.info("cross离床告警离床时间在范围时间内,配置:{}", config.getRuleConfig());
platAlarmCheckDTO.setPlatAlarmConfig(config);
noticeAlarm(alarmRedisDTO, platAlarmCheckDTO, deviceId);
return;
}
......@@ -175,8 +182,8 @@ public class OffBedAlarm implements IAlarm {
boolean noInOverTime = mills >= duration * 60;
if (noInOverTime) {
platAlarmCheckDTO.setAbnormalValue(String.valueOf(currentTimeMillis - firstOffBedLong));
platAlarmCheckDTO.setPlatAlarmConfig(config);
log.info("cross离床告警第一次离床时间在范围前,配置:{}", config.getRuleConfig());
platAlarmCheckDTO.setPlatAlarmConfig(config);
noticeAlarm(alarmRedisDTO, platAlarmCheckDTO, deviceId);
} else {
log.info("cross离床告警,第一次离床时间在范围前,未预警,配置:{},时间持续:{},start:{}", config.getRuleConfig(), mills, startLocalDteTime);
......@@ -189,7 +196,8 @@ public class OffBedAlarm implements IAlarm {
}
/**
* 处理跨天业务
* 处理未跨天业务
*
* @param alarmRedisDTO
* @param ruleConfig
* @param platAlarmCheckDTO
......@@ -200,7 +208,7 @@ public class OffBedAlarm implements IAlarm {
PlatAlarmCheckDTO platAlarmCheckDTO,
PlatAlarmConfig config,
String deviceId) {
log.info("uncross_config:{},第一次离床时间:{}", config.getRuleConfig(), longToTime(alarmRedisDTO.getStartLong()));
Integer duration = ruleConfig.getDuration();
LocalTime startTime = ruleConfig.getOffBedStart();
LocalDateTime startLocalDteTime = LocalDateTime.of(LocalDate.now(), startTime);
......@@ -210,18 +218,16 @@ public class OffBedAlarm implements IAlarm {
Long firstOffBedLong = alarmRedisDTO.getStartLong();
long currentTimeMillis = currentLong();
boolean isOverTime = (currentTimeMillis - firstOffBedLong) / 1000 >= duration * 60;
LocalDateTime firstOffBedTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(firstOffBedLong), ZoneOffset.of("+8"));
LocalTime firstTime = firstOffBedTime.toLocalTime();
LocalTime firstTime = longToTime(firstOffBedLong).toLocalTime();
boolean isInTime = firstTime.isAfter(startTime) && firstTime.isBefore(endTime);
LocalTime endTimeLimit = endTime.plusMinutes(-duration);
// 离床时间在范围内
if (isInTime && isOverTime) {
if (firstTime.isAfter(endTimeLimit)) {
log.info("handleUnCrossDay第一次离床时间,{}+持续时间:{}将超过范围,{}", firstTime, duration, endTime);
return;
}
// if (firstTime.isAfter(endTimeLimit)) {
// log.info("handleUnCrossDay第一次离床时间,{}+持续时间:{}将超过范围,{}", firstTime, duration, endTime);
// return;
// }
platAlarmCheckDTO.setAbnormalValue(String.valueOf(currentTimeMillis - firstOffBedLong));
platAlarmCheckDTO.setPlatAlarmConfig(config);
log.info("uncross离床告警离床时间在范围时间内,配置:{}", config.getRuleConfig());
......@@ -236,8 +242,8 @@ public class OffBedAlarm implements IAlarm {
boolean noInOverTime = mills >= duration * 60;
if (noInOverTime) {
platAlarmCheckDTO.setAbnormalValue(String.valueOf(currentTimeMillis - firstOffBedLong));
platAlarmCheckDTO.setPlatAlarmConfig(config);
log.info("uncross离床告警第一次离床时间在范围前,配置:{}", config.getRuleConfig());
platAlarmCheckDTO.setPlatAlarmConfig(config);
noticeAlarm(alarmRedisDTO, platAlarmCheckDTO, deviceId);
} else {
log.info("uncross离床告警第一次离床时间在范围前,未预警,配置:{},时间持续:{},start:{}", config.getRuleConfig(), mills, startLocalDteTime);
......@@ -249,22 +255,15 @@ public class OffBedAlarm implements IAlarm {
private void sendToRedis(AlarmRedisDTO alarmRedisDTO, String deviceId) {
Date now = toDate();
// Date now = new Date();
long endLong = now.getTime();
// 第一次上报
if (alarmRedisDTO == null) {
alarmRedisDTO = new AlarmRedisDTO();
alarmRedisDTO.setAlarm(CommonEnum.NO.getValue());
alarmRedisDTO.setStart(now);
endLong = currentLong();
alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStartLong(currentLong());
RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO);
// log.info("离床告警 离床设备存储redis,第一次上报时间:{},开始上报时间:{},是否上报:{}",
// alarmRedisDTO.getStartLong(), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm());
} else {
alarmRedisDTO.setStart(now);
// log.info("离床告警离床更新redis,第一次上报时间:{},更新时间:{},是否上报:{}",
// longToTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm());
RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO);
}
}
......@@ -278,8 +277,9 @@ public class OffBedAlarm implements IAlarm {
alarmRedisDTO.setStart(new Date());
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO);
log.info("离床告警推送离床消息,第一次上报时间:{},开始上报时间:{},是否上报:{}",
longToTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm());
log.info("离床告警推送离床消息,第一次上报时间:{},开始上报时间:{},是否上报:{},上报的config:{}",
longToTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm()
, platAlarmConfig.getRuleConfig());
}
@Override
......@@ -321,15 +321,15 @@ public class OffBedAlarm implements IAlarm {
}
private LocalDateTime currentTime() {
return LocalDateTime.now().plusHours(5);
// return LocalDateTime.now();
// return LocalDateTime.now().plusHours(3);
return LocalDateTime.now();
}
private LocalDateTime longToTime(Long longTime) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(longTime), ZoneOffset.of("+8"));
}
private Date toDate(){
private Date toDate() {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = currentTime().atZone(zoneId);
return Date.from(zdt.toInstant());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment