Browse Source

data-adapter
配置文件添加
#taos中ai测点的超级表名
di_stable_name: windturbinedi
#taos中di测点的超级表名
ai_stable_name: windturbineai
此配置必须配置正确才能保证data-adapter能从taos中查询数据

SpringStarAfter中添加taos库初始化方法
可以在关系库基础表view_tspoint,windturbine,windpowerstation表及数据存在时,创建taos库

wanghs 1 year ago
parent
commit
ce0ad6bf29

+ 0 - 1
data-adapter/src/main/java/com/gyee/wisdom/dataadapter/dto/ElectricalDto.java

@@ -2,7 +2,6 @@ package com.gyee.wisdom.dataadapter.dto;
 
 import lombok.Data;
 
-import javax.persistence.Column;
 import java.io.Serializable;
 
 @Data

+ 141 - 28
data-adapter/src/main/java/com/gyee/wisdom/dataadapter/runner/SpringStartAfter.java

@@ -55,34 +55,40 @@ public class SpringStartAfter implements ApplicationRunner {
     @Override
     public void run(ApplicationArguments args) throws Exception {
 
-        // initDatabase("HNJ_FDC");
-
-        Random r = new Random();
-        Long ts = new Date().getTime();
-        final List<TsPoint> allTsPoint = thingsPointDao.getAllTsPoint().stream().filter(s -> !s.getThingId().equals("BY_FDC")).collect(Collectors.toList());
-        List<TsPointData> dataList = new ArrayList<>();
-        for (TsPoint point :
-                allTsPoint) {
-            TsPointData tsPointData = new TsPointData();
-            tsPointData.setTagName(point.getId());
-            GeneralTsData generalTsData = new GeneralTsData();
-            Double speed = r.nextDouble() * 6 + 3;
-            generalTsData.setDoubleValue(java.util.Optional.of(speed));
-            ts = ts + 1000;
-            generalTsData.setTs(ts);
-            tsPointData.setTsData(generalTsData);
-            dataList.add(tsPointData);
-        }
-
-        while (true) {
-            Thread.sleep(999);
-            writeThread(dataList).run();
-
-        }
+        //牛首山风电场 taos库创建,taos库保存数据为90天
+//        initDatabase("HNJ_FDC", 90);
+//        //牛首山风电场 ai测点表创建,超级表名为windturbineai,风机型号为UP82
+//        initTableAI("HNJ_FDC", "windturbineai", "MY-1500");
+//        //牛首山风电场 di测点表创建,超级表名为windturbinedi,风机型号为UP82
+//        initTableDI("HNJ_FDC", "windturbinedi", "MY-1500");
+
+//        Random r = new Random();
+//        Long ts = new Date().getTime();
+//        final List<TsPoint> allTsPoint = thingsPointDao.getAllTsPoint().stream().filter(s -> !s.getThingId().equals("BY_FDC")).collect(Collectors.toList());
+//        List<TsPointData> dataList = new ArrayList<>();
+//        for (TsPoint point :
+//                allTsPoint) {
+//            TsPointData tsPointData = new TsPointData();
+//            tsPointData.setTagName(point.getId());
+//            GeneralTsData generalTsData = new GeneralTsData();
+//            Double speed = r.nextDouble() * 6 + 3;
+//            generalTsData.setDoubleValue(java.util.Optional.of(speed));
+//            ts = ts + 1000;
+//            generalTsData.setTs(ts);
+//            tsPointData.setTsData(generalTsData);
+//            dataList.add(tsPointData);
+//        }
+//
+//        while (true) {
+//            Thread.sleep(999);
+//            writeThread(dataList).run();
+//
+//        }
 
 
     }
 
+    //模拟taos数据写入
     private Thread writeThread(List<TsPointData> list) {
         Thread t = new Thread() {
 
@@ -120,10 +126,61 @@ public class SpringStartAfter implements ApplicationRunner {
 
     }
 
-    private void initDatabase(String stationName) throws ClassNotFoundException {
+    /**
+     * @param
+     * @param stationName 风场id
+     * @param keepDay     数据存储天数
+     * @return
+     * @author Wanghs
+     * @description
+     * @date 2023/2/22
+     **/
+
+    private void initDatabase(String stationName, int keepDay) throws ClassNotFoundException {
+
+
+        log.error("开始执行创建taos库");
+        try {
+//            final List<Windturbine> windturbines = windturbineService.queryWindturbine(stationName, "MY-1500");
+//
+//            log.error("查询风机完毕" + windturbines.size());
+            // Class.forName("com.taosdata.jdbc.TSDBDriver");
+            // String jdbcUrl = "jdbc:TAOS://" + serverIp + ":" + serverPort + "/" + dbName + "?user=" + userName + "&password=" + password;
+
+            Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
+            String jdbcUrl = "jdbc:TAOS-RS://" + serverIp + ":" + serverPort + "/" + dbName + "?user=" + userName + "&password=" + password;
+
+            Properties connProps = new Properties();
+            connProps.setProperty("charset", "UTF-8");
+            connProps.setProperty("locale", "en_US.UTF-8");
+            connProps.setProperty("timezone", "UTC-8");
+            final Connection connection = DriverManager.getConnection(jdbcUrl, connProps);
+
+
+            //String createDatabaseSql="create database if not exists "+stationName;
+            final Statement statement = connection.createStatement();
+            //statement.executeUpdate(createDatabaseSql);
+
+            String createSTableSql = "create database " + stationName + " replica 1 quorum 1 days 1 keep " + keepDay + " cache 16 blocks 6" +
+                    " minrows 100 maxrows 4096 wal 1 fsync 3000 comp 2 cachelast 0 precision 'ms' update 1";
+            statement.executeUpdate(createSTableSql);
+
+
+        } catch (SQLException ex) {
+            log.error(ex.getMessage());
+            log.error("=============");
+            ex.printStackTrace();
+            log.error(ex.getStackTrace().toString());
+        }
+
+
+    }
+
+
+    private void initTableAI(String stationId, String stableName, String modelId) throws ClassNotFoundException {
         log.error("开始执行创建taos库");
         try {
-            final List<Windturbine> windturbines = windturbineService.queryWindturbine(stationName, "MY-1500");
+            final List<Windturbine> windturbines = windturbineService.queryWindturbine(stationId, modelId);
 
             log.error("查询风机完毕" + windturbines.size());
             // Class.forName("com.taosdata.jdbc.TSDBDriver");
@@ -143,7 +200,61 @@ public class SpringStartAfter implements ApplicationRunner {
             final Statement statement = connection.createStatement();
             //statement.executeUpdate(createDatabaseSql);
 
-            String createSTableSql = "create stable if not exists " + stationName + ".windturbinedi(ts timestamp,value bool)tags(point binary(50));";
+            String createSTableSql = "create stable if not exists " + stationId + "." + stableName + "(ts timestamp,value double)tags(point binary(50));";
+            statement.executeUpdate(createSTableSql);
+
+
+            final List<TsPoint> allTsPoint = thingsPointDao.getAllTsPoint().stream().filter(s -> s.getTsDataType() == TsDataType.DOUBLE).collect(Collectors.toList());
+
+            Date st = new Date();
+            for (Windturbine data :
+                    windturbines) {
+
+                final List<TsPoint> collect = allTsPoint.stream().filter(s -> s.getThingId().equals(data.getCode())).collect(Collectors.toList());
+
+                for (TsPoint point :
+                        collect) {
+                    String createTableSql = "create table if not exists " + stationId + "." + point.getId() + " using " + stationId + "." + stableName + " tags(\"" + point.getId() + "\"" + ");";
+
+                    statement.executeUpdate(createTableSql);
+                }
+            }
+            Date et = new Date();
+            log.error("数据库创建完毕,耗时" + (et.getTime() - st.getTime()));
+        } catch (SQLException ex) {
+            log.error(ex.getMessage());
+            log.error("=============");
+            ex.printStackTrace();
+            log.error(ex.getStackTrace().toString());
+        }
+
+
+    }
+
+    private void initTableDI(String stationId, String stableName, String modelId) throws ClassNotFoundException {
+        log.error("开始执行创建taos库");
+        try {
+            final List<Windturbine> windturbines = windturbineService.queryWindturbine(stationId, modelId);
+
+            log.error("查询风机完毕" + windturbines.size());
+            // Class.forName("com.taosdata.jdbc.TSDBDriver");
+            // String jdbcUrl = "jdbc:TAOS://" + serverIp + ":" + serverPort + "/" + dbName + "?user=" + userName + "&password=" + password;
+
+            Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
+            String jdbcUrl = "jdbc:TAOS-RS://" + serverIp + ":" + serverPort + "/" + dbName + "?user=" + userName + "&password=" + password;
+
+            Properties connProps = new Properties();
+            connProps.setProperty("charset", "UTF-8");
+            connProps.setProperty("locale", "en_US.UTF-8");
+            connProps.setProperty("timezone", "UTC-8");
+            final Connection connection = DriverManager.getConnection(jdbcUrl, connProps);
+
+
+            //String createDatabaseSql="create database if not exists "+stationName;
+            final Statement statement = connection.createStatement();
+            //statement.executeUpdate(createDatabaseSql);
+
+            String createSTableSql = "create stable if not exists " + stationId + "." + stableName + "(ts timestamp,value bool)tags(point binary(50));";
             statement.executeUpdate(createSTableSql);
 
 
@@ -157,7 +268,8 @@ public class SpringStartAfter implements ApplicationRunner {
 
                 for (TsPoint point :
                         collect) {
-                    String createTableSql = "create table if not exists " + stationName + "." + point.getId() + " using windturbinedi tags(\"" + point.getId() + "\"" + ");";
+                    String createTableSql = "create table if not exists " + stationId + "." + point.getId() + " using " + stationId + "." + stableName + " tags(\"" + point.getId() + "\"" + ");";
+
 
                     statement.executeUpdate(createTableSql);
                 }
@@ -173,4 +285,5 @@ public class SpringStartAfter implements ApplicationRunner {
 
 
     }
+
 }

+ 15 - 7
data-adapter/src/main/resources/application.yaml

@@ -1,6 +1,8 @@
 server:
   port: 8012
   connection-timeout: 3000
+  max-http-header-size: 128KB
+
 
 spring:
   application:
@@ -17,7 +19,7 @@ spring:
 #    password: gdnxfd123
     # ----------------------------------------------------------------
     driver-class-name: com.mysql.jdbc.Driver
-    url: jdbc:mysql://123.60.219.66/wisdom_cs?useUnicode=true&characterEncoding=UTF-8
+    url: jdbc:mysql://123.60.219.66/wisdom_cs_hnj?useUnicode=true&characterEncoding=UTF-8
     username: root
     password: gyeepd@123
     # ----------------------------------------------------------------
@@ -49,10 +51,10 @@ knife4j:
   redis:
     # 是否采用json序列化方式,若不采用jackson序列化
     jsonSerialType: 'Fastjson'
-    host: 192.168.1.252
-    password: gyee123
+    host: 114.55.105.194
+    password: wanghs123
     port: 6379
-    databases: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] # 要使用的库,会根据此处填写的库生成redisTemplate
+    databases: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] # 要使用的库,会根据此处填写的库生成redisTemplate
     timeout: 60s
     lettuce: # lettuce基于netty,线程安全,支持并发
       pool:
@@ -102,15 +104,21 @@ taos:
   pool_size: 10
   max_pool_size: 100
 
+#适配器链接taos数据库配置信息
 taoscz:
-  server_ip: 192.168.1.252
-  server_port: 6030
+  server_ip: 123.60.219.66
+  server_port: 6041
   db_name: hnj_fdc
   user_name: root
   password: taosdata
   pool_size: 10
   max_pool_size: 100
-  driver_type: com.taosdata.jdbc.TSDBDriver
+  driver_type: com.taosdata.jdbc.rs.RestfulDriver
+  #driver_type: com.taosdata.jdbc.TSDBDriver
+  #taos中ai测点的超级表名
+  di_stable_name: windturbinedi
+  #taos中di测点的超级表名
+  ai_stable_name: windturbineai
 
 #EDOS 数据库信息
 edos: