Pārlūkot izejas kodu

修改抓取数据的电压如果为负数,则赋值为0

lingpeng.li 3 mēneši atpakaļ
vecāks
revīzija
2105aa1a85

+ 4 - 0
jeecg-module-gather/src/main/java/org/jeecg/modules/watch/PostgreSQLWatch.java

@@ -131,6 +131,7 @@ public class PostgreSQLWatch {
                                         new BigDecimal("0.8")   // 假设功率因数为 0.8,这里可以替换为实际功率因数
                                 );
                                 fpgGatherInsert.setRunCurrent(value);
+                                powerValue = powerValue.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : powerValue; // 如果是负数,设置为 0
                                 fpgGatherInsert.setActivePower(powerValue);
                             } else {
                                 // 如果不满足条件,直接设置电流
@@ -142,6 +143,7 @@ public class PostgreSQLWatch {
                                 continue; // 跳过后续处理
                             } else {
                                 // 正常设置功率
+                                value = value.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : value; // 如果是负数,设置为 0
                                 fpgGatherInsert.setActivePower(value);
                             }
                         }
@@ -164,6 +166,7 @@ public class PostgreSQLWatch {
                                 BigDecimal runCurrent = fpgGatherData.getRunCurrent() == null ? value : fpgGatherData.getRunCurrent().add(value);
                                 fpgGatherData.setRunCurrent(runCurrent);
                                 BigDecimal activePower = fpgGatherData.getActivePower() == null ? powerValue : fpgGatherData.getActivePower().add(powerValue);
+                                activePower = activePower.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : activePower; // 如果是负数,设置为 0
                                 fpgGatherData.setActivePower(activePower);
                             } else {
                                 BigDecimal runCurrent = fpgGatherData.getRunCurrent() == null ? value : fpgGatherData.getRunCurrent().add(value);
@@ -175,6 +178,7 @@ public class PostgreSQLWatch {
                                 continue;
                             } else {
                                 BigDecimal activePower = fpgGatherData.getActivePower() == null ? value : fpgGatherData.getActivePower().add(value);
+                                activePower = activePower.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : activePower; // 如果是负数,设置为 0
                                 fpgGatherData.setActivePower(activePower);
                             }
                         }