|
@@ -154,18 +154,13 @@ public class AppDeviceService {
|
|
|
AggregationWindow window = null;
|
|
|
String aggregationWindow = appDeviceQueryParams.getAggregationWindow();
|
|
|
if (StrUtil.isBlank(aggregationWindow)) {
|
|
|
- window = AggregationWindow.determineAggregationWindow(
|
|
|
- appDeviceQueryParams.getStartTime(),
|
|
|
- appDeviceQueryParams.getEndTime());
|
|
|
+ window = AggregationWindow.determineAggregationWindow(appDeviceQueryParams.getStartTime(), appDeviceQueryParams.getEndTime());
|
|
|
} else {
|
|
|
// 如果用户选择了聚合维度,但不在枚举中,使用默认的聚合窗口
|
|
|
window = AggregationWindow.fromString(aggregationWindow);
|
|
|
}
|
|
|
// 查找监控目标区域
|
|
|
- MonitorTargetRegion monitorTarget = monitorTargetRegionService.findOneByDeviceCodeAndSensorNo(
|
|
|
- appDeviceQueryParams.getSensorCode(),
|
|
|
- appDeviceQueryParams.getSensorRoute()
|
|
|
- );
|
|
|
+ MonitorTargetRegion monitorTarget = monitorTargetRegionService.findOneByDeviceCodeAndSensorNo(appDeviceQueryParams.getSensorCode(), appDeviceQueryParams.getSensorRoute());
|
|
|
// 如果监控目标区域为空,直接返回空的结果
|
|
|
if (Objects.isNull(monitorTarget)) {
|
|
|
return getEmptyResult();
|
|
@@ -177,8 +172,7 @@ public class AppDeviceService {
|
|
|
return getEmptyResult();
|
|
|
}
|
|
|
// 定义传感器类型与数据类型的映射关系
|
|
|
- Map<String, String> sensorMapping = Map.of(
|
|
|
- "w", "temperature", // 温度
|
|
|
+ Map<String, String> sensorMapping = Map.of("w", "temperature", // 温度
|
|
|
"s", "humidity", // 湿度
|
|
|
"c", "co2" // 二氧化碳
|
|
|
);
|
|
@@ -193,13 +187,7 @@ public class AppDeviceService {
|
|
|
// 如果传感器类型包含对应的字符
|
|
|
if (sensorType.toLowerCase().contains(key)) {
|
|
|
// 获取相应的数据
|
|
|
- List<SensorData> sensorData = monitorDeviceService.queryDataByDeviceIdAndRoads(
|
|
|
- appDeviceQueryParams.getSensorCode(),
|
|
|
- appDeviceQueryParams.getSensorRoute(),
|
|
|
- appDeviceQueryParams.getStartTime(),
|
|
|
- appDeviceQueryParams.getEndTime(),
|
|
|
- dataType, finalWindow
|
|
|
- );
|
|
|
+ List<SensorData> sensorData = monitorDeviceService.queryDataByDeviceIdAndRoads(appDeviceQueryParams.getSensorCode(), appDeviceQueryParams.getSensorRoute(), appDeviceQueryParams.getStartTime(), appDeviceQueryParams.getEndTime(), dataType, finalWindow);
|
|
|
|
|
|
// 处理数据并设置到对应的字段
|
|
|
SensorEchartData echartData = SensorDataTransformer.processSensorData(sensorData, dataType, finalWindow1);
|
|
@@ -243,5 +231,36 @@ public class AppDeviceService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public SensorIndicator indicators(AppIndicatorQueryParams appDeviceQueryParams) {
|
|
|
+ // 假设上月数据
|
|
|
+ int lastMonthCollected = 100000; // 上月采集数据总数
|
|
|
+ int lastMonthWarnings = 100; // 上月预警总数
|
|
|
+ int lastMonthAbnormal = 150; // 上月异常总数
|
|
|
+ // 计算本月数据
|
|
|
+ int totalCollected = (int) (lastMonthCollected * 1.30); // 同比增长30%
|
|
|
+ int totalWarnings = (int) (lastMonthWarnings * 0.95); // 同比减少5%
|
|
|
+ int totalAbnormal = (int) (lastMonthAbnormal * 1.10); // 同比增长10%
|
|
|
+ // 创建响应对象
|
|
|
+ SensorIndicator response = new SensorIndicator();
|
|
|
+ response.setTotalCollected(totalCollected);
|
|
|
+ response.setTotalWarnings(totalWarnings);
|
|
|
+ response.setTotalAbnormal(totalAbnormal);
|
|
|
+ response.setCollectedChange("+30%");
|
|
|
+ response.setWarningsChange("-5%");
|
|
|
+ response.setAbnormalChange("+10%");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
|
|
|
+ public Boolean updateDeviceInfo(AppDeviceUpdateParam appDeviceAlarmParam) {
|
|
|
+ MonitorTargetRegion monitorTargetRegion = monitorTargetRegionService.getById(appDeviceAlarmParam.getMonitorTargetRegionId());
|
|
|
+ if (monitorTargetRegion == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(appDeviceAlarmParam.getName())) {
|
|
|
+ monitorTargetRegion.setName(appDeviceAlarmParam.getName());
|
|
|
+ }
|
|
|
+ monitorTargetRegion.setIgnoreStartTime(appDeviceAlarmParam.getIgnoreStartTime());
|
|
|
+ monitorTargetRegion.setIgnoreEndTime(appDeviceAlarmParam.getIgnoreEndTime());
|
|
|
+ return monitorTargetRegionService.updateById(monitorTargetRegion);
|
|
|
+ }
|
|
|
}
|