|
@@ -9,6 +9,8 @@ import com.zksy.api.mapper.WarningThresholdMapper;
|
|
|
import com.zksy.api.service.WarningThresholdService;
|
|
import com.zksy.api.service.WarningThresholdService;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.time.LocalTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -29,7 +31,29 @@ public class WarningThresholdServiceImpl extends ServiceImpl<WarningThresholdMap
|
|
|
.apply("CONCAT(',', device_code, ',') LIKE CONCAT('%,', {0}, ',%')", deviceCode)
|
|
.apply("CONCAT(',', device_code, ',') LIKE CONCAT('%,', {0}, ',%')", deviceCode)
|
|
|
.eq(WarningThreshold::getWarningCode,warningCodes);
|
|
.eq(WarningThreshold::getWarningCode,warningCodes);
|
|
|
|
|
|
|
|
- return baseMapper.selectOne(lambdaQueryWrapper);
|
|
|
|
|
|
|
+ List<WarningThreshold> thresholds = baseMapper.selectList(lambdaQueryWrapper);
|
|
|
|
|
+ if (thresholds == null || thresholds.isEmpty()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 分时阈值支持:同一设备+预警编码可配置多条不同生效时段阈值,
|
|
|
|
|
+ // 优先返回当前时间生效的阈值;未命中分时时段时返回全天阈值(无分时字段),
|
|
|
|
|
+ // 两者都没有时返回第一条。
|
|
|
|
|
+ String now = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm"));
|
|
|
|
|
+ WarningThreshold fullDayThreshold = null;
|
|
|
|
|
+ for (WarningThreshold threshold : thresholds) {
|
|
|
|
|
+ boolean hasPeriod = threshold.getPeriodStart() != null && !threshold.getPeriodStart().isEmpty()
|
|
|
|
|
+ && threshold.getPeriodEnd() != null && !threshold.getPeriodEnd().isEmpty();
|
|
|
|
|
+ if (!hasPeriod) {
|
|
|
|
|
+ if (fullDayThreshold == null) {
|
|
|
|
|
+ fullDayThreshold = threshold;
|
|
|
|
|
+ }
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (now.compareTo(threshold.getPeriodStart()) >= 0 && now.compareTo(threshold.getPeriodEnd()) <= 0) {
|
|
|
|
|
+ return threshold;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return fullDayThreshold != null ? fullDayThreshold : thresholds.get(0);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|