|
@@ -12,7 +12,9 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
+import java.sql.ResultSetMetaData;
|
|
|
import java.sql.Statement;
|
|
|
+import java.sql.Timestamp;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -38,10 +40,10 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
String[] tagNames = entry.getValue().stream().map(TsPoint::getId).toArray(String[]::new);
|
|
|
if (entry.getKey() == TsDataType.DOUBLE) {
|
|
|
result.putAll(getDoubleTsDataSnapshots(tagNames));
|
|
|
- } else if (entry.getKey() == TsDataType.LONG) {
|
|
|
- result.putAll(getLongTsDataSnapshots(tagNames));
|
|
|
} else if (entry.getKey() == TsDataType.BOOLEAN) {
|
|
|
result.putAll(getBooleanTsDataSnapshots(tagNames));
|
|
|
+ } else if (entry.getKey() == TsDataType.LONG) {
|
|
|
+ result.putAll(getLongTsDataSnapshots(tagNames));
|
|
|
} else {
|
|
|
throw new WisdomException("Taos不支持数据类型:" + entry.getKey());
|
|
|
}
|
|
@@ -55,16 +57,16 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
public int writeDoubleLatest(List<TsPointData> list) throws Exception {
|
|
|
Statement st = config.getInstance().createStatement();
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("insert into ");
|
|
|
+ sb.append("INSERT INTO ");
|
|
|
for (TsPointData obj : list) {
|
|
|
long time = obj.getTsData().getTs();
|
|
|
String point = config.getTableName(obj.getTagName());
|
|
|
double value = obj.getTsData().getDoubleValue().get();
|
|
|
// sb.append(TaosCovertUtil.coverStationPrefix(point)).append(".");
|
|
|
- sb.append(point).append(" values (");
|
|
|
- sb.append(time).append(",").append(value).append(")");
|
|
|
+ sb.append(point).append(" VALUES (");
|
|
|
+ sb.append(time).append(",").append(value).append(") ");
|
|
|
}
|
|
|
-
|
|
|
+ sb.append(";");
|
|
|
val i = st.executeUpdate(sb.toString());
|
|
|
|
|
|
return i == list.size() ? list.size() : 0;
|
|
@@ -99,11 +101,12 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
boolean value = obj.getTsData().getBooleanValue().get();
|
|
|
// sb.append(TaosCovertUtil.coverStationPrefix(point)).append(".");
|
|
|
sb.append(point).append(" values (");
|
|
|
- sb.append(time).append(",").append(value).append(")");
|
|
|
+ sb.append(time).append(",").append(value).append(") ");
|
|
|
}
|
|
|
- boolean flag = st.execute(sb.toString());
|
|
|
+ sb.append(";");
|
|
|
+ int i = st.executeUpdate(sb.toString());
|
|
|
|
|
|
- return flag == true ? list.size() : 0;
|
|
|
+ return i;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -174,17 +177,11 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
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);
|
|
|
-//
|
|
|
-// ResultSet rs = st.executeQuery("select last_row(*) from " + tableName);
|
|
|
-// while (rs.next()) {
|
|
|
-// tsDataMap.put(tag, new DoubleTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getDouble(2)));
|
|
|
-// }
|
|
|
-// }
|
|
|
|
|
|
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;");
|
|
|
+ inString = "select last_row(*),tbname from " + config.getDbName() + "." + config.getAIStableName()
|
|
|
+ + " where tbname in (" + inString + ") group by tbname;";
|
|
|
+ ResultSet rs = st.executeQuery(inString);
|
|
|
|
|
|
while (rs.next()) {
|
|
|
tsDataMap.put(rs.getString(3).toUpperCase(), new DoubleTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getDouble(2)));
|
|
@@ -210,7 +207,8 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
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;");
|
|
|
+ ResultSet rs = st.executeQuery("select last_row(*),tbname from " + config.getDbName() + "." + config.getDIStableName() +
|
|
|
+ " where tbname 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)));
|