Commit 1e0979e1 by 汪志阳

fix:离床时间跨天处理

parent 204b709d
......@@ -79,6 +79,10 @@ public class OffBedAlarm implements IAlarm {
log.error("离床告警配置解析失败,config:{}", JSONUtil.toJsonStr(config));
return;
}
if (!"0".equals(ruleConfig.getStartTimeType())
|| ruleConfig.getOffBedStart().isAfter(ruleConfig.getOffBedEnd())) {
return;
}
JSONObject properties = platAlarmCheckDTO.getProperties();
if (properties == null) {
properties = new JSONObject();
......@@ -93,6 +97,7 @@ public class OffBedAlarm implements IAlarm {
LocalDateTime startTime = timeRange.get(0);
LocalDateTime endTime = timeRange.get(1);
Integer duration = ruleConfig.getDuration();
boolean isNextDay = "1".equals(ruleConfig.getEndTimeType());
String personState = Convert.toStr(properties.get("person"));
boolean isOffBed = "0".equals(personState);
// 1-有人 0-无人
......@@ -133,7 +138,9 @@ public class OffBedAlarm implements IAlarm {
return;
}
}
if (isNextDay) {
endTime = endTime.plusDays(1);
}
LocalDateTime validEndTime = endTime.plusMinutes(duration);
// 离床时间在范围时间内(小于范围结束时间-持续分钟)
boolean isOffBedValid = firstOffBedTime.isAfter(startTime) && firstOffBedTime.isBefore(validEndTime);
......@@ -187,9 +194,8 @@ public class OffBedAlarm implements IAlarm {
public static void main(String[] args) {
LocalDateTime startTime = LocalDateTime.of(2023,12,12,15,43);
boolean over = (Math.abs(Duration.between(LocalDateTime.now(), startTime).toMillis())) / 1000 >= 2 * 60;
System.out.println(over);
System.out.println(Duration.between(LocalDateTime.now(), startTime).toMillis());
System.out.println(startTime);
System.out.println(startTime.plusDays(1));
}
private void sendToRedis(AlarmRedisDTO alarmRedisDTO, String deviceId) {
......
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