Przeglądaj źródła

场站属性获取3

xushili 7 miesięcy temu
rodzic
commit
93cdf7dfe5

+ 155 - 12
ruoyi-admin/src/main/java/com/ruoyi/web/controller/JavaFunctionJobHandler.java

@@ -143,6 +143,12 @@ public class JavaFunctionJobHandler extends IJobHandler {
         return list;
     }
 
+    public StationInfoMin getStationinfoByMinOne(Date date, String stId) {
+        QueryWrapper<StationInfoMin> wrapper = new QueryWrapper<>();
+        wrapper.eq("record_date", date).eq("station_id", stId);
+        return stationInfoMinService.getOne(wrapper, false);
+    }
+
 
     public StationInfoDay getStationinfoByDate(Date date, String stId) {
         QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
@@ -3190,7 +3196,6 @@ public class JavaFunctionJobHandler extends IJobHandler {
     //此处加公式
 
     public Map<String, Double> calcRealtimeTurbineZt(String stId) {
-
         List<PointInfo> turbineZt = calcRealtimeTurbineDizt();
         List<PointInfo> turbineAizt = calcRealtimeTurbineAizt();
         turbineZt.addAll(turbineAizt);
@@ -3202,6 +3207,47 @@ public class JavaFunctionJobHandler extends IJobHandler {
         return collect;
     }
 
+    public void calcStationMinZtts(Date time, String stId) {
+        Map<Double, Long> map = calcSectionStationZtts(time, stId);
+        StationInfoMin byMin = getStationinfoByMinOne(time, stId);
+        //0 待机
+        //1 运行
+        //2 故障
+        //3 检修
+        //4 限电
+        //5 受累
+        //6 离线
+        byMin.setDjts(map.get(0));
+        byMin.setYxts(map.get(1));
+        byMin.setGzts(map.get(2));
+        byMin.setJxts(map.get(3));
+        stationInfoMinService.saveOrUpdate(byMin);
+    }
+
+    public Map<Double, Long> calcSectionStationZtts(Date time, String stId) {
+        Map<Double, Long> diztTs = calcSectionStationDiztTs(time, stId);
+        Map<Double, Long> aiztTs = calcSectionStationAiztTs(time, stId);
+        if (diztTs.isEmpty()) {
+            return aiztTs;
+        } else if (aiztTs.isEmpty()) {
+            return diztTs;
+        } else if (diztTs.size() > aiztTs.size()) {
+            diztTs.forEach((k, v) -> {
+                long l = aiztTs.getOrDefault(k, 0L);
+                if (v == null) v = 0L;
+                v = v + l;
+            });
+            return diztTs;
+        } else {
+            aiztTs.forEach((k, v) -> {
+                long l = diztTs.getOrDefault(k, 0L);
+                if (v == null) v = 0L;
+                v = v + l;
+            });
+            return aiztTs;
+        }
+    }
+
     // 计算每种状态的总持续时间
     public void calcTurbineStateMin(Date date) {
         //date当天零点
@@ -3258,7 +3304,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
     public void getRawDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end) {
         for (PointInfo info : entity) {
             List<PointData> snap = adapter.getHistoryRaw(uri, info.getPointKey(), start.getTime(), end.getTime());
-//            ThreadUtil.sleep(5);
+            //            ThreadUtil.sleep(5);
             info.setPointDatas(snap);
         }
     }
@@ -3400,6 +3446,103 @@ public class JavaFunctionJobHandler extends IJobHandler {
         return result;
     }
 
+    public Map<Double, Long> calcSectionStationDiztTs(Date time, String stId) {
+        List<PointInfo> entity = new ArrayList<>();
+        List<PointInfo> result = new ArrayList<>();
+        List<PointInfo> entity0 = getEntity("MX000", "state");
+        List<PointInfo> entity1 = getEntity("MX001", "state");
+        List<PointInfo> entity2 = getEntity("MX002", "state");
+        List<PointInfo> entity4 = getEntity("MX004", "state");
+        List<PointInfo> entity6 = getEntity("MX006", "state");
+        entity.addAll(entity0);
+        entity.addAll(entity1);
+        entity.addAll(entity2);
+        entity.addAll(entity4);
+        entity.addAll(entity6);
+        entity = entity.stream().filter(pi -> stId.equals(pi.getStationId())).collect(Collectors.toList());
+        if (CollUtil.isEmpty(entity)) return new HashMap<>();
+        String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
+        Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), keys, time.getTime());
+
+        Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
+        wtUcPis.forEach((wtId, map) -> {
+            PointInfo info2 = map.get("MX002");
+            PointData data2 = latest.get(info2.getPointKey());
+            if (data2.getValue() == 1.0) {
+                data2.setDoubleValue(2.0);
+                data2.setBooleanValue(false);
+                info2.setPointDatas(Collections.singletonList(data2));
+                result.add(info2);
+            } else {
+                PointInfo info0 = map.get("MX000");
+                PointData data0 = latest.get(info0.getPointKey());
+                if (data0.getValue() == 1.0) {
+                    data0.setDoubleValue(0.0);
+                    data0.setBooleanValue(false);
+                    info0.setPointDatas(Collections.singletonList(data0));
+                    result.add(info0);
+                } else {
+                    PointInfo info6 = map.get("MX006");
+                    PointData data6 = latest.get(info6.getPointKey());
+                    if (data6.getValue() == 1.0) {
+                        data6.setDoubleValue(6.0);
+                        data6.setBooleanValue(false);
+                        info6.setPointDatas(Collections.singletonList(data6));
+                        result.add(info6);
+                    } else {
+                        PointInfo info4 = map.get("MX004");
+                        PointData data4 = latest.get(info4.getPointKey());
+                        if (data4.getValue() == 1.0) {
+                            data4.setDoubleValue(4.0);
+                            data4.setBooleanValue(false);
+                            info4.setPointDatas(Collections.singletonList(data4));
+                            result.add(info4);
+                        } else {
+                            PointInfo info1 = map.get("MX001");
+                            PointData data1 = latest.get(info1.getPointKey());
+                            if (data1.getValue() == 1.0) {
+                                data1.setDoubleValue(1.0);
+                                data1.setBooleanValue(false);
+                                info1.setPointDatas(Collections.singletonList(data1));
+                                result.add(info1);
+                            } else {
+                                data1.setDoubleValue(2.0);
+                                System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
+                                info1.setPointDatas(Collections.singletonList(data1));
+                                result.add(info1);
+                            }
+                        }
+                    }
+                }
+            }
+        });
+        Map<Double, Long> longMap = result.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
+        return longMap;
+    }
+
+    public Map<Double, Long> calcSectionStationAiztTs(Date time, String stId) {
+        List<PointInfo> entityAiZt = getEntity("AI422", "state");
+        entityAiZt = entityAiZt.stream().filter(pi -> stId.equals(pi.getStationId())).collect(Collectors.toList());
+        if (CollUtil.isEmpty(entityAiZt)) return new HashMap<>();
+        List<StateAi> list = stateAiService.list();
+        //机型,源状态,目标状态
+        Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
+        String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
+        Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), collect, time.getTime());
+        for (PointInfo info : entityAiZt) {
+            PointData data = latest.get(info.getPointKey());
+            Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
+            if (m == null) {
+                m = 2;
+                System.out.println("ai状态未配对:" + data.getValue());
+            }
+            data.setDoubleValue(m);
+            info.setPointDatas(Collections.singletonList(data));
+        }
+        Map<Double, Long> longMap = entityAiZt.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
+        return longMap;
+    }
+
     public List<PointInfo> calcRealtimeTurbineAizt() {
         List<PointInfo> entityAiZt = getEntity("AI422", "state");
         List<StateAi> list = stateAiService.list();
@@ -4110,26 +4253,26 @@ public class JavaFunctionJobHandler extends IJobHandler {
 
         for (StationInfoMin day : byDate) {
             String id = day.getStationId();
-//            if (day.getPjfs() == null || day.getPjfs() == 0) {
+            //            if (day.getPjfs() == null || day.getPjfs() == 0) {
             List<PointInfo> fsInfos = fssMap.get(id);
             double pjfs = fsInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
             day.setPjfs(pjfs);
-//            }
-//            if (day.getPjgl() == null || day.getPjgl() == 0) {
+            //            }
+            //            if (day.getPjgl() == null || day.getPjgl() == 0) {
             PointInfo cxInfo = statMapCx.get(id);
             double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
             cxgl = cxgl * cxInfo.getCoef();
 
             if (cxgl < 0 && pjfs > 3) cxgl = nihe(pjfs);
             day.setPjgl(cxgl);
-//            }
-//            if (day.getAgc() == null || day.getAgc() == 0) {
+            //            }
+            //            if (day.getAgc() == null || day.getAgc() == 0) {
             PointInfo agcInfo = mapAgc.get(id);
             double agc = agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef();
             if (agc < cxgl) agc = cxgl;
             day.setAgc(agc);
-//            }
-//            if (day.getRfdl() == null || day.getRfdl() == 0) {
+            //            }
+            //            if (day.getRfdl() == null || day.getRfdl() == 0) {
             List<PointInfo> fdlInfos = fdlsMap.get(id);
             double rfdl = fdlInfos.stream().mapToDouble(pi -> {
                 double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
@@ -4139,12 +4282,12 @@ public class JavaFunctionJobHandler extends IJobHandler {
             }).sum();
             if (rfdl < 660 && cxgl > 0) rfdl = cxgl / 4.0;
             day.setRfdl(rfdl);
-//            }
-//            if (day.getHjwd() == null || day.getHjwd() == 0) {
+            //            }
+            //            if (day.getHjwd() == null || day.getHjwd() == 0) {
             List<PointInfo> hjwdInfos = hjwdsMap.get(id);
             double hjwd = hjwdInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
             day.setHjwd(hjwd);
-//            }
+            //            }
         }
         stationInfoMinService.saveOrUpdateBatch(byDate);
     }

+ 25 - 0
universal-computing-platform/src/main/java/com/ruoyi/ucp/entity/StationInfoMin.java

@@ -46,6 +46,31 @@ public class StationInfoMin implements Serializable {
     private Double rfdl;
 
     private Double hjwd;
+    //待机,运行,故障,检修
+    private Long djts;
+    private Long yxts;
+    private Long gzts;
+    private Long jxts;
+
+    public void setDjts(Long djts) {
+        if (djts == null) djts = 0L;
+        this.djts = djts;
+    }
+
+    public void setYxts(Long yxts) {
+        if (yxts == null) yxts = 0L;
+        this.yxts = yxts;
+    }
+
+    public void setGzts(Long gzts) {
+        if (gzts == null) gzts = 0L;
+        this.gzts = gzts;
+    }
+
+    public void setJxts(Long jxts) {
+        if (jxts == null) jxts = 0L;
+        this.jxts = jxts;
+    }
 
     public void setPjfs(Double pjfs) {
         if (pjfs == null || pjfs < 0) pjfs = 0.0;

+ 10 - 0
universal-computing-platform/src/main/java/com/ruoyi/ucp/service/impl/StationInfoMinServiceImpl.java

@@ -39,4 +39,14 @@ public class StationInfoMinServiceImpl extends ServiceImpl<StationInfoMinMapper,
     public List<StationInfoMin> list(Wrapper<StationInfoMin> queryWrapper) {
         return super.list(queryWrapper);
     }
+
+    @Override
+    public StationInfoMin getOne(Wrapper<StationInfoMin> queryWrapper) {
+        return super.getOne(queryWrapper);
+    }
+
+    @Override
+    public StationInfoMin getOne(Wrapper<StationInfoMin> queryWrapper, boolean throwEx) {
+        return super.getOne(queryWrapper, throwEx);
+    }
 }