Explorar o código

各区间偏差率统计取数修改

王波 hai 2 meses
pai
achega
78bc22c948

+ 18 - 42
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/EarlyWarning/WindReportService.java

@@ -42,8 +42,6 @@ public class WindReportService {
     @Resource
     private IProEconEquipmentInfoDay5Service day5Service;
     @Resource
-    private IProEconFaultLiminatedefectsService proEconFaultLiminatedefectsService;
-    @Resource
     private IProEconBrownoutsEvent2Service event2Service;
 
     // 定义等级常量,便于维护
@@ -104,7 +102,8 @@ public class WindReportService {
         List<StationInfoDay> zhcyyearlist = stationInfoDayService.getyearList(time);
 
         List<ProEconCurveFittMonthMain> getqxlist = curveFittMonthMainService.getlist(year, month);
-        List<ProEconEquipmentInfoDay4> getpcllist = day4Service.getpcllist(time);
+        Map<String, Object> getpcllist = day4Service.getpcllist(time);
+        Map<String, Object>pcllist = day4Service.pcllist(time);
         List<ProEconInOrOutSpeedTotal> outSpeedtopTotals = proEconInOrOutSpeedTotalService.gettoplist(time);
         List<ProEconInOrOutSpeedTotal> outSpeedTotals = proEconInOrOutSpeedTotalService.getlist(time);
         List<ProEconWindturbineGoodness> getnhtop = goodnessService.gettop(time);
@@ -152,11 +151,6 @@ public class WindReportService {
                 ProEconCurveFittMonthMain::getWindturbineId,
                 ProEconCurveFittMonthMain::setWindturbineId);
 
-        // 分组 3: ProEconEquipmentInfoDay4 相关列表
-        applySetIdFromNemCode(wtls, Arrays.asList(getpcllist),
-                ProEconEquipmentInfoDay4::getWindturbineId,
-                ProEconEquipmentInfoDay4::setWindturbineId);
-
         // 分组 4: ProEconEquipmentInfoDay5 相关列表
         applySetIdFromNemCode(wtls, Arrays.asList(
                        threestateRateList, threesystateRateList, threestateRatebotList),
@@ -381,41 +375,23 @@ public class WindReportService {
                 "" + qxtopid[1] + "号风机:偏差率" + qxpcl[1] + "%,排名: 2\n" +
                 "" + qxtopid[2] + "号风机:偏差率" + qxpcl[2] + "%,排名: 3");
 
-        double pcl_35 = getpcllist.stream().mapToDouble(ProEconEquipmentInfoDay4::getR35mqxpcl).average().getAsDouble();
-        // 获取最小值对应的数据
-        Optional<ProEconEquipmentInfoDay4> min_35 = getpcllist.stream()
-                .min(Comparator.comparingDouble(ProEconEquipmentInfoDay4::getR35mqxpcl));
-        // 获取最大值对应的数据
-        Optional<ProEconEquipmentInfoDay4> max_35 = getpcllist.stream()
-                .max(Comparator.comparingDouble(ProEconEquipmentInfoDay4::getR35mqxpcl));
-
-        String min_35Id = min_35.map(ProEconEquipmentInfoDay4::getWindturbineId).orElse(null);
-        String max_35Id = max_35.map(ProEconEquipmentInfoDay4::getWindturbineId).orElse(null);
-
-
-        double pcl_511 = getpcllist.stream().mapToDouble(ProEconEquipmentInfoDay4::getR511mqxpcl).average().getAsDouble();
-        Optional<ProEconEquipmentInfoDay4> min_511 = getpcllist.stream()
-                .min(Comparator.comparingDouble(ProEconEquipmentInfoDay4::getR511mqxpcl));
-        // 获取最大值对应的数据
-        Optional<ProEconEquipmentInfoDay4> max_511 = getpcllist.stream()
-                .max(Comparator.comparingDouble(ProEconEquipmentInfoDay4::getR511mqxpcl));
-
-        String min_511Id = min_511.map(ProEconEquipmentInfoDay4::getWindturbineId).orElse(null);
-        String max_511Id = max_511.map(ProEconEquipmentInfoDay4::getWindturbineId).orElse(null);
-
-        double pcl_1125 = getpcllist.stream().mapToDouble(ProEconEquipmentInfoDay4::getR11mycqxpcl).average().getAsDouble();
-        Optional<ProEconEquipmentInfoDay4> min_1125 = getpcllist.stream()
-                .min(Comparator.comparingDouble(ProEconEquipmentInfoDay4::getR511mqxpcl));
-        // 获取最大值对应的数据
-        Optional<ProEconEquipmentInfoDay4> max_1125 = getpcllist.stream()
-                .max(Comparator.comparingDouble(ProEconEquipmentInfoDay4::getR511mqxpcl));
-
-        String min_1125Id = min_1125.map(ProEconEquipmentInfoDay4::getWindturbineId).orElse(null);
-        String max_1125Id = max_1125.map(ProEconEquipmentInfoDay4::getWindturbineId).orElse(null);
+       String min_35Id = pcllist.get("min_r35_nem_code").toString() !=null ? pcllist.get("min_r35_nem_code").toString() :"";
+       String max_35Id = pcllist.get("max_r35_nem_code").toString() !=null ? pcllist.get("max_r35_nem_code").toString() :"";
+
+       String min_511Id = pcllist.get("min_r511_nem_code").toString() !=null ? pcllist.get("min_r511_nem_code").toString() :"";
+       String max_511Id = pcllist.get("max_r511_nem_code").toString() !=null ? pcllist.get("max_r511_nem_code").toString() :"";
+
+       String min_1125Id = pcllist.get("min_r11_nem_code").toString() !=null ? pcllist.get("min_r11_nem_code").toString() :"";
+       String max_1125Id = pcllist.get("max_r11_nem_code").toString() !=null ? pcllist.get("max_r11_nem_code").toString() :"";
+
+        double avgR35mqxpcl = getpcllist.get("avg_r35mqxpcl") != null ? ((Number) getpcllist.get("avg_r35mqxpcl")).doubleValue() : 0.0;
+        double avgR511mqxpcl = getpcllist.get("avg_r511mqxpcl") != null ? ((Number) getpcllist.get("avg_r511mqxpcl")).doubleValue() : 0.0;
+        double avgR11mycqxpcl = getpcllist.get("avg_r11mycqxpcl") != null ? ((Number) getpcllist.get("avg_r11mycqxpcl")).doubleValue() : 0.0;
+
         map.put("各区间偏差率统计", "各区间偏差率统计:\n" +
-                "3-5m/s区间:平均偏差率" + StringUtils.round(pcl_35, 2) + "%,偏差率最大风机:" + max_35Id + "号,偏差率最小风机:" + min_35Id + "号\n" +
-                "5-11m/s区间:平均偏差率" + StringUtils.round(pcl_511, 2) + "%,偏差率最大风机:" + max_511Id + "号,偏差率最小风机:" + min_511Id + "号\n" +
-                "11-25m/s区间:平均偏差率" + StringUtils.round(pcl_1125, 2) + "%,偏差率最大风机:" + max_1125Id + "号,偏差率最小风机:" + min_1125Id + "号");
+                "3-5m/s区间:平均偏差率" + StringUtils.round(avgR35mqxpcl, 2) + "%,偏差率最大风机:" + max_35Id + "号,偏差率最小风机:" + min_35Id + "号\n" +
+                "5-11m/s区间:平均偏差率" + StringUtils.round(avgR511mqxpcl, 2) + "%,偏差率最大风机:" + max_511Id + "号,偏差率最小风机:" + min_511Id + "号\n" +
+                "11-25m/s区间:平均偏差率" + StringUtils.round(avgR11mycqxpcl, 2) + "%,偏差率最大风机:" + max_1125Id + "号,偏差率最小风机:" + min_1125Id + "号");
 
         String[] yqrtopid = new String[3];
         double[] yqrfs = new double[3];

+ 3 - 1
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/auto/IProEconEquipmentInfoDay4Service.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.gyee.runeconomy.model.auto.ProEconEquipmentInfoDay4;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -15,6 +16,7 @@ import java.util.List;
  */
 public interface IProEconEquipmentInfoDay4Service extends IService<ProEconEquipmentInfoDay4> {
 
-    List<ProEconEquipmentInfoDay4> getpcllist (String time);
+    Map<String, Object> getpcllist (String time);
+    Map<String, Object> pcllist (String time);
 
 }

+ 100 - 5
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/auto/impl/ProEconEquipmentInfoDay4ServiceImpl.java

@@ -1,14 +1,17 @@
 package com.gyee.runeconomy.service.auto.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.runeconomy.init.CacheContext;
 import com.gyee.runeconomy.mapper.auto.ProEconEquipmentInfoDay4Mapper;
+import com.gyee.runeconomy.model.auto.ProBasicEquipment;
 import com.gyee.runeconomy.model.auto.ProEconEquipmentInfoDay4;
 import com.gyee.runeconomy.service.auto.IProEconEquipmentInfoDay4Service;
 import org.springframework.stereotype.Service;
 
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -22,10 +25,102 @@ import java.util.List;
 public class ProEconEquipmentInfoDay4ServiceImpl extends ServiceImpl<ProEconEquipmentInfoDay4Mapper, ProEconEquipmentInfoDay4> implements IProEconEquipmentInfoDay4Service {
 
     @Override
-    public List<ProEconEquipmentInfoDay4> getpcllist(String time) {
+    public Map<String, Object> getpcllist(String time) {
         QueryWrapper<ProEconEquipmentInfoDay4> qw = new QueryWrapper<>();
         qw.eq("to_char(record_date,'yyyy-MM')", time);
-        List<ProEconEquipmentInfoDay4> infoDay4s = baseMapper.selectList(qw);
-        return infoDay4s;
+
+        // 1. 计算三个字段的平均值(使用聚合查询)
+        qw.select(
+                "AVG(r35mqxpcl) as avg_r35mqxpcl",
+                "AVG(r511mqxpcl) as avg_r511mqxpcl",
+                "AVG(r11mycqxpcl) as avg_r11mycqxpcl"
+        );
+        // 不需要groupBy,因为是整个时间段的聚合
+        Map<String, Object> avgMap = getBaseMapper().selectMaps(qw).get(0);  // 返回单条Map
+        return avgMap;
+    }
+
+    @Override
+    public Map<String, Object> pcllist(String time) {
+        List<ProBasicEquipment> wtls = CacheContext.wtls;
+
+        // 创建ID到nem_code的映射,方便快速查找
+        Map<String, String> idToNemCodeMap = wtls.stream()
+                .collect(Collectors.toMap(
+                        ProBasicEquipment::getId,
+                        ProBasicEquipment::getNemCode,
+                        (existing, replacement) -> existing // 如果有重复,取第一个
+                ));
+
+        // 1. 找出 r35mqxpcl 的最小记录,并获取nem_code
+        QueryWrapper<ProEconEquipmentInfoDay4> minQwR35 = Wrappers.query();
+        minQwR35.select("windturbine_id", "r35mqxpcl") // 只查询需要的字段
+                .eq("to_char(record_date,'yyyy-MM')", time)
+                .orderByAsc("r35mqxpcl")
+                .last("LIMIT 1");
+        ProEconEquipmentInfoDay4 minR35Record = getOne(minQwR35);
+        String minR35NemCode = minR35Record != null && idToNemCodeMap.containsKey(minR35Record.getWindturbineId())
+                ? idToNemCodeMap.get(minR35Record.getWindturbineId()) : null;
+
+        // 2. 找出 r35mqxpcl 的最大记录,并获取nem_code
+        QueryWrapper<ProEconEquipmentInfoDay4> maxQwR35 = Wrappers.query();
+        maxQwR35.select("windturbine_id", "r35mqxpcl")
+                .eq("to_char(record_date,'yyyy-MM')", time)
+                .orderByDesc("r35mqxpcl")
+                .last("LIMIT 1");
+        ProEconEquipmentInfoDay4 maxR35Record = getOne(maxQwR35);
+        String maxR35NemCode = maxR35Record != null && idToNemCodeMap.containsKey(maxR35Record.getWindturbineId())
+                ? idToNemCodeMap.get(maxR35Record.getWindturbineId()) : null;
+
+        // 3. r511mqxpcl 最小记录
+        QueryWrapper<ProEconEquipmentInfoDay4> minQwR511 = Wrappers.query();
+        minQwR511.select("windturbine_id", "r511mqxpcl")
+                .eq("to_char(record_date,'yyyy-MM')", time)
+                .orderByAsc("r511mqxpcl")
+                .last("LIMIT 1");
+        ProEconEquipmentInfoDay4 minR511Record = getOne(minQwR511);
+        String minR511NemCode = minR511Record != null && idToNemCodeMap.containsKey(minR511Record.getWindturbineId())
+                ? idToNemCodeMap.get(minR511Record.getWindturbineId()) : null;
+
+        // 4. r511mqxpcl 最大记录
+        QueryWrapper<ProEconEquipmentInfoDay4> maxQwR511 = Wrappers.query();
+        maxQwR511.select("windturbine_id", "r511mqxpcl")
+                .eq("to_char(record_date,'yyyy-MM')", time)
+                .orderByDesc("r511mqxpcl")
+                .last("LIMIT 1");
+        ProEconEquipmentInfoDay4 maxR511Record = getOne(maxQwR511);
+        String maxR511NemCode = maxR511Record != null && idToNemCodeMap.containsKey(maxR511Record.getWindturbineId())
+                ? idToNemCodeMap.get(maxR511Record.getWindturbineId()) : null;
+
+        // 5. r11mycqxpcl 最小记录
+        QueryWrapper<ProEconEquipmentInfoDay4> minQwR11 = Wrappers.query();
+        minQwR11.select("windturbine_id", "r11mycqxpcl")
+                .eq("to_char(record_date,'yyyy-MM')", time)
+                .orderByAsc("r11mycqxpcl")
+                .last("LIMIT 1");
+        ProEconEquipmentInfoDay4 minR11Record = getOne(minQwR11);
+        String minR11NemCode = minR11Record != null && idToNemCodeMap.containsKey(minR11Record.getWindturbineId())
+                ? idToNemCodeMap.get(minR11Record.getWindturbineId()) : null;
+
+        // 6. r11mycqxpcl 最大记录
+        QueryWrapper<ProEconEquipmentInfoDay4> maxQwR11 = Wrappers.query();
+        maxQwR11.select("windturbine_id", "r11mycqxpcl")
+                .eq("to_char(record_date,'yyyy-MM')", time)
+                .orderByDesc("r11mycqxpcl")
+                .last("LIMIT 1");
+        ProEconEquipmentInfoDay4 maxR11Record = getOne(maxQwR11);
+        String maxR11NemCode = maxR11Record != null && idToNemCodeMap.containsKey(maxR11Record.getWindturbineId())
+                ? idToNemCodeMap.get(maxR11Record.getWindturbineId()) : null;
+
+        // 可以根据需要构建不同的返回格式,这里示例返回所有nem_code
+        Map<String, Object> summary = new HashMap<>();
+        summary.put("min_r35_nem_code", minR35NemCode);
+        summary.put("max_r35_nem_code", maxR35NemCode);
+        summary.put("min_r511_nem_code", minR511NemCode);
+        summary.put("max_r511_nem_code", maxR511NemCode);
+        summary.put("min_r11_nem_code", minR11NemCode);
+        summary.put("max_r11_nem_code", maxR11NemCode);
+
+        return summary;
     }
 }