GYEE преди 6 месеца
родител
ревизия
b56ddf9a81

+ 7 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/PredictController.java

@@ -249,7 +249,9 @@ public class PredictController {
         tbPis.forEach((tbId,pis)->{
             GlycSj glycSj = new GlycSj();
             for (PointInfo info : pis) {
-                double v1 = latest.get(info.getPointKey()).getValue();
+                PointData data = latest.get(info.getPointKey());
+                Double v1 = 0.0;
+                if(data!=null) v1=data.getValue();
                 try {
                     switch (info.getUniformCode()) {
                         case "AI114":
@@ -444,11 +446,13 @@ public class PredictController {
             }
             List<RealtimePredict> rpList = new ArrayList<>();
             List<HistoryPredict> hpList = new ArrayList<>();
+            List<String> ids=new ArrayList<>();
             data.forEach((tbId,glycsjs)->{
                 PointInfo info = tbInfos.get(tbId);
                 for (GlycSj2 glycsj : glycsjs) {
                     RealtimePredict rp = new RealtimePredict();
                     rp.setId(tbId+glycsj.getTime());
+                    ids.add(rp.getId());
                     rp.setModelId("1");
                     rp.setPredictType("CDQ");
                     rp.setDeviceType("turbine");
@@ -475,7 +479,8 @@ public class PredictController {
                     hpList.add(hp);
                 }
             });
-            realtimePredictService.saveOrUpdateBatch(rpList);
+            realtimePredictService.removeBatchByIds(ids);
+            realtimePredictService.saveBatch(rpList);
             historyPredictService.saveBatch(hpList);
         } catch (Exception e) {
             e.printStackTrace();

+ 235 - 14
ruoyi-admin/src/test/java/com/ruoyi/GetDataTest.java

@@ -4,19 +4,28 @@ import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.text.csv.CsvUtil;
 import cn.hutool.core.text.csv.CsvWriter;
+import cn.hutool.core.thread.ExecutorBuilder;
+import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.CharsetUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.ruoyi.ucp.entity.*;
 import com.ruoyi.ucp.feign.AdapterApi;
 import com.ruoyi.ucp.service.*;
+import com.ruoyi.web.controller.JavaFunctionJobHandler;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import javax.annotation.Resource;
 import java.net.URI;
 import java.util.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.stream.Collectors;
 
 @SpringBootTest
 @RunWith(SpringRunner.class)
@@ -26,22 +35,232 @@ public class GetDataTest {
     private IPointInfoService pointInfoService;
     @Resource
     private AdapterApi adapterApi;
+    @Resource
+    private JavaFunctionJobHandler task;
 
     @Test
     public void test() {
-        DateTime start = DateUtil.parse("2023-06-01");
-        DateTime end = DateUtil.parse("2024-10-14");
-        start = DateUtil.offsetMonth(end, -30);
-
-        String[] names = {"AI004", "AI005", "AI006", "AI007", "AI008", "AI009", "AI073", "AI037", "AI039", "AI038", "AI047", "AI048", "AI056", "AI057", "AI060", "DI022", "AI066", "AI067", "AI069", "AI072", "AI074", "DI025", "DI080", "AI082", "AI084", "AI083", "AI065"};
+        DateTime start = DateUtil.parse("2023-03-20");
+        DateTime end = DateUtil.parse("2024-10-16");
+//        DateTime start = DateUtil.offsetMonth(end, -30);
+//        String[] names = {"AI004", "AI005", "AI006", "AI007", "AI008", "AI009", "AI073", "AI037", "AI039", "AI038", "AI047", "AI048", "AI056", "AI057", "AI060", "DI022", "AI066", "AI067", "AI069", "AI072", "AI074", "DI025", "DI080", "AI082", "AI084", "AI083", "AI065","AI114"};
+        String[] names = {"AI114", "AI066", "AI060", "AI067", "AI082", "AI073", "AI004", "AI047", "AI072", "AI074"};
+//        String[] names = {"AI067"};
         QueryWrapper<PointInfo> wrapper = new QueryWrapper<>();
         wrapper.lambda().eq(PointInfo::getInstitutionType, "turbine")
-//                .eq(PointInfo::getStationId,"GJNY_SXGS_LJS_FDC_STA")
-                .eq(PointInfo::getTurbineId, "GJNY_SXGS_LJS_F_WT_0011_EQ")
+//                .eq(PointInfo::getTurbineId, "GJNY_SXGS_LJS_F_WT_0011_EQ")
                 .in(PointInfo::getUniformCode, names);
         List<PointInfo> list = pointInfoService.list(wrapper);
+//        String a = "GJNY_SXGS_ZZ_F_WT_0005_EQGJNY_SXGS_ZZ_F_WT_0028_EQGJNY_SXGS_ZZ_F_WT_0022_EQGJNY_SXGS_ZZ_F_WT_0045_EQGJNY_SXGS_ZZ_F_WT_0038_EQGJNY_SXGS_ZZ_F_WT_0035_EQGJNY_SXGS_ZZ_F_WT_0050_EQGJNY_SXGS_ZZ_F_WT_0019_EQGJNY_SXGS_ZZ_F_WT_0012_EQGJNY_SXGS_ZZ_F_WT_0002_EQGJNY_SXGS_ZZ_F_WT_0031_EQ";
+//        String a = "GJNY_SXGS_FSG_FDC_STA";
+        String a = "GJNY_SXGS_FSG_F_WT_0022_EQ\n" +
+                "GJNY_SXGS_FSG_F_WT_0064_EQ\n";
+//        list=list.stream().filter(pi->a.equals(pi.getStationId())).collect(Collectors.toList());
+        list=list.stream().filter(pi->a.contains(pi.getTurbineId())).collect(Collectors.toList());
+//        list = list.stream().filter(pi -> "GJNY_SXGS_LJS_F_WT_0007_EQ".equals(pi.getTurbineId())).collect(Collectors.toList());
+        Map<String, Map<String, List<PointInfo>>> collect = list.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.groupingBy(PointInfo::getTurbineId)));
+
+        ExecutorService executor = ExecutorBuilder.create()
+                .setCorePoolSize(3)
+                .setMaxPoolSize(3)
+                .build();
+        Vector<Future<String>> fts = new Vector<>();
+        Vector<Future<String>> ftfs = new Vector<>();
+        collect.forEach((stId, tbPiMap) -> {
+            tbPiMap.forEach((tbId, Pis) -> {
+                Future<String> future = executor.submit(() -> {
+                    List<PointData> zt = task.calcTurbineSimpleZt(start, end, 60 * 5, tbId);
+                    Map<String, GlycSj> map = new TreeMap<>();
+                    for (PointInfo info : Pis) {
+                        try {
+                            long j = start.getTime();
+                            List<PointData> s = adapterApi.getHistorySnap(URI.create("http://172.16.12.103:8017/ts"), info.getPointKey(),
+                                    j, end.getTime(), 60 * 5);
+                            String dt = null;
+                            GlycSj glycSj = null;
+                            //AI066	风速,AI060	发电机转速,AI065	风机状态点,AI067	风向,AI082	桨叶1角度,AI073	机舱方向/对风角度
+                            //AI004	U1绕组温度,AI047	电机温度2,AI072	环境温度,AI074	机舱温度
+                            if(s==null||s.isEmpty()){
+                                System.out.println(tbId+","+info.getUniformCode());
+                            }
+                            switch (info.getUniformCode()) {
+                                case "AI114":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setGl(s.get(i).getValue());
+
+                                        glycSj.setZt(zt.get(i)==null?null:zt.get(i).getValue());
+//                                        glycSj.setActualTime(DateUtil.formatDateTime(DateUtil.date(zt.get(i)==null?0L:zt.get(i).getTs())));
+                                        j += 60 * 1000 * 5;//GJNY_SXGS_LJS_F_WT_
+//                                    glycSj.setTurbineId(info.getTurbineId().replaceFirst("GJNY_SXGS_","").replaceFirst("F_WT_","").replaceFirst("_EQ",""));
+                                        glycSj.setTurbineId(info.getTurbineId().replaceFirst("GJNY_SXGS_.+_F_WT_", "").replaceFirst("_EQ", ""));
+                                    }
+                                    break;
+                                case "AI066":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setFs(s.get(i).getValue());
+                                        j += 60 * 1000 * 5;
+                                    }
+                                    break;
+                                case "AI060":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setFdjzs(s.get(i).getValue());
+                                        j += 60 * 1000 * 5;
+                                    }
+                                    break;
+                                case "AI065":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setZt(s.get(i).getValue());
+                                        j += 60 * 1000 * 5;
+                                    }
+                                    break;
+                                case "AI067":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setFx(s.get(i).getValue());
+                                        j += 60 * 1000 * 5;
+                                    }
+                                    break;
+                                case "AI082":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setJyjd(s.get(i).getValue());
+                                        j += 60 * 1000 * 5;
+                                    }
+                                    break;
+                                case "AI073":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setDfjd(s.get(i).getValue());
+                                        j += 60 * 1000 * 5;
+                                    }
+                                    break;
+                                case "AI004":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setNjwd(s.get(i).getValue());
+                                        j += 60 * 1000 * 5;
+                                    }
+                                    break;
+                                case "AI047":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setDjwd(s.get(i).getValue());
+                                        j += 60 * 1000 * 5;
+                                    }
+                                    break;
+                                case "AI072":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setHjwd(s.get(i).getValue());
+                                        j += 60 * 1000 * 5;
+                                    }
+                                    break;
+                                case "AI074":
+                                    for (int i = 0; i < s.size(); i++) {
+                                        dt = DateUtil.formatDateTime(new Date(j));
+                                        glycSj = map.get(dt);
+                                        if (glycSj == null) {
+                                            glycSj = new GlycSj();
+                                            map.put(dt, glycSj);
+                                        }
+                                        glycSj.setJcwd(s.get(i).getValue());
+                                        j += 60 * 1000 * 5;
+                                    }
+                                    break;
+                            }
+                            map.forEach((k, v) -> {
+                                v.setTime(k);
+                            });
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                    Future<String> b=ThreadUtil.execAsync(() -> {
+                        writerData(map.values(), stId, tbId);
+                        return "ok";
+                    });
+                    ftfs.add(b);
+                    return "ok";
+                });
+                fts.add(future);
+            });
+        });
+        for (Future<String> ft : fts) {
+            try {
+                ft.get();
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            } catch (ExecutionException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        for (Future<String> ft : ftfs) {
+            try {
+                ft.get();
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            } catch (ExecutionException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        //按行写出
+//        writer.write(new String[]{"时间", "时间戳", "对齐时间戳", "值"});
+        /*writer.write(new String[]{"时间", "时间戳", "对齐时间戳", "值"});
         for (PointInfo pi : list) {
-            CsvWriter writer = null;
             if (pi.getPointKey().equals("INITIAL")) {
                 //指定路径和编码
                 writer = CsvUtil.getWriter("D:/数据/" + pi.getTurbineId() + "/" + pi.getName() + "无测点" +
@@ -59,13 +278,9 @@ public class GetDataTest {
                         ".csv", CharsetUtil.CHARSET_GBK);
                 continue;
             }
-
             //指定路径和编码
             writer = CsvUtil.getWriter("D:/数据/" + pi.getTurbineId() + "/" + pi.getName() +
                     ".csv", CharsetUtil.CHARSET_GBK);
-            //按行写出
-            writer.write(new String[]{"时间", "时间戳", "对齐时间戳", "值"});
-
             long j = start.getTime();
             for (int i = 0; i < s.size(); i++) {
                 String[] r = new String[4];
@@ -74,9 +289,15 @@ public class GetDataTest {
                 r[2] = Long.toString(j);
                 r[3] = Double.toString(s.get(i).getValue());
                 writer.write(r);
-                j += 60 * 1000;
+                j += 60 * 1000 * 5;
             }
+        }*/
+    }
 
-        }
+    //    @Async
+    void writerData(Collection<GlycSj> values, String stId, String tbId) {
+        CsvWriter writer = CsvUtil.getWriter("D:/数据/" + stId + "/" + tbId + ".csv", CharsetUtil.CHARSET_UTF_8);
+        writer.writeBeans(values);
+        writer.flush();
     }
 }

+ 11 - 11
universal-computing-platform/src/main/java/com/ruoyi/ucp/entity/GlycSj.java

@@ -9,17 +9,17 @@ public class GlycSj {
     //AI114	AI066	AI060	AI065	AI067	AI082	AI073	AI004	AI047	AI072	AI074
     private String turbineId;
     private String time;
-    private Double gl;
-    private Double fs;
-    private Double fdjzs;
-    private Double zt;
-    private Double fx;
-    private Double jyjd;
-    private Double dfjd;
-    private Double njwd;
-    private Double djwd;
-    private Double hjwd;
-    private Double jcwd;
+    private Double gl = 0.0;
+    private Double fs = 0.0;
+    private Double fdjzs = 0.0;
+    private Double zt = 0.0;
+    private Double fx = 0.0;
+    private Double jyjd = 0.0;
+    private Double dfjd = 0.0;
+    private Double njwd = 0.0;
+    private Double djwd = 0.0;
+    private Double hjwd = 0.0;
+    private Double jcwd = 0.0;
 
     public void setGl(Double gl) {
         if (gl == null || gl < 0 || gl > 40000) gl = 0.0;

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

@@ -29,11 +29,31 @@ public class RealtimePredictServiceImpl extends ServiceImpl<RealtimePredictMappe
     }
 
     @Override
+    public boolean removeBatchByIds(Collection<?> list) {
+        return super.removeBatchByIds(list);
+    }
+
+    @Override
     public boolean saveOrUpdateBatch(Collection<RealtimePredict> entityList, int batchSize) {
         return super.saveOrUpdateBatch(entityList, batchSize);
     }
 
     @Override
+    public boolean saveBatch(Collection<RealtimePredict> entityList, int batchSize) {
+        return super.saveBatch(entityList, batchSize);
+    }
+
+    @Override
+    public boolean removeByIds(Collection<?> list) {
+        return super.removeByIds(list);
+    }
+
+    @Override
+    public boolean saveBatch(Collection<RealtimePredict> entityList) {
+        return super.saveBatch(entityList);
+    }
+
+    @Override
     public List<RealtimePredict> list(Wrapper<RealtimePredict> queryWrapper) {
         return super.list(queryWrapper);
     }