Commit 35d8f542 by 汪志阳

fix:离床预警时间bug修复

parent 5d960feb
......@@ -91,7 +91,7 @@ public class OffBedAlarm implements IAlarm {
}
String deviceId = platDevice.getId();
List<LocalDateTime> timeRange = getOffTimeRange(ruleConfig);
if (CollUtil.isEmpty(timeRange)) {
if (CollUtil.isEmpty(timeRange) || timeRange.get(0) == null || timeRange.get(1) == null) {
log.error("离床告警配置时间段解析失败,config:{}", JSONUtil.toJsonStr(ruleConfig));
return;
}
......@@ -203,16 +203,27 @@ public class OffBedAlarm implements IAlarm {
}
/**
* 22-4 :昨天22-今天4 22-20:昨天22-今天20 22-23:今天22-23
* @param ruleConfig
* @return
*/
private List<LocalDateTime> getOffTimeRange(PlatAlarmConfigOffBedDTOVO ruleConfig) {
List<LocalDateTime> result = new ArrayList<>();
LocalTime offBedStart = ruleConfig.getOffBedStart();
LocalTime offBedEnd = ruleConfig.getOffBedEnd();
LocalDate localDate = LocalDate.now();
LocalDateTime startTime = LocalDateTime.of(localDate, ruleConfig.getOffBedStart());
LocalDateTime endTime;
boolean isNextDay = ruleConfig.getOffBedStart().isAfter(ruleConfig.getOffBedEnd());
if (isNextDay) {
endTime = LocalDateTime.of(localDate.plusDays(1), ruleConfig.getOffBedEnd());
} else {
endTime = LocalDateTime.of(localDate, ruleConfig.getOffBedEnd());
LocalDateTime startTime = null;
LocalDateTime endTime = null;
// 22-23:今天22-23
if (offBedStart.isBefore(offBedEnd)) {
startTime = LocalDateTime.of(localDate, offBedStart);
endTime = LocalDateTime.of(localDate, offBedEnd);
}
// 22-4 :昨天22-今天4
if (offBedStart.isAfter(offBedEnd)) {
startTime = LocalDateTime.of(localDate.plusDays(-1), offBedStart);
endTime = LocalDateTime.of(localDate, offBedEnd);
}
result.add(startTime);
result.add(endTime);
......
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