瀏覽代碼

修改异常功率的设备的采集逻辑

lingpeng.li 5 月之前
父節點
當前提交
8109b9e4f6

+ 41 - 0
jeecg-module-gather/src/main/java/org/jeecg/modules/utils/PowerCalculatorUtil.java

@@ -0,0 +1,41 @@
+package org.jeecg.modules.utils;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+public class PowerCalculatorUtil {
+
+    /**
+     * 计算三相电功率,并以 kW 为单位返回
+     *
+     * @param voltage 电压 (U_L),单位:伏特(V)
+     * @param current 电流 (I_L),单位:安培(A)
+     * @param powerFactor 功率因数 (cos φ)
+     * @return 功率 (P),单位:千瓦(kW)
+     */
+    public static BigDecimal calculateThreePhasePowerInKW(BigDecimal voltage, BigDecimal current, BigDecimal powerFactor) {
+        // √3 的值
+        BigDecimal sqrt3 = new BigDecimal(Math.sqrt(3));
+
+        // P = √3 × U_L × I_L × cos φ (单位为瓦特 W)
+        BigDecimal powerInWatts = sqrt3.multiply(voltage).multiply(current).multiply(powerFactor);
+
+        // 转换为千瓦 (kW),即除以 1000
+        BigDecimal powerInKW = powerInWatts.divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP);
+
+        return powerInKW;
+    }
+
+    public static void main(String[] args) {
+        // 示例参数
+        BigDecimal voltage = new BigDecimal("10000");   // 电压 10kV
+        BigDecimal current = new BigDecimal("30");      // 电流 60A
+        BigDecimal powerFactor = new BigDecimal("0.8"); // 功率因数 0.8
+
+        // 计算功率
+        BigDecimal powerInKW = calculateThreePhasePowerInKW(voltage, current, powerFactor);
+
+        // 输出结果
+        System.out.println("三相电功率为: " + powerInKW + " kW");
+    }
+}

+ 43 - 7
jeecg-module-gather/src/main/java/org/jeecg/modules/watch/PostgreSQLWatch.java

@@ -15,6 +15,7 @@ import org.jeecg.modules.gatherData.mapper.FpgGatherDataMapper;
 import org.jeecg.modules.peaksAndValleysTimeConfig.entity.SystemVariable;
 import org.jeecg.modules.peaksAndValleysTimeConfig.service.ISystemVariableService;
 import org.jeecg.modules.utils.PostgreSQLUtil;
+import org.jeecg.modules.utils.PowerCalculatorUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.scheduling.annotation.Async;
@@ -119,11 +120,29 @@ public class PostgreSQLWatch {
                     if (fpgGatherData == null) { // 直接新增
                         FpgGatherData fpgGatherInsert = new FpgGatherData();
                         fpgGatherInsert.setCreateTime(timestamp);
-                        // 处理电流+电压
+                        // 根据 point_code 和电流或功率的类型进行判断
                         if ("Ia".equals(point.getCurrentPower())) {
-                            fpgGatherInsert.setRunCurrent(value);
+                            // 如果 point_code 为 YC.3167 或 YC.3151,计算功率
+                            if ("YC.3167".equals(point.getPointCode()) || "YC.3151".equals(point.getPointCode())) {
+                                BigDecimal powerValue = PowerCalculatorUtil.calculateThreePhasePowerInKW(
+                                        new BigDecimal("10000"), // 假设电压为 10kV,这里可以替换为实际电压值
+                                        value,                  // 当前电流值
+                                        new BigDecimal("0.8")   // 假设功率因数为 0.8,这里可以替换为实际功率因数
+                                );
+                                fpgGatherInsert.setRunCurrent(value);
+                                fpgGatherInsert.setActivePower(powerValue);
+                            } else {
+                                // 如果不满足条件,直接设置电流
+                                fpgGatherInsert.setRunCurrent(value);
+                            }
                         } else if ("P".equals(point.getCurrentPower())) {
-                            fpgGatherInsert.setActivePower(value);
+                            // 如果 point_code 为 YC.3154 或 YC.3168,不进行任何处理
+                            if ("YC.3154".equals(point.getPointCode()) || "YC.3168".equals(point.getPointCode())) {
+                                continue; // 跳过后续处理
+                            } else {
+                                // 正常设置功率
+                                fpgGatherInsert.setActivePower(value);
+                            }
                         }
                         fpgGatherInsert.setDevicePointId(pointIdListStrs);
                         fpgGatherInsert.setDeviceInformationId(point.getDeviceId());
@@ -134,11 +153,28 @@ public class PostgreSQLWatch {
                     } else { // 编辑处理
                         // 处理数据点类型和值的累计
                         if ("Ia".equals(point.getCurrentPower())) {
-                            BigDecimal runCurrent = fpgGatherData.getRunCurrent() == null ? value : fpgGatherData.getRunCurrent().add(value);
-                            fpgGatherData.setRunCurrent(runCurrent);
+                            if ("YC.3167".equals(point.getPointCode()) || "YC.3151".equals(point.getPointCode())) {
+                                BigDecimal powerValue = PowerCalculatorUtil.calculateThreePhasePowerInKW(
+                                        new BigDecimal("10000"), // 假设电压为 10kV,这里可以替换为实际电压值
+                                        value,                  // 当前电流值
+                                        new BigDecimal("0.8")   // 假设功率因数为 0.8,这里可以替换为实际功率因数
+                                );
+                                BigDecimal runCurrent = fpgGatherData.getRunCurrent() == null ? value : fpgGatherData.getRunCurrent().add(value);
+                                fpgGatherData.setRunCurrent(runCurrent);
+                                BigDecimal activePower = fpgGatherData.getActivePower() == null ? powerValue : fpgGatherData.getActivePower().add(powerValue);
+                                fpgGatherData.setActivePower(activePower);
+                            } else {
+                                BigDecimal runCurrent = fpgGatherData.getRunCurrent() == null ? value : fpgGatherData.getRunCurrent().add(value);
+                                fpgGatherData.setRunCurrent(runCurrent);
+                            }
                         } else if ("P".equals(point.getCurrentPower())) {
-                            BigDecimal activePower = fpgGatherData.getActivePower() == null ? value : fpgGatherData.getActivePower().add(value);
-                            fpgGatherData.setActivePower(activePower);
+                            if ("YC.3154".equals(point.getPointCode()) || "YC.3168".equals(point.getPointCode())) {
+                                // 跳过特殊点的处理
+                                continue;
+                            } else {
+                                BigDecimal activePower = fpgGatherData.getActivePower() == null ? value : fpgGatherData.getActivePower().add(value);
+                                fpgGatherData.setActivePower(activePower);
+                            }
                         }
                         fpgGatherData.setId(fpgGatherData.getId());
                         fpgGatherDataMapper.updateById(fpgGatherData);