Commit 1284b262 by 汪志阳

离床异常消息警告

parent 8e1c37cb
......@@ -3,7 +3,7 @@ INSERT INTO `saas_user`(`id`, `username`, `account`, `password`, `mobile`, `stat
INSERT INTO `plat_alarm_config`(`id`, `alarm_type`, `status`, `org_id`, `city_org_id`, `district_org_id`, `street_org_id`, `org_path`, `rule_config`, `content`, `notify_channel`, `notify_relation`, `notify_way`, `notify_user`, `description`, `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `tenant_id`, `content_audit`) VALUES ('1699667670087065604', '1', '1', '1701542574740770817', NULL, NULL, NULL, NULL, '{}', '[#长者姓名]在[#房间名]跌倒,请及时处理!', '', '1', '1', NULL, NULL, 'platAdmin02', '2023-09-07 14:15:26', '测试clt', '2023-09-12 17:09:17', '0', '0', NULL);
INSERT INTO `plat_alarm_config`(`id`, `alarm_type`, `status`, `org_id`, `city_org_id`, `district_org_id`, `street_org_id`, `org_path`, `rule_config`, `content`, `notify_channel`, `notify_relation`, `notify_way`, `notify_user`, `description`, `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `tenant_id`, `content_audit`) VALUES ('16996678722776842251', '2', '1', '1701542574740770817', NULL, NULL, NULL, NULL, '{\"respiratoryRateStart\":\"10\",\"respiratoryRateEnd\":\"120\",\"duration\":\"5\"}', '[#长者姓名][#呼吸状态],请及时处理!', '', '1', '1', NULL, NULL, 'platAdmin02', '2023-09-07 14:16:14', 'platAdmin02', '2023-09-07 14:16:14', '0', '0', NULL);
INSERT INTO `plat_alarm_config`(`id`, `alarm_type`, `status`, `org_id`, `city_org_id`, `district_org_id`, `street_org_id`, `org_path`, `rule_config`, `content`, `notify_channel`, `notify_relation`, `notify_way`, `notify_user`, `description`, `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `tenant_id`, `content_audit`) VALUES ('16996680489417687051', '3', '1', '1701542574740770817', NULL, NULL, NULL, NULL, '{\"heartRateStart\":\"60\",\"heartRateeEnd\":\"90\",\"duration\":\"5\"}', '[#长者姓名][#心率状态],请及时处理!', '', '1', '1', NULL, NULL, 'platAdmin02', '2023-09-07 14:16:56', 'platAdmin02', '2023-09-07 14:16:56', '0', '0', NULL);
INSERT INTO `plat_alarm_config`(`id`, `alarm_type`, `status`, `org_id`, `city_org_id`, `district_org_id`, `street_org_id`, `org_path`, `rule_config`, `content`, `notify_channel`, `notify_relation`, `notify_way`, `notify_user`, `description`, `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `tenant_id`, `content_audit`) VALUES ('16996680489417687051', '3', '1', '1701542574740770817', NULL, NULL, NULL, NULL, '{\"heartRateStart\":\"60\",\"heartRateEnd\":\"90\",\"duration\":\"5\"}', '[#长者姓名][#心率状态],请及时处理!', '', '1', '1', NULL, NULL, 'platAdmin02', '2023-09-07 14:16:56', 'platAdmin02', '2023-09-07 14:16:56', '0', '0', NULL);
INSERT INTO `plat_alarm_config`(`id`, `alarm_type`, `status`, `org_id`, `city_org_id`, `district_org_id`, `street_org_id`, `org_path`, `rule_config`, `content`, `notify_channel`, `notify_relation`, `notify_way`, `notify_user`, `description`, `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `tenant_id`, `content_audit`) VALUES ('16996682046846648331', '4', '1', '1701542574740770817', NULL, NULL, NULL, NULL, '{\"averageDuration\":\"5\"}', '[#长者姓名]在[#上级空间名-房间名]内存在行为异常,请及时处理!', '', '1', '1', NULL, NULL, 'platAdmin02', '2023-09-07 14:17:33', 'platAdmin02', '2023-09-07 14:17:33', '0', '0', NULL);
......
ALTER TABLE `plat_device_other`
ALTER TABLE `plat_device_other`
......@@ -61,3 +61,5 @@ ALTER TABLE `plat_alarm_config` modify column alarm_type char(1) comment '告警
INSERT INTO `plat_alarm_config`(`id`, `alarm_type`, `status`, `org_id`, `city_org_id`, `district_org_id`, `street_org_id`, `org_path`, `rule_config`, `content`, `notify_channel`, `notify_relation`, `notify_way`, `notify_user`, `description`, `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `tenant_id`, `content_audit`)
VALUES ('16996678722776842252', '5', '1', '1701542574740770817', NULL, NULL, NULL, NULL, '{\"offBedStart\":\"0:00\",\"startTimeType\":\"1\",\"offBedEnd\":\"10:00\",\"endTimeType\":\"2\",\"duration\":\"5\"}', '[#长者姓名]离床时间过长,请及时处理!', '', '1', '1', NULL, NULL, 'platAdmin02', NOW(), 'platAdmin02', NOW(), '0', '0', NULL);
## 离床异常字典
INSERT INTO `sys_dictionary` VALUES ('204', 'alarm.alarmType.offBed', '离床异常', '5', 5, '', '200', NOW(), NOW(), '0', NULL, NULL, NULL);
......@@ -96,6 +96,7 @@ public class RedisConst {
public static final String ALARM_DEVICE_HR_ID = "alarm:device:hr:id:";
public static final String ALARM_DEVICE_FALL_ID = "alarm:device:fall:id:";
public static final String ALARM_DEVICE_BEHAVIOR_ID = "alarm:device:behavior:id:";
public static final String ALARM_DEVICE_OFF_BED_ID = "alarm:device:off_bed:id:";
public static final String ALARM_CONFIG_ORG_ID = "alarm:config:org:id:";
public static final String PLAT_IOT_DEVICE_PREFIX = "plat:iot:device:";
......
......@@ -62,7 +62,7 @@ public class PlatAlarmRecordWechatController {
@ApiOperation("已读")
@PostMapping("read")
public ApiResponseEntity<Void> read(@RequestBody BaseIdDTO dto) {
platAlarmRecordService.read(dto.getId(), PlatformTypeEnum.WECHAT);
platAlarmRecordService.read(dto.getId(), PlatformTypeEnum.PC);
return ApiResponseUtils.success();
}
@ApiOperation("通知家属")
......
......@@ -22,7 +22,7 @@ public class PlatAlarmConfigHeartDTOVO {
private Integer heartRateStart;
@ApiModelProperty("心率正常范围结束")
private Integer heartRateeEnd;
private Integer heartRateEnd;
@ApiModelProperty("异常持续时间")
private Integer duration;
......
......@@ -7,7 +7,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import java.time.LocalTime;
/**
* <p>
......@@ -25,7 +25,7 @@ public class PlatAlarmConfigOffBedDTOVO {
@ApiModelProperty("离床开始时间")
@DateTimeFormat(pattern = "HH:mm")
@JsonFormat(pattern = "HH:mm",timezone="GMT+8")
private LocalDateTime offBedStart;
private LocalTime offBedStart;
@ApiModelProperty("离床时间类型 :1-当日,2-次日")
private String startTimeType;
......@@ -33,7 +33,7 @@ public class PlatAlarmConfigOffBedDTOVO {
@ApiModelProperty("离床结束时间")
@DateTimeFormat(pattern = "HH:mm")
@JsonFormat(pattern = "HH:mm",timezone="GMT+8")
private LocalDateTime offBedEnd;
private LocalTime offBedEnd;
@ApiModelProperty("离床时间类型 :1-当日,2-次日")
private String endTimeType;
......
......@@ -65,7 +65,7 @@ public class PlatHealthConfigDTO {
if(heartConfig){
PlatAlarmConfigHeartDTOVO dto = new PlatAlarmConfigHeartDTOVO();
dto.setHeartRateStart(heartRateStart);
dto.setHeartRateeEnd(heartRateEnd);
dto.setHeartRateEnd(heartRateEnd);
dto.setDuration(heartDuration);
return dto;
}
......
......@@ -12,8 +12,8 @@ import lombok.Getter;
@AllArgsConstructor
public enum PlatformTypeEnum {
PC("1", "pc端"),
WECHAT("2", "微信小程序");
PC("1", "pc端、小程序"),
WECHAT("2", "子女端小程序");
private String code;
private String value;
......
......@@ -81,7 +81,7 @@ public class HeartAlarm implements IAlarm {
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getId();
Integer start = ruleConfig.getHeartRateStart();
Integer end = ruleConfig.getHeartRateeEnd();
Integer end = ruleConfig.getHeartRateEnd();
Integer duration = ruleConfig.getDuration();
String personState = Convert.toStr(properties.get("personState"));
//心率
......
package com.makeit.service.platform.alarm.alarmStrategy;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
import com.makeit.dto.platform.alarm.PlatAlarmConfigOffBedDTOVO;
import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.redis.RedisConst;
import com.makeit.module.iot.enums.DeviceInfoContentBreatheEnum;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.data.convert.JsonUtil;
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.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
@Slf4j
public class OffBedAlarm implements IAlarm {
@Resource
private PlatAlarmRecordService platAlarmRecordService;
private final String CURRENT_DAY = "1";
private final PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.OFF_BED;
@Override
public boolean support(String alarmType) {
return StringUtils.equals(alarmType, alarmTypeEnum.getValue());
}
/**
* 4.离床异常:长者绑定的呼吸心率设备在配置时间段内,检测到长者的离床状态(设备状态无人)持续时间超过配置的离床持续时间,则告警
*
* @param platAlarmCheckDTO
*/
@Override
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if (CollectionUtils.isEmpty(platElderList)) {
log.error("呼吸告警心率设备未关联长者,设备plat_id:" + platAlarmCheckDTO.getPlatDevice().getId());
return;
}
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
if (!"5".equals(config.getAlarmType())) {
log.error("呼吸告警配置不存在,config:{}", JSONUtil.toJsonStr(config));
return;
}
if (CommonEnum.NO.getValue().equals(config.getStatus())) {
log.error("离床告警配置为禁用,告警配置id:" + config.getId());
return;
}
String ruleConfigStr = config.getRuleConfig();
if (StringUtils.isBlank(ruleConfigStr)) {
log.error("离床告警配置未配置,告警配置id:" + config.getId());
return;
}
PlatAlarmConfigOffBedDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigOffBedDTOVO.class);
if (ruleConfig == null) {
log.error("离床告警配置解析失败,config:{}", JSONUtil.toJsonStr(config));
return;
}
JSONObject properties = platAlarmCheckDTO.getProperties();
if (properties == null) {
properties = new JSONObject();
}
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getId();
List<LocalDateTime> timeRange = getOffTimeRange(ruleConfig);
if (CollUtil.isEmpty(timeRange)) {
log.error("离床告警配置时间段解析失败,config:{}", JSONUtil.toJsonStr(ruleConfig));
return;
}
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 (!DeviceInfoContentBreatheEnum.PersonStateEnum.NOBODY.eq(personState) || !isInRange) {
return;
}
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.error("发现长者设备状态无人,设备plat_id:" + deviceId);
return;
}
Date now = new Date();
long endLong = now.getTime();
Long startLong = alarmRedisDTO.getStartLong();
long count = endLong - startLong;
String messageType = platAlarmCheckDTO.getMessageType();
if (count / 1000 >= duration && !StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) {
// platAlarmCheckDTO.setAbnormalValue(Convert.toStr(br));
alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStart(now);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO);
notice(platAlarmCheckDTO);
}
if (StringUtils.equalsAnyIgnoreCase(messageType, "REPORT_PROPERTY", "OFFLINE", "DISCONNECT")) {
RedisUtil.delete(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId);
}
}
private List<LocalDateTime> getOffTimeRange(PlatAlarmConfigOffBedDTOVO ruleConfig) {
List<LocalDateTime> result = new ArrayList<>();
LocalDate localDate = LocalDate.now();
LocalDateTime startTime;
LocalDateTime endTime;
if (CURRENT_DAY.equals(ruleConfig.getStartTimeType())) {
startTime = LocalDateTime.of(localDate, ruleConfig.getOffBedStart());
} else {
startTime = LocalDateTime.of(localDate.plusDays(1), ruleConfig.getOffBedStart());
}
if (CURRENT_DAY.equals(ruleConfig.getEndTimeType())) {
endTime = LocalDateTime.of(localDate, ruleConfig.getOffBedEnd());
} else {
endTime = LocalDateTime.of(localDate.plusDays(1), ruleConfig.getOffBedEnd());
}
result.add(startTime);
result.add(endTime);
return result;
}
@Override
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
if (CommonEnum.NO.getValue().equals(config.getStatus())) {
log.error("离床告警配置为禁用,告警配置id:" + config.getId());
return;
}
if (StringUtils.isBlank(config.getRuleConfig())) {
log.error("离床告警配置未配置,告警配置id:" + config.getId());
return;
}
if (CollectionUtils.isEmpty(platElderList)) {
log.error("离床告警配置未关联长者,设备plat_id:" + platDevice.getId());
return;
}
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
for (PlatElder platElder : platElderList) {
List<String> param = new ArrayList<>();
param.add(platRoom.getName());
param.add(platElder.getName());
platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO, platElder);
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
log.error("离床告警配置,发出告警,设备id:" + platDevice.getId() + ", 长者名称:" + platElder.getName());
}
}
}
......@@ -147,8 +147,14 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
}
this.updateById(space);
List<PlatRoom> platRoomList = platRoomService.listBySpaceId(space.getId());
List<String> laseSpaceIds = recursionLastSpaceIds(space.getId(), new ArrayList<>());
if (CollUtil.isEmpty(laseSpaceIds)) {
return;
}
List<PlatRoom> platRoomList = platRoomService.list(Wrappers.<PlatRoom>lambdaQuery().in(PlatRoom::getSpaceId, laseSpaceIds));
if (CollUtil.isEmpty(platRoomList)) {
return;
}
for (PlatRoom platRoom : platRoomList) {
platRoom.setSpacePath(dto.getParentPath() + "," + space.getId());
platRoomService.updateById(platRoom);
......@@ -174,6 +180,17 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
}
}
private List<String> recursionLastSpaceIds(String spaceId, List<String> result) {
List<PlatSpace> platSpaces = this.list(Wrappers.<PlatSpace>lambdaQuery().eq(PlatSpace::getParentId, spaceId));
if (CollUtil.isNotEmpty(platSpaces)) {
platSpaces.forEach(p -> recursionLastSpaceIds(p.getId(), result));
} else {
result.add(spaceId);
return result;
}
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void del(String id) {
......
......@@ -30,7 +30,7 @@ public class PlatAlarmRecordVO extends BaseTenantDTO {
@ApiModelProperty(value = "通知家属 数据字典 1、同步通知 2 可选通知 3 不通知")
private String notifyRelation;
@ApiModelProperty(value = "告警类型 数据字典 1 长者跌倒 2 呼吸异常 3 心率异常 4 行为异常")
@ApiModelProperty(value = "告警类型 数据字典 1 长者跌倒 2 呼吸异常 3 心率异常 4 行为异常,5 离床异常")
private String alarmType;
@ApiModelProperty(value = "告警时间")
......
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