Commit d36fe34a by 汪志阳

fix:修复bug

parent fe2f04d3
...@@ -21,7 +21,7 @@ public class PlatAlarmRecord extends BaseBusEntity { ...@@ -21,7 +21,7 @@ public class PlatAlarmRecord extends BaseBusEntity {
*/ */
private String alarmId; private String alarmId;
@ApiModelProperty(value = "告警类型 数据字典 1 长者跌倒 2 呼吸异常 3 心率异常 4 行为异常") @ApiModelProperty(value = "告警类型 数据字典 1 长者跌倒 2 呼吸异常 3 心率异常 4 行为异常, 5 离床异常")
private String alarmType; private String alarmType;
/** /**
......
...@@ -23,6 +23,8 @@ import org.apache.commons.lang3.StringUtils; ...@@ -23,6 +23,8 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -53,6 +55,7 @@ public class OffBedAlarm implements IAlarm { ...@@ -53,6 +55,7 @@ public class OffBedAlarm implements IAlarm {
@Override @Override
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) { public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO); platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
log.info("执行离床checkConfig方法:");
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList(); List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if (CollectionUtils.isEmpty(platElderList)) { if (CollectionUtils.isEmpty(platElderList)) {
log.error("离床告警心率设备未关联长者,设备plat_id:" + platAlarmCheckDTO.getPlatDevice().getId()); log.error("离床告警心率设备未关联长者,设备plat_id:" + platAlarmCheckDTO.getPlatDevice().getId());
...@@ -77,7 +80,6 @@ public class OffBedAlarm implements IAlarm { ...@@ -77,7 +80,6 @@ public class OffBedAlarm implements IAlarm {
log.error("离床告警配置解析失败,config:{}", JSONUtil.toJsonStr(config)); log.error("离床告警配置解析失败,config:{}", JSONUtil.toJsonStr(config));
return; return;
} }
JSONObject properties = platAlarmCheckDTO.getProperties(); JSONObject properties = platAlarmCheckDTO.getProperties();
if (properties == null) { if (properties == null) {
properties = new JSONObject(); properties = new JSONObject();
...@@ -92,11 +94,17 @@ public class OffBedAlarm implements IAlarm { ...@@ -92,11 +94,17 @@ public class OffBedAlarm implements IAlarm {
LocalDateTime startTime = timeRange.get(0); LocalDateTime startTime = timeRange.get(0);
LocalDateTime endTime = timeRange.get(1); LocalDateTime endTime = timeRange.get(1);
Integer duration = ruleConfig.getDuration(); Integer duration = ruleConfig.getDuration();
String personState = Convert.toStr(properties.get("personState")); String personState = Convert.toStr(properties.get("person"));
boolean isInRange = LocalDateTime.now().isAfter(startTime) && LocalDateTime.now().isBefore(endTime); // 1-有人 0-无人
if (!"0".equals(personState) || !isInRange) { log.warn("离床config:{}",JSONUtil.toJsonStr(properties));
return; if ("1".equals(personState)) {
log.warn("离床有人状态下,删除redis!");
RedisUtil.delete(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId);
} }
// 设备无人,在范围内上报存储redis,超过离床持续时间,则预警
boolean isInRange = LocalDateTime.now().isAfter(startTime) && LocalDateTime.now().isBefore(endTime);
if ("0".equals(personState) && isInRange) {
AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId); AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId);
if (alarmRedisDTO == null) { if (alarmRedisDTO == null) {
Date now = new Date(); Date now = new Date();
...@@ -106,27 +114,29 @@ public class OffBedAlarm implements IAlarm { ...@@ -106,27 +114,29 @@ public class OffBedAlarm implements IAlarm {
alarmRedisDTO.setStart(now); alarmRedisDTO.setStart(now);
alarmRedisDTO.setStartLong(endLong); alarmRedisDTO.setStartLong(endLong);
RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO);
log.warn("发现长者设备状态无人,设备plat_id:" + deviceId); log.warn("离床设备存储redis,第一次上报时间:{},开始上报时间:{},是否上报:{}",
getDateTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm());
return; return;
} }
log.warn("redis获取offbed数据:{}", JSONUtil.toJsonStr(alarmRedisDTO));
Date now = new Date(); Date now = new Date();
long endLong = now.getTime(); long endLong = now.getTime();
Long startLong = alarmRedisDTO.getStartLong(); Long startLong = alarmRedisDTO.getStartLong();
long count = endLong - startLong; long count = endLong - startLong;
String messageType = platAlarmCheckDTO.getMessageType(); // 持续时间满足、且未预警过
if (count / 1000 >= duration) { if (count / 1000 >= duration * 60 && StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.NO.getValue())) {
if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) { log.warn("离床持续时间:{} 秒,当前时间:{},duration:{}", count / 1000, now, duration);
log.warn("离床告警已告警过,设备plat_id:" + deviceId); // alarmRedisDTO.setStartLong(endLong);
return;
}
alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStart(now); alarmRedisDTO.setStart(now);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue()); alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
platAlarmCheckDTO.setAbnormalValue(String.valueOf(count)); platAlarmCheckDTO.setAbnormalValue(String.valueOf(count / 1000));
RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO);
log.warn("推送离床消息,第一次上报时间:{},开始上报时间:{},是否上报:{}",
getDateTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm());
notice(platAlarmCheckDTO); notice(platAlarmCheckDTO);
} else if (StringUtils.equalsAnyIgnoreCase(messageType, "REPORT_PROPERTY", "OFFLINE", "DISCONNECT")) { }
}
String messageType = platAlarmCheckDTO.getMessageType();
if (StringUtils.equalsAnyIgnoreCase(messageType,"OFFLINE", "DISCONNECT")) {
log.warn("删除redisoffbed预警"); log.warn("删除redisoffbed预警");
RedisUtil.delete(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId); RedisUtil.delete(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId);
} }
...@@ -186,7 +196,25 @@ public class OffBedAlarm implements IAlarm { ...@@ -186,7 +196,25 @@ public class OffBedAlarm implements IAlarm {
} }
} }
private static String getDateTime(long longTime) {
return dateToString(new Date(longTime), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
}
/**
* 日期类型转换成字符串类型
*
* @param date 日期
* @param dateFormat 日期格式
* @return 日期字符串
*/
private static String dateToString(Date date, DateFormat dateFormat) {
return dateFormat.format(date);
}
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(); System.out.println(new Date().getTime());
// 1702279283249
System.out.println(new Date().getTime()-1702279283249L);
} }
} }
...@@ -87,6 +87,7 @@ import java.time.LocalDateTime; ...@@ -87,6 +87,7 @@ import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -744,7 +745,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -744,7 +745,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
private void saveDeviceOtherInfo(Collection<PlatDevice> platDevices) { private void saveDeviceOtherInfo(Collection<PlatDevice> platDevices) {
List<String> deviceIdList = platDevices.stream().map(BaseEntity::getId).collect(Collectors.toList()); List<String> deviceIdList = platDevices.stream().map(BaseEntity::getId).collect(Collectors.toList());
List<PlatDeviceOther> platDeviceOtherList = platDeviceOtherService.list(new QueryWrapper<PlatDeviceOther>().lambda().in(PlatDeviceOther::getDeviceId, deviceIdList)); List<PlatDeviceOther> platDeviceOtherList = platDeviceOtherService.list(new QueryWrapper<PlatDeviceOther>().lambda().in(PlatDeviceOther::getDeviceId, deviceIdList));
Map<String, PlatDeviceOther> deviceOtherMap = StreamUtil.toMap(platDeviceOtherList, PlatDeviceOther::getDeviceId); Map<String, PlatDeviceOther> deviceOtherMap = platDeviceOtherList.stream().collect(Collectors.toMap(PlatDeviceOther::getDeviceId, Function.identity(),(v1,v2)->v1));
for (PlatDevice platDevice : platDevices) { for (PlatDevice platDevice : platDevices) {
PlatDeviceOther platDeviceOther = deviceOtherMap.get(platDevice.getId()); PlatDeviceOther platDeviceOther = deviceOtherMap.get(platDevice.getId());
if (platDeviceOther == null) { if (platDeviceOther == null) {
......
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