From 785ee71b316f9c55151bd4b2a9ff855e06ddb162 Mon Sep 17 00:00:00 2001
From: liriming <1343021927@qq.com>
Date: 星期三, 16 四月 2025 16:15:47 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java |  125 ++++++++++++++++++++++++++++-------------
 1 files changed, 85 insertions(+), 40 deletions(-)

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 8260a43..91b9ada 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
@@ -1,12 +1,15 @@
 package com.iailab.module.ansteel.api.controller.admin;
 
+import com.alibaba.fastjson.JSONObject;
 import com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants;
 import com.iailab.framework.common.pojo.CommonResult;
 import com.iailab.framework.common.util.object.ConvertUtils;
 import com.iailab.module.ansteel.api.dto.*;
-import com.iailab.module.ansteel.api.entity.*;
-import com.iailab.module.ansteel.api.service.*;
+import com.iailab.module.ansteel.power.entity.*;
+import com.iailab.module.ansteel.power.service.*;
 import com.iailab.module.data.api.point.DataPointApi;
+import com.iailab.module.model.api.mcs.McsApi;
+import com.iailab.module.model.api.mcs.dto.PredictLastValueReqVO;
 import io.swagger.v3.oas.annotations.Operation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -50,6 +53,9 @@
     @Resource
     private DataPointApi dataPointApi;
 
+    @Resource
+    private McsApi mcsApi;
+
     @GetMapping("/net-factor/list")
     @Operation(summary = "功率因数-电网拓扑")
     public CommonResult<List<PowerNetFactorDTO>> getPowerNetFactorList(@RequestParam Map<String, Object> params) {
@@ -58,37 +64,78 @@
         if (CollectionUtils.isEmpty(result)) {
             return success(result);
         }
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.MILLISECOND, 0);
+        calendar.set(Calendar.SECOND, 0);
+        calendar.set(Calendar.MINUTE, 0);
+        calendar.set(Calendar.HOUR_OF_DAY, 0);
+
         for (PowerNetFactorDTO dto : result) {
-            List<String> points = new ArrayList<>();
-            if (StringUtils.isNotBlank(dto.getCurP())) {
-                points.add(dto.getCurP());
-            }
-            if (StringUtils.isNotBlank(dto.getCurQ())) {
-                points.add(dto.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());
+            try {
+                List<String> points = new ArrayList<>();
+                if (StringUtils.isNotBlank(dto.getCurP())) {
+                    points.add(dto.getCurP());
                 }
-                if (pointsRealValue.get(dto.getCurQ()) != null) {
-                    dto.setCurQ(pointsRealValue.get(dto.getCurQ()).toString());
+                if (StringUtils.isNotBlank(dto.getCurQ())) {
+                    points.add(dto.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(dto.getCurQ()) != null) {
+                        dto.setCurQ(pointsRealValue.get(dto.getCurQ()).toString());
+                    }
+                    if (pointsRealValue.get(dto.getCurCos()) != null) {
+                        dto.setCurCos(pointsRealValue.get(dto.getCurCos()).toString());
+                    }
+                }
+            } catch (Exception ex) {
+                log.info(dto.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(dto.getPreQ())) {
+                    itemNos.add(dto.getPreQ().split(","));
+                }
+                if (StringUtils.isNotBlank(dto.getPreCos())) {
+                    itemNos.add(dto.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(dto.getPreQ()) && preValues.get(dto.getPreQ()) != null) {
+                        dto.setPreQ(preValues.get(dto.getPreQ()).toString());
+                    }
+                    if (StringUtils.isNotBlank(dto.getPreCos()) && preValues.get(dto.getPreCos()) != null) {
+                        dto.setPreCos(preValues.get(dto.getPreCos()).toString());
+                    }
+                }
+            } catch (Exception ex) {
+                log.info(dto.getNodeName() + "获取预测值异常," + ex.getMessage());
             }
         }
-
         return success(result);
     }
 
-    /*
+    /**
      * 判断 curCos 是否超上下限
      * {nodeName}功率因数超上限/下限。
-     *
+     * <p>
      * 判断 curQ
      * {nodeName}发生无功返送
-     *
-     * */
-
+     */
     @GetMapping("/net-factor/alarm")
     @Operation(summary = "功率因数-电网拓扑预警信息")
     public CommonResult<List<String>> getPowerNetFactorAlarm(@RequestParam Map<String, Object> params) {
@@ -99,39 +146,37 @@
             return success(result);
         }
         for (PowerNetFactorDTO dto : dtoList) {
-            String message = "";
             List<String> points = new ArrayList<>();
+            String message = "";
             if (StringUtils.isNotBlank(dto.getCurQ())) {
                 points.add(dto.getCurQ());
             }
+            if (StringUtils.isNotBlank(dto.getCurCos())) {
+                points.add(dto.getCurCos());
+            }
             if (CollectionUtils.isEmpty(points)) {
-                return success(result);
+                continue;
             }
+
             Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points);
-            if (pointsRealValue.get(dto.getCurQ()) == null) {
-                return success(result);
-            }
-            BigDecimal curQ = new BigDecimal(pointsRealValue.get(dto.getCurQ()).toString());
-            if (dto.getCurFlag().compareTo(BigDecimal.ZERO) > 0) {
-                if (curQ.compareTo(BigDecimal.ZERO) > 0) {
-                    message = dto.getNodeName() + "发生无功返送;";
-                }
-            } else {
-                if (curQ.compareTo(BigDecimal.ZERO) < 0) {
+            if (pointsRealValue.get(dto.getCurQ()) != null) {
+                BigDecimal curQ = new BigDecimal(pointsRealValue.get(dto.getCurQ()).toString());
+                if (curQ.compareTo(BigDecimal.ZERO) == dto.getCurFlag()) {
                     message = dto.getNodeName() + "发生无功返送;";
                 }
             }
-            BigDecimal curCos = new BigDecimal(dto.getCurCos());
-            if (curCos.compareTo(dto.getLimitH()) > 0) {
-                message += dto.getNodeName() + "功率因数超上限";
-            }else if (curCos.compareTo(dto.getLimitL()) < 0) {
-                message += dto.getNodeName() + "功率因数超下限";
+            if (pointsRealValue.get(dto.getCurCos()) != null) {
+                BigDecimal curCos = new BigDecimal(pointsRealValue.get(dto.getCurCos()).toString());
+                if (curCos.compareTo(dto.getLimitH()) > 0) {
+                    message += dto.getNodeName() + "功率因数超上限";
+                } else if (curCos.compareTo(dto.getLimitL()) < 0) {
+                    message += dto.getNodeName() + "功率因数超下限";
+                }
             }
-            if(!"".equals(message)) {
+            if (!message.isEmpty()) {
                 result.add(message);
             }
         }
-
         return success(result);
     }
 

--
Gitblit v1.9.3