From 98afa8e170e13db0b850c5d866376a0c7a44761a Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期一, 28 四月 2025 14:08:52 +0800
Subject: [PATCH] 负荷移植-功率因数查询

---
 ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java |  117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 114 insertions(+), 3 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 fd54b9e..c161ca8 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
@@ -13,6 +13,7 @@
 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.data.api.point.dto.ApiPointsValueQueryDTO;
 import com.iailab.module.model.api.mcs.McsApi;
 import com.iailab.module.model.api.mcs.dto.PredictLastValueReqVO;
 import io.swagger.v3.oas.annotations.Operation;
@@ -509,7 +510,7 @@
     }
 
     @GetMapping("/demand-dropdown/list")
-    @Operation(summary = "负荷移植-电网拓扑下拉列表")
+    @Operation(summary = "负荷移植-功率因数下拉列表")
     public CommonResult<List<PowerNetDropdownDTO>> getDemandDropdownList(@RequestParam String code) {
         if (StringUtils.isBlank(code)) {
             log.info("code isBlank");
@@ -520,12 +521,12 @@
         List<PowerNetDropdownDTO> result = new ArrayList<>();
         PowerDemandEntity entity = powerDemandService.getByCode(code);
         if (entity == null) {
+            log.info("PowerDemandEntity is null");
             return success(result);
         }
-        List<PowerNetDropdownEntity> list = new ArrayList<>();
         Map<String, Object> params0 = new HashMap<>();
         params0.put("groupName", entity.getName());
-        list = powerNetDropdownService.list(params0);
+        List<PowerNetDropdownEntity> list = powerNetDropdownService.list(params0);
         List<String> points = list.stream().map(item -> {
             return item.getCurCos();
         }).collect(Collectors.toList());
@@ -545,6 +546,116 @@
         return success(result);
     }
 
+    @PostMapping("/demand-query/list")
+    @Operation(summary = "负荷移植-功率因数查询")
+    public CommonResult<List<PowerNetDropdownDTO>> getDemandDropdownList(@RequestBody PowerDemandQueryDTO queryDto) {
+        List<PowerNetDropdownDTO> result = new ArrayList<>();
+        if (StringUtils.isBlank(queryDto.getCode())) {
+            log.info("code isBlank");
+        }
+        log.info("code=" + queryDto.getCode());
+        if (StringUtils.isBlank(queryDto.getNodeCode())) {
+            log.info("NodeCode isBlank");
+        }
+        PowerDemandEntity entity = powerDemandService.getByCode(queryDto.getCode());
+        if (entity == null) {
+            log.info("PowerDemandEntity is null");
+            return success(result);
+        }
+        Map<String, Object> params0 = new HashMap<>();
+        params0.put("groupName", entity.getName());
+        List<PowerNetDropdownEntity> list = powerNetDropdownService.list(params0);
+        List<String> points = list.stream().map(item -> {
+            return item.getCurCos();
+        }).collect(Collectors.toList());
+        if (queryDto.getCurCos() == null) {
+            log.info("查询当前值");
+            Map<String, Object> pointsRealValue = new HashMap<>();
+            if (!CollectionUtils.isEmpty(points)) {
+                pointsRealValue = dataPointApi.queryPointsRealValue(points);
+            }
+            for (PowerNetDropdownEntity netDropdown : list) {
+                PowerNetDropdownDTO dto = ConvertUtils.sourceToTarget(netDropdown, PowerNetDropdownDTO.class);
+                BigDecimal curCos = BigDecimal.ZERO;
+                if (pointsRealValue.get(netDropdown.getCurCos()) != null) {
+                    curCos = new BigDecimal(pointsRealValue.get(netDropdown.getCurCos()).toString());
+                }
+                dto.setCurCos(curCos);
+                result.add(dto);
+            }
+        } else {
+            log.info("查询历史值");
+            String nodeCode = queryDto.getNodeCode();
+            if (StringUtils.isBlank(nodeCode)) {
+                log.info("nodeCode isBlank");
+                return success(result);
+            }
+            PowerNetDropdownEntity powerNetDropdownEntity = powerNetDropdownService.getByNodeCode(nodeCode);
+            if (powerNetDropdownEntity == null) {
+                log.info("PowerNetDropdownEntity is null");
+                return success(result);
+            }
+            ApiPointsValueQueryDTO valueQueryDTO = new ApiPointsValueQueryDTO();
+            valueQueryDTO.setPointNos(points);
+            Calendar calendar = Calendar.getInstance();
+            calendar.set(Calendar.MILLISECOND, 0);
+            calendar.set(Calendar.SECOND, 0);
+            Date startTime = queryDto.getStartTime();
+            Date endTime = queryDto.getEndTime();
+            if (endTime == null) {
+                endTime = calendar.getTime();
+            }
+            if (startTime == null) {
+                calendar.add(Calendar.DAY_OF_YEAR, -1);
+                startTime = calendar.getTime();
+            }
+            valueQueryDTO.setStart(startTime);
+            valueQueryDTO.setEnd(endTime);
+            Map<String, List<Map<String, Object>>> pointsHisValues = dataPointApi.queryPointsHistoryValue(valueQueryDTO);
+            if (CollectionUtils.isEmpty(pointsHisValues)) {
+                log.info("pointsHisValues is null");
+                return success(result);
+            }
+
+            ApiPointValueQueryDTO pointValueQueryDTO = new ApiPointValueQueryDTO();
+            pointValueQueryDTO.setStart(startTime);
+            pointValueQueryDTO.setEnd(endTime);
+            pointValueQueryDTO.setPointNo(powerNetDropdownEntity.getCurCos());
+            List<ApiPointValueDTO> hisValue = dataPointApi.queryPointHistoryValue(pointValueQueryDTO);
+            if (CollectionUtils.isEmpty(hisValue)) {
+                log.info("hisValue is null");
+            }
+            ApiPointValueDTO curValue = null;
+            Collections.reverse(hisValue);
+            for (ApiPointValueDTO valueDTO : hisValue) {
+                curValue = valueDTO;
+                if ((queryDto.getCurCos().doubleValue() - valueDTO.getV()) <= 0.0001) {
+                    break;
+                }
+            }
+            if (curValue == null) {
+                log.info("curValue is null");
+                return success(result);
+            }
+            log.info("curValue=" + curValue);
+            for (PowerNetDropdownEntity netDropdown : list) {
+                PowerNetDropdownDTO dto = ConvertUtils.sourceToTarget(netDropdown, PowerNetDropdownDTO.class);
+
+                if (CollectionUtils.isEmpty(pointsHisValues.get(netDropdown.getCurCos()))) {
+                    continue;
+                }
+                Map<String, BigDecimal> pointValueMap = new HashMap<>();
+                pointsHisValues.get(netDropdown.getCurCos()).forEach(item -> {
+                    pointValueMap.put(item.get("time").toString(), DecimalUtil.toBigDecimal(item.get("value")));
+
+                });
+                dto.setCurCos(pointValueMap.get(DateUtils.format(curValue.getT(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)));
+                result.add(dto);
+            }
+        }
+        return success(result);
+    }
+
     @PostMapping("/net-factor/history")
     @Operation(summary = "功率因数-根据nodeName获取最近1440min历史数据,月最大,最小值")
     public CommonResult<PowerHistoryDTO> getPowerHistoryData(@RequestBody PowerNetFactorHisReqDTO dto) {

--
Gitblit v1.9.3