|
@@ -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 {
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|