瀏覽代碼

修改taos di测点查询逻辑

wanghs 1 年之前
父節點
當前提交
b35b44f012

+ 18 - 1
dao/dao-taoscz/src/main/java/com/gyee/wisdom/dao/taoscz/TaosConfig.java

@@ -41,6 +41,12 @@ 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;
 
     public Connection getInstance() {
@@ -74,8 +80,19 @@ public class TaosConfig {
     }
 
     public String getTableName(String tagName) {
-
         return dbName + "." + tagName;
     }
 
+    public String getDbName() {
+        return dbName;
+    }
+
+
+    public String getAIStableName() {
+        return aiStableName;
+    }
+
+    public String getDIStableName() {
+        return diStableName;
+    }
 }

+ 33 - 35
dao/dao-taoscz/src/main/java/com/gyee/wisdom/dao/taoscz/TaosLatestDao.java

@@ -167,13 +167,13 @@ public class TaosLatestDao implements ILatestDao {
                 int count = writeLongLatest(pointDataList);
                 writeCount = writeCount + count;
             }
-            }
-            return writeCount > 0 ? true : false;
         }
+        return writeCount > 0 ? true : false;
+    }
 
-        public Map<String, TsData> getDoubleTsDataSnapshots (String...tagNames) throws Exception {
-            Map<String, TsData> tsDataMap = new HashMap<>();
-            Statement st = config.getInstance().createStatement();
+    public Map<String, TsData> getDoubleTsDataSnapshots(String... tagNames) throws Exception {
+        Map<String, TsData> tsDataMap = new HashMap<>();
+        Statement st = config.getInstance().createStatement();
 //        for (String tag : tagNames) {
 //            String tableName = config.getTableName(tag);
 //
@@ -183,41 +183,39 @@ public class TaosLatestDao implements ILatestDao {
 //            }
 //        }
 
-            String inString = Arrays.stream(tagNames).map(s -> "'" + s + "'").collect(Collectors.joining(","));
-            ResultSet rs = st.executeQuery("select last_row(*) from by_fdc.windturbineai  where point in (" + inString + ") group by tbname;");
+        String inString = Arrays.stream(tagNames).map(s -> "'" + s + "'").collect(Collectors.joining(","));
+        ResultSet rs = st.executeQuery("select last_row(*) from " + config.getDbName() + "." + config.getAIStableName() + " where point in (" + inString + ") group by tbname;");
 
-            while (rs.next()) {
-                tsDataMap.put(rs.getString(3).toUpperCase(), new DoubleTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getDouble(2)));
-            }
-            return tsDataMap;
+        while (rs.next()) {
+            tsDataMap.put(rs.getString(3).toUpperCase(), new DoubleTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getDouble(2)));
         }
+        return tsDataMap;
+    }
 
-        public Map<String, TsData> getLongTsDataSnapshots (String...tagNames) throws Exception {
-            Map<String, TsData> tsDataMap = new HashMap<>();
-            Statement st = config.getInstance().createStatement();
-            for (String tag : tagNames) {
-                String tableName = config.getTableName(tag);
-                ResultSet rs = st.executeQuery("select last_row(*) from " + tableName);
-                while (rs.next()) {
-                    tsDataMap.put(tag, new LongTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getLong(2)));
-                }
+    public Map<String, TsData> getLongTsDataSnapshots(String... tagNames) throws Exception {
+        Map<String, TsData> tsDataMap = new HashMap<>();
+        Statement st = config.getInstance().createStatement();
+        for (String tag : tagNames) {
+            String tableName = config.getTableName(tag);
+            ResultSet rs = st.executeQuery("select last_row(*) from " + tableName);
+            while (rs.next()) {
+                tsDataMap.put(tag, new LongTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getLong(2)));
             }
-            return tsDataMap;
         }
+        return tsDataMap;
+    }
 
-        public Map<String, TsData> getBooleanTsDataSnapshots (String...tagNames) throws Exception {
-            Map<String, TsData> tsDataMap = new HashMap<>();
-            Statement st = config.getInstance().createStatement();
-
-            for (String tag : tagNames) {
-                String tableName = config.getTableName(tag);
-                ResultSet rs = st.executeQuery("select last_row(*) from " + tableName);
-                while (rs.next()) {
-                    tsDataMap.put(tag, new LongTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getLong(2)));
-                    tsDataMap.put(rs.getString(3).toUpperCase(), new BooleanTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getBoolean(2)));
-                }
-            }
-            return tsDataMap;
-        }
+    public Map<String, TsData> getBooleanTsDataSnapshots(String... tagNames) throws Exception {
+        Map<String, TsData> tsDataMap = new HashMap<>();
+        Statement st = config.getInstance().createStatement();
 
+        String inString = Arrays.stream(tagNames).map(s -> "'" + s + "'").collect(Collectors.joining(","));
+        ResultSet rs = st.executeQuery("select last_row(*) from " + config.getDbName() + "." + config.getDIStableName() + " where point in (" + inString + ") group by tbname;");
+
+        while (rs.next()) {
+            tsDataMap.put(rs.getString(3).toUpperCase(), new BooleanTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getBoolean(2)));
+        }
+        return tsDataMap;
     }
+
+}