|
@@ -1,5 +1,6 @@
|
|
|
package com.zksy.cockpit.foundation;
|
|
package com.zksy.cockpit.foundation;
|
|
|
|
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.Clock;
|
|
import java.time.Clock;
|
|
@@ -14,7 +15,6 @@ import java.util.Objects;
|
|
|
public class CockpitFreshnessService {
|
|
public class CockpitFreshnessService {
|
|
|
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
|
private static final ZoneId BUSINESS_ZONE = ZoneId.of("Asia/Shanghai");
|
|
private static final ZoneId BUSINESS_ZONE = ZoneId.of("Asia/Shanghai");
|
|
|
- private static final int DEFAULT_CALIBRATION_PERIOD_SECONDS = 60;
|
|
|
|
|
private static final int MAX_CALIBRATION_PERIOD_SECONDS = 3600;
|
|
private static final int MAX_CALIBRATION_PERIOD_SECONDS = 3600;
|
|
|
|
|
|
|
|
private final CockpitFreshnessAdapter adapter;
|
|
private final CockpitFreshnessAdapter adapter;
|
|
@@ -24,10 +24,14 @@ public class CockpitFreshnessService {
|
|
|
public CockpitFreshnessService(
|
|
public CockpitFreshnessService(
|
|
|
CockpitFreshnessAdapter adapter,
|
|
CockpitFreshnessAdapter adapter,
|
|
|
Clock clock,
|
|
Clock clock,
|
|
|
|
|
+ @Value("${cockpit.freshness.default-calibration-period-seconds:60}")
|
|
|
int defaultCalibrationPeriodSeconds) {
|
|
int defaultCalibrationPeriodSeconds) {
|
|
|
this.adapter = adapter;
|
|
this.adapter = adapter;
|
|
|
this.clock = clock;
|
|
this.clock = clock;
|
|
|
this.defaultCalibrationPeriodSeconds = defaultCalibrationPeriodSeconds;
|
|
this.defaultCalibrationPeriodSeconds = defaultCalibrationPeriodSeconds;
|
|
|
|
|
+ if (defaultCalibrationPeriodSeconds < 1 || defaultCalibrationPeriodSeconds > MAX_CALIBRATION_PERIOD_SECONDS) {
|
|
|
|
|
+ throw new IllegalArgumentException("defaultCalibrationPeriodSeconds must be between 1 and 3600 seconds");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public CockpitFreshnessResponse load(String requestId, String deviceCode, Integer calibrationPeriodSeconds) {
|
|
public CockpitFreshnessResponse load(String requestId, String deviceCode, Integer calibrationPeriodSeconds) {
|
|
@@ -166,4 +170,4 @@ public class CockpitFreshnessService {
|
|
|
private static boolean isBlank(String value) {
|
|
private static boolean isBlank(String value) {
|
|
|
return value == null || value.trim().isEmpty();
|
|
return value == null || value.trim().isEmpty();
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|