Commit 3242daaf by 汪志阳

fix:模拟测试夜间时间

parent 44d77a2e
...@@ -23,8 +23,6 @@ import org.apache.commons.lang3.StringUtils; ...@@ -23,8 +23,6 @@ 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.*; import java.time.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
...@@ -61,7 +59,6 @@ public class OffBedAlarm implements IAlarm { ...@@ -61,7 +59,6 @@ public class OffBedAlarm implements IAlarm {
return; return;
} }
PlatAlarmConfig config = alarmConfigCacheUtil.get(platDevice.getOrgId(), PlatAlarmConfigEnum.AlarmTypeEnum.OFF_BED.getValue()); PlatAlarmConfig config = alarmConfigCacheUtil.get(platDevice.getOrgId(), PlatAlarmConfigEnum.AlarmTypeEnum.OFF_BED.getValue());
log.info("离床预警配置:{},orgid:{}", JSONUtil.toJsonStr(config), platDevice.getOrgId());
if (config == null || StringUtils.isBlank(config.getRuleConfig()) || !"5".equals(config.getAlarmType())) { if (config == null || StringUtils.isBlank(config.getRuleConfig()) || !"5".equals(config.getAlarmType())) {
log.error("离床告警配置不存在,config:{}", JSONUtil.toJsonStr(config)); log.error("离床告警配置不存在,config:{}", JSONUtil.toJsonStr(config));
return; return;
...@@ -118,7 +115,7 @@ public class OffBedAlarm implements IAlarm { ...@@ -118,7 +115,7 @@ public class OffBedAlarm implements IAlarm {
alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId); alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId);
Long firstOffBedLong = alarmRedisDTO.getStartLong(); Long firstOffBedLong = alarmRedisDTO.getStartLong();
LocalDateTime firstOffBedTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(firstOffBedLong), ZoneOffset.of("+8")); LocalDateTime firstOffBedTime = longToTime(firstOffBedLong);
log.info("离床告警第一次离床时间为:" + firstOffBedTime); log.info("离床告警第一次离床时间为:" + firstOffBedTime);
if ("1".equals(alarmRedisDTO.getAlarm())) { if ("1".equals(alarmRedisDTO.getAlarm())) {
...@@ -150,16 +147,15 @@ public class OffBedAlarm implements IAlarm { ...@@ -150,16 +147,15 @@ public class OffBedAlarm implements IAlarm {
Long firstOffBedLong = alarmRedisDTO.getStartLong(); Long firstOffBedLong = alarmRedisDTO.getStartLong();
long currentTimeMillis = System.currentTimeMillis(); long currentTimeMillis = System.currentTimeMillis();
// 模拟时间 // todo 模拟时间
LocalDateTime nowTest = LocalDateTime.now().plusHours(12).plusMinutes(40); currentTimeMillis = currentLong();
currentTimeMillis = nowTest.toInstant(ZoneOffset.of("+8")).toEpochMilli();
boolean isOverTime = (currentTimeMillis - firstOffBedLong) / 1000 >= duration * 60; boolean isOverTime = (currentTimeMillis - firstOffBedLong) / 1000 >= duration * 60;
LocalDateTime firstOffBedTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(firstOffBedLong), ZoneOffset.of("+8")); LocalDateTime firstOffBedTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(firstOffBedLong), ZoneOffset.of("+8"));
LocalTime firstTime = firstOffBedTime.toLocalTime(); LocalTime firstTime = firstOffBedTime.toLocalTime();
boolean isInTime = firstTime.isAfter(startTime) || firstTime.isBefore(endTime); boolean isInTime = firstTime.isAfter(startTime) || firstTime.isBefore(endTime);
LocalTime endTimeLimit = endTime.plusMinutes(-duration); // LocalTime endTimeLimit = endTime.plusMinutes(-duration);
// 离床时间在范围内 // 离床时间在范围内
if (isInTime && isOverTime) { if (isInTime && isOverTime) {
platAlarmCheckDTO.setAbnormalValue(String.valueOf(currentTimeMillis - firstOffBedLong)); platAlarmCheckDTO.setAbnormalValue(String.valueOf(currentTimeMillis - firstOffBedLong));
...@@ -168,7 +164,9 @@ public class OffBedAlarm implements IAlarm { ...@@ -168,7 +164,9 @@ public class OffBedAlarm implements IAlarm {
noticeAlarm(alarmRedisDTO, platAlarmCheckDTO, deviceId); noticeAlarm(alarmRedisDTO, platAlarmCheckDTO, deviceId);
return; return;
} }
LocalDateTime now = LocalDateTime.now().plusHours(12).plusMinutes(40); // LocalDateTime now = LocalDateTime.now();
// todo 模拟时间
LocalDateTime now = currentTime();
LocalDateTime startLocalDteTime = LocalDateTime.of(LocalDate.now(), startTime); LocalDateTime startLocalDteTime = LocalDateTime.of(LocalDate.now(), startTime);
if (!isInTime) { if (!isInTime) {
long mills = Duration.between(startLocalDteTime, now).toMillis() / 1000; long mills = Duration.between(startLocalDteTime, now).toMillis() / 1000;
...@@ -201,8 +199,8 @@ public class OffBedAlarm implements IAlarm { ...@@ -201,8 +199,8 @@ public class OffBedAlarm implements IAlarm {
Long firstOffBedLong = alarmRedisDTO.getStartLong(); Long firstOffBedLong = alarmRedisDTO.getStartLong();
long currentTimeMillis = System.currentTimeMillis(); long currentTimeMillis = System.currentTimeMillis();
LocalDateTime nowTest = LocalDateTime.now().plusHours(12).plusMinutes(40); // todo 模拟时间
currentTimeMillis = nowTest.toInstant(ZoneOffset.of("+8")).toEpochMilli(); currentTimeMillis = currentLong();
boolean isOverTime = (currentTimeMillis - firstOffBedLong) / 1000 >= duration * 60; boolean isOverTime = (currentTimeMillis - firstOffBedLong) / 1000 >= duration * 60;
LocalDateTime firstOffBedTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(firstOffBedLong), ZoneOffset.of("+8")); LocalDateTime firstOffBedTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(firstOffBedLong), ZoneOffset.of("+8"));
LocalTime firstTime = firstOffBedTime.toLocalTime(); LocalTime firstTime = firstOffBedTime.toLocalTime();
...@@ -223,7 +221,9 @@ public class OffBedAlarm implements IAlarm { ...@@ -223,7 +221,9 @@ public class OffBedAlarm implements IAlarm {
return; return;
} }
LocalDateTime now = LocalDateTime.now().plusHours(12).plusMinutes(40); // todo 模拟时间
// LocalDateTime now = LocalDateTime.now();
LocalDateTime now = currentTime();
LocalTime localTime = LocalTime.now(); LocalTime localTime = LocalTime.now();
if (!isInTime && localTime.isAfter(startTime) && localTime.isBefore(endTime)) { if (!isInTime && localTime.isAfter(startTime) && localTime.isBefore(endTime)) {
long mills = Duration.between(startLocalDteTime, now).toMillis() / 1000; long mills = Duration.between(startLocalDteTime, now).toMillis() / 1000;
...@@ -249,25 +249,31 @@ public class OffBedAlarm implements IAlarm { ...@@ -249,25 +249,31 @@ public class OffBedAlarm implements IAlarm {
alarmRedisDTO = new AlarmRedisDTO(); alarmRedisDTO = new AlarmRedisDTO();
alarmRedisDTO.setAlarm(CommonEnum.NO.getValue()); alarmRedisDTO.setAlarm(CommonEnum.NO.getValue());
alarmRedisDTO.setStart(now); alarmRedisDTO.setStart(now);
// todo 模拟时间
endLong = currentLong();
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.info("离床告警 离床设备存储redis,第一次上报时间:{},开始上报时间:{},是否上报:{}", log.info("离床告警 离床设备存储redis,第一次上报时间:{},开始上报时间:{},是否上报:{}",
getDateTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm()); alarmRedisDTO.getStartLong(), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm());
} else { } else {
alarmRedisDTO.setStart(now); alarmRedisDTO.setStart(now);
log.info("离床告警离床更新redis,第一次上报时间:{},更新时间:{},是否上报:{}", log.info("离床告警离床更新redis,第一次上报时间:{},更新时间:{},是否上报:{}",
getDateTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm()); longToTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm());
RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO);
} }
} }
private void noticeAlarm(AlarmRedisDTO alarmRedisDTO, PlatAlarmCheckDTO platAlarmCheckDTO, String deviceId) { private void noticeAlarm(AlarmRedisDTO alarmRedisDTO, PlatAlarmCheckDTO platAlarmCheckDTO, String deviceId) {
PlatAlarmConfig platAlarmConfig = platAlarmCheckDTO.getPlatAlarmConfig();
LocalDateTime firstOffBedTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(alarmRedisDTO.getStartLong()), ZoneOffset.of("+8"));
String remark = "第一次离床时间:" + firstOffBedTime + ",config:" + platAlarmConfig.getRuleConfig() + ",当前时间:" + LocalDateTime.now();
platAlarmCheckDTO.setRemark(remark);
notice(platAlarmCheckDTO); notice(platAlarmCheckDTO);
alarmRedisDTO.setStart(new Date()); alarmRedisDTO.setStart(new Date());
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue()); alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_OFF_BED_ID + deviceId, alarmRedisDTO);
log.info("离床告警推送离床消息,第一次上报时间:{},开始上报时间:{},是否上报:{}", log.info("离床告警推送离床消息,第一次上报时间:{},开始上报时间:{},是否上报:{}",
getDateTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm()); longToTime(alarmRedisDTO.getStartLong()), alarmRedisDTO.getStart(), alarmRedisDTO.getAlarm());
} }
@Override @Override
...@@ -301,26 +307,23 @@ public class OffBedAlarm implements IAlarm { ...@@ -301,26 +307,23 @@ public class OffBedAlarm implements IAlarm {
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO, platElder); PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO, platElder);
platAlarmRecord.setElderName(platElder.getName()); platAlarmRecord.setElderName(platElder.getName());
platAlarmRecord.setElderIds(platElder.getId()); platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setRemark(platAlarmCheckDTO.getRemark());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord); platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
log.info("离床告警配置,发出告警,设备id:" + platDevice.getId() + ", 长者名称:" + platElder.getName() log.info("离床告警配置,发出告警,设备id:" + platDevice.getId() + ", 长者名称:" + platElder.getName()
+ "config_id:" + config.getId() + "--" + config.getRuleConfig()); + "config_id:" + config.getId() + "--" + config.getRuleConfig());
} }
} }
private static String getDateTime(long longTime) { private long currentLong() {
return dateToString(new Date(longTime), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); return currentTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
} }
/** private LocalDateTime currentTime() {
* 日期类型转换成字符串类型 return LocalDateTime.now().plusHours(9).plusMinutes(10);
*
* @param date 日期
* @param dateFormat 日期格式
* @return 日期字符串
*/
private static String dateToString(Date date, DateFormat dateFormat) {
return dateFormat.format(date);
} }
private LocalDateTime longToTime(Long longTime) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(longTime), ZoneOffset.of("+8"));
}
} }
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