From 1ac5226ccc10d1d33bfcf4129c09a9b095a9f82e Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期一, 21 四月 2025 10:59:30 +0800
Subject: [PATCH] 异常溯源折线图 修改

---
 ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java |  161 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 148 insertions(+), 13 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 6c95486..d7cb177 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,5 +1,7 @@
 package com.iailab.module.ansteel.api.controller.admin;
 
+import cn.hutool.core.util.NumberUtil;
+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;
@@ -7,6 +9,10 @@
 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.data.api.point.dto.ApiPointValueDTO;
+import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO;
+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;
@@ -47,8 +53,14 @@
     @Autowired
     private PowerGenStatusDaoService powerGenStatusDaoService;
 
+    @Autowired
+    private PowerDemandService powerDemandService;
+
     @Resource
     private DataPointApi dataPointApi;
+
+    @Resource
+    private McsApi mcsApi;
 
     @GetMapping("/net-factor/list")
     @Operation(summary = "功率因数-电网拓扑")
@@ -58,25 +70,89 @@
         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());
+            boolean cosFlag = false;
+            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());
+                        cosFlag = true;
+                    }
+                }
+            } 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());
+            }
+
+            // 设置状态
+            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);
+                } else {
+                    dto.setStatus(0);
                 }
             }
         }
+        return success(result);
+    }
 
+    @GetMapping("/net-factor-dropdown/list")
+    @Operation(summary = "功率因数-电网拓扑下拉列表")
+    public CommonResult<List<PowerNetFactorDropdownDTO>> getPowerNetFactorDropdownList(@RequestParam String nodeName) {
+        List<PowerNetFactorEntity> list = powerNetFactorService.listDropdown(nodeName);
+        List<PowerNetFactorDropdownDTO> result = ConvertUtils.sourceToTarget(list, PowerNetFactorDropdownDTO.class);
         return success(result);
     }
 
@@ -220,4 +296,63 @@
         });
         return success(result);
     }
+    @GetMapping("/demand/list")
+    @Operation(summary = "负荷移植-月最大需量,实测需量,有功功率")
+    public CommonResult<List<PowerDemandDTO>> getPowerDemandList(@RequestParam Map<String, Object> params) {
+        List<PowerDemandEntity> list = powerDemandService.list(params);
+        List<PowerDemandDTO> result = ConvertUtils.sourceToTarget(list, PowerDemandDTO.class);
+        if (CollectionUtils.isEmpty(result)) {
+            return success(result);
+        }
+        for (PowerDemandDTO dto : result) {
+            List<String> points = new ArrayList<>();
+            if (StringUtils.isNotBlank(dto.getCurDemand())) {
+                points.add(dto.getCurDemand());
+            }
+            if (StringUtils.isNotBlank(dto.getActivePower())) {
+                points.add(dto.getActivePower());
+            }
+
+            if (!CollectionUtils.isEmpty(points)) {
+
+                Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points);
+
+                if (pointsRealValue.get(dto.getCurDemand()) != null) {
+                    dto.setCurDemand(pointsRealValue.get(dto.getCurDemand()).toString());
+                }
+                if (pointsRealValue.get(dto.getActivePower()) != null) {
+                    dto.setActivePower(pointsRealValue.get(dto.getActivePower()).toString());
+                }
+            }
+
+            if (!StringUtils.isEmpty(dto.getMaxDemand())) {
+                Calendar calendar = Calendar.getInstance();
+                calendar.set(Calendar.DAY_OF_MONTH, 1);
+                calendar.set(Calendar.HOUR_OF_DAY, 0);
+                calendar.set(Calendar.MINUTE, 0);
+                calendar.set(Calendar.SECOND, 0);
+                calendar.set(Calendar.MILLISECOND, 0);
+                Date start = calendar.getTime();
+                calendar.add(Calendar.MONTH, 1);
+                Date end = calendar.getTime();
+                ApiPointValueQueryDTO apiPointValueQueryDTO = new ApiPointValueQueryDTO();
+                apiPointValueQueryDTO.setStart(start);
+                apiPointValueQueryDTO.setEnd(end);
+                apiPointValueQueryDTO.setPointNo(dto.getMaxDemand());
+
+                List<ApiPointValueDTO> monthValues = dataPointApi.queryPointHistoryValue(apiPointValueQueryDTO);
+                double max = 0;
+                for (int i = 0; i < monthValues.size()-1; i++) {
+                    if(max < monthValues.get(i).getV()){
+                        max = monthValues.get(i).getV();
+                    }
+                }
+                dto.setMaxDemand(String.valueOf(max));
+            }
+
+
+        }
+
+        return success(result);
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3