ansteel-biz/db/mysql.sql | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ansteel-biz/src/main/java/com/iailab/module/ansteel/common/utils/PowerUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ansteel-biz/src/main/java/com/iailab/module/ansteel/power/entity/PowerNetFactorEntity.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
ansteel-biz/db/mysql.sql
@@ -885,3 +885,13 @@ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='峰谷平累计计算配置'; CREATE INDEX `idx_occur_time` ON `t_power_maxdemand_main`(`occur_time`); ALTER TABLE `t_power_net_factor` ADD COLUMN `p_day` varchar(50) NULL DEFAULT NULL COMMENT '有功日累计'; ALTER TABLE `t_power_net_factor` ADD COLUMN `q_day` varchar(50) NULL DEFAULT NULL COMMENT '无功日累计'; ALTER TABLE `t_power_net_factor` ADD COLUMN `p_mon` varchar(50) NULL DEFAULT NULL COMMENT '有功月累计'; ALTER TABLE `t_power_net_factor` ADD COLUMN `q_mon` varchar(50) NULL DEFAULT NULL COMMENT '无功月累计'; ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java
@@ -11,6 +11,7 @@ import com.iailab.module.ansteel.api.vo.PowerCapacitorHisPageReqVO; import com.iailab.module.ansteel.api.vo.PowerMaxDemandMainPageReqVO; import com.iailab.module.ansteel.common.utils.DecimalUtil; import com.iailab.module.ansteel.common.utils.PowerUtil; import com.iailab.module.ansteel.power.entity.*; import com.iailab.module.ansteel.power.service.*; import com.iailab.module.data.api.point.DataPointApi; @@ -232,6 +233,32 @@ powerNetFactorDTO.setQstatus(1); } } // 日功率因数 if (entity.getPDay() != null && entity.getQDay() != null) { List<String> pointNos = new ArrayList<>(); pointNos.add(entity.getPDay()); pointNos.add(entity.getQDay()); Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(pointNos); if (!CollectionUtils.isEmpty(pointsRealValue)) { double pValue = new BigDecimal(pointsRealValue.get(entity.getPDay()).toString()).doubleValue(); double qValue = new BigDecimal(pointsRealValue.get(entity.getQDay()).toString()).doubleValue(); powerNetFactorDTO.setDayCos(new BigDecimal(PowerUtil.calculateCos(pValue, qValue)).setScale(2, BigDecimal.ROUND_HALF_UP)) ; } } // 月功率因数 if (entity.getPMon() != null && entity.getQMon() != null) { List<String> pointNos = new ArrayList<>(); pointNos.add(entity.getPMon()); pointNos.add(entity.getQMon()); Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(pointNos); if (!CollectionUtils.isEmpty(pointsRealValue)) { double pValue = new BigDecimal(pointsRealValue.get(entity.getPMon()).toString()).doubleValue(); double qValue = new BigDecimal(pointsRealValue.get(entity.getQMon()).toString()).doubleValue(); powerNetFactorDTO.setMonthCos(new BigDecimal(PowerUtil.calculateCos(pValue, qValue)).setScale(2, BigDecimal.ROUND_HALF_UP)) ; } } result.add(powerNetFactorDTO); } return success(result); ansteel-biz/src/main/java/com/iailab/module/ansteel/common/utils/PowerUtil.java
对比新文件 @@ -0,0 +1,32 @@ package com.iailab.module.ansteel.common.utils; import java.math.BigDecimal; /** * 电力工具类 * * @author PanZhibao * @Description * @createTime 2025年05月28日 */ public class PowerUtil { /** * 计算功率因数 p /(根号:p²+Q²) **/ public static Double calculateCos(double PValue, double QValue) { // 绝对值 PValue = Math.abs(PValue); QValue = Math.abs(QValue); //PValue或QValue 小于 1 直接判断为关闭返回0 if (QValue < 0.01) { return 0.0; } else { BigDecimal result = new BigDecimal(PValue).divide(BigDecimal.valueOf(Math.sqrt(Math.pow(PValue, 2) + Math.pow(QValue, 2))), 2, BigDecimal.ROUND_HALF_UP); if (result.compareTo(BigDecimal.ONE) >= 0) { return 0.99; } return result.doubleValue(); } } } ansteel-biz/src/main/java/com/iailab/module/ansteel/power/entity/PowerNetFactorEntity.java
@@ -121,4 +121,24 @@ * 功率因数上限 */ private BigDecimal cosLimitH; /** * 有功日累计 */ private String pDay; /** * 无功日累计 */ private String qDay; /** * 有功月累计 */ private String pMon; /** * 无功月累计 */ private String qMon; }