GYEE 8 months ago
parent
commit
621babb7be

+ 6 - 0
ruoyi-admin/pom.xml

@@ -93,6 +93,12 @@
             <artifactId>ruoyi-generator</artifactId>
         </dependency>-->
 
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.8.25</version>
+        </dependency>
+
     </dependencies>
 
     <build>

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

@@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
-@Service
+//@Service
 public class JavaFunctionJobHandler extends IJobHandler {
 
     @Resource

+ 32 - 12
ruoyi-admin/src/main/java/com/ruoyi/web/runner/LoadDataSourceRunner.java

@@ -1,6 +1,10 @@
 package com.ruoyi.web.runner;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateRange;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.file.FileReader;
 import com.alibaba.druid.pool.DruidDataSource;
 import com.alibaba.fastjson2.JSON;
@@ -16,18 +20,19 @@ import com.ruoyi.ucp.entity.UcpDataSource;
 import com.ruoyi.ucp.feign.AdapterApi;
 import com.ruoyi.ucp.service.*;
 import com.ruoyi.ucp.util.CalcCache;
+import com.ruoyi.web.controller.JavaFunctionJobHandler;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.io.File;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 
 @Component
 public class LoadDataSourceRunner implements CommandLineRunner {
@@ -53,10 +58,13 @@ public class LoadDataSourceRunner implements CommandLineRunner {
     @Resource
     private IFormulaService formulaService;
     @Resource
-    @Autowired
     private RedisTemplate redisTemplate;
+    @Resource
+    private StringRedisTemplate stringRedisTemplate;
     @Value("${ruoyi.profile}")
     private String path;
+//    @Resource
+//    private JavaFunctionJobHandler task;
 
     @Override
     public void run(String... args) {
@@ -91,10 +99,10 @@ public class LoadDataSourceRunner implements CommandLineRunner {
             e.printStackTrace();
         }
 
-        LettuceConnectionFactory factory = (LettuceConnectionFactory) redisTemplate.getConnectionFactory();
+        LettuceConnectionFactory factory = (LettuceConnectionFactory) stringRedisTemplate.getConnectionFactory();
         int database = factory.getDatabase();
         factory.setDatabase(9);
-        redisTemplate.setConnectionFactory(factory);
+        stringRedisTemplate.setConnectionFactory(factory);
         factory.afterPropertiesSet();
         factory.resetConnection();
         /*Set<String> keys = redisTemplate.keys("monthCurve_*");
@@ -109,13 +117,13 @@ public class LoadDataSourceRunner implements CommandLineRunner {
             CalcCache.wtMcfMap.put(powerList.get(0).getWindturbineId(), collect);
         }*/
 
-        String zllgl = (String) redisTemplate.opsForValue().get("ZLLGL");
+        String zllgl = stringRedisTemplate.opsForValue().get("ZLLGL");
         //字符串类型转换为list月拟合曲线集合
         Map<String, Map<Double, ProBasicModelPowerRd>> bzgl = JSON.parseObject(zllgl, new TypeReference<Map<String, Map<Double, ProBasicModelPowerRd>>>() {
         }.getType());
-        Map<String, Map<Double, Double>> bz = new HashMap<>();
+        Map<String, ConcurrentHashMap<Double, Double>> bz = new HashMap<>();
         bzgl.forEach((modeId, map) -> {
-            Map<Double, Double> mdd = new HashMap<>();
+            ConcurrentHashMap<Double, Double> mdd = new ConcurrentHashMap<>();
             map.forEach((speed, mprd) -> {
                 mdd.put(speed, mprd.getEnsurePower());
             });
@@ -126,8 +134,20 @@ public class LoadDataSourceRunner implements CommandLineRunner {
         factory.setDatabase(database);
         factory.afterPropertiesSet();
         factory.resetConnection();
-        String glqxnh = (String) redisTemplate.opsForValue().get("glqxnh");
-        CalcCache.fitcoef = JSON.parseObject(glqxnh, new TypeReference<Map<String, double[]>>() {
-        }.getType());
+
+
+        Set<String> keys = stringRedisTemplate.keys("glqxnh:5:*");
+        for (String key : keys) {
+            String yc = stringRedisTemplate.opsForValue().get(key);
+            ConcurrentHashMap<Double, Double> wtyc = JSON.parseObject(yc, new TypeReference<ConcurrentHashMap<Double, Double>>() {}.getType());
+            CalcCache.fitcoef.put(key.replaceFirst("glqxnh:5:",""),wtyc);
+        }
+
+
+
+//        DateTime start = DateUtil.parse("2024-03-25");
+//        DateTime end = DateUtil.parse("2024-06-25");
+//        task.calcGlqxnh(start,end);
+//        System.out.println("选否");
     }
 }

+ 14 - 13
ruoyi-admin/src/main/resources/application-druid.yml

@@ -5,20 +5,21 @@ spring:
     driver-class-name: org.postgresql.Driver                # pgsql驱动包
     druid:
       master:
-        url: jdbc:postgresql://192.168.126.128:5432/calc_hub
-        username: gfhd
-        password: zghww693
+#        url: jdbc:postgresql://192.168.126.128:5432/calc_hub
+#        username: gfhd
+#        password: zghww693
+        url: jdbc:postgresql://172.16.12.102:5432/calc_hub
+        username: postgres
+        password: GYee@#56
       taos:
-        url: jdbc:TAOS-RS://192.168.126.128:6041/jsfw_db?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8
+#        url: jdbc:TAOS-RS://192.168.126.128:6041/jsfw_db?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8
+        url: jdbc:TAOS-RS://172.16.12.101:6041/jsfw_db?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8
         username: root
         password: taosdata
         driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
 #        url: jdbc:postgresql://123.60.219.66:5432/ry-vue
 #        username: postgres
 #        password: gyeepd@123
-#        url: jdbc:postgresql://172.16.12.102:5432/calc_hub
-#        username: postgres
-#        password: GYee@#56
 #        url: jdbc:mysql://49.234.50.218:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
 #        username: root
 #        password: zghww693
@@ -27,15 +28,15 @@ spring:
 #        url: jdbc:postgresql://192.168.126.128:5432/postgres
 #        username: gfhd
 #        password: zghww693
-        url: jdbc:postgresql://192.168.2.232:5432/power_lcm
-        username: postgres
-        password: gd123
+#        url: jdbc:postgresql://192.168.2.232:5432/power_lcm
+#        username: postgres
+#        password: gd123
 #        url: jdbc:postgresql://123.60.219.66:5432/power_lcm
 #        username: postgres
 #        password: gyeepd@123
-#        url: jdbc:postgresql://172.16.12.102:5432/power_lcm
-#        username: postgres
-#        password: GYee@#56
+        url: jdbc:postgresql://172.16.12.102:5432/power_lcm
+        username: postgres
+        password: GYee@#56
 #        driver-class-name: org.postgresql.Driver
         enabled: true
       # 初始连接数

+ 13 - 6
ruoyi-admin/src/main/resources/application.yml

@@ -9,7 +9,8 @@ ruoyi:
   # 实例演示开关
   demoEnabled: true
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
-  profile: D:/ruoyi/uploadPath
+#  profile: /home/ruoyi
+  profile: D:/ruoyi/
   # 获取ip地址开关
   addressEnabled: false
   # 验证码类型 math 数组计算 char 字符验证
@@ -77,15 +78,15 @@ spring:
   # redis 配置
   redis:
     # 地址
-#    host: 172.16.12.103
-    host: 127.0.0.1
+    host: 172.16.12.103
+#    host: 127.0.0.1
     # 端口,默认为6379
     port: 6379
     # 数据库索引
     database: 5
     # 密码
-#    password: GYee@#56
-    password:
+    password: GYee@#56
+#    password:
     # 连接超时时间
     timeout: 10s
     lettuce:
@@ -145,4 +146,10 @@ xss:
   # 匹配链接
   urlPatterns: /system/*,/monitor/*,/tool/*
 
-url: ws://43.156.3.30:8080/gs-guide-websocket
+#url: ws://43.156.3.30:8080/gs-guide-websocket
+feign:
+  client:
+    config:
+      default:
+        connect-timeout: 5000
+        read-timeout: 300000

+ 71 - 0
ruoyi-admin/src/test/java/com/ruoyi/GetDataTest.java

@@ -0,0 +1,71 @@
+package com.ruoyi;
+
+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.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 org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.net.URI;
+import java.util.*;
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class GetDataTest {
+
+    @Resource
+    private IPointInfoService pointInfoService;
+    @Resource
+    private AdapterApi adapterApi;
+    @Test
+    public void test() {
+        DateTime start = DateUtil.parse("2023-06-01");
+        DateTime end = DateUtil.parse("2024-05-31");
+
+        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"};
+        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_0001_EQ")
+                .in(PointInfo::getUniformCode,names);
+        List<PointInfo> list = pointInfoService.list(wrapper);
+        for (PointInfo pi : list) {
+            CsvWriter writer = null;
+            if(pi.getPointKey().equals("INITIAL")){
+                //指定路径和编码
+                writer = CsvUtil.getWriter("D:/数据/"+pi.getTurbineId()+"/"+pi.getName()+"无测点"+
+                        ".csv", CharsetUtil.CHARSET_GBK);
+                continue;
+            }
+            List<PointData> s = adapterApi.getHistorySnap(URI.create("http://172.16.12.103:8011/ts"), pi.getPointKey(),
+                    start.getTime(), end.getTime(), 60);
+
+                //指定路径和编码
+                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];
+                r[0]=DateUtil.formatDateTime(new Date(j));
+                r[1]=Long.toString(s.get(i).getTs());
+                r[2]=Long.toString(j);
+                r[3]=Double.toString(s.get(i).getValue());
+                writer.write(r);
+                j+=60*1000;
+            }
+
+        }
+    }
+}

File diff suppressed because it is too large
+ 987 - 258
ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java


+ 68 - 0
ruoyi-admin/src/test/java/com/ruoyi/NewTests.java

@@ -0,0 +1,68 @@
+package com.ruoyi;
+
+import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateRange;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.NumberUtil;
+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.ucp.util.CalcCache;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.net.URI;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@SpringBootTest//classes = RuoYiApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
+@RunWith(SpringRunner.class)
+public class NewTests {
+
+    @Resource
+    private JavaFunctionJobHandler task;
+
+    @Test
+    public void test() {
+        Date date = DateUtil.date().toJdkDate();
+//        calcStationZhcydl(date);
+//        calcNhglZs(date);
+        // 创建日期范围生成器
+        DateTime start = DateUtil.parse("2024-06-26");
+//        DateTime start = DateUtil.parse("2024-05-01");
+        DateTime end = DateUtil.parse("2024-06-26");
+        DateRange range = DateUtil.range(start, end, DateField.DAY_OF_YEAR);
+        for (DateTime time : range) {
+            date=time.toJdkDate();
+            System.out.println(DateUtil.date().toString() + ":" + time.toString());
+            //安全天数
+//            calcAQTS(time.toJdkDate());
+//            task.calcLineDjlRfdl(date);
+//            //上网购网厂用电量
+//            task.calcStationSwGwCyDl(date);
+//            //计算综合厂用电量
+//            task.calcStationZhcydl(date);
+//
+//            task.calcTurbineRFDL(date);
+//            task.calcStationRfdlFj(date);
+//            task.writeReportPool(date);
+
+//            task.writeReportPool(date);
+//            task.calcTurbine5s2(date);
+
+        }
+//        task.calcGlqxnh(start,end);
+//        calcTurbineRFDL(date);
+        task.calcTurbine5s2(date);
+//        writeReportPool(date);
+
+//        task.calcStationSspjfs();
+    }
+}