Commit d36fe34a by 汪志阳

fix:修复bug

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