Commit 844213b9 by 李小龙

fixbug:心率告警 呼吸告警

parent 5682ce89
Showing with 509 additions and 111 deletions
...@@ -92,11 +92,16 @@ public class RedisConst { ...@@ -92,11 +92,16 @@ public class RedisConst {
public static final String TENANT_PREFIX = "tenant:"; public static final String TENANT_PREFIX = "tenant:";
public static final String ALARM_DEVICE_ID = "alarm:device:id:"; public static final String ALARM_DEVICE_BR_ID = "alarm:device:br:id:";
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_CONFIG_ORG_ID = "alarm:config:org:id:"; public static final String ALARM_CONFIG_ORG_ID = "alarm:config:org:id:";
public static final String PLAT_IOT_DEVICE_PREFIX = "plat:iot:device:"; public static final String PLAT_IOT_DEVICE_PREFIX = "plat:iot:device:";
public static final String ELDER_DAY_DURATION_PREFIX = "plat:day:duration:device:";
......
...@@ -20,6 +20,8 @@ public class MsgSendDTO { ...@@ -20,6 +20,8 @@ public class MsgSendDTO {
private Collection<String> receiverList; private Collection<String> receiverList;
private Collection<String> emailSet;
private String oriContent; private String oriContent;
/** /**
......
package com.makeit.utils.msg.sender; package com.makeit.utils.msg.sender;
import com.makeit.exception.BusinessException;
import com.makeit.utils.msg.SendTypeEnum; import com.makeit.utils.msg.SendTypeEnum;
import com.makeit.utils.msg.dto.MsgSendDTO; import com.makeit.utils.msg.dto.MsgSendDTO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -36,12 +35,12 @@ public class MailMsgSender implements IMsgSender { ...@@ -36,12 +35,12 @@ public class MailMsgSender implements IMsgSender {
MimeMessage message = mailSender.createMimeMessage(); MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true); MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(from); helper.setFrom(from);
helper.setTo(msgDTO.getReceiverList().toArray(new String[msgDTO.getReceiverList().size()])); helper.setTo(msgDTO.getEmailSet().toArray(new String[msgDTO.getReceiverList().size()]));
helper.setSubject(msgDTO.getSubject()); helper.setSubject(msgDTO.getSubject());
helper.setText(msgDTO.getOriContent(), false); helper.setText(msgDTO.getOriContent(), false);
mailSender.send(message); mailSender.send(message);
} catch (Exception e) { } catch (Exception e) {
throw new BusinessException(e.getMessage()); log.error("发送邮箱异常:",e);
} }
} }
......
...@@ -8,6 +8,8 @@ import com.makeit.utils.msg.config.SmsConfig; ...@@ -8,6 +8,8 @@ import com.makeit.utils.msg.config.SmsConfig;
import com.makeit.utils.msg.dto.MsgSendDTO; import com.makeit.utils.msg.dto.MsgSendDTO;
import com.makeit.utils.old.encode.CryptoUtil; import com.makeit.utils.old.encode.CryptoUtil;
import com.makeit.utils.third.HttpClient; import com.makeit.utils.third.HttpClient;
import lombok.extern.slf4j.Slf4j;
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.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
...@@ -20,6 +22,7 @@ import java.util.HashMap; ...@@ -20,6 +22,7 @@ import java.util.HashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
@Slf4j
public class SmsMsgSender implements IMsgSender{ public class SmsMsgSender implements IMsgSender{
@Autowired @Autowired
...@@ -40,6 +43,9 @@ public class SmsMsgSender implements IMsgSender{ ...@@ -40,6 +43,9 @@ public class SmsMsgSender implements IMsgSender{
@Override @Override
public void send(MsgSendDTO msgDTO) { public void send(MsgSendDTO msgDTO) {
try { try {
if(CollectionUtils.isEmpty(msgDTO.getReceiverList())){
log.info("发送短信时,没有接收人,短信内容:"+msgDTO.getOriContent());
}
Date now = new Date(); Date now = new Date();
String time = String.valueOf(now.getTime()); String time = String.valueOf(now.getTime());
Collection<String> receiverList = msgDTO.getReceiverList(); Collection<String> receiverList = msgDTO.getReceiverList();
...@@ -57,10 +63,13 @@ public class SmsMsgSender implements IMsgSender{ ...@@ -57,10 +63,13 @@ public class SmsMsgSender implements IMsgSender{
JSONObject jsonObject = JSON.parseObject(resStr); JSONObject jsonObject = JSON.parseObject(resStr);
String status = String.valueOf(jsonObject.get("status")); String status = String.valueOf(jsonObject.get("status"));
if (!StringUtils.equals(status, "0")) { if (!StringUtils.equals(status, "0")) {
log.error("发送短信失败:"+jsonObject.get("status_code"));
throw new BusinessException((String) jsonObject.get("status_code")); throw new BusinessException((String) jsonObject.get("status_code"));
}else {
log.info("发送短信成功");
} }
}catch (Exception e){ }catch (Exception e){
throw new BusinessException(e.getMessage()); log.error("发送短信异常:",e);
} }
} }
......
...@@ -8,6 +8,8 @@ import com.makeit.utils.msg.config.SmsVoiceConfig; ...@@ -8,6 +8,8 @@ import com.makeit.utils.msg.config.SmsVoiceConfig;
import com.makeit.utils.msg.dto.MsgSendDTO; import com.makeit.utils.msg.dto.MsgSendDTO;
import com.makeit.utils.old.encode.CryptoUtil; import com.makeit.utils.old.encode.CryptoUtil;
import com.makeit.utils.third.HttpClient; import com.makeit.utils.third.HttpClient;
import lombok.extern.slf4j.Slf4j;
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.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
...@@ -22,6 +24,7 @@ import java.util.function.BiConsumer; ...@@ -22,6 +24,7 @@ import java.util.function.BiConsumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
@Slf4j
public class SmsVoiceSender implements IMsgSender{ public class SmsVoiceSender implements IMsgSender{
@Autowired @Autowired
...@@ -42,6 +45,9 @@ public class SmsVoiceSender implements IMsgSender{ ...@@ -42,6 +45,9 @@ public class SmsVoiceSender implements IMsgSender{
@Override @Override
public void send(MsgSendDTO msgDTO) { public void send(MsgSendDTO msgDTO) {
try { try {
if(CollectionUtils.isEmpty(msgDTO.getReceiverList())){
log.info("发送语音短信时,没有接收人,短信内容:"+msgDTO.getOriContent());
}
Date now = new Date(); Date now = new Date();
String time = String.valueOf(now.getTime()); String time = String.valueOf(now.getTime());
Collection<String> receiverList = msgDTO.getReceiverList(); Collection<String> receiverList = msgDTO.getReceiverList();
...@@ -67,10 +73,11 @@ public class SmsVoiceSender implements IMsgSender{ ...@@ -67,10 +73,11 @@ public class SmsVoiceSender implements IMsgSender{
JSONObject jsonObject = JSON.parseObject(resStr); JSONObject jsonObject = JSON.parseObject(resStr);
String status = String.valueOf(jsonObject.get("status")); String status = String.valueOf(jsonObject.get("status"));
if (!StringUtils.equals(status, "0")) { if (!StringUtils.equals(status, "0")) {
log.error("发送语音短信失败:"+jsonObject.get("status_code"));
throw new BusinessException((String) jsonObject.get("status_code")); throw new BusinessException((String) jsonObject.get("status_code"));
} }
}catch (Exception e){ }catch (Exception e){
throw new BusinessException(e.getMessage().toString()); log.error("发送语音异常:",e);
} }
} }
} }
...@@ -160,4 +160,22 @@ public class LocalDateTimeUtils { ...@@ -160,4 +160,22 @@ public class LocalDateTimeUtils {
Long until = start.until(end, ChronoUnit.HOURS); Long until = start.until(end, ChronoUnit.HOURS);
return until.intValue(); return until.intValue();
} }
public static Integer getDaySub(LocalDateTime start, LocalDateTime end) {
if(start==null || end == null ){
return 0;
}
Long until = start.until(end, ChronoUnit.DAYS);
return until.intValue();
}
/**
* 修改为一天的开始时间,例如:2020-02-02 00:00:00,000
*
* @param time 日期时间
* @return 一天的开始时间
*/
public static LocalDateTime beginOfDay(LocalDateTime time) {
return time.with(LocalTime.MIN);
}
} }
...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.makeit.entity.platform.alarm.PlatAlarmConfig; import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder; import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRegionSetting;
import com.makeit.entity.platform.space.PlatRoom; import com.makeit.entity.platform.space.PlatRoom;
import lombok.Data; import lombok.Data;
...@@ -27,4 +28,6 @@ public class PlatAlarmCheckDTO { ...@@ -27,4 +28,6 @@ public class PlatAlarmCheckDTO {
//PlatAlarmRecord.remark //PlatAlarmRecord.remark
private String remark; private String remark;
private PlatRegionSetting platRegionSetting;
} }
package com.makeit.dto.platform.alarm;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class PlatDayDurationRecordDTO {
private LocalDateTime start;
private LocalDateTime end;
private List<String> dayStrList;
}
package com.makeit.entity.platform.alarm; package com.makeit.entity.platform.alarm;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.makeit.common.entity.BaseBusEntity; import com.makeit.common.entity.BaseBusEntity;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -70,12 +71,15 @@ public class PlatAlarmRecord extends BaseBusEntity { ...@@ -70,12 +71,15 @@ public class PlatAlarmRecord extends BaseBusEntity {
private String deviceId; private String deviceId;
/** /**
* 老人id,逗号拼接 * 老人id,一个老人一条记录
*/ */
private String elderIds; private String elderIds;
private String remark; private String remark;
@TableField(exist = false)
private String elderName;
} }
......
...@@ -2,6 +2,7 @@ package com.makeit.entity.platform.alarm; ...@@ -2,6 +2,7 @@ package com.makeit.entity.platform.alarm;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.makeit.common.entity.BaseBusEntity; import com.makeit.common.entity.BaseBusEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.Date; import java.util.Date;
...@@ -42,4 +43,14 @@ public class PlatDayDurationRecord extends BaseBusEntity { ...@@ -42,4 +43,14 @@ public class PlatDayDurationRecord extends BaseBusEntity {
* 本次离开时间 * 本次离开时间
*/ */
private Date endDate; private Date endDate;
@ApiModelProperty("区域名称")
private String regionName;
@ApiModelProperty("设备ID")
private String deviceId;
@ApiModelProperty("房间ID")
private String roomId;
} }
\ No newline at end of file
...@@ -2,7 +2,11 @@ package com.makeit.mapper.platform.alarm; ...@@ -2,7 +2,11 @@ package com.makeit.mapper.platform.alarm;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.makeit.dto.platform.alarm.PlatDayDurationRecordDTO;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord; import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* @author lixl * @author lixl
...@@ -13,4 +17,5 @@ import com.makeit.entity.platform.alarm.PlatDayDurationRecord; ...@@ -13,4 +17,5 @@ import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
public interface PlatDayDurationRecordMapper extends BaseMapper<PlatDayDurationRecord> { public interface PlatDayDurationRecordMapper extends BaseMapper<PlatDayDurationRecord> {
List<PlatDayDurationRecord> getDayMaxDurationList(@Param("param") PlatDayDurationRecordDTO param);
} }
...@@ -2,8 +2,11 @@ package com.makeit.service.platform.alarm; ...@@ -2,8 +2,11 @@ package com.makeit.service.platform.alarm;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.dto.platform.alarm.PlatDayDurationRecordDTO;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord; import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import java.util.List;
/** /**
* @author lixl * @author lixl
* @description 针对表【plat_day_duration_record(每天停留时长记录)】的数据库操作Service * @description 针对表【plat_day_duration_record(每天停留时长记录)】的数据库操作Service
...@@ -11,4 +14,5 @@ import com.makeit.entity.platform.alarm.PlatDayDurationRecord; ...@@ -11,4 +14,5 @@ import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
*/ */
public interface PlatDayDurationRecordService extends IService<PlatDayDurationRecord> { public interface PlatDayDurationRecordService extends IService<PlatDayDurationRecord> {
List<PlatDayDurationRecord> getDayMaxDurationList(PlatDayDurationRecordDTO param);
} }
...@@ -10,6 +10,7 @@ import com.makeit.entity.platform.alarm.PlatAlarmRecord; ...@@ -10,6 +10,7 @@ import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord; import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder; import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRegionSetting;
import com.makeit.entity.platform.space.PlatRoom; import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.enums.CommonEnum; import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum; import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
...@@ -17,12 +18,14 @@ import com.makeit.enums.redis.RedisConst; ...@@ -17,12 +18,14 @@ import com.makeit.enums.redis.RedisConst;
import com.makeit.service.platform.alarm.PlatAlarmRecordService; import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.alarm.PlatDayDurationRecordService; import com.makeit.service.platform.alarm.PlatDayDurationRecordService;
import com.makeit.utils.AlarmRedisDTO; import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.DayDurationUtil;
import com.makeit.utils.data.convert.JsonUtil; import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.redis.RedisUtil; import com.makeit.utils.redis.RedisUtil;
import com.makeit.utils.time.LocalDateTimeUtils;
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.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -35,17 +38,20 @@ import java.util.List; ...@@ -35,17 +38,20 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
public class BehaviorAlarm implements IAlarm{ @Slf4j
public class BehaviorAlarm implements IAlarm {
@Autowired @Autowired
private PlatAlarmRecordService platAlarmRecordService; private PlatAlarmRecordService platAlarmRecordService;
@Autowired @Autowired
private PlatDayDurationRecordService platDayDurationRecordService; private PlatDayDurationRecordService platDayDurationRecordService;
@Autowired
private DayDurationUtil dayDurationUtil;
private PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR; private final PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR;
@Override @Override
public boolean support(String alarmType) { public boolean support(String alarmType) {
return StringUtils.equals(alarmType,alarmTypeEnum.getValue()); return StringUtils.equals(alarmType, alarmTypeEnum.getValue());
} }
/** /**
...@@ -53,6 +59,7 @@ public class BehaviorAlarm implements IAlarm{ ...@@ -53,6 +59,7 @@ public class BehaviorAlarm implements IAlarm{
* 取前七天的日最长时间,然后取中位数 * 取前七天的日最长时间,然后取中位数
* 前七天:没有满足七条记录则跳过,如果七条没都包含长者则跳过 * 前七天:没有满足七条记录则跳过,如果七条没都包含长者则跳过
* 记录的保存和缓存读取 * 记录的保存和缓存读取
*
* @param platAlarmCheckDTO * @param platAlarmCheckDTO
*/ */
@Override @Override
...@@ -63,91 +70,131 @@ public class BehaviorAlarm implements IAlarm{ ...@@ -63,91 +70,131 @@ public class BehaviorAlarm implements IAlarm{
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice(); PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId(); String deviceId = platDevice.getOriDeviceId();
if (StringUtils.isBlank(ruleConfigStr)) { if (StringUtils.isBlank(ruleConfigStr)) {
log.info("行为告警配置未配置,告警配置id:" + config.getId());
return; return;
} }
String personState = Convert.toStr(properties.get("personState")); String personState = Convert.toStr(properties.get("personState"));
PlatAlarmConfigBehaviorDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigBehaviorDTOVO.class); PlatAlarmConfigBehaviorDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigBehaviorDTOVO.class);
Integer duration = ruleConfig.getDuration();//分钟 Integer duration = ruleConfig.getDuration();//分钟
duration = duration*60; PlatDayDurationRecord platDayDurationRecord = dayDurationUtil.get(platDevice.getOriDeviceId());
//todo duration+平均停留时长 if (platDayDurationRecord == null) {
log.info("行为告警未找到行为异常平均时长,设备id:" + platDevice.getId());
return;
}
Long duration1 = platDayDurationRecord.getDuration();
duration = duration * 60 + (int) (duration1 / 1000);
//duration+平均停留时长
List<String> personStateList = Arrays.asList("1", "2", "3"); List<String> personStateList = Arrays.asList("1", "2", "3");
//有人 //有人
//计数 //计数
Date now = new Date(); Date now = new Date();
long endLong = now.getTime(); long endLong = now.getTime();
AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_ID + deviceId); AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_BEHAVIOR_ID + deviceId);
if(alarmRedisDTO==null){ if (alarmRedisDTO == null) {
alarmRedisDTO= new AlarmRedisDTO(); alarmRedisDTO = new AlarmRedisDTO();
} }
//有人 //有人
if (personStateList.contains(personState)) { if (personStateList.contains(personState)) {
//第一次进入空间 //第一次进入空间
Long startLong = alarmRedisDTO.getStartLong(); Long startLong = alarmRedisDTO.getStartLong();
if(startLong == null ){ if (startLong == null) {
alarmRedisDTO.setStartLong(endLong); alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStart(now); alarmRedisDTO.setStart(now);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_BEHAVIOR_ID + deviceId, alarmRedisDTO);
log.info("空间雷达上报进入房间,设备id:" + platDevice.getId());
return; return;
} }
long count = endLong - startLong; long count = endLong - startLong;
//进入空间时间满足告警时长,判断是否已经告警过了 //进入空间时间满足告警时长,判断是否已经告警过了
if (count/1000 >= duration && StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.NO.getValue())) { if (count / 1000 >= duration && StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.NO.getValue())) {
log.info("空间雷达发出告警,设备id:" + platDevice.getId());
notice(platAlarmCheckDTO); notice(platAlarmCheckDTO);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue()); alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_BEHAVIOR_ID + deviceId, alarmRedisDTO);
} }
}else {//没人 } else {//没人
// 是否有第一次进入记录,有则保存db // 是否有第一次进入记录,有则保存db
Long startLong = alarmRedisDTO.getStartLong(); Long startLong = alarmRedisDTO.getStartLong();
if(startLong==null){ if (startLong == null) {
return; return;
} }
//保存每次进入空间时长 //保存每次进入空间时长
saveDayDurationRecord(platAlarmCheckDTO,alarmRedisDTO); saveDayDurationRecord(platAlarmCheckDTO, alarmRedisDTO);
RedisUtil.delete(RedisConst.ALARM_DEVICE_ID + deviceId); RedisUtil.delete(RedisConst.ALARM_DEVICE_BEHAVIOR_ID + deviceId);
} }
} }
/**
* 保存停留时长记录
* 进入雷达开始
* 走出雷达结束
*
* @param platAlarmCheckDTO
* @param alarmRedisDTO
*/
private void saveDayDurationRecord(PlatAlarmCheckDTO platAlarmCheckDTO, AlarmRedisDTO alarmRedisDTO) { private void saveDayDurationRecord(PlatAlarmCheckDTO platAlarmCheckDTO, AlarmRedisDTO alarmRedisDTO) {
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig(); PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice(); PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
PlatRegionSetting platRegionSetting = platAlarmCheckDTO.getPlatRegionSetting();
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 - alarmRedisDTO.getStartLong(); long count = endLong - alarmRedisDTO.getStartLong();
//save db //save db
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO); platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
if(CollectionUtils.isEmpty(platAlarmCheckDTO.getPlatElderList())){
log.info("未关联长者,设备id:"+platDevice.getId());
return;
}
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList(); List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
PlatDayDurationRecord durationRecord = new PlatDayDurationRecord(); PlatDayDurationRecord durationRecord = new PlatDayDurationRecord();
durationRecord.setElderIds(platElderList.stream().map(BaseEntity::getId).collect(Collectors.joining(","))); durationRecord.setElderIds(platElderList.stream().map(BaseEntity::getId).collect(Collectors.joining(",")));
durationRecord.setDuration(count); durationRecord.setDuration(count);
durationRecord.setOriDeviceId(platDevice.getOriDeviceId()); durationRecord.setOriDeviceId(platDevice.getOriDeviceId());
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
durationRecord.setDay(dateTimeFormatter.format( LocalDateTime.ofEpochSecond(startLong /1000, 0, ZoneOffset.ofHours(8)))); durationRecord.setDay(dateTimeFormatter.format(LocalDateTime.ofEpochSecond(startLong / 1000, 0, ZoneOffset.ofHours(8))));
durationRecord.setStartDate(alarmRedisDTO.getStart()); durationRecord.setStartDate(alarmRedisDTO.getStart());
durationRecord.setEndDate(now); durationRecord.setEndDate(now);
durationRecord.setTenantId(config.getTenantId()); durationRecord.setTenantId(config.getTenantId());
durationRecord.setRoomId(platRoom.getId());
durationRecord.setDeviceId(platDevice.getId());
if (platRegionSetting != null) {
durationRecord.setRegionName(platRegionSetting.getRegionName());
}
platDayDurationRecordService.saveOrUpdate(durationRecord); platDayDurationRecordService.saveOrUpdate(durationRecord);
} }
@Override @Override
@Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) { public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
//获取长者 空间信息 //获取长者 空间信息
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO); platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList(); List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if(CollectionUtils.isEmpty(platElderList)){ if (CollectionUtils.isEmpty(platElderList)) {
log.info("未关联长者,设备id:"+platAlarmCheckDTO.getPlatDevice().getId());
return; return;
} }
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom(); PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
for (PlatElder platElder : platElderList) { for (PlatElder platElder : platElderList) {
//判断是否已入住七天
LocalDateTime checkInTime = platElder.getCheckInTime();
if (checkInTime == null) {
continue;
}
Integer daySub = LocalDateTimeUtils.getDaySub(checkInTime, LocalDateTime.now());
if (daySub < 7) {
continue;
}
List<String> param = new ArrayList<>(); List<String> param = new ArrayList<>();
param.add(platElder.getName()); param.add(platElder.getName());
param.add(platRoom.getName()); param.add(platRoom.getName());
platAlarmCheckDTO.setParam(param); platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO); PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord); platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
} }
} }
} }
...@@ -8,16 +8,17 @@ import com.makeit.entity.platform.alarm.PlatAlarmConfig; ...@@ -8,16 +8,17 @@ import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.alarm.PlatAlarmRecord; import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder; 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.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.redis.RedisConst; import com.makeit.enums.redis.RedisConst;
import com.makeit.service.platform.alarm.PlatAlarmRecordService; import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.data.convert.JsonUtil; import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.redis.RedisUtil; import com.makeit.utils.redis.RedisUtil;
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.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -25,23 +26,25 @@ import java.util.Date; ...@@ -25,23 +26,25 @@ import java.util.Date;
import java.util.List; import java.util.List;
@Component @Component
public class BreathAlarm implements IAlarm{ @Slf4j
public class BreathAlarm implements IAlarm {
@Autowired @Autowired
private PlatAlarmRecordService platAlarmRecordService; private PlatAlarmRecordService platAlarmRecordService;
private PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE; private final PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE;
@Override @Override
public boolean support(String alarmType) { public boolean support(String alarmType) {
return StringUtils.equals(alarmType,alarmTypeEnum.getValue()); return StringUtils.equals(alarmType, alarmTypeEnum.getValue());
} }
/** /**
* 2.呼吸异常/心率异常:长者关联的呼吸心率雷达上报的呼吸和心率不在配置的阈值范围内,且满足持续时间进行告警, * 2.呼吸异常/心率异常:长者关联的呼吸心率雷达上报的呼吸和心率不在配置的阈值范围内,且满足持续时间进行告警,
* 若该长者在长者管理处有配置阈值,则以长者个人的阈值为准,若无,则以此处配置的通用规则为准 * 若该长者在长者管理处有配置阈值,则以长者个人的阈值为准,若无,则以此处配置的通用规则为准
* * <p>
* 心率呼吸率低于阈值且满足持续时间,则对应状态为呼吸过缓/心率过缓,高于阈值且满足持续时间, * 心率呼吸率低于阈值且满足持续时间,则对应状态为呼吸过缓/心率过缓,高于阈值且满足持续时间,
* 对应状态为呼吸过速/心率过速,呼吸心率为0且满足持续时间为呼吸暂停 * 对应状态为呼吸过速/心率过速,呼吸心率为0且满足持续时间为呼吸暂停
*
* @param platAlarmCheckDTO * @param platAlarmCheckDTO
*/ */
@Override @Override
...@@ -52,6 +55,7 @@ public class BreathAlarm implements IAlarm{ ...@@ -52,6 +55,7 @@ public class BreathAlarm implements IAlarm{
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice(); PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId(); String deviceId = platDevice.getOriDeviceId();
if (StringUtils.isBlank(ruleConfigStr)) { if (StringUtils.isBlank(ruleConfigStr)) {
log.info("呼吸告警配置未配置,告警配置id:" + config.getId());
return; return;
} }
String personState = Convert.toStr(properties.get("personState")); String personState = Convert.toStr(properties.get("personState"));
...@@ -62,52 +66,80 @@ public class BreathAlarm implements IAlarm{ ...@@ -62,52 +66,80 @@ public class BreathAlarm implements IAlarm{
Integer start = ruleConfig.getRespiratoryRateStart(); Integer start = ruleConfig.getRespiratoryRateStart();
Integer end = ruleConfig.getRespiratoryRateEnd(); Integer end = ruleConfig.getRespiratoryRateEnd();
Integer duration = ruleConfig.getDuration(); Integer duration = ruleConfig.getDuration();
long endLong = new Date().getTime(); Date now = new Date();
long endLong = now.getTime();
//计数 //计数
Long startLong = RedisUtil.get(RedisConst.ALARM_DEVICE_ID + deviceId); AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_BR_ID + deviceId);
if (StringUtils.equals(personState, "0")|| startLong == null) {
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000); if (StringUtils.equals(personState, CommonEnum.NO.getValue())) {
RedisUtil.delete(RedisConst.ALARM_DEVICE_BR_ID + deviceId);
return; return;
} }
long count = endLong - startLong;
if (br > end || br < start) {
if (count >= duration) { if ((br > end || br < start)) {
if(br>end){ if(alarmRedisDTO==null){
platAlarmCheckDTO.setRemark("呼吸过速"); alarmRedisDTO = new AlarmRedisDTO();
} alarmRedisDTO.setAlarm(CommonEnum.NO.getValue());
if(br < start){ alarmRedisDTO.setStart(now);
platAlarmCheckDTO.setRemark("呼吸过缓"); alarmRedisDTO.setStartLong(endLong);
RedisUtil.set(RedisConst.ALARM_DEVICE_BR_ID + deviceId,alarmRedisDTO);
log.info("发现长者呼吸异常,设备id:"+deviceId);
return;
}
Long startLong = alarmRedisDTO.getStartLong();
long count = endLong - startLong;
if (count/1000 >= duration) {
if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) {
log.info("呼吸已告警,设备id:" + platDevice.getId());
return;
} }
fillRemark(platAlarmCheckDTO, br, start, end);
notice(platAlarmCheckDTO); notice(platAlarmCheckDTO);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000); alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStart(now);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_BR_ID + deviceId, alarmRedisDTO);
} }
} else { } else {
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000); RedisUtil.delete(RedisConst.ALARM_DEVICE_BR_ID + deviceId);
}
}
private void fillRemark(PlatAlarmCheckDTO platAlarmCheckDTO, int br, Integer start, Integer end) {
if (br > end) {
platAlarmCheckDTO.setRemark("呼吸过速");
}
if (br < start) {
platAlarmCheckDTO.setRemark("呼吸过缓");
}
if (br == 0) {
platAlarmCheckDTO.setRemark("呼吸暂停");
} }
return;
} }
/** /**
* [#长者姓名][#呼吸状态],请及时处理! * [#长者姓名][#呼吸状态],请及时处理!
*
* @param platAlarmCheckDTO * @param platAlarmCheckDTO
*/ */
@Override @Override
@Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) { public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO); platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList(); List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if(CollectionUtils.isEmpty(platElderList)){ if (CollectionUtils.isEmpty(platElderList)) {
log.info("未关联长者,设备id:"+platAlarmCheckDTO.getPlatDevice().getId());
return; return;
} }
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
for (PlatElder platElder : platElderList) { for (PlatElder platElder : platElderList) {
List<String> param = new ArrayList<>(); List<String> param = new ArrayList<>();
param.add(platElder.getName()); param.add(platElder.getName());
param.add(platAlarmCheckDTO.getRemark()); param.add(platAlarmCheckDTO.getRemark());
platAlarmCheckDTO.setParam(param); platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO); PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord); platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
} }
} }
} }
...@@ -4,10 +4,16 @@ import cn.hutool.core.convert.Convert; ...@@ -4,10 +4,16 @@ import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO; import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
import com.makeit.entity.platform.alarm.PlatAlarmRecord; 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.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRoom; import com.makeit.entity.platform.space.PlatRoom;
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.service.platform.alarm.PlatAlarmRecordService; import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.redis.RedisUtil;
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.beans.factory.annotation.Autowired;
...@@ -17,35 +23,47 @@ import java.util.ArrayList; ...@@ -17,35 +23,47 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@Component @Component
public class FallAlarm implements IAlarm{ @Slf4j
public class FallAlarm implements IAlarm {
@Autowired @Autowired
private PlatAlarmRecordService platAlarmRecordService; private PlatAlarmRecordService platAlarmRecordService;
private PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.FALL; private final PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.FALL;
@Override @Override
public boolean support(String alarmType) { public boolean support(String alarmType) {
return StringUtils.equals(alarmType,alarmTypeEnum.getValue()); return StringUtils.equals(alarmType, alarmTypeEnum.getValue());
} }
/** /**
* 1.长者跌倒:长者所在空间的跌倒监测雷达上报跌倒,若一个空间内有多为长者,则同时告警多条 * 1.长者跌倒:长者所在空间的跌倒监测雷达上报跌倒,若一个空间内有多为长者,则同时告警多条
*
* @param platAlarmCheckDTO * @param platAlarmCheckDTO
*/ */
@Override @Override
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) { public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
JSONObject properties = platAlarmCheckDTO.getProperties(); JSONObject properties = platAlarmCheckDTO.getProperties();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId();
String personState = Convert.toStr(properties.get("personState")); String personState = Convert.toStr(properties.get("personState"));
if (StringUtils.equals(personState, "1")) { AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_FALL_ID + deviceId);
notice(platAlarmCheckDTO); if (StringUtils.equals(personState, CommonEnum.YES.getValue())) {
notice(platAlarmCheckDTO);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_FALL_ID, alarmRedisDTO);
} else {
alarmRedisDTO.setAlarm(CommonEnum.NO.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_FALL_ID, alarmRedisDTO);
} }
} }
@Override @Override
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) { public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO); platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList(); List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if(CollectionUtils.isEmpty(platElderList)){ if (CollectionUtils.isEmpty(platElderList)) {
log.info("跌倒设备未关联长者,设备id:" + platDevice.getId());
return; return;
} }
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom(); PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
...@@ -55,7 +73,9 @@ public class FallAlarm implements IAlarm{ ...@@ -55,7 +73,9 @@ public class FallAlarm implements IAlarm{
param.add(platRoom.getName()); param.add(platRoom.getName());
platAlarmCheckDTO.setParam(param); platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO); PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord); platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
} }
} }
} }
...@@ -8,16 +8,17 @@ import com.makeit.entity.platform.alarm.PlatAlarmConfig; ...@@ -8,16 +8,17 @@ import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.alarm.PlatAlarmRecord; import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder; 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.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.redis.RedisConst; import com.makeit.enums.redis.RedisConst;
import com.makeit.service.platform.alarm.PlatAlarmRecordService; import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.data.convert.JsonUtil; import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.redis.RedisUtil; import com.makeit.utils.redis.RedisUtil;
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.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -25,15 +26,16 @@ import java.util.Date; ...@@ -25,15 +26,16 @@ import java.util.Date;
import java.util.List; import java.util.List;
@Component @Component
@Slf4j
public class HeartAlarm implements IAlarm { public class HeartAlarm implements IAlarm {
@Autowired @Autowired
private PlatAlarmRecordService platAlarmRecordService; private PlatAlarmRecordService platAlarmRecordService;
private PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.HEART; private final PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.HEART;
@Override @Override
public boolean support(String alarmType) { public boolean support(String alarmType) {
return StringUtils.equals(alarmType,alarmTypeEnum.getValue()); return StringUtils.equals(alarmType, alarmTypeEnum.getValue());
} }
@Override @Override
...@@ -44,6 +46,7 @@ public class HeartAlarm implements IAlarm { ...@@ -44,6 +46,7 @@ public class HeartAlarm implements IAlarm {
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice(); PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId(); String deviceId = platDevice.getOriDeviceId();
if (StringUtils.isBlank(ruleConfigStr)) { if (StringUtils.isBlank(ruleConfigStr)) {
log.info("心率告警配置未配置,告警配置id:" + config.getId());
return; return;
} }
String personState = Convert.toStr(properties.get("personState")); String personState = Convert.toStr(properties.get("personState"));
...@@ -53,47 +56,73 @@ public class HeartAlarm implements IAlarm { ...@@ -53,47 +56,73 @@ public class HeartAlarm implements IAlarm {
Integer start = ruleConfig.getHeartRateStart(); Integer start = ruleConfig.getHeartRateStart();
Integer end = ruleConfig.getHeartRateEnd(); Integer end = ruleConfig.getHeartRateEnd();
Integer duration = ruleConfig.getDuration(); Integer duration = ruleConfig.getDuration();
long endLong = new Date().getTime(); Date now = new Date();
long endLong = now.getTime();
//计数 //计数
Long startLong = RedisUtil.get(RedisConst.ALARM_DEVICE_ID + deviceId); AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_HR_ID + deviceId);
if (StringUtils.equals(personState, "0")|| startLong == null) {
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000); if (StringUtils.equals(personState, CommonEnum.NO.getValue())) {
RedisUtil.delete(RedisConst.ALARM_DEVICE_HR_ID + deviceId);
return; return;
} }
long count = endLong - startLong;
if (hr > end || hr < start) {
if (count >= duration) { if ((hr > end || hr < start)) {
if(hr>end){ if(alarmRedisDTO==null){
platAlarmCheckDTO.setRemark("心率过速"); alarmRedisDTO = new AlarmRedisDTO();
} alarmRedisDTO.setAlarm(CommonEnum.NO.getValue());
if(hr < start){ alarmRedisDTO.setStart(now);
platAlarmCheckDTO.setRemark("心率过缓"); alarmRedisDTO.setStartLong(endLong);
RedisUtil.set(RedisConst.ALARM_DEVICE_HR_ID + deviceId,alarmRedisDTO);
log.info("发现长者心率异常,设备id:"+deviceId);
return;
}
Long startLong = alarmRedisDTO.getStartLong();
long count = endLong - startLong;
if (count/1000 >= duration) {
if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) {
log.info("心率已告警,设备id:" + platDevice.getId());
return;
} }
fillRemark(platAlarmCheckDTO, hr, start, end);
notice(platAlarmCheckDTO); notice(platAlarmCheckDTO);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000); alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStart(now);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_HR_ID + deviceId, alarmRedisDTO);
} }
} else { } else {
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
RedisUtil.delete(RedisConst.ALARM_DEVICE_HR_ID + deviceId);
}
}
private void fillRemark(PlatAlarmCheckDTO platAlarmCheckDTO, int hr, Integer start, Integer end) {
if (hr > end) {
platAlarmCheckDTO.setRemark("心率过快");
}
if (hr < start) {
platAlarmCheckDTO.setRemark("心率过缓");
} }
} }
@Override @Override
@Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) { public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO); platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList(); List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if(CollectionUtils.isEmpty(platElderList)){ if (CollectionUtils.isEmpty(platElderList)) {
log.info("跌倒设备未关联长者,设备id:" + platAlarmCheckDTO.getPlatDevice().getId());
return; return;
} }
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
for (PlatElder platElder : platElderList) { for (PlatElder platElder : platElderList) {
List<String> param = new ArrayList<>(); List<String> param = new ArrayList<>();
param.add(platElder.getName()); param.add(platElder.getName());
param.add(platAlarmCheckDTO.getRemark()); param.add(platAlarmCheckDTO.getRemark());
platAlarmCheckDTO.setParam(param); platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO); PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord); platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
} }
} }
} }
...@@ -15,9 +15,11 @@ import com.makeit.entity.platform.auth.PlatUser; ...@@ -15,9 +15,11 @@ import com.makeit.entity.platform.auth.PlatUser;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder; import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.elder.PlatElderChildrenInfo; import com.makeit.entity.platform.elder.PlatElderChildrenInfo;
import com.makeit.entity.platform.space.PlatRegionSetting;
import com.makeit.entity.platform.space.PlatRoom; import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.entity.platform.space.PlatRoomBedDevice; import com.makeit.entity.platform.space.PlatRoomBedDevice;
import com.makeit.enums.CommonEnum; import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.device.PlatDeviceEnum;
import com.makeit.exception.BusinessException; import com.makeit.exception.BusinessException;
import com.makeit.global.aspect.tenant.TenantIdIgnore; import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.mapper.platform.alarm.PlatAlarmRecordMapper; import com.makeit.mapper.platform.alarm.PlatAlarmRecordMapper;
...@@ -26,6 +28,7 @@ import com.makeit.service.platform.alarm.PlatAlarmRecordService; ...@@ -26,6 +28,7 @@ import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.auth.PlatUserService; import com.makeit.service.platform.auth.PlatUserService;
import com.makeit.service.platform.elder.PlatElderChildrenInfoService; import com.makeit.service.platform.elder.PlatElderChildrenInfoService;
import com.makeit.service.platform.elder.PlatElderService; import com.makeit.service.platform.elder.PlatElderService;
import com.makeit.service.platform.space.PlatRegionSettingService;
import com.makeit.service.platform.space.PlatRoomBedDeviceService; import com.makeit.service.platform.space.PlatRoomBedDeviceService;
import com.makeit.service.platform.space.PlatRoomService; import com.makeit.service.platform.space.PlatRoomService;
import com.makeit.utils.data.convert.BeanDtoVoUtils; import com.makeit.utils.data.convert.BeanDtoVoUtils;
...@@ -39,6 +42,7 @@ import com.makeit.utils.user.common.CommonUserVO; ...@@ -39,6 +42,7 @@ import com.makeit.utils.user.common.CommonUserVO;
import com.makeit.utils.user.wechat.WechatUserInfo; import com.makeit.utils.user.wechat.WechatUserInfo;
import com.makeit.utils.user.wechat.WechatUserUtil; import com.makeit.utils.user.wechat.WechatUserUtil;
import com.makeit.vo.platform.alarm.PlatAlarmRecordVO; import com.makeit.vo.platform.alarm.PlatAlarmRecordVO;
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.beans.factory.annotation.Autowired;
...@@ -62,6 +66,7 @@ import java.util.stream.Collectors; ...@@ -62,6 +66,7 @@ import java.util.stream.Collectors;
* @createDate 2023-09-06 14:26:05 * @createDate 2023-09-06 14:26:05
*/ */
@Service @Service
@Slf4j
public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMapper, PlatAlarmRecord> public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMapper, PlatAlarmRecord>
implements PlatAlarmRecordService { implements PlatAlarmRecordService {
@Autowired @Autowired
...@@ -82,6 +87,8 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -82,6 +87,8 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
private PlatElderService platElderService; private PlatElderService platElderService;
@Autowired @Autowired
private PlatRoomService platRoomService; private PlatRoomService platRoomService;
@Autowired
private PlatRegionSettingService platRegionSettingService;
@Override @Override
...@@ -182,8 +189,12 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -182,8 +189,12 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
@TenantIdIgnore @TenantIdIgnore
public void noticeDeviceAlarm(PlatAlarmConfig alarmConfig, PlatAlarmRecord alarmRecord) { public void noticeDeviceAlarm(PlatAlarmConfig alarmConfig, PlatAlarmRecord alarmRecord) {
//判断是否需要同时通知家属 //判断是否需要同时通知家属
if (StringUtils.equals(alarmConfig.getNotifyRelation(), "1")) { try {
noticeChildren(alarmConfig, alarmRecord); if (StringUtils.equals(alarmConfig.getNotifyRelation(), "1")) {
noticeChildren(alarmConfig, alarmRecord);
}
}catch (Exception e){
log.error("通知家属异常",e);
} }
//通知内部人员 //通知内部人员
noticeUser(alarmConfig, alarmRecord); noticeUser(alarmConfig, alarmRecord);
...@@ -205,16 +216,13 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -205,16 +216,13 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
String elderIds = alarmRecord.getElderIds(); String elderIds = alarmRecord.getElderIds();
List<PlatElderChildrenInfo> allChildInfoList = new ArrayList<>(); List<PlatElderChildrenInfo> allChildInfoList = new ArrayList<>();
String[] elderIdSplit = elderIds.split(",");
//通知每个长者的子女 //通知每个长者的子女
for (String elderId : elderIdSplit) {
LambdaQueryWrapper<PlatElderChildrenInfo> childrenInfoLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PlatElderChildrenInfo> childrenInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
childrenInfoLambdaQueryWrapper.eq(BaseBusEntity::getTenantId, alarmConfig.getTenantId()); childrenInfoLambdaQueryWrapper.eq(BaseBusEntity::getTenantId, alarmConfig.getTenantId());
childrenInfoLambdaQueryWrapper.and(qw -> qw.apply("find_in_set('" + elderId + "',elder_id)")); childrenInfoLambdaQueryWrapper.and(qw -> qw.apply("find_in_set('" + elderIds + "',elder_id)"));
List<PlatElderChildrenInfo> childrenInfoList = platElderChildrenInfoService.list(childrenInfoLambdaQueryWrapper); List<PlatElderChildrenInfo> childrenInfoList = platElderChildrenInfoService.list(childrenInfoLambdaQueryWrapper);
if (CollectionUtils.isEmpty(childrenInfoList)) { if (CollectionUtils.isEmpty(childrenInfoList)) {
log.debug("子女端账号未绑定长者"); throw new BusinessException("子女端账号未绑定长者,长者id:"+elderIds);
continue;
} }
allChildInfoList.addAll(childrenInfoList); allChildInfoList.addAll(childrenInfoList);
Set<String> phoneSet = childrenInfoList.stream().map(PlatElderChildrenInfo::getPhone).collect(Collectors.toSet()); Set<String> phoneSet = childrenInfoList.stream().map(PlatElderChildrenInfo::getPhone).collect(Collectors.toSet());
...@@ -222,14 +230,15 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -222,14 +230,15 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
List<SendTypeEnum> notifyChannelList = Arrays.asList(SendTypeEnum.SMS, SendTypeEnum.VOICE_SMS, SendTypeEnum.CHILD_WECHAT); List<SendTypeEnum> notifyChannelList = Arrays.asList(SendTypeEnum.SMS, SendTypeEnum.VOICE_SMS, SendTypeEnum.CHILD_WECHAT);
//发送消息 //发送消息
noticeByChannel(alarmConfig, alarmRecord, phoneSet, notifyChannelList); noticeByChannel(alarmConfig, alarmRecord, phoneSet,null, notifyChannelList);
}
String childIdJoin = allChildInfoList.stream().map(BaseEntity::getId).collect(Collectors.joining(",")); String childIdJoin = allChildInfoList.stream().map(BaseEntity::getId).collect(Collectors.joining(","));
//通知的子女 //通知的子女
alarmConfig.setNotifyRelation(childIdJoin); alarmConfig.setNotifyRelation(childIdJoin);
alarmRecord.setNoticeStatus(CommonEnum.YES.getValue()); alarmRecord.setNoticeStatus(CommonEnum.YES.getValue());
alarmRecord.setTenantId(alarmConfig.getTenantId()); alarmRecord.setTenantId(alarmConfig.getTenantId());
saveOrUpdate(alarmRecord); saveOrUpdate(alarmRecord);
} }
/** /**
...@@ -264,13 +273,13 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -264,13 +273,13 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
} }
platUserList.removeIf(Objects::isNull); platUserList.removeIf(Objects::isNull);
if (CollectionUtils.isEmpty(platUserList)) { if (CollectionUtils.isEmpty(platUserList)) {
log.debug("通知工作人员时,找不到人员数据;" + "orgId:" + alarmConfig.getOrgId() + ",tenantId:" + alarmConfig.getTenantId() + "alarmConfigId:" + alarmConfig.getId()); throw new BusinessException("通知工作人员时,找不到人员数据;" + "orgId:" + alarmConfig.getOrgId() + ",tenantId:" + alarmConfig.getTenantId() + "alarmConfigId:" + alarmConfig.getId());
return;
} }
List<SendTypeEnum> notifyChannelList = Arrays.asList(SendTypeEnum.SMS, SendTypeEnum.VOICE_SMS, SendTypeEnum.MAIL); List<SendTypeEnum> notifyChannelList = Arrays.asList(SendTypeEnum.SMS, SendTypeEnum.VOICE_SMS, SendTypeEnum.MAIL);
Set<String> phoneSet = platUserList.stream().map(PlatUser::getMobile).collect(Collectors.toSet()); Set<String> phoneSet = platUserList.stream().map(PlatUser::getMobile).collect(Collectors.toSet());
Set<String> emailSet = platUserList.stream().map(PlatUser::getEmail).collect(Collectors.toSet());
//发送消息 //发送消息
noticeByChannel(alarmConfig, alarmRecord, phoneSet, notifyChannelList); noticeByChannel(alarmConfig, alarmRecord, phoneSet,emailSet, notifyChannelList);
String userIdJoin = platUserList.stream().map(PlatUser::getId).collect(Collectors.joining(",")); String userIdJoin = platUserList.stream().map(PlatUser::getId).collect(Collectors.joining(","));
alarmRecord.setNotifyUser(userIdJoin); alarmRecord.setNotifyUser(userIdJoin);
...@@ -287,7 +296,7 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -287,7 +296,7 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
* @param phoneSet 工作人员手机号 * @param phoneSet 工作人员手机号
* @param notifyChannelList 通知渠道 * @param notifyChannelList 通知渠道
*/ */
private void noticeByChannel(PlatAlarmConfig alarmConfig, PlatAlarmRecord alarmRecord, Set<String> phoneSet, List<SendTypeEnum> notifyChannelList) { private void noticeByChannel(PlatAlarmConfig alarmConfig, PlatAlarmRecord alarmRecord, Set<String> phoneSet,Set<String> emailSet, List<SendTypeEnum> notifyChannelList) {
String notifyChannel = alarmConfig.getNotifyChannel(); String notifyChannel = alarmConfig.getNotifyChannel();
String[] split = notifyChannel.split(","); String[] split = notifyChannel.split(",");
for (String sendType : split) { for (String sendType : split) {
...@@ -297,7 +306,10 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -297,7 +306,10 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
MsgSendDTO msgSendDTO = new MsgSendDTO(); MsgSendDTO msgSendDTO = new MsgSendDTO();
msgSendDTO.setSendTypeEnum(sendTypeEnum); msgSendDTO.setSendTypeEnum(sendTypeEnum);
msgSendDTO.setReceiverList(phoneSet); msgSendDTO.setReceiverList(phoneSet);
msgSendDTO.setEmailSet(emailSet);
msgSendDTO.setOriContent(alarmRecord.getContent()); msgSendDTO.setOriContent(alarmRecord.getContent());
msgSendDTO.setSubject(alarmRecord.getContent());
msgSendDTO.setParam(alarmRecord.getElderName());
//todo 小程序消息 //todo 小程序消息
msgUtil.send(msgSendDTO); msgUtil.send(msgSendDTO);
} }
...@@ -339,17 +351,24 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -339,17 +351,24 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
if(platRoomBedDevice==null){ if(platRoomBedDevice==null){
throw new BusinessException("设备没绑定房间:"+platDevice.getId()); throw new BusinessException("设备没绑定房间:"+platDevice.getId());
} }
PlatRoom platRoom = platRoomService.getById(platRoomBedDevice.getRoomId());
platAlarmCheckDTO.setPlatRoom(platRoom); if(StringUtils.equals(platDevice.getCategory(), PlatDeviceEnum.CategoryEnum.SPACE.getValue())) {
PlatRoom platRoom = platRoomService.getById(platRoomBedDevice.getRoomId());
platAlarmCheckDTO.setPlatRoom(platRoom);
LambdaQueryWrapper<PlatRegionSetting> platRegionSettingLambdaQueryWrapper = new LambdaQueryWrapper<>();
platRegionSettingLambdaQueryWrapper.eq(PlatRegionSetting::getRoomId, platRoom.getId())
.eq(PlatRegionSetting::getDeviceId, platDevice.getId());
//区域设置
PlatRegionSetting platRegionSetting = platRegionSettingService.getOne(platRegionSettingLambdaQueryWrapper, false);
platAlarmCheckDTO.setPlatRegionSetting(platRegionSetting);
}
String bedId = platRoomBedDevice.getBedId(); String bedId = platRoomBedDevice.getBedId();
if (StringUtils.isNotBlank(bedId)) { if (StringUtils.isNotBlank(bedId)) {
LambdaQueryWrapper<PlatElder> elderLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PlatElder> elderLambdaQueryWrapper = new LambdaQueryWrapper<>();
elderLambdaQueryWrapper.eq(PlatElder::getBedId, bedId); elderLambdaQueryWrapper.eq(PlatElder::getBedId, bedId);
List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper); List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper);
platAlarmCheckDTO.setPlatElderList(list); platAlarmCheckDTO.setPlatElderList(list);
if(CollectionUtils.isEmpty(list)){
throw new BusinessException("床位没人");
}
} }
String roomId = platRoomBedDevice.getRoomId(); String roomId = platRoomBedDevice.getRoomId();
...@@ -358,9 +377,6 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -358,9 +377,6 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
elderLambdaQueryWrapper.eq(PlatElder::getRoomId, roomId); elderLambdaQueryWrapper.eq(PlatElder::getRoomId, roomId);
List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper); List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper);
platAlarmCheckDTO.setPlatElderList(list); platAlarmCheckDTO.setPlatElderList(list);
if(CollectionUtils.isEmpty(list)) {
throw new BusinessException("房间没人");
}
} }
} }
......
...@@ -2,11 +2,14 @@ package com.makeit.service.platform.alarm.impl; ...@@ -2,11 +2,14 @@ package com.makeit.service.platform.alarm.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.dto.platform.alarm.PlatDayDurationRecordDTO;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord; import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import com.makeit.mapper.platform.alarm.PlatDayDurationRecordMapper; import com.makeit.mapper.platform.alarm.PlatDayDurationRecordMapper;
import com.makeit.service.platform.alarm.PlatDayDurationRecordService; import com.makeit.service.platform.alarm.PlatDayDurationRecordService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* @author lixl * @author lixl
* @description 针对表【plat_day_duration_record(每天停留时长记录)】的数据库操作Service实现 * @description 针对表【plat_day_duration_record(每天停留时长记录)】的数据库操作Service实现
...@@ -16,4 +19,8 @@ import org.springframework.stereotype.Service; ...@@ -16,4 +19,8 @@ import org.springframework.stereotype.Service;
public class PlatDayDurationRecordServiceImpl extends ServiceImpl<PlatDayDurationRecordMapper, PlatDayDurationRecord> public class PlatDayDurationRecordServiceImpl extends ServiceImpl<PlatDayDurationRecordMapper, PlatDayDurationRecord>
implements PlatDayDurationRecordService { implements PlatDayDurationRecordService {
@Override
public List<PlatDayDurationRecord> getDayMaxDurationList(PlatDayDurationRecordDTO param){
return baseMapper.getDayMaxDurationList(param);
}
} }
package com.makeit.task;
import com.makeit.utils.DayDurationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class DayDurationTask {
@Autowired
private DayDurationUtil dayDurationUtil;
@Scheduled(cron = "0 */1 * * * ?")
public void updateDayDuration() {
dayDurationUtil.getAll();
}
}
...@@ -20,5 +20,8 @@ public class AlarmRedisDTO implements Serializable { ...@@ -20,5 +20,8 @@ public class AlarmRedisDTO implements Serializable {
*/ */
private String alarm = "0"; private String alarm = "0";
/**
* 雷达开始上报
*/
private Date start; private Date start;
} }
package com.makeit.utils;
import com.makeit.dto.platform.alarm.PlatDayDurationRecordDTO;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import com.makeit.enums.redis.RedisConst;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.alarm.PlatDayDurationRecordService;
import com.makeit.utils.redis.RedisUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class DayDurationUtil implements ApplicationRunner {
@Autowired
private PlatDayDurationRecordService platDayDurationRecordService;
public void getAll() {
DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDateTime now = LocalDateTime.now();
List<String> dateStrList = new ArrayList<>();
for (int i = 1; i <= 7 ; i++) {
LocalDateTime dateTime = now.plusDays(-i);
dateStrList.add(yyyyMMdd.format(dateTime));
}
PlatDayDurationRecordDTO platDayDurationRecordDTO = new PlatDayDurationRecordDTO();
platDayDurationRecordDTO.setDayStrList(dateStrList);
List<PlatDayDurationRecord> platDayDurationRecords = platDayDurationRecordService.getDayMaxDurationList(platDayDurationRecordDTO);
if(CollectionUtils.isEmpty(platDayDurationRecords)){
return;
}
Map<String, List<PlatDayDurationRecord>> deviceIdMap = platDayDurationRecords.stream().collect(Collectors.groupingBy(PlatDayDurationRecord::getOriDeviceId));
deviceIdMap.entrySet().stream().map(vo -> {
List<PlatDayDurationRecord> value = vo.getValue();
int size = value.size();
int mid = size / 2;
return value.get(mid);
}).forEach(vo->{
put(vo);
});
return;
}
public void put(PlatDayDurationRecord platDayDurationRecord) {
RedisUtil.set(RedisConst.ELDER_DAY_DURATION_PREFIX + platDayDurationRecord.getOriDeviceId(), platDayDurationRecord);
}
public PlatDayDurationRecord get(String oriDeviceId) {
PlatDayDurationRecord platDayDurationRecord = RedisUtil.get(RedisConst.ELDER_DAY_DURATION_PREFIX + oriDeviceId);
if(platDayDurationRecord==null){
getAll();
}
return RedisUtil.get(RedisConst.ELDER_DAY_DURATION_PREFIX + oriDeviceId);
}
/**
* Callback used to run the bean.
*
* @param args incoming application arguments
* @throws Exception on error
*/
@Override
@TenantIdIgnore
public void run(ApplicationArguments args) throws Exception {
getAll();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.makeit.mapper.platform.alarm.PlatDayDurationRecordMapper">
<resultMap id="BaseResultMap" type="com.makeit.entity.platform.alarm.PlatDayDurationRecord">
<id property="id" column="id" jdbcType="VARCHAR"/>
<result property="elderIds" column="elder_ids" jdbcType="VARCHAR"/>
<result property="duration" column="duration" jdbcType="VARCHAR"/>
<result property="oriDeviceId" column="ori_device_id" jdbcType="VARCHAR"/>
<result property="day" column="day" jdbcType="VARCHAR"/>
<result property="startDate" column="start_date" jdbcType="TIMESTAMP"/>
<result property="endDate" column="end_date" jdbcType="TIMESTAMP"/>
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
<result property="createDate" column="create_date" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
<result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
<result property="tenantId" column="tenant_id" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id,elder_ids,duration,
ori_device_id,day,start_date,
end_date,create_by,create_date,
update_by,update_date,del_flag,
tenant_id
</sql>
<select id="getDayMaxDurationList" resultType="com.makeit.entity.platform.alarm.PlatDayDurationRecord">
select
pddr.ori_device_id,
pddr.day,
max(pddr.duration) as duration
from plat_day_duration_record pddr
<where>
<if test="param.start != null ">
and pddr.create_date >= #{param.start}
</if>
<if test="param.end != null ">
and pddr.create_date <![CDATA[<= #{param.end}]]>
</if>
<if test="param.dayStrList != null and param.dayStrList.size()>0">
AND pddr.day IN
<foreach collection="param.dayStrList" item="item" separator="," open="(" close=")" index="">
#{item}
</foreach>
</if>
</where>
group by pddr.ori_device_id, pddr.day
order by duration
</select>
</mapper>
...@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.Objects;
@Component @Component
...@@ -81,7 +82,12 @@ public class PushCallback implements MqttCallback { ...@@ -81,7 +82,12 @@ public class PushCallback implements MqttCallback {
//iot设备id //iot设备id
PlatDevice platDevice = deviceCacheUtil.get(deviceId); PlatDevice platDevice = deviceCacheUtil.get(deviceId);
if(platDevice==null){
logger.info("设备信息异常,设备iot-id:"+deviceId);
return;
}
List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice); List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice);
deviceAlarmConfigList.removeIf(Objects::isNull);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) { if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
logger.info("该设备没有告警配置:"+deviceId); logger.info("该设备没有告警配置:"+deviceId);
return; return;
......
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