소스 검색

适配器taoscz更新

xushili 1 년 전
부모
커밋
fa3092c8ac

+ 30 - 0
data-adapter/src/main/java/com/gyee/wisdom/dataadapter/configuration/FilePathConfig.java

@@ -0,0 +1,30 @@
+package com.gyee.wisdom.dataadapter.configuration;
+
+import org.springframework.boot.system.ApplicationHome;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+
+@Component
+public class FilePathConfig {
+    private static String filePath;
+    private static String excelPath;
+
+    public static String getFilePath() {
+        if(filePath==null){
+            ApplicationHome home = new ApplicationHome(FilePathConfig.class);
+            filePath=home.getSource().getParentFile().getAbsolutePath();
+        }
+        return filePath;
+    }
+
+    public static String getExcelPath() {
+        if(excelPath==null){
+            getFilePath();
+            excelPath = filePath+"\\excel\\";
+            File file = new File(excelPath);
+            if(!file.exists()) file.mkdirs();
+        }
+        return excelPath;
+    }
+}

+ 58 - 11
transport/redis2taos/src/main/java/com/gyee/wisdom/taos/TaosConfig.java

@@ -13,13 +13,13 @@ import java.util.Properties;
 @Configuration
 public class TaosConfig {
 
-    @Value("${taoscz.server_ip:123.60.219.66}")
+    @Value("${taoscz.server_ip:192.168.1.60}")
     private String serverIp;
 
-    @Value("${taoscz.server_port:6041}")
+    @Value("${taoscz.server_port:6030}")
     private int serverPort;
 
-    @Value("${taoscz.db_name:by_fdc}")
+    @Value("${taoscz.db_name:power_test}")
     private String dbName;
 
     @Value("${taoscz.user_name:root}")
@@ -37,20 +37,60 @@ public class TaosConfig {
     @Value("${taoscz.driver_type:com.taosdata.jdbc.rs.RestfulDriver}")
     private String driverType;
 
+    @Value("${taoscz.ai_stable_name:windturbineai}")
+    private String aiStableName;
+
+    @Value("${taoscz.di_stable_name:windturbinedi}")
+    private String diStableName;
+
     private Connection connection = null;
+    private Connection createCon = null;
 
-    public Connection getInstance() {
+    public Connection getInstance() throws Exception {
         if (null == connection)
             connection = getConnection();
 
         return connection;
     }
 
+    public Connection getCreateCon() throws Exception {
+        if (null == createCon || createCon.isClosed()){
+            Class.forName(driverType);
+            String jdbcUrl = "jdbc:TAOS-RS://" + serverIp + ":" + serverPort + "?user=" + userName + "&password=" + password;
+            if (driverType.equals("com.taosdata.jdbc.TSDBDriver"))
+                jdbcUrl = "jdbc:TAOS://" + serverIp + ":" + serverPort + "?user=" + userName + "&password=" + password;
+            Properties connProps = new Properties();
+            connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
+            connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
+            connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
+            createCon = DriverManager.getConnection(jdbcUrl, connProps);
+        }
+        return createCon;
+    }
 
-    private Connection getConnection() {
+    public void closeCon() throws Exception {
+        if (null != createCon)
+            connection.close();
+    }
+
+    private Connection getConnection2() throws Exception {
         Connection connection = null;
 
-        try {
+        Class.forName(driverType);
+        String jdbcUrl = "jdbc:TAOS-RS://" + serverIp + ":" + serverPort + "?user=" + userName + "&password=" + password;
+        if (driverType.equals("com.taosdata.jdbc.TSDBDriver"))
+            jdbcUrl = "jdbc:TAOS://" + serverIp + ":" + serverPort + "?user=" + userName + "&password=" + password;
+        Properties connProps = new Properties();
+        connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
+        connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
+        connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
+        connection = DriverManager.getConnection(jdbcUrl, connProps);
+
+        return connection;
+    }
+
+    private Connection getConnection() throws Exception {
+        Connection connection = null;
 
             Class.forName(driverType);
             String jdbcUrl = "jdbc:TAOS-RS://" + serverIp + ":" + serverPort + "/" + dbName + "?user=" + userName + "&password=" + password;
@@ -61,17 +101,24 @@ public class TaosConfig {
             connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
             connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
             connection = DriverManager.getConnection(jdbcUrl, connProps);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
 
         return connection;
     }
 
     public String getTableName(String tagName) {
-
         return dbName + "." + tagName;
     }
 
+    public String getDbName() {
+        return dbName;
+    }
+
+
+    public String getAIStableName() {
+        return aiStableName;
+    }
+
+    public String getDIStableName() {
+        return diStableName;
+    }
 }