Bladeren bron

预警报告修改

王波 3 weken geleden
bovenliggende
commit
f002b1969a

+ 1 - 1
runeconomy-xk/src/main/java/com/gyee/runeconomy/controller/EarlyWarning/EarlyWarningController.java

@@ -54,7 +54,7 @@ public class EarlyWarningController {
             @ApiImplicitParam(name = "wpid", value = "场站", required = true, dataType = "string", paramType = "query")})
     public JSONObject getreportinformation(String time, String wpid) throws Exception {
 
-        Map<String, String> map = new HashMap<>();
+        Map<String, Object> map = new HashMap<>();
         if (!time.isEmpty()) {
             map = earlyWarninggetService.Electricity(time, wpid);
         }

+ 79 - 258
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/EarlyWarning/EarlyWarninggetService.java

@@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
@@ -30,298 +31,118 @@ public class EarlyWarninggetService {
     private ProEconIssPlanService proEconIssPlanService;
 
     public Map Electricity(String time, String wpid) throws Exception {
-
         Map<String, Object> map = new HashMap<>();
 
+        // 只取第一个电站
+        ProBasicPowerstation proBasicPowerstation = powerstationService.selectwpid(wpid)
+                .stream().findFirst().orElse(null);
 
-        List<ProBasicPowerstation> selectwpid = powerstationService.selectwpid(wpid);
-        ProBasicPowerstation proBasicPowerstation = null;
-        if (selectwpid.size() > 0) {
-            proBasicPowerstation = selectwpid.get(0);
-        }
         List<ReliabilityIssues> iskkx = reliabilityIssuesService.getReliabilityIssues(wpid, time);
 
-        /*************************************************************筛选结果***********************************************/
+        /*********************** 提前分组,避免 O(n²) ************************/
+        Map<String, List<ReliabilityIssues>> issuesByTurbine = iskkx.stream()
+                .collect(Collectors.groupingBy(ReliabilityIssues::getTurbineId));
 
-        // 筛选 reliabilityIssue 字段为 "是",并且 reliabilityIs 字段为 1 的记录
-        String wdl = iskkx.stream()
-                .filter(issue -> "是".equals(issue.getReliabilityIssue()) && issue.getReliabilityIs() == 1)
-                .sorted(Comparator.comparing(ReliabilityIssues::getTurbineId))  // 根据 turbineId 排序
-                .map(ReliabilityIssues::getTurbineId)
-                .collect(Collectors.joining(","));
+        /*********************** 提前建缓存 Map,避免重复查 DB ************************/
+        Map<String, ProBasicEquipment> equipmentMap = CacheContext.wtls.stream()
+                .collect(Collectors.toMap(ProBasicEquipment::getAname, e -> e, (a, b) -> a));
 
-        // 筛选 reliabilityIssue 字段为 "是",并且 reliabilityIs 字段为 2 的记录
-        String ztl = iskkx.stream()
-                .filter(issue -> "是".equals(issue.getReliabilityIssue()) && issue.getReliabilityIs() == 2)
-                .sorted(Comparator.comparing(ReliabilityIssues::getTurbineId))  // 根据 turbineId 排序
-                .map(ReliabilityIssues::getTurbineId)
-                .collect(Collectors.joining(","));
+        Map<String, List<ProEconAlarmRule>> ruleCache = new HashMap<>();
+        Map<String, List<ProEconAlarmReal>> realCache = new HashMap<>();
+        Map<String, List<ProEconIssPlan>> planCache = new HashMap<>();
 
-        // 筛选 reliabilityIssue 字段为 "是",并且 reliabilityIs 字段为 3 的记录
-        String ztwdl = iskkx.stream()
-                .filter(issue -> "是".equals(issue.getReliabilityIssue()) && issue.getReliabilityIs() == 3)
-                .sorted(Comparator.comparing(ReliabilityIssues::getTurbineId))  // 根据 turbineId 排序
-                .map(ReliabilityIssues::getTurbineId)
-                .collect(Collectors.joining(","));
+        // 辅助方法,封装检修建议查询
+        Function<String, String> getProcessMethod = (typeAndModelId) -> {
+            String[] arr = typeAndModelId.split("#");
+            String type = arr[0];
+            String modelId = arr[1];
 
+            List<ProEconAlarmRule> ruleList = ruleCache.computeIfAbsent(typeAndModelId,
+                    k -> ruleService.getProEconAlarmRuleList(type, modelId));
 
-        // 拼接相关字段,检查每个字段是否为空,并加入结果中
-        StringBuilder sxjgBuilder = new StringBuilder();
+            if (ruleList.isEmpty()) return null;
 
+            String ruleId = ruleList.get(0).getId();
+            List<ProEconAlarmReal> reals = realCache.computeIfAbsent(ruleId, realService::getProEconAlarmReal);
+            if (reals.isEmpty()) return null;
 
-        if (wdl != null && !wdl.isEmpty()) {
-            sxjgBuilder.append("以下风机存在温度类隐患:").append(wdl).append("\n");
-        }
-        if (ztl != null && !ztl.isEmpty()) {
-            sxjgBuilder.append("以下风机存在状态类隐患:").append(ztl).append("\n");
-        }
-        if (ztwdl != null && !ztwdl.isEmpty()) {
-            sxjgBuilder.append("以下风机存在状态类及温度类隐患:").append(ztwdl).append("\n");
-        }
-
-        //不去掉换行符
-        String sxjg = sxjgBuilder.toString();
-        if (sxjg.endsWith("\n")) {
-            sxjg = sxjg.substring(0, sxjg.length() - 1);  // 去掉最后一个换行符
-        }
-        //去掉换行符
-//        String sxjg = sxjgBuilder.toString().trim();
+            String alarmPlan = reals.get(0).getAlarmPlan();
+            List<ProEconIssPlan> plans = planCache.computeIfAbsent(alarmPlan,
+                    proEconIssPlanService::selectAlarmPlanByProId);
 
-        /*************************************************************筛选结果***********************************************/
+            return plans.isEmpty() ? null : plans.get(0).getProcessMethod();
+        };
 
-        Map<String,List> jxjymap = new TreeMap<>();
-        Map<String, List> finalReport = new TreeMap<>();
-
-        for (ReliabilityIssues vo : iskkx) {
-            List<ReliabilityIssues> collect = iskkx.stream().filter(v -> vo.getTurbineId().equals(v.getTurbineId())).collect(Collectors.toList());
-            StringBuilder kkxBuilder = new StringBuilder();
-            List<String> qksm = new ArrayList<>();
-            List<String> jxjyls = new ArrayList<>();
+        /*********************** 构造筛选结果 ************************/
+        String wdl = iskkx.stream()
+                .filter(i -> "是".equals(i.getReliabilityIssue()) && i.getReliabilityIs() == 1)
+                .map(ReliabilityIssues::getTurbineId).sorted().collect(Collectors.joining(","));
 
-            List<ProBasicEquipment> equipments = CacheContext.wtls.stream()
-                    .filter(wt -> vo.getTurbineId().equals(wt.getAname())).collect(Collectors.toList());
-            String modelId = equipments.get(0).getModelId();
+        String ztl = iskkx.stream()
+                .filter(i -> "是".equals(i.getReliabilityIssue()) && i.getReliabilityIs() == 2)
+                .map(ReliabilityIssues::getTurbineId).sorted().collect(Collectors.joining(","));
 
-            /*******************************************************添加检修建议*************************************************/
-            if (collect.size() > 0) {
-                if (collect.get(0).getMainShaftType() != null && !collect.get(0).getMainShaftType().equals("无")){
-                    kkxBuilder.append(collect.get(0).getMainShaftType()).append(",");
-                    String mainShaftType = collect.get(0).getMainShaftType();
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(mainShaftType,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add(mainShaftType + ":" + plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
+        String ztwdl = iskkx.stream()
+                .filter(i -> "是".equals(i.getReliabilityIssue()) && i.getReliabilityIs() == 3)
+                .map(ReliabilityIssues::getTurbineId).sorted().collect(Collectors.joining(","));
 
-                }
-                if (collect.get(0).getGeneratorType() != null && !collect.get(0).getGeneratorType().equals("无")){
-                    kkxBuilder.append(collect.get(0).getGeneratorType()).append(",");
-                    String generatorType = collect.get(0).getGeneratorType();
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(generatorType,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add( generatorType + ":" + plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
+        StringBuilder sxjgBuilder = new StringBuilder();
+        if (!wdl.isEmpty()) sxjgBuilder.append("以下风机存在温度类隐患:").append(wdl).append("\n");
+        if (!ztl.isEmpty()) sxjgBuilder.append("以下风机存在状态类隐患:").append(ztl).append("\n");
+        if (!ztwdl.isEmpty()) sxjgBuilder.append("以下风机存在状态类及温度类隐患:").append(ztwdl).append("\n");
+        String sxjg = sxjgBuilder.toString().replaceAll("\n$", "");
 
-                }
-                if (collect.get(0).getGearboxType() !=null && !collect.get(0).getGearboxType().equals("无")){
-                    kkxBuilder.append(collect.get(0).getGearboxType()).append(",");
-                    String gearboxType = collect.get(0).getGearboxType();
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(gearboxType,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add(gearboxType + ":" + plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
-                }
-                if (collect.get(0).getPitchSystemType() !=null && !collect.get(0).getPitchSystemType().equals("无")){
-                    kkxBuilder.append(collect.get(0).getPitchSystemType()).append(",");
-                    String pitchSystemType = collect.get(0).getPitchSystemType();
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(pitchSystemType,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add(pitchSystemType + ":" + plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
-                }
-                if (collect.get(0).getTemperatureOtherIssues() !=null && !collect.get(0).getTemperatureOtherIssues().equals("无")) {
-                    kkxBuilder.append(collect.get(0).getTemperatureOtherIssues()).append(",");
+        /*********************** 遍历 turbineId,生成检修建议 ************************/
+        Map<String, List> jxjymap = new TreeMap<>();
+        Map<String, List> finalReport = new TreeMap<>();
 
-                    String temperatureOtherIssues = collect.get(0).getTemperatureOtherIssues();
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(temperatureOtherIssues,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add(temperatureOtherIssues + ":" + plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
-                }
-                if (collect.get(0).getVibrationType() !=null && !collect.get(0).getVibrationType().equals("无")){
-                    kkxBuilder.append(collect.get(0).getVibrationType()).append(",");
-                    String vibrationType = collect.get(0).getVibrationType();
+        for (Map.Entry<String, List<ReliabilityIssues>> entry : issuesByTurbine.entrySet()) {
+            String turbineId = entry.getKey();
+            List<ReliabilityIssues> collect = entry.getValue();
 
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(vibrationType,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add(vibrationType + ":" + plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
-                }
-                if (collect.get(0).getMechanicalType() !=null && !collect.get(0).getMechanicalType().equals("无")){
-                    kkxBuilder.append(collect.get(0).getMechanicalType()).append(",");
-                    String mechanicalType = collect.get(0).getMechanicalType();
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(mechanicalType,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add(mechanicalType + ":" + plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
-                }
-                if (collect.get(0).getElectricalType() !=null  && !collect.get(0).getElectricalType().equals("无")){
-                    kkxBuilder.append(collect.get(0).getElectricalType()).append(",");
-                    String electricalType = collect.get(0).getElectricalType();
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(electricalType,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add(electricalType + ":" + plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
-                }
-                if (collect.get(0).getHydraulicType() !=null && !collect.get(0).getHydraulicType().equals("无")){
-                    kkxBuilder.append(collect.get(0).getHydraulicType()).append(",");
-                    String hydraulicType = collect.get(0).getHydraulicType();
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(hydraulicType,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add(hydraulicType + ":" + plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
-                }
-                if (collect.get(0).getWindMeasurementType() !=null && !collect.get(0).getWindMeasurementType().equals("无")){
-                    kkxBuilder.append(collect.get(0).getWindMeasurementType()).append(",");
-                    String windMeasurementType = collect.get(0).getWindMeasurementType();
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(windMeasurementType,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add(windMeasurementType + ":" + plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
-                }
-                if (collect.get(0).getOtherIssues() !=null && !collect.get(0).getOtherIssues().equals("无")){
-                    kkxBuilder.append(collect.get(0).getOtherIssues()).append(",");
-                    String otherIssues = collect.get(0).getOtherIssues();
-                    List<ProEconAlarmRule> ruleList = ruleService.getProEconAlarmRuleList(otherIssues,modelId);
-                    if (ruleList.size() > 0) {
-                        String id = ruleList.get(0).getId();
-                        List<ProEconAlarmReal> realid = realService.getProEconAlarmReal(id);
-                        if (realid.size() > 0){
-                            String alarmPlan = realid.get(0).getAlarmPlan();
-                            List<ProEconIssPlan> plans = proEconIssPlanService.selectAlarmPlanByProId(alarmPlan);
-                            if (plans.size() > 0){
-                                jxjyls.add(otherIssues + ":"+ plans.get(0).getProcessMethod());
-                            }
-                        }
-                    }
-                }
-            }
-            /*******************************************************添加检修建议*************************************************/
+            ProBasicEquipment equipment = equipmentMap.get(turbineId);
+            String modelId = (equipment != null) ? equipment.getModelId() : null;
 
+            List<String> qksm = new ArrayList<>();
+            List<String> jxjyls = new ArrayList<>();
+            StringBuilder kkxBuilder = new StringBuilder();
 
-            String issue = "0";
-            Integer issis = null;
-            if (collect.size() > 0) {
-                issue = collect.get(0).getReliabilityIssue();
-                issis = collect.get(0).getReliabilityIs();
-                if (Objects.isNull(issis)) {
-                    issis = 3; // 如果为空则赋值为3
+            ReliabilityIssues first = collect.get(0);
+            // 遍历所有类型字段
+            List<String> types = Arrays.asList(
+                    first.getMainShaftType(), first.getGeneratorType(), first.getGearboxType(),
+                    first.getPitchSystemType(), first.getTemperatureOtherIssues(), first.getVibrationType(),
+                    first.getMechanicalType(), first.getElectricalType(), first.getHydraulicType(),
+                    first.getWindMeasurementType(), first.getOtherIssues()
+            );
+
+            for (String type : types) {
+                if (type != null && !"无".equals(type) && modelId != null) {
+                    kkxBuilder.append(type).append(",");
+                    String method = getProcessMethod.apply(type + "#" + modelId);
+                    if (method != null) jxjyls.add(type + ":" + method);
                 }
             }
 
-            if (kkxBuilder.length() > 0 && issue.equals("是")) {
+            if (kkxBuilder.length() > 0 && "是".equals(first.getReliabilityIssue())) {
                 kkxBuilder.insert(0, "可靠性问题:");
-                kkxBuilder.deleteCharAt(kkxBuilder.length() - 1);
-                kkxBuilder.append("。"); // 添加句号,删除最后一个字符
-                String kkxresult = kkxBuilder.toString();
-                qksm.add(kkxresult);
-            }
-
-            if (qksm.size() > 0) {
-                finalReport.put(vo.getTurbineId(), qksm);
+                kkxBuilder.deleteCharAt(kkxBuilder.length() - 1).append("。");
+                qksm.add(kkxBuilder.toString());
             }
 
-            if (jxjyls.size() > 0) {
-                jxjymap.put(vo.getTurbineId(), jxjyls);
-            }
+            if (!qksm.isEmpty()) finalReport.put(turbineId, qksm);
+            if (!jxjyls.isEmpty()) jxjymap.put(turbineId, jxjyls);
         }
 
+        /*********************** 返回结果 ************************/
+        iskkx.sort(Comparator.comparing(ReliabilityIssues::getTurbineId));
         map.put("stationid", proBasicPowerstation);
         map.put("reporttime", time);
-        iskkx.sort(Comparator.comparing(ReliabilityIssues::getTurbineId));
         map.put("kkxwtls", iskkx);
         map.put("FilterResults", sxjg);
-        map.put("qksm",finalReport);
-        map.put("jxjy",jxjymap);
+        map.put("qksm", finalReport);
+        map.put("jxjy", jxjymap);
+
         return map;
     }
 }

+ 0 - 3
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/impl/ProEconIssPlanServiceImpl.java

@@ -1,14 +1,11 @@
 package com.gyee.runeconomy.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gyee.runeconomy.model.ProEconAlarmPlan;
 import com.gyee.runeconomy.model.ProEconIssPlan;
 import com.gyee.runeconomy.mapper.ProEconIssPlanMapper;
 import com.gyee.runeconomy.service.ProEconIssPlanService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
-
-import java.util.Collections;
 import java.util.List;
 
 /**