浏览代码

Merge branch 'master' of http://124.70.43.205:3000/xushili/calc-hub

xushili 9 月之前
父节点
当前提交
200d9de3e7

+ 169 - 17
ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java

@@ -361,9 +361,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
         lineInfoDayService.saveOrUpdateBatch(lineInfos);
     }
 
-    public void calcLineSwGWCyDlSameDay(Date time) {
+    public void calcLineSwGWCyDlSameDay() {
         //date当天零点
-        DateTime time0 = DateUtil.beginOfDay(time);
+        DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
 
         List<StationInfoDay> stationInfos = getStationinfoByDate(time0);
         Map<String, StationInfoDay> stationMap = stationInfos.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
@@ -418,9 +418,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
         stationInfoDayService.saveOrUpdateBatch(byDate);
     }
 
-    public void calcStationZhcyRfDlSameDay(Date time) {
+    public void calcStationZhcyRfDlSameDay() {
         //date当天零点
-        DateTime time0 = DateUtil.beginOfDay(time);
+        DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
 
         QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
         wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
@@ -493,9 +493,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
         stationInfoDayService.saveOrUpdateBatch(byDate);
     }
 
-    public void calcStationSwGwCyDlSameDay(Date time) {
+    public void calcStationSwGwCyDlSameDay() {
         //date当天零点
-        DateTime time0 = DateUtil.beginOfDay(time);
+        DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
 
         List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
         List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
@@ -665,9 +665,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
     }
 
 
-    public void calcLineRfdlSameDay(Date time) {
+    public void calcLineRfdlSameDay() {
         //date当天零点
-        DateTime time0 = DateUtil.beginOfDay(time);
+        DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
 
         List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
         entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
@@ -2009,9 +2009,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
 
     }
 
-    public void writeReportPoolSameDay(Date time) {
+    public void writeReportPoolSameDay() {
         //date当天零点
-        DateTime time0 = DateUtil.beginOfDay(time);
+        DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
         DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
         DateTime beginOfYear = DateUtil.beginOfYear(time0);
 
@@ -2031,6 +2031,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
         QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
         wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
         List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperRp);
+        wrapperRp = new QueryWrapper<>();
+        wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
+        ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
 
         StationInfoDay day, month, year;
         if (pools.isEmpty()) {
@@ -2056,6 +2059,16 @@ public class JavaFunctionJobHandler extends IJobHandler {
             }
         }
         reportIndicatorPoolService.saveOrUpdateBatch(pools);
+        if (poolsCompany == null) {
+            poolsCompany = new ProEconReportIndicatorPool();
+            poolsCompany.setRecordDate(time0);
+            poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
+            poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
+            poolSetValueDl(poolsCompany, pools);
+        } else {
+            poolSetValueDl(poolsCompany, pools);
+        }
+        reportIndicatorPoolService.saveOrUpdate(poolsCompany);
     }
 
     public void poolSetValueDl1(ProEconReportIndicatorPool pool, StationInfoDay day, StationInfoDay month, StationInfoDay year) {
@@ -2094,6 +2107,25 @@ public class JavaFunctionJobHandler extends IJobHandler {
         pool.setNzhcydldb(year.getRfdl().doubleValue() + year.getGwdl() - year.getSwdl());
     }
 
+    public void poolSetValueDl(ProEconReportIndicatorPool pool, List<ProEconReportIndicatorPool> pools) {
+        ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
+        pool.setRfdldb(p.getRfdldb());
+        pool.setRswdldb(p.getRswdldb());
+        pool.setRgwgwdldb(p.getRgwgwdldb());
+        pool.setRfdcydldb(p.getRfdcydldb());
+        pool.setRzhcydldb(p.getRzhcydldb());
+        pool.setYfdldb(p.getYfdldb());
+        pool.setYswdldb(p.getYswdldb());
+        pool.setYgwgwdldb(p.getYgwgwdldb());
+        pool.setYfdcydldb(p.getYfdcydldb());
+        pool.setYzhcydldb(p.getYzhcydldb());
+        pool.setNfdldb(p.getNfdldb());
+        pool.setNswdldb(p.getNswdldb());
+        pool.setNgwgwdldb(p.getNgwgwdldb());
+        pool.setNfdcydldb(p.getNfdcydldb());
+        pool.setNzhcydldb(p.getNzhcydldb());
+    }
+
     public void writeReportPoolProject(Date date) {
         //date当天零点
         DateTime time = DateUtil.beginOfDay(date);
@@ -2165,9 +2197,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
         }
     }
 
-    public void writeReportPoolProjectSameDay(Date time) {
+    public void writeReportPoolProjectSameDay() {
         //date当天零点
-        DateTime time0 = DateUtil.beginOfDay(time);
+        DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
         DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
         DateTime beginOfYear = DateUtil.beginOfYear(time0);
 
@@ -2455,9 +2487,17 @@ public class JavaFunctionJobHandler extends IJobHandler {
 
     }
 
-
     public void calcRealtimeTurbineZt() {
-        DateTime date = DateUtil.date();
+        DateTime date0 = DateUtil.date();
+        boolean isOnMin = false;
+        //分钟变化
+        if (CalcCache.minuteNow.minute() != date0.minute()) {
+            date0 = DateUtil.beginOfMinute(date0);
+            CalcCache.minuteNow = date0;
+            isOnMin = true;
+        }
+        DateTime date = date0;
+
         List<PointInfo> turbineZt = calcRealtimeTurbineDizt();
         List<PointInfo> turbineAizt = calcRealtimeTurbineAizt();
         turbineZt.addAll(turbineAizt);
@@ -2542,15 +2582,110 @@ public class JavaFunctionJobHandler extends IJobHandler {
         Map<String, String> entityMxzt = getEntityMap("MXZT", "turbine");
         List<PointData> dataList = turbineZt.stream().map(zt -> {
             PointData data = zt.getPointDatas().get(0);
-            data.setTs(DateUtil.date().getTime());
+            data.setTs(date.getTime());
             data.setTagName(entityMxzt.get(zt.getTurbineId()));
             return data;
         }).collect(Collectors.toList());
-        adapter.writeHistoryBatch(taosUri(), dataList);
-        ThreadUtil.sleep(1000);
+        if (isOnMin) {
+            adapter.writeHistoryBatch(taosUri(), dataList);
+        } else {
+            List<PointData> collect = dataList.stream().filter(d -> {
+                if (Objects.equals(CalcCache.statusCache.get(d.getTagName()), d.getValue())) {
+                    return false;
+                } else {
+                    CalcCache.statusCache.put(d.getTagName(), d.getValue());
+                    return true;
+                }
+            }).collect(Collectors.toList());
+            adapter.writeHistoryBatch(taosUri(), collect);
+        }
     }
     //此处加公式
 
+    // 计算每种状态的总持续时间
+    public void calcTurbineStateMin(Date date) {
+        //date当天零点
+        DateTime time = DateUtil.beginOfDay(date);
+        //date昨天零点
+        DateTime time0 = DateUtil.offsetDay(time, -1);
+
+        List<PointInfo> entityMxzt = getEntity("MXZT", "turbine");
+        getRawDataByEntity(entityMxzt, taosUri(), time0, time);
+
+        Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entityMxzt);
+
+        for (PointInfo info : entityMxzt) {
+            TurbineInfoDay infoDay = byDate.get(info.getTurbineId());
+            Map<Double, Long> durations = calculateStateDurations(info.getPointDatas());
+            infoDay.setDjMin(durations.getOrDefault(0.0, 0L) / 60000.0);
+            infoDay.setTjMin(durations.getOrDefault(1.0, 0L) / 60000.0);
+            infoDay.setYxMin(durations.getOrDefault(2.0, 0L) / 60000.0);
+            infoDay.setGzMin(durations.getOrDefault(4.0, 0L) / 60000.0);
+            infoDay.setJxMin(durations.getOrDefault(6.0, 0L) / 60000.0);
+            infoDay.setXdMin(durations.getOrDefault(8.0, 0L) / 60000.0);
+            infoDay.setLxMin(durations.getOrDefault(12.0, 0L) / 60000.0);
+        }
+        turbineInfoDayService.saveOrUpdateBatch(byDate.values());
+    }
+
+    public Map<Double, Long> calculateStateDurations(List<PointData> datas) {
+        if (CollUtil.isEmpty(datas)) return Collections.emptyMap();
+
+        Map<Double, Long> durations = new HashMap<>();
+        double prevState = datas.get(0).getValue(); // 初始状态
+        long prevTs = datas.get(0).getTs(); // 初始时间戳
+
+        PointData current;
+        double currentState;
+        long currentTs;
+        for (int i = 1; i < datas.size(); i++) {
+            current = datas.get(i);
+            currentState = current.getValue();
+            currentTs = current.getTs();
+
+            if (currentState != prevState) {
+                // 当状态变化时,计算前一个状态的持续时间并更新map
+                durations.put(prevState, durations.getOrDefault(prevState, 0L) + (currentTs - prevTs));
+                prevState = currentState;
+                prevTs = currentTs;
+            }
+        }
+        // 不要忘记计算列表中最后一个状态的持续时间(如果列表没有以状态变化结束)
+        durations.put(prevState, durations.getOrDefault(prevState, 0L) + (datas.get(datas.size() - 1).getTs() - prevTs));
+        return durations;
+    }
+
+    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);
+            info.setPointDatas(snap);
+        }
+    }
+
+    // 主函数或测试方法(如果需要)
+    public static void main(String[] args) {
+        Double b = 2.0;
+        double c = 2.0;
+        System.out.println(b == c);
+        Double d = Double.valueOf(c);
+        System.out.println(Objects.equals(b, c));
+        System.out.println(Objects.equals(d, b));
+        System.out.println(Objects.equals(null, null));
+
+
+        List<PointData> points = new ArrayList<>();
+        points.add(new PointData(1000, 1));
+        points.add(new PointData(1500, 2));
+        points.add(new PointData(2000, 1));
+        points.add(new PointData(2500, 3));
+
+//        Map<Integer, Long> durations = calculateStateDurations(points);
+//        for (Map.Entry<Integer, Long> entry : durations.entrySet()) {
+//            System.out.println("State " + entry.getKey() + ": " + entry.getValue() + "ms");
+//        }
+    }
+
     public List<PointInfo> getLatest(String uniformCode, String institutionType) {
         List<PointInfo> entity = getEntity(uniformCode, institutionType);
         String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
@@ -3025,6 +3160,23 @@ public class JavaFunctionJobHandler extends IJobHandler {
         if (b == null) b = 0.0;
         return a + b;
     }
+
+    public double calcQfzt(double ssgl, double zsgl) {
+        double qfzt, ratioll;
+        ratioll = zsgl != 0 ? (zsgl - ssgl) / zsgl : 0;
+        if (ratioll < 0.05) {
+            qfzt = 0;
+        } else if (ratioll < 0.1) {
+            qfzt = 1;
+        } else if (ratioll < 0.2) {
+            qfzt = 2;
+        } else if (ratioll < 0.4) {
+            qfzt = 3;
+        } else {
+            qfzt = 4;
+        }
+        return qfzt;
+    }
 }
 
 

+ 21 - 10
ruoyi-admin/src/test/java/com/ruoyi/NewTests.java

@@ -32,13 +32,14 @@ public class NewTests {
 
     @Test
     public void test() {
-        Date date = DateUtil.date().toJdkDate();
+        Date date = DateUtil.date();
+        task.calcTurbineStateMin(date);
 //        calcStationZhcydl(date);
 //        calcNhglZs(date);
         // 创建日期范围生成器
-        DateTime start = DateUtil.parse("2024-01-02");
+        DateTime start = DateUtil.parse("2024-07-02");
 //        DateTime start = DateUtil.parse("2024-05-01");
-        DateTime end = DateUtil.parse("2024-07-15");
+        DateTime end = DateUtil.parse("2024-07-18");
         DateRange range = DateUtil.range(start, end, DateField.DAY_OF_YEAR);
         for (DateTime time : range) {
             date = time.toJdkDate();
@@ -51,17 +52,27 @@ public class NewTests {
             task.calcLineSwGWCyDl(date);
             task.writeReportPool(date);
             task.writeReportPoolProject(date);*/
+//            task.calcLineSwGWCyDl(date,"GJNY_SXGS_XZ_FDC_STA");
+//            task.writeReportPoolProject(date);
 //            //计算综合厂用电量
 //            task.calcStationZhcydl(date);
 //
-            task.calcTurbineRFDL(date);
+            /*task.calcTurbineRFDL(date);
             task.calcStationRfdlFj(date);
             task.calcTurbine5s2(date);
-            task.writeReportPool5SPjfsLlfdl(date);
+            task.writeReportPool5SPjfsLlfdl(date);*/
 
 //            task.writeReportPool(date);
 //            int test = task.test(date, "zuozhuang.610825F02Y0AFA10GS009DQ0251DG02RAW00", 1320);
 //            System.out.println(test);
+
+
+            /*task.calcLineRfdlSameDay();
+            task.calcStationSwGwCyDlSameDay();
+            task.calcStationZhcyRfDlSameDay();
+            task.calcLineSwGWCyDlSameDay();
+            task.writeReportPoolSameDay();
+            task.writeReportPoolProjectSameDay();*/
         }
 //        task.calcGlqxnh(start,end);
 //        calcTurbineRFDL(date);
@@ -69,10 +80,10 @@ public class NewTests {
 //        writeReportPool(date);
 
 //        task.calcStationSspjfs();
-//        while (true) {
-//            task.calcRealtimeTurbineZt();
-//            ThreadUtil.sleep(1000);
-//        }
+        /*while (true) {
+            task.calcRealtimeTurbineZt();
+            ThreadUtil.sleep(1000);
+        }*/
     }
 
     @Test
@@ -87,7 +98,7 @@ public class NewTests {
 //            task.calcStationSwGwCyRdl(date,"GJNY_SXGS_JSL_FDC_STA");
 //            task.calcStationZhcyRfDl(date,"GJNY_SXGS_JSL_FDC_STA");
 //            task.calcLineSwGWCyDl(date,"GJNY_SXGS_JSL_FDC_STA");
-            task.writeReportPool(date);
+//            task.writeReportPool(date);
             task.writeReportPoolProject(date);
         }
     }

+ 7 - 1
universal-computing-platform/src/main/java/com/ruoyi/ucp/entity/TurbineInfoDay.java

@@ -42,5 +42,11 @@ public class TurbineInfoDay implements Serializable {
     private Double hjwd;
     private Double djss;
     private Double gzss;
-
+    private Double djMin;
+    private Double tjMin;
+    private Double yxMin;
+    private Double gzMin;
+    private Double jxMin;
+    private Double xdMin;
+    private Double lxMin;
 }

+ 4 - 0
universal-computing-platform/src/main/java/com/ruoyi/ucp/util/CalcCache.java

@@ -1,5 +1,7 @@
 package com.ruoyi.ucp.util;
 
+import cn.hutool.core.date.DateTime;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeMap;
@@ -17,4 +19,6 @@ public class CalcCache {
      * 保证功率
      */
     public static Map<String, ConcurrentHashMap<Double, Double>> bzgl = new ConcurrentHashMap<>();
+    public static DateTime minuteNow = DateTime.now();
+    public static Map<String, Double> statusCache = new ConcurrentHashMap<>();
 }