Преглед изворни кода

Merge branch 'fu-dev' of uskycloud/usky-modules into master

hanzhengyi пре 2 недеља
родитељ
комит
399d6009b8

+ 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 {

+ 14 - 14
service-cdi/service-cdi-biz/src/main/java/com/usky/cdi/service/util/DeviceDataSyncService.java

@@ -26,18 +26,18 @@ public class DeviceDataSyncService {
      * fixedDelay:任务执行完成后固定延迟29分钟执行下一次
      * initialDelay:初始化后立即执行第一次任务
      */
-    @Scheduled(fixedDelay = 5 * 60 * 1000, initialDelay = 0)
-    public void scheduledDeviceDataSync() {
-        Integer tenantId = 1222;
-        Long engineeringId = 3101100021L;
-        String username = "3101100021";
-        String password = "SIixzph1";
-        log.info("开始执行桃浦象屿人防设备数据同步定时任务,租户ID:{},工程ID:{}", tenantId, engineeringId);
-
-        try {
-            iotDataTransferService.synchronizeDeviceData(tenantId, engineeringId, username, password);
-        } catch (Exception e) {
-            log.error("定时任务执行设备数据同步失败:{}", e.getMessage(), e);
-        }
-    }
+    // @Scheduled(fixedDelay = 5 * 60 * 1000, initialDelay = 0)
+    // public void scheduledDeviceDataSync() {
+    //     Integer tenantId = 1222;
+    //     Long engineeringId = 3101100021L;
+    //     String username = "3101100021";
+    //     String password = "SIixzph1";
+    //     log.info("开始执行桃浦象屿人防设备数据同步定时任务,租户ID:{},工程ID:{}", tenantId, engineeringId);
+    //
+    //     try {
+    //         iotDataTransferService.synchronizeDeviceData(tenantId, engineeringId, username, password);
+    //     } catch (Exception e) {
+    //         log.error("定时任务执行设备数据同步失败:{}", e.getMessage(), e);
+    //     }
+    // }
 }