From 145f3c2fa994f7fdc37248fa0e2222a14ac5c7d9 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 06 五月 2025 18:15:13 +0800
Subject: [PATCH] 功率因数-电网拓扑 增加有功无功预警

---
 ansteel-biz/src/main/java/com/iailab/module/ansteel/api/dto/PowerNetFactorDTO.java            |   20 ++++--
 ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java |   96 +++++++++++++++++++++-----------
 ansteel-biz/src/main/java/com/iailab/module/ansteel/power/entity/PowerNetFactorEntity.java    |   20 ++++++
 ansteel-biz/db/mysql.sql                                                                      |    9 +++
 4 files changed, 105 insertions(+), 40 deletions(-)

diff --git a/ansteel-biz/db/mysql.sql b/ansteel-biz/db/mysql.sql
index 7dfe3eb..2726640 100644
--- a/ansteel-biz/db/mysql.sql
+++ b/ansteel-biz/db/mysql.sql
@@ -250,6 +250,15 @@
 ALTER TABLE `t_power_net_factor`
     ADD COLUMN `node_code` varchar(50) NULL DEFAULT NULL COMMENT '节点编号';
 
+ALTER TABLE `t_power_net_factor`
+    ADD COLUMN `p_limit_l` decimal(9, 3) NULL DEFAULT NULL COMMENT '有功下限';
+ALTER TABLE `t_power_net_factor`
+    ADD COLUMN `p_limit_h` decimal(9, 3) NULL DEFAULT NULL COMMENT '有功上限';
+ALTER TABLE `t_power_net_factor`
+    ADD COLUMN `q_limit_l` varchar(50) NULL DEFAULT NULL COMMENT '无功下限';
+ALTER TABLE `t_power_net_factor`
+    ADD COLUMN `q_limit_h` varchar(50) NULL DEFAULT NULL COMMENT '无功上限';
+
 -- ----------------------------
 -- 电力功率因数-发电机组实时状态
 -- ----------------------------
diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java
index 4da99de..e80f133 100644
--- a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java
+++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java
@@ -84,7 +84,7 @@
     @Operation(summary = "功率因数-电网拓扑")
     public CommonResult<List<PowerNetFactorDTO>> getPowerNetFactorList(@RequestParam Map<String, Object> params) {
         List<PowerNetFactorEntity> list = powerNetFactorService.list(params);
-        List<PowerNetFactorDTO> result = ConvertUtils.sourceToTarget(list, PowerNetFactorDTO.class);
+        List<PowerNetFactorDTO> result = new ArrayList<>();
         if (CollectionUtils.isEmpty(result)) {
             return success(result);
         }
@@ -94,72 +94,102 @@
         calendar.set(Calendar.MINUTE, 0);
         calendar.set(Calendar.HOUR_OF_DAY, 0);
 
-        for (PowerNetFactorDTO dto : result) {
+        for (PowerNetFactorEntity entity : list) {
+            PowerNetFactorDTO powerNetFactorDTO = new PowerNetFactorDTO();
+            powerNetFactorDTO.setId(entity.getId());
+            powerNetFactorDTO.setGroupName(entity.getGroupName());
+            powerNetFactorDTO.setNodeCode(entity.getNodeCode());
+            powerNetFactorDTO.setNodeName(entity.getNodeName());
             boolean cosFlag = false;
             try {
                 List<String> points = new ArrayList<>();
-                if (StringUtils.isNotBlank(dto.getCurP())) {
-                    points.add(dto.getCurP());
+                if (StringUtils.isNotBlank(entity.getCurP())) {
+                    points.add(entity.getCurP());
                 }
-                if (StringUtils.isNotBlank(dto.getCurQ())) {
-                    points.add(dto.getCurQ());
+                if (StringUtils.isNotBlank(entity.getCurQ())) {
+                    points.add(entity.getCurQ());
                 }
                 if (!CollectionUtils.isEmpty(points)) {
                     Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points);
-                    if (pointsRealValue.get(dto.getCurP()) != null) {
-                        dto.setCurP(pointsRealValue.get(dto.getCurP()).toString());
+                    if (pointsRealValue.get(entity.getCurP()) != null) {
+                        powerNetFactorDTO.setCurP(new BigDecimal(pointsRealValue.get(entity.getCurP()).toString()));
                     }
-                    if (pointsRealValue.get(dto.getCurQ()) != null) {
-                        dto.setCurQ(pointsRealValue.get(dto.getCurQ()).toString());
+                    if (pointsRealValue.get(entity.getCurQ()) != null) {
+                        powerNetFactorDTO.setCurQ(new BigDecimal(pointsRealValue.get(entity.getCurQ()).toString()));
                     }
-                    if (pointsRealValue.get(dto.getCurCos()) != null) {
-                        dto.setCurCos(pointsRealValue.get(dto.getCurCos()).toString());
+                    if (pointsRealValue.get(entity.getCurCos()) != null) {
+                        powerNetFactorDTO.setCurCos(new BigDecimal(pointsRealValue.get(entity.getCurCos()).toString()));
                         cosFlag = true;
                     }
                 }
             } catch (Exception ex) {
-                log.info(dto.getNodeName() + "获取当前值异常" + ex.getMessage());
+                log.info(entity.getNodeName() + "获取当前值异常" + ex.getMessage());
             }
 
             try {
                 PredictLastValueReqVO reqVO = new PredictLastValueReqVO();
                 reqVO.setPredictTime(calendar.getTime());
                 List<String[]> itemNos = new ArrayList<>();
-                if (StringUtils.isNotBlank(dto.getPreP())) {
-                    itemNos.add(dto.getPreP().split(","));
+                if (StringUtils.isNotBlank(entity.getPreP())) {
+                    itemNos.add(entity.getPreP().split(","));
                 }
-                if (StringUtils.isNotBlank(dto.getPreQ())) {
-                    itemNos.add(dto.getPreQ().split(","));
+                if (StringUtils.isNotBlank(entity.getPreQ())) {
+                    itemNos.add(entity.getPreQ().split(","));
                 }
-                if (StringUtils.isNotBlank(dto.getPreCos())) {
-                    itemNos.add(dto.getPreCos().split(","));
+                if (StringUtils.isNotBlank(entity.getPreCos())) {
+                    itemNos.add(entity.getPreCos().split(","));
                 }
                 if (!CollectionUtils.isEmpty(itemNos)) {
                     reqVO.setItemNos(itemNos);
                     log.info("reqVO=" + JSONObject.toJSONString(reqVO));
                     Map<String, BigDecimal> preValues = mcsApi.getPredictValueByTime(reqVO);
-                    if (StringUtils.isNotBlank(dto.getPreP()) && preValues.get(dto.getPreP()) != null) {
-                        dto.setPreP(preValues.get(dto.getPreP()).toString());
+                    if (StringUtils.isNotBlank(entity.getPreP()) && preValues.get(entity.getPreP()) != null) {
+                        powerNetFactorDTO.setPreP(new BigDecimal(preValues.get(entity.getPreP()).toString()));
                     }
-                    if (StringUtils.isNotBlank(dto.getPreQ()) && preValues.get(dto.getPreQ()) != null) {
-                        dto.setPreQ(preValues.get(dto.getPreQ()).toString());
+                    if (StringUtils.isNotBlank(entity.getPreQ()) && preValues.get(entity.getPreQ()) != null) {
+                        powerNetFactorDTO.setPreQ(new BigDecimal(preValues.get(entity.getPreQ()).toString()));
                     }
-                    if (StringUtils.isNotBlank(dto.getPreCos()) && preValues.get(dto.getPreCos()) != null) {
-                        dto.setPreCos(preValues.get(dto.getPreCos()).toString());
+                    if (StringUtils.isNotBlank(entity.getPreCos()) && preValues.get(entity.getPreCos()) != null) {
+                        powerNetFactorDTO.setPreCos(new BigDecimal(preValues.get(entity.getPreCos()).toString()));
                     }
                 }
             } catch (Exception ex) {
-                log.info(dto.getNodeName() + "获取预测值异常," + ex.getMessage());
+                log.info(entity.getNodeName() + "获取预测值异常," + ex.getMessage());
             }
 
-            // 设置状态
-            if (cosFlag && StringUtils.isNotBlank(dto.getCurCos()) && NumberUtil.isNumber(dto.getCurCos())) {
-                BigDecimal curCos = new BigDecimal(dto.getCurCos());
-                if (dto.getLimitL() != null && dto.getLimitH() != null &&
-                        curCos.compareTo(dto.getLimitL()) < 0 || curCos.compareTo(dto.getLimitH()) > 0) {
-                    dto.setStatus(1);
+            // 设置功率因数状态
+            if (cosFlag && powerNetFactorDTO.getCurCos() != null) {
+                BigDecimal curCos = powerNetFactorDTO.getCurCos();
+                if (entity.getLimitL() != null && curCos.compareTo(entity.getLimitL()) < 0) {
+                    powerNetFactorDTO.setStatus(1);
+                } else if (entity.getLimitH() != null && curCos.compareTo(entity.getLimitH()) > 0) {
+                    powerNetFactorDTO.setStatus(1);
                 } else {
-                    dto.setStatus(0);
+                    powerNetFactorDTO.setStatus(0);
+                }
+            }
+
+            // 设置有功预警状态
+            if (powerNetFactorDTO.getCurP() != null) {
+                BigDecimal curP = powerNetFactorDTO.getCurP();
+                if (entity.getPLimitH() != null && curP.compareTo(entity.getPLimitL()) < 0) {
+                    powerNetFactorDTO.setStatus(1);
+                } else if (entity.getPLimitH() != null && curP.compareTo(entity.getPLimitH()) > 0) {
+                    powerNetFactorDTO.setStatus(1);
+                } else {
+                    powerNetFactorDTO.setStatus(0);
+                }
+            }
+
+            // 设置无功预警状态
+            if (powerNetFactorDTO.getCurQ() != null) {
+                BigDecimal curQ = powerNetFactorDTO.getCurQ();
+                if (entity.getQLimitH() != null && curQ.compareTo(entity.getQLimitL()) < 0) {
+                    powerNetFactorDTO.setStatus(1);
+                } else if (entity.getQLimitH() != null && curQ.compareTo(entity.getQLimitH()) > 0) {
+                    powerNetFactorDTO.setStatus(1);
+                } else {
+                    powerNetFactorDTO.setStatus(0);
                 }
             }
         }
diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/dto/PowerNetFactorDTO.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/dto/PowerNetFactorDTO.java
index b769dc2..56cbd9a 100644
--- a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/dto/PowerNetFactorDTO.java
+++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/dto/PowerNetFactorDTO.java
@@ -29,25 +29,25 @@
     private String nodeName;
 
     @Schema(description = "当前有功")
-    private String curP;
+    private BigDecimal curP;
 
     @Schema(description = "当前无功")
-    private String curQ;
+    private BigDecimal curQ;
 
     @Schema(description = "当前功率因数")
-    private String curCos;
+    private BigDecimal curCos;
 
     @Schema(description = "无功返送(1:大于0是,-1:小于0是)")
     private Integer curFlag;
 
     @Schema(description = "预测有功")
-    private String preP;
+    private BigDecimal preP;
 
     @Schema(description = "预测无功")
-    private String preQ;
+    private BigDecimal preQ;
 
     @Schema(description = "预测功率因数")
-    private String preCos;
+    private BigDecimal preCos;
 
     @Schema(description = "上限")
     private BigDecimal limitH;
@@ -55,11 +55,17 @@
     @Schema(description = "下限")
     private BigDecimal limitL;
 
-    @Schema(description = "是否超限(0:正常,1:超限)")
+    @Schema(description = "功率因数是否超限(0:正常,1:超限)")
     private Integer status;
 
     @Schema(description = "排序")
     private Integer sort;
 
+    @Schema(description = "有功是否超限(0:正常,1:超限)")
+    private Integer pStatus;
+
+    @Schema(description = "无功是否超限(0:正常,1:超限)")
+    private Integer qStatus;
+
 
 }
\ No newline at end of file
diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/power/entity/PowerNetFactorEntity.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/power/entity/PowerNetFactorEntity.java
index d49ca2f..7930ac2 100644
--- a/ansteel-biz/src/main/java/com/iailab/module/ansteel/power/entity/PowerNetFactorEntity.java
+++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/power/entity/PowerNetFactorEntity.java
@@ -87,4 +87,24 @@
      * 排序
      */
 	private Integer sort;
+
+    /**
+     * 有功下限
+     */
+    private BigDecimal pLimitL;
+
+    /**
+     * 有功上限
+     */
+    private BigDecimal pLimitH;
+
+    /**
+     * 无功下限
+     */
+    private BigDecimal qLimitL;
+
+    /**
+     * 无功上限
+     */
+    private BigDecimal qLimitH;
 }
\ No newline at end of file

--
Gitblit v1.9.3