Kaynağa Gözat

优化调整人防代码

fuyuchuan 10 saat önce
ebeveyn
işleme
9df27d1605

+ 28 - 4
service-cdi/service-cdi-biz/src/main/java/com/usky/cdi/service/util/DeviceDataQuery.java

@@ -347,9 +347,12 @@ public class DeviceDataQuery {
         // System.out.println("深拷贝当前时间戳:" + currentTime);
 
         // 获取天气数据(仅在需要时)
-        // 修复:707(温度)和708(湿度)都需要天气数据作为模拟基准,原条件遗漏了708导致NPE
+        // 期望:只有“象屿模板为空/缺字段”时,才用天气数据对温湿度做修正;有象屿模板就不要再相加
+        boolean needWeatherForTemp = (deviceType != null && deviceType == 707) && (standard == null || standard.get("wd") == null);
+        boolean needWeatherForHumi = (deviceType != null && deviceType == 708) && (standard == null || standard.get("sd") == null);
+        boolean needWeatherForElectric = (deviceType != null && deviceType == 704) && (standard == null);
         Map<String, Double> weatherData = null;
-        if (standard == null && (deviceType == 707 || deviceType == 708 || deviceType == 704)) {
+        if (needWeatherForTemp || needWeatherForHumi || needWeatherForElectric) {
             weatherData = WeatherFetcher.fetchWeather();
         }
 
@@ -374,6 +377,27 @@ public class DeviceDataQuery {
                     simData.put("deviceuuid", device.getDeviceUuid());
                 }
 
+                // 若象屿模板里缺少温湿度字段,则再回退到天气+差值逻辑补齐(避免“所有情况都相加”)
+                if (deviceType != null && deviceType == 707 && simData.get("wd") == null) {
+                    double temp707;
+                    if (weatherData != null && !weatherData.isEmpty()) {
+                        double floating = BasementClimateUtil.getTempDiffWithOutdoor();
+                        temp707 = weatherData.get("temperature") + floating;
+                    } else {
+                        temp707 = BasementClimateUtil.getCurrentTempRange();
+                    }
+                    simData.put("wd", temp707);
+                } else if (deviceType != null && deviceType == 708 && simData.get("sd") == null) {
+                    double humi708;
+                    if (weatherData != null && !weatherData.isEmpty()) {
+                        double floating = BasementClimateUtil.getHumiDiffWithOutdoor();
+                        humi708 = weatherData.get("humidity") + floating;
+                    } else {
+                        humi708 = BasementClimateUtil.getCurrentHumiRange();
+                    }
+                    simData.put("sd", humi708);
+                }
+
                 addNoiseToNumericFields(simData, deviceType);
                 // System.out.println("深拷贝时间戳2:" + simData.getLong("realtime"));
             } else {
@@ -385,7 +409,7 @@ public class DeviceDataQuery {
                 switch (deviceType) {
                     case 707:
                         double temp707 = 0.0;
-                        if (!weatherData.isEmpty()) {
+                        if (weatherData != null && !weatherData.isEmpty()) {
                             double floating = BasementClimateUtil.getTempDiffWithOutdoor();
                             temp707 = weatherData.get("temperature") + floating;
                         } else {
@@ -396,7 +420,7 @@ public class DeviceDataQuery {
 
                     case 708:
                         double humi708 = 0.0;
-                        if (!weatherData.isEmpty()) {
+                        if (weatherData != null && !weatherData.isEmpty()) {
                             double floating = BasementClimateUtil.getHumiDiffWithOutdoor();
                             humi708 = weatherData.get("humidity") + floating;
                         } else {