|
@@ -105,6 +105,24 @@ public class AppDeviceService {
|
|
|
if (sensorData.getTime() != null) {
|
|
|
appDeviceData.setTimestamp(Date.from(sensorData.getTime()));
|
|
|
}
|
|
|
+ if (Objects.nonNull(sensorData.getTemperature())) {
|
|
|
+ float temperatureUp = Math.abs(appDeviceData.getTemperatureUp() - sensorData.getTemperature());
|
|
|
+ float temperatureDown = Math.abs(appDeviceData.getTemperatureDown() - sensorData.getTemperature());
|
|
|
+ appDeviceData.setTemperatureStatus(getDataStatus(temperatureUp, temperatureDown,
|
|
|
+ appDeviceData.getTemperatureUp(), appDeviceData.getTemperatureDown(), sensorData));
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(sensorData.getHumidity())) {
|
|
|
+ float humidityUp = Math.abs(appDeviceData.getHumidityUp() - sensorData.getHumidity());
|
|
|
+ float humidityDown = Math.abs(appDeviceData.getHumidityDown() - sensorData.getHumidity());
|
|
|
+ appDeviceData.setHumidityStatus(getDataStatus(humidityUp, humidityDown,
|
|
|
+ appDeviceData.getHumidityUp(), appDeviceData.getHumidityDown(), sensorData));
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(sensorData.getCo2())) {
|
|
|
+ float co2Up = Math.abs(appDeviceData.getCo2Up() - sensorData.getCo2());
|
|
|
+ float co2Down = Math.abs(appDeviceData.getCo2Down() - sensorData.getCo2());
|
|
|
+ appDeviceData.setCo2Status(getDataStatus(co2Up, co2Down,
|
|
|
+ appDeviceData.getCo2Up(), appDeviceData.getCo2Down(), sensorData));
|
|
|
+ }
|
|
|
appDeviceData.setHumidity(sensorData.getHumidity());
|
|
|
appDeviceData.setTemperature(sensorData.getTemperature());
|
|
|
appDeviceData.setCo2Level(sensorData.getCo2());
|
|
@@ -137,6 +155,26 @@ public class AppDeviceService {
|
|
|
return pageResult;
|
|
|
}
|
|
|
|
|
|
+ private static String getDataStatus(float absUp, float absDown, float up, float down, SensorData sensorData) {
|
|
|
+ if (absUp < absDown) {
|
|
|
+ if (up > sensorData.getTemperature() && absUp > 5) {
|
|
|
+ return "0";
|
|
|
+ } else if (up > sensorData.getTemperature() && absUp <= 5) {
|
|
|
+ return "1";
|
|
|
+ } else {
|
|
|
+ return "2";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (down < sensorData.getTemperature() && absDown > 5) {
|
|
|
+ return "0";
|
|
|
+ } else if (down < sensorData.getTemperature() && absDown <= 5) {
|
|
|
+ return "1";
|
|
|
+ } else {
|
|
|
+ return "2";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 分页设备关键字查询 jackzhou 25-1-7 废弃
|
|
@@ -245,7 +283,7 @@ public class AppDeviceService {
|
|
|
* @return
|
|
|
*/
|
|
|
public DeviceStatus getDeviceStatus(String keyword, String roomId) {
|
|
|
- TargetStatus targetCount = monitorTargetService.getTargetCount(keyword,roomId);
|
|
|
+ TargetStatus targetCount = monitorTargetService.getTargetCount(keyword, roomId);
|
|
|
DeviceStatus deviceStatus = new DeviceStatus();
|
|
|
BeanUtil.copyProperties(targetCount, deviceStatus);
|
|
|
return deviceStatus;
|
|
@@ -338,13 +376,14 @@ public class AppDeviceService {
|
|
|
|
|
|
public SensorIndicator indicators(AppIndicatorQueryParams appDeviceQueryParams) {
|
|
|
// 假设上月数据
|
|
|
- long lastMonthCollected = jfcloudSensorDataService.getLastMonthDataCount(appDeviceQueryParams.getSensorCode(),appDeviceQueryParams.getSensorRoute());
|
|
|
- long lastMonthWarnings = jfcloudSensorDataService.getLastMonthAlarmCount(appDeviceQueryParams.getSensorCode(),appDeviceQueryParams.getSensorRoute()); // 上月预警总数
|
|
|
- long lastMonthAbnormal = jfcloudSensorDataService.getLastMonthOfflineCount(appDeviceQueryParams.getSensorCode(),appDeviceQueryParams.getSensorRoute()); // 上月异常总数
|
|
|
+ long lastMonthCollected = jfcloudSensorDataService.getLastMonthDataCount(appDeviceQueryParams.getSensorCode(), appDeviceQueryParams.getSensorRoute());
|
|
|
+ long lastMonthWarnings = jfcloudSensorDataService.getLastMonthAlarmCount(appDeviceQueryParams.getSensorCode(), appDeviceQueryParams.getSensorRoute()); // 上月预警总数
|
|
|
+ long lastMonthAbnormal = jfcloudSensorDataService.getLastMonthOfflineCount(appDeviceQueryParams.getSensorCode(), appDeviceQueryParams.getSensorRoute()); // 上月异常总数
|
|
|
// 计算本月数据
|
|
|
- long totalCollected = jfcloudSensorDataService.getCurrentMonthDataCount(appDeviceQueryParams.getSensorCode(),appDeviceQueryParams.getSensorRoute());
|
|
|
- long totalWarnings = jfcloudSensorDataService.getCurrentMonthAlarmCount(appDeviceQueryParams.getSensorCode(),appDeviceQueryParams.getSensorRoute()); // 同比减少5%
|
|
|
- long totalAbnormal = jfcloudSensorDataService.getCurrentMonthOfflineCount(appDeviceQueryParams.getSensorCode(),appDeviceQueryParams.getSensorRoute()); ; // 同比增长10%
|
|
|
+ long totalCollected = jfcloudSensorDataService.getCurrentMonthDataCount(appDeviceQueryParams.getSensorCode(), appDeviceQueryParams.getSensorRoute());
|
|
|
+ long totalWarnings = jfcloudSensorDataService.getCurrentMonthAlarmCount(appDeviceQueryParams.getSensorCode(), appDeviceQueryParams.getSensorRoute()); // 同比减少5%
|
|
|
+ long totalAbnormal = jfcloudSensorDataService.getCurrentMonthOfflineCount(appDeviceQueryParams.getSensorCode(), appDeviceQueryParams.getSensorRoute());
|
|
|
+ ; // 同比增长10%
|
|
|
// 创建响应对象
|
|
|
SensorIndicator response = new SensorIndicator();
|
|
|
response.setTotalCollected(totalCollected);
|
|
@@ -356,6 +395,7 @@ public class AppDeviceService {
|
|
|
response.setAbnormalChange(formatChange(calculateChange(lastMonthAbnormal, totalAbnormal)));
|
|
|
return response;
|
|
|
}
|
|
|
+
|
|
|
// 计算百分比变化的辅助方法
|
|
|
private double calculateChange(long lastMonthValue, long currentMonthValue) {
|
|
|
if (lastMonthValue == 0) {
|