|
@@ -56,18 +56,18 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
Statement st = config.getInstance().createStatement();
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.append("insert into ");
|
|
|
- for (TsPointData obj : list){
|
|
|
+ for (TsPointData obj : list) {
|
|
|
long time = obj.getTsData().getTs();
|
|
|
- String point =config.getTableName(obj.getTagName()) ;
|
|
|
+ String point = config.getTableName(obj.getTagName());
|
|
|
double value = obj.getTsData().getDoubleValue().get();
|
|
|
- // sb.append(TaosCovertUtil.coverStationPrefix(point)).append(".");
|
|
|
+ // sb.append(TaosCovertUtil.coverStationPrefix(point)).append(".");
|
|
|
sb.append(point).append(" values (");
|
|
|
sb.append(time).append(",").append(value).append(")");
|
|
|
}
|
|
|
|
|
|
val i = st.executeUpdate(sb.toString());
|
|
|
|
|
|
- return i==list.size()? list.size() : 0;
|
|
|
+ return i == list.size() ? list.size() : 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -75,11 +75,11 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
Statement st = config.getInstance().createStatement();
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.append("insert into ");
|
|
|
- for (TsPointData obj : list){
|
|
|
+ for (TsPointData obj : list) {
|
|
|
long time = obj.getTsData().getTs();
|
|
|
String point = obj.getTagName();
|
|
|
String value = obj.getTsData().getStringValue().get();
|
|
|
- // sb.append(TaosCovertUtil.coverStationPrefix(point)).append(".");
|
|
|
+ // sb.append(TaosCovertUtil.coverStationPrefix(point)).append(".");
|
|
|
sb.append(point).append(" values (");
|
|
|
sb.append(time).append(",'").append(value).append("') ");
|
|
|
}
|
|
@@ -93,11 +93,11 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
Statement st = config.getInstance().createStatement();
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.append("insert into ");
|
|
|
- for (TsPointData obj : list){
|
|
|
+ for (TsPointData obj : list) {
|
|
|
long time = obj.getTsData().getTs();
|
|
|
String point = obj.getTagName();
|
|
|
boolean value = obj.getTsData().getBooleanValue().get();
|
|
|
- // sb.append(TaosCovertUtil.coverStationPrefix(point)).append(".");
|
|
|
+ // sb.append(TaosCovertUtil.coverStationPrefix(point)).append(".");
|
|
|
sb.append(point).append(" values (");
|
|
|
sb.append(time).append(",").append(value).append(")");
|
|
|
}
|
|
@@ -111,7 +111,7 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
Statement st = config.getInstance().createStatement();
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.append("insert into ");
|
|
|
- for (TsPointData obj : list){
|
|
|
+ for (TsPointData obj : list) {
|
|
|
long time = obj.getTsData().getTs();
|
|
|
String point = obj.getTagName();
|
|
|
long value = obj.getTsData().getLongValue().get();
|
|
@@ -131,11 +131,12 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
|
|
|
@Override
|
|
|
public int writeCoordinateLatest(List<TsPointData> list) throws Exception {
|
|
|
- return 0;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 由于taos数据库中全部是DOUBLE类型,故不需要区分类型
|
|
|
+ *
|
|
|
* @param dataList
|
|
|
* @return
|
|
|
* @throws Exception
|
|
@@ -147,32 +148,32 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
Map<TsDataType, List<TsPointData>> pointGroup = dataList.stream().collect(Collectors.groupingBy(TsPointData::findDataType));
|
|
|
for (Map.Entry<TsDataType, List<TsPointData>> entry : pointGroup.entrySet()) {
|
|
|
List<TsPointData> pointDataList = entry.getValue();
|
|
|
-// if (entry.getKey() == TsDataType.DOUBLE) {
|
|
|
+ if (entry.getKey() == TsDataType.DOUBLE) {
|
|
|
int count = writeDoubleLatest(pointDataList);
|
|
|
writeCount = writeCount + count;
|
|
|
-// } else if (entry.getKey() == TsDataType.BOOLEAN) {
|
|
|
-// int count = writeBooleanLatest(pointDataList);
|
|
|
-// writeCount = writeCount + count;
|
|
|
-// } else if (entry.getKey() == TsDataType.STRING) {
|
|
|
-// int count = writeStringLatest(pointDataList);
|
|
|
-// writeCount = writeCount + count;
|
|
|
-// } else if (entry.getKey() == TsDataType.BLOB) {
|
|
|
-// int count = writeBlobLatest(pointDataList);
|
|
|
-// writeCount = writeCount + count;
|
|
|
-// } else if (entry.getKey() == TsDataType.COORDINATE) {
|
|
|
-// int count = writeCoordinateLatest(pointDataList);
|
|
|
-// writeCount = writeCount + count;
|
|
|
-// } else if (entry.getKey() == TsDataType.LONG) {
|
|
|
-// int count = writeLongLatest(pointDataList);
|
|
|
-// writeCount = writeCount + count;
|
|
|
-// }
|
|
|
+ } else if (entry.getKey() == TsDataType.BOOLEAN) {
|
|
|
+ int count = writeBooleanLatest(pointDataList);
|
|
|
+ writeCount = writeCount + count;
|
|
|
+ } else if (entry.getKey() == TsDataType.STRING) {
|
|
|
+ int count = writeStringLatest(pointDataList);
|
|
|
+ writeCount = writeCount + count;
|
|
|
+ } else if (entry.getKey() == TsDataType.BLOB) {
|
|
|
+ int count = writeBlobLatest(pointDataList);
|
|
|
+ writeCount = writeCount + count;
|
|
|
+ } else if (entry.getKey() == TsDataType.COORDINATE) {
|
|
|
+ int count = writeCoordinateLatest(pointDataList);
|
|
|
+ writeCount = writeCount + count;
|
|
|
+ } else if (entry.getKey() == TsDataType.LONG) {
|
|
|
+ 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);
|
|
|
//
|
|
@@ -181,39 +182,39 @@ public class TaosLatestDao implements ILatestDao {
|
|
|
// 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 by_fdc.windturbine 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 by_fdc.windturbine 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)));
|
|
|
+ while (rs.next()) {
|
|
|
+ tsDataMap.put(rs.getString(3).toUpperCase(), new DoubleTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getDouble(2)));
|
|
|
+ }
|
|
|
+ return tsDataMap;
|
|
|
}
|
|
|
- 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 BooleanTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getBoolean(2)));
|
|
|
+ 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 BooleanTsData(rs.getTimestamp(1).getTime(), (short) 0, rs.getBoolean(2)));
|
|
|
+ }
|
|
|
}
|
|
|
+ return tsDataMap;
|
|
|
}
|
|
|
- return tsDataMap;
|
|
|
- }
|
|
|
|
|
|
-}
|
|
|
+ }
|