From 634d18758efbd8616d03945da447cc242c880491 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 15 四月 2025 09:54:08 +0800
Subject: [PATCH] 功率因数-发电机组实时状态

---
 ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java |  104 +++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 94 insertions(+), 10 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 72756bc..fb210d5 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
@@ -3,24 +3,26 @@
 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.PowerCapacitorStatusDTO;
-import com.iailab.module.ansteel.api.dto.PowerControlDetDTO;
-import com.iailab.module.ansteel.api.dto.PowerNetFactorDTO;
+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.data.api.point.DataPointApi;
 import io.swagger.v3.oas.annotations.Operation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 
 import static com.iailab.framework.common.pojo.CommonResult.success;
 
@@ -48,11 +50,70 @@
     @Autowired
     private PowerControlDetService powerControlDetService;
 
+    @Autowired
+    private PowerGenStatusDaoService powerGenStatusDaoService;
+
+    @Resource
+    private DataPointApi dataPointApi;
+
     @GetMapping("/net-factor/list")
     @Operation(summary = "功率因数-电网拓扑")
     public CommonResult<List<PowerNetFactorDTO>> getPowerNetFactorList(@RequestParam Map<String, Object> params) {
         List<PowerNetFactorEntity> list = powerNetFactorService.list(params);
-        return success(ConvertUtils.sourceToTarget(list, PowerNetFactorDTO.class));
+        List<PowerNetFactorDTO> result = ConvertUtils.sourceToTarget(list, PowerNetFactorDTO.class);
+        if (CollectionUtils.isEmpty(result)) {
+            return success(result);
+        }
+        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());
+                }
+                if (pointsRealValue.get(dto.getCurQ()) != null) {
+                    dto.setCurQ(pointsRealValue.get(dto.getCurQ()).toString());
+                }
+            }
+        }
+
+        return success(result);
+    }
+
+    @GetMapping("/gen-status/list")
+    @Operation(summary = "功率因数-发电机组实时状态")
+    public CommonResult<List<PowerGenStatusDTO>> getPowerGenStatusList(@RequestParam Map<String, Object> params) {
+        List<PowerGenStatusEntity> list = powerGenStatusDaoService.list(params);
+        List<PowerGenStatusDTO> result = ConvertUtils.sourceToTarget(list, PowerGenStatusDTO.class);
+        if (CollectionUtils.isEmpty(result)) {
+            return success(result);
+        }
+        for(PowerGenStatusDTO 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());
+                }
+                if (pointsRealValue.get(dto.getCurQ()) != null) {
+                    dto.setCurQ(pointsRealValue.get(dto.getCurQ()).toString());
+                }
+            }
+        }
+
+        return success(result);
     }
 
     @GetMapping("/capacitor-status/list")
@@ -62,8 +123,29 @@
         return success(ConvertUtils.sourceToTarget(list, PowerCapacitorStatusDTO.class));
     }
 
+    @GetMapping("/control-main/list")
+    @Operation(summary = "功率因数-管控变电站列表")
+    public CommonResult<List<PowerControlMainDTO>> getPowerControlMainList(@RequestParam Map<String, Object> params) {
+        List<PowerControlMainEntity> list = powerControlMainService.list(params);
+        return success(ConvertUtils.sourceToTarget(list, PowerControlMainDTO.class));
+    }
+
+    @GetMapping("/control-main/update")
+    @Operation(summary = "功率因数-管控变电站修改上下限")
+    public CommonResult<Boolean> updatePowerControlMain(PowerControlMainDTO dto) {
+        if (StringUtils.isBlank(dto.getId())) {
+            return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST);
+        }
+        PowerControlMainEntity entity = new PowerControlMainEntity();
+        entity.setId(dto.getId());
+        entity.setLimitH(dto.getLimitH());
+        entity.setLimitL(dto.getLimitL());
+        powerControlMainService.update(entity);
+        return success(true);
+    }
+
     @GetMapping("/control-det/list")
-    @Operation(summary = "功率因数-管控功率因数")
+    @Operation(summary = "功率因数-管控功率因数详情")
     public CommonResult<List<PowerControlDetDTO>> getPowerControlDetList(@RequestParam Map<String, Object> params) {
         List<PowerControlDetDTO> result = new ArrayList<>();
         String name = (String)params.get("name");
@@ -79,14 +161,16 @@
 
         result.forEach(item -> {
             // 设置随机数据,0.8左右
-            double randomDouble = Math.random();
-            double min = 0.7;
-            double max = 0.9;
-            double randomNumber = (randomDouble * (max - min + 1)) + min;
-            BigDecimal rv = new BigDecimal(randomNumber).setScale(4, BigDecimal.ROUND_HALF_UP);
+            Random rand = new Random();
+            int min = 700;
+            int max = 900;
+            int randomNumber = rand.nextInt(max - min + 1) + min;
+            BigDecimal rv = new BigDecimal(randomNumber * 0.001).setScale(4, BigDecimal.ROUND_HALF_UP);
             item.setValue(rv);
             if (item.getLimitL() != null && rv.compareTo(item.getLimitL()) < 0) {
                 item.setStatus(1);
+            } else {
+                item.setStatus(0);
             }
         });
         return success(result);

--
Gitblit v1.9.3