Quellcode durchsuchen

经济运行报告调整

王波 vor 2 Wochen
Ursprung
Commit
fbf7b24579

+ 78 - 186
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/EarlyWarning/ReportService.java

@@ -19,6 +19,7 @@ import java.time.YearMonth;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
@@ -60,197 +61,60 @@ public class ReportService {
 
         List<IndicatorData> result = new ArrayList<>();
 
-        double currentPower = turbineList.stream()
-                .mapToDouble(t -> t.getRfdl() == null ? 0 : Math.round(t.getRfdl().doubleValue() * 100.0) / 100.0)
-                .sum(); // 本月实际发电量
-        double lastYearPower = tqturbineList.stream()
-                .mapToDouble(t -> t.getRfdl() == null ? 0 : Math.round(t.getRfdl().doubleValue() * 100.0) / 100.0)
-                .sum(); // 去年同期实际发电量
 
-
-        double currentTheoryPower = turbineList.stream()
-                .mapToDouble(t -> t.getLlfdl() == null ? 0 : Math.round(t.getLlfdl().doubleValue() * 100.0) / 100.0)
-                .sum(); // 本月理论发电量
-        double lastYearTheoryPower = tqturbineList.stream()
-                .mapToDouble(t -> t.getLlfdl() == null ? 0 : Math.round(t.getLlfdl().doubleValue() * 100.0) / 100.0)
-                .sum(); // 去年同期理论发电量
-
-
-        double currentWindSpeed = new BigDecimal(
-                turbineList.stream()
-                        .mapToDouble(t -> t.getPjfs() == null ? 0 : t.getPjfs().doubleValue())
-                        .average()
-                        .orElse(0.0)
-        ).setScale(2, RoundingMode.HALF_UP)
-                .doubleValue();// 本月平均风速
-
-        double lastYearWindSpeed = new BigDecimal(
-                tqturbineList.stream()
-                        .mapToDouble(t -> t.getPjfs() == null ? 0 : t.getPjfs().doubleValue())
-                        .average()
-                        .orElse(0.0)
-        ).setScale(2, RoundingMode.HALF_UP)
-                .doubleValue(); // 去年同期平均风速
-
-
-        double currentUtilization = DoubleUtils.getRoundingNum(currentPower / sbrl, 0); // 本月利用小时
+        // 计算值
+        double currentPower = sumRounded(turbineList, t -> t.getRfdl());
+        double lastYearPower = sumRounded(tqturbineList, t -> t.getRfdl());
+        double currentTheoryPower = sumRounded(turbineList, t -> t.getLlfdl());
+        double lastYearTheoryPower = sumRounded(tqturbineList, t -> t.getLlfdl());
+        double currentWindSpeed = averageRounded(turbineList, t -> t.getPjfs());
+        double lastYearWindSpeed = averageRounded(tqturbineList, t -> t.getPjfs());
+        double currentUtilization = DoubleUtils.getRoundingNum(currentPower / sbrl, 0);
         double lastYearUtilization = DoubleUtils.getRoundingNum(lastYearPower / sbrl, 0);
-        ; // 去年同期利用小时
-
-        //计划运行时间
         int jhyxsj = daysInMonth * 24;
         int tqjhyxsj = qnInMonth * 24;
-
-        //运行时间
-        double yxsj = turbineList.stream()
-                .mapToDouble(t -> t.getYxMin() == null ? 0 : Math.round(t.getYxMin().doubleValue() * 100.0) / 100.0)
-                .sum();
-        double tqyxsj = tqturbineList.stream()
-                .mapToDouble(t -> t.getYxMin() == null ? 0 : Math.round(t.getYxMin().doubleValue() * 100.0) / 100.0)
-                .sum();
-
-        // 计算本月设备可利用率
-        double currentEquipmentUtilization = yxsj / jhyxsj * 100;
-        // 格式化保留两位小数
-        currentEquipmentUtilization = Double.parseDouble(String.format("%.2f", currentEquipmentUtilization));
-
-        // 计算去年同期设备可利用率
-        double lastYearEquipmentUtilization = tqyxsj / tqjhyxsj * 100;
-        // 格式化保留两位小数
-        lastYearEquipmentUtilization = Double.parseDouble(String.format("%.2f", lastYearEquipmentUtilization));
-
-        //检修时间
-        double jxsj = turbineList.stream()
-                .mapToDouble(t -> t.getYxMin() == null ? 0 : Math.round(t.getYxMin().doubleValue() * 100.0) / 100.0)
-                .sum();
-        double tqjxsj = tqturbineList.stream()
-                .mapToDouble(t -> t.getYxMin() == null ? 0 : Math.round(t.getYxMin().doubleValue() * 100.0) / 100.0)
-                .sum();
-
+        double yxsj = sumRounded(turbineList, t -> t.getYxMin());
+        double tqyxsj = sumRounded(tqturbineList, t -> t.getYxMin());
+        double currentEquipmentUtilization = (yxsj / jhyxsj * 100);
+        currentEquipmentUtilization = new BigDecimal(currentEquipmentUtilization).setScale(2, RoundingMode.HALF_UP).doubleValue();
+        double lastYearEquipmentUtilization = (tqyxsj / tqjhyxsj * 100);
+        lastYearEquipmentUtilization = new BigDecimal(lastYearEquipmentUtilization).setScale(2, RoundingMode.HALF_UP).doubleValue();
+        double jxsj = sumRounded(turbineList, t -> t.getJxMin()); // 假设正确字段
+        double tqjxsj = sumRounded(tqturbineList, t -> t.getJxMin());
         double currentEfficiencyCoefficient = (yxsj + jxsj) / jhyxsj * 100;
-        currentEfficiencyCoefficient = Double.parseDouble(String.format("%.2f", currentEfficiencyCoefficient));
-        // 本月等效可用系数
-        double lastYearEfficiencyCoefficient = (tqyxsj + tqjxsj) / tqjhyxsj * 100; // 去年同期等效可用系数
-        lastYearEfficiencyCoefficient = Double.parseDouble(String.format("%.2f", lastYearEfficiencyCoefficient));
-
-
-        double currentSmallWindSpeed = new BigDecimal(
-                turbineList.stream()
-                        .mapToDouble(t -> t.getXfqrfs() == null ? 0 : t.getXfqrfs().doubleValue())
-                        .average()
-                        .orElse(0.0)
-        ).setScale(2, RoundingMode.HALF_UP)
-                .doubleValue(); // 本月小风切入风速
-        double lastYearSmallWindSpeed = new BigDecimal(
-                tqturbineList.stream()
-                        .mapToDouble(t -> t.getXfqrfs() == null ? 0 : t.getXfqrfs().doubleValue())
-                        .average()
-                        .orElse(0.0)
-        ).setScale(2, RoundingMode.HALF_UP)
-                .doubleValue(); // 去年同期小风切入风速
-
-//        double currentSmallWindRate = 0.95; // 本月小风切入合格率
-//        double lastYearSmallWindRate = 0.93; // 去年同期小风切入合格率
-
-        double currentRunningWindHours = turbineList.stream()
-                .mapToDouble(t -> t.getYxfss() == null ? 0 : Math.round(t.getYxfss().doubleValue() * 100.0) / 100.0)
-                .sum(); // 本月有效风时数
-        double lastYearRunningWindHours = tqturbineList.stream()
-                .mapToDouble(t -> t.getYxfss() == null ? 0 : Math.round(t.getYxfss().doubleValue() * 100.0) / 100.0)
-                .sum(); // 去年同期有效风时数
-
-        double currentFaultLossPower = turbineList.stream()
-                .mapToDouble(t -> t.getGzss() == null ? 0 : Math.round(t.getGzss().doubleValue() * 100.0) / 100.0)
-                .sum(); // 本月故障损失电量
-        double lastYearFaultLossPower = tqturbineList.stream()
-                .mapToDouble(t -> t.getGzss() == null ? 0 : Math.round(t.getGzss().doubleValue() * 100.0) / 100.0)
-                .sum(); // 去年同期故障损失电量
-
-
-        double currentDispatchLossPower = turbineList.stream()
-                .mapToDouble(t -> t.getXdss() == null ? 0 : new BigDecimal(t.getXdss().doubleValue())
-                        .setScale(2, BigDecimal.ROUND_HALF_UP) // 保留两位小数并四舍五入
-                        .doubleValue())
-                .sum();
-        currentDispatchLossPower = new BigDecimal(currentDispatchLossPower)
-                .setScale(2, BigDecimal.ROUND_HALF_UP) // 确保最后的结果保留两位小数
-                .doubleValue();// 本月调度限电损失电量
-
-
-        double lastYearDispatchLossPower = tqturbineList.stream()
-                .mapToDouble(t -> t.getXdss() == null ? 0 : new BigDecimal(t.getXdss().doubleValue())
-                        .setScale(2, BigDecimal.ROUND_HALF_UP) // 保留两位小数并四舍五入
-                        .doubleValue())
-                .sum();
-        lastYearDispatchLossPower = new BigDecimal(lastYearDispatchLossPower)
-                .setScale(2, BigDecimal.ROUND_HALF_UP) // 确保最后的结果保留两位小数
-                .doubleValue();// 去年同期调度限电损失电量
-
-
-        double currentPlannedMaintenanceLossPower = turbineList.stream()
-                .mapToDouble(t -> t.getJhjxss() == null ? 0 : Math.round(t.getJhjxss().doubleValue() * 100.0) / 100.0)
-                .sum(); // 本月计划检修损失电量
-        double lastYearPlannedMaintenanceLossPower = tqturbineList.stream()
-                .mapToDouble(t -> t.getJhjxss() == null ? 0 : Math.round(t.getJhjxss().doubleValue() * 100.0) / 100.0)
-                .sum(); // 去年同期计划检修损失电量
-
-        double currentPerformanceLossPower = turbineList.stream()
-                .mapToDouble(t -> t.getXnss() == null ? 0 : new BigDecimal(t.getXnss().doubleValue())
-                        .setScale(2, BigDecimal.ROUND_HALF_UP) // 保留两位小数并四舍五入
-                        .doubleValue())
-                .sum(); // 本月性能未达标损失电量
-        currentPerformanceLossPower = new BigDecimal(currentPerformanceLossPower)
-                .setScale(2, BigDecimal.ROUND_HALF_UP) // 确保最后的结果保留两位小数
-                .doubleValue();
-
-
-        double lastYearPerformanceLossPower = tqturbineList.stream()
-                .mapToDouble(t -> t.getXnss() == null ? 0 : new BigDecimal(t.getXnss().doubleValue())
-                        .setScale(2, BigDecimal.ROUND_HALF_UP) // 保留两位小数并四舍五入
-                        .doubleValue())
-                .sum(); // 去年同期性能未达标损失电量
-        lastYearPerformanceLossPower = new BigDecimal(lastYearPerformanceLossPower)
-                .setScale(2, BigDecimal.ROUND_HALF_UP)
-                .doubleValue();
-
-
-        double currentFaultDowntime = turbineList.stream()
-                .mapToDouble(t -> t.getGzMin() == null ? 0 : Math.round(t.getGzMin().doubleValue() * 100.0) / 100.0)
-                .sum(); // 本月故障停运时间
-        double lastYearFaultDowntime = tqturbineList.stream()
-                .mapToDouble(t -> t.getGzMin() == null ? 0 : Math.round(t.getGzMin().doubleValue() * 100.0) / 100.0)
-                .sum(); // 去年同期故障停运时间
-
-        double currentMaintenanceDowntime = jxsj; // 本月检修停运时间
-        double lastYearMaintenanceDowntime = tqjxsj; // 去年同期检修停运时间
-
-        double currentGridConnectionTime = turbineList.stream()
-                .mapToDouble(t -> t.getYxMin() == null ? 0 : Math.round(t.getYxMin().doubleValue() * 100.0) / 100.0)
-                .sum(); // 本月并网时间
-        double lastYearGridConnectionTime = tqturbineList.stream()
-                .mapToDouble(t -> t.getYxMin() == null ? 0 : Math.round(t.getYxMin().doubleValue() * 100.0) / 100.0)
-                .sum(); // 去年同期并网时间
-
-        double currentStandbyTime = turbineList.stream()
-                .mapToDouble(t -> t.getDjMin() == null ? 0 : Math.round(t.getDjMin().doubleValue() * 100.0) / 100.0)
-                .sum(); // 本月待机时间
-        double lastYearStandbyTime = tqturbineList.stream()
-                .mapToDouble(t -> t.getDjMin() == null ? 0 : Math.round(t.getDjMin().doubleValue() * 100.0) / 100.0)
-                .sum(); // 去年同期待机时间
-
-        double currentCommFailureTime = turbineList.stream()
-                .mapToDouble(t -> t.getTjMin() == null ? 0 : Math.round(t.getTjMin().doubleValue() * 100.0) / 100.0)
-                .sum(); // 本月通讯中断时间
-        double lastYearCommFailureTime = tqturbineList.stream()
-                .mapToDouble(t -> t.getTjMin() == null ? 0 : Math.round(t.getTjMin().doubleValue() * 100.0) / 100.0)
-                .sum(); // 去年同期通讯中断时间
-
-        double currentCalmWindFrequency = turbineList.stream()
-                .mapToDouble(t -> t.getJfpl() == null ? 0 : Math.round(t.getJfpl().doubleValue() * 100.0) / 100.0)
-                .sum(); // 本月静风频率
-        double lastYearCalmWindFrequency = tqturbineList.stream()
-                .mapToDouble(t -> t.getJfpl() == null ? 0 : Math.round(t.getJfpl().doubleValue() * 100.0) / 100.0)
-                .sum(); // 去年同期静风频率
+        currentEfficiencyCoefficient = new BigDecimal(currentEfficiencyCoefficient).setScale(2, RoundingMode.HALF_UP).doubleValue();
+        double lastYearEfficiencyCoefficient = (tqyxsj + tqjxsj) / tqjhyxsj * 100;
+        lastYearEfficiencyCoefficient = new BigDecimal(lastYearEfficiencyCoefficient).setScale(2, RoundingMode.HALF_UP).doubleValue();
+        double currentSmallWindSpeed = averageRounded(turbineList, t -> t.getXfqrfs());
+        double lastYearSmallWindSpeed = averageRounded(tqturbineList, t -> t.getXfqrfs());
+        double currentRunningWindHours = sumRounded(turbineList, t -> t.getYxfss());
+        double lastYearRunningWindHours = sumRounded(tqturbineList, t -> t.getYxfss());
+        double currentFaultLossPower = sumRounded(turbineList, t -> t.getGzss());
+        double lastYearFaultLossPower = sumRounded(tqturbineList, t -> t.getGzss());
+        double currentDispatchLossPower = sumRounded(turbineList, t -> t.getXdss());
+        currentDispatchLossPower = new BigDecimal(currentDispatchLossPower).setScale(2, RoundingMode.HALF_UP).doubleValue();
+        double lastYearDispatchLossPower = sumRounded(tqturbineList, t -> t.getXdss());
+        lastYearDispatchLossPower = new BigDecimal(lastYearDispatchLossPower).setScale(2, RoundingMode.HALF_UP).doubleValue();
+        double currentPlannedMaintenanceLossPower = sumRounded(turbineList, t -> t.getJhjxss());
+        currentPlannedMaintenanceLossPower = new BigDecimal(currentPlannedMaintenanceLossPower).setScale(2, RoundingMode.HALF_UP).doubleValue();
+        double lastYearPlannedMaintenanceLossPower = sumRounded(tqturbineList, t -> t.getJhjxss());
+        lastYearPlannedMaintenanceLossPower = new BigDecimal(lastYearPlannedMaintenanceLossPower).setScale(2, RoundingMode.HALF_UP).doubleValue();
+        double currentPerformanceLossPower = sumRounded(turbineList, t -> t.getXnss());
+        currentPerformanceLossPower = new BigDecimal(currentPerformanceLossPower).setScale(2, RoundingMode.HALF_UP).doubleValue();
+        double lastYearPerformanceLossPower = sumRounded(tqturbineList, t -> t.getXnss());
+        lastYearPerformanceLossPower = new BigDecimal(lastYearPerformanceLossPower).setScale(2, RoundingMode.HALF_UP).doubleValue();
+        double currentFaultDowntime = sumRounded(turbineList, t -> t.getGzMin());
+        double lastYearFaultDowntime = sumRounded(tqturbineList, t -> t.getGzMin());
+        double currentMaintenanceDowntime = jxsj;
+        double lastYearMaintenanceDowntime = tqjxsj;
+        double currentGridConnectionTime = yxsj;
+        double lastYearGridConnectionTime = tqyxsj;
+        double currentStandbyTime = sumRounded(turbineList, t -> t.getDjMin());
+        double lastYearStandbyTime = sumRounded(tqturbineList, t -> t.getDjMin());
+        double currentCommFailureTime = sumRounded(turbineList, t -> t.getTjMin());
+        double lastYearCommFailureTime = sumRounded(tqturbineList, t -> t.getTjMin());
+        double currentCalmWindFrequency = sumRounded(turbineList, t -> t.getJfpl());
+        double lastYearCalmWindFrequency = sumRounded(tqturbineList, t -> t.getJfpl());
 
         // 使用方法来简化添加数据
         result.add(createIndicatorData("实际发电量", currentPower, lastYearPower));
@@ -312,4 +176,32 @@ public class ReportService {
                 df.format(calculateGrowthRate(currentValue, lastYearValue))
         );
     }
+
+    // 定义辅助方法
+    private double sumRounded(List<TurbineInfoDay> list, Function<TurbineInfoDay, Double> getter) {
+        BigDecimal sum = BigDecimal.ZERO;
+        for (TurbineInfoDay t : list) {
+            Double value = getter.apply(t);
+            BigDecimal bdValue = value == null ? BigDecimal.ZERO : new BigDecimal(value).setScale(2, RoundingMode.HALF_UP);
+            sum = sum.add(bdValue);
+        }
+        return sum.doubleValue();
+    }
+
+    private double averageRounded(List<TurbineInfoDay> list, Function<TurbineInfoDay, Double> getter) {
+        if (list.isEmpty()) {
+            return 0.0;
+        }
+        BigDecimal total = BigDecimal.ZERO;
+        int count = 0;
+        for (TurbineInfoDay t : list) {
+            Double value = getter.apply(t);
+            if (value != null) {
+                total = total.add(new BigDecimal(value));
+                count++;
+            }
+        }
+        BigDecimal avg = total.divide(new BigDecimal(count), 2, RoundingMode.HALF_UP);
+        return avg.doubleValue();
+    }
 }