From 4565dd1660ace1311267b4b89fa893489d7ce02f Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期三, 16 四月 2025 16:35:04 +0800 Subject: [PATCH] 电网拓扑状态 --- ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java | 252 +++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 226 insertions(+), 26 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 678c606..9ee6709 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,33 +1,26 @@ package com.iailab.module.ansteel.api.controller.admin; -import com.iailab.framework.common.exception.ErrorCode; +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; -import com.iailab.module.ansteel.api.dto.PowerCapacitorStatusDTO; -import com.iailab.module.ansteel.api.dto.PowerControlDetDTO; -import com.iailab.module.ansteel.api.dto.PowerControlMainDTO; -import com.iailab.module.ansteel.api.dto.PowerNetFactorDTO; -import com.iailab.module.ansteel.api.entity.PowerControlDetEntity; -import com.iailab.module.ansteel.api.entity.PowerControlMainEntity; -import com.iailab.module.ansteel.api.entity.PowerNetFactorEntity; -import com.iailab.module.ansteel.api.entity.PowerRunStateEntity; -import com.iailab.module.ansteel.api.service.PowerControlDetService; -import com.iailab.module.ansteel.api.service.PowerControlMainService; -import com.iailab.module.ansteel.api.service.PowerNetFactorService; -import com.iailab.module.ansteel.api.service.PowerRunStateService; +import com.iailab.module.ansteel.api.dto.*; +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; import org.springframework.beans.factory.annotation.Autowired; -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 org.springframework.web.servlet.View; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.Map; +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.*; import static com.iailab.framework.common.pojo.CommonResult.success; @@ -47,7 +40,7 @@ private PowerNetFactorService powerNetFactorService; @Autowired - private PowerRunStateService powerRunStateService; + private PowerCapacitorStatusService powerCapacitorStatusService; @Autowired private PowerControlMainService powerControlMainService; @@ -55,24 +48,215 @@ @Autowired private PowerControlDetService powerControlDetService; + @Autowired + private PowerGenStatusDaoService powerGenStatusDaoService; + + @Resource + private DataPointApi dataPointApi; + + @Resource + private McsApi mcsApi; + @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); + } + 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) { + boolean cosFlag = false; + try { + 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()); + } + 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); + } + + /** + * 判断 curCos 是否超上下限 + * {nodeName}功率因数超上限/下限。 + * <p> + * 判断 curQ + * {nodeName}发生无功返送 + */ + @GetMapping("/net-factor/alarm") + @Operation(summary = "功率因数-电网拓扑预警信息") + public CommonResult<List<String>> getPowerNetFactorAlarm(@RequestParam Map<String, Object> params) { + List<String> result = new ArrayList<>(); + List<PowerNetFactorEntity> list = powerNetFactorService.list(params); + List<PowerNetFactorDTO> dtoList = ConvertUtils.sourceToTarget(list, PowerNetFactorDTO.class); + if (CollectionUtils.isEmpty(dtoList)) { + return success(result); + } + for (PowerNetFactorDTO dto : dtoList) { + 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)) { + continue; + } + + Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points); + 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() + "发生无功返送;"; + } + } + 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 (!message.isEmpty()) { + result.add(message); + } + } + 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") @Operation(summary = "功率因数-电容器投运状态") public CommonResult<List<PowerCapacitorStatusDTO>> getPowerCapacitorStatusList(@RequestParam Map<String, Object> params) { - List<PowerRunStateEntity> list = powerRunStateService.list(params); + List<PowerCapacitorStatusEntity> list = powerCapacitorStatusService.list(params); 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)); + } + + @PostMapping("/control-main/update") + @Operation(summary = "功率因数-管控变电站修改上下限") + public CommonResult<Boolean> updatePowerControlMain(@RequestBody 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) { - String name = (String)params.get("name"); + List<PowerControlDetDTO> result = new ArrayList<>(); + String name = (String) params.get("name"); if (StringUtils.isBlank(name)) { return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST); } @@ -81,6 +265,22 @@ return CommonResult.error(GlobalErrorCodeConstants.NOT_FOUND); } List<PowerControlDetEntity> list = powerControlDetService.list(main.getId()); - return success(ConvertUtils.sourceToTarget(list, PowerControlDetDTO.class)); + result = ConvertUtils.sourceToTarget(list, PowerControlDetDTO.class); + + result.forEach(item -> { + // 设置随机数据,0.8左右 + 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); } } \ No newline at end of file -- Gitblit v1.9.3