删除不必要的工具类
parent
eacd2806b8
commit
50f9dcbff5
|
@ -1,55 +0,0 @@
|
||||||
package com.template.controller;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
/**
|
|
||||||
* @Author:liuxinyue
|
|
||||||
* @Package:com.template.controller
|
|
||||||
* @Project:cloud-server
|
|
||||||
* @name:ServiceController
|
|
||||||
* @Date:2024/9/22 22:12
|
|
||||||
*/
|
|
||||||
@Log4j2
|
|
||||||
public class ServiceController {
|
|
||||||
|
|
||||||
private final String IOTDB_DRIVER="org.apache.iotdb.jdbc.IoTDBDriver";
|
|
||||||
private static final String url="jdbc:iotdb://47.116.173.119:6667/";
|
|
||||||
private static final String userName="root";
|
|
||||||
private static final String passWord="root";
|
|
||||||
|
|
||||||
public void ToIoTDB(String url, String userName, String passWord){
|
|
||||||
log.info("Connecting to IoTDB");
|
|
||||||
log.info("地址是:"+url);
|
|
||||||
log.info("用户名是:"+userName);
|
|
||||||
log.info("密码是:"+passWord);
|
|
||||||
log.info("红红火火恍恍惚惚");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try{
|
|
||||||
Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
|
|
||||||
DriverManager.getConnection(url,userName,passWord);
|
|
||||||
}catch(SQLException e){
|
|
||||||
log.error("SQLException: " + e.getMessage());
|
|
||||||
log.error("SQLState: " + e.getSQLState());
|
|
||||||
log.error("VendorError: " + e.getErrorCode());
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createConnection() throws ClassNotFoundException, SQLException {
|
|
||||||
|
|
||||||
try{
|
|
||||||
Class.forName(IOTDB_DRIVER);
|
|
||||||
DriverManager.getConnection(url,userName,passWord);
|
|
||||||
}catch(SQLException e){
|
|
||||||
log.error("SQLException: " + e.getMessage());
|
|
||||||
log.error("SQLState: " + e.getSQLState());
|
|
||||||
log.error("VendorError: " + e.getErrorCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,7 +5,7 @@ import com.template.mapper.TemplateMapper;
|
||||||
import com.template.service.CarService;
|
import com.template.service.CarService;
|
||||||
import com.template.service.MessageTemplateTypeService;
|
import com.template.service.MessageTemplateTypeService;
|
||||||
import com.template.service.TemplateService;
|
import com.template.service.TemplateService;
|
||||||
import com.template.util.ToIoTDB;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||||
|
@ -14,6 +14,7 @@ import org.apache.iotdb.session.SessionDataSet;
|
||||||
import org.apache.iotdb.session.util.Version;
|
import org.apache.iotdb.session.util.Version;
|
||||||
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
|
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -39,8 +40,11 @@ public class TemplateServiceImpl implements TemplateService{
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageTemplateTypeService messageTemplateTypeService;
|
private MessageTemplateTypeService messageTemplateTypeService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ToIoTDB toIoTDB;
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Template> templateList() {
|
public List<Template> templateList() {
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package com.template.util;
|
|
||||||
import java.sql.Connection;
|
|
||||||
/**
|
|
||||||
* @Author:liuxinyue
|
|
||||||
* @Package:com.template.util
|
|
||||||
* @Project:cloud-server
|
|
||||||
* @name:IOTDBConnectionTets
|
|
||||||
* @Date:2024/9/24 10:34
|
|
||||||
*/
|
|
||||||
public class IOTDBConnectionTets {
|
|
||||||
|
|
||||||
private static final String url = "jdbc:iotdb://47.116.173.119:6667/";
|
|
||||||
private static final String username = "root";
|
|
||||||
private static final String password = "root";
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Connection conn = new IOTdbJDBCUtils(url, username, password).getConnection();
|
|
||||||
System.out.println(conn != null ? "打开连接成功!" : "打开连接失败!");
|
|
||||||
IOTdbJDBCUtils.close(conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
package com.template.util;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author:liuxinyue
|
|
||||||
* @Package:com.template.util
|
|
||||||
* @Project:cloud-server
|
|
||||||
* @name:IOTdbJDBCUtils
|
|
||||||
* @Date:2024/9/24 10:18
|
|
||||||
*/
|
|
||||||
public class IOTdbJDBCUtils {
|
|
||||||
private static final String driver = "org.apache.iotdb.jdbc.IoTDBDriver";
|
|
||||||
private final String url;
|
|
||||||
private final String username;
|
|
||||||
private final String password;
|
|
||||||
|
|
||||||
public IOTdbJDBCUtils(String url, String username, String password) {
|
|
||||||
this.url = url;
|
|
||||||
this.username = username;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
Class.forName(driver);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
System.out.println("当前加载的驱动不存在........,请检查后重试!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection getConnection() {
|
|
||||||
Connection connection = null;
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(url, username, password);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void close(Connection conn) {
|
|
||||||
if (conn != null) {
|
|
||||||
try {
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.template.util;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:liuxinyue
|
||||||
|
* @Package:com.template.util
|
||||||
|
* @Project:cloud-server
|
||||||
|
* @name:StringCutterUtils
|
||||||
|
* @Date:2024/9/25 21:18
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class StringCutterUtils {
|
||||||
|
|
||||||
|
public static String hexadecimalCharacter(String s){
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
int len = s.length();
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
char c = s.charAt(i);
|
||||||
|
String hexString = Integer.toHexString(c);
|
||||||
|
stringBuilder.append(hexString+" ");
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String s = hexadecimalCharacter("3C3F786D6C2076657273696F6E3D22312E30223F3E0D0A3C6D6F6E69746F72526F6F7420747970653D22706172616D223E3C73796E6368726F6E697A65537970746F6D206576656E743D22302220696E697469616C3D2274727565223E3C416374696F6E5F4543473E3C52687974686D3E53696E75733C2F52687974686D3E3C48523E38303C2F48523E3C454D443E4E6F204368616E67653C2F454D443E3C436F6E647563743E303C2F436F6E647563743E3C2F416374696F6E5F4543473E3C416374696F6E5F4F7361742076616C75653D2239342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F425020697352656C617469766550657263656E743D2266616C7365223E3C536872696E6B2076616C75653D22313230222F3E3C537472657463682076616C75653D223830222F3E3C2F416374696F6E5F42503E3C416374696F6E5F5265737020627265617468547970653D224E6F726D616C222076616C75653D2231342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F6574434F322076616C75653D2233342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F54656D70657261747572652076616C75653D2233352E32222F3E3C416374696F6E5F4356502076616C75653D22362E30222F3E3C416374696F6E5F5041504469612076616C75653D223130222F3E3C416374696F6E5F5041505379732076616C75653D223235222F3E3C416374696F6E5F57502076616C75653D2239222F3E3C2F73796E6368726F6E697A65537970746F6D3E3C2F6D6F6E69746F72526F6F743E0D0A");
|
||||||
|
String string = toString(s);
|
||||||
|
log.info(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toString(String s){
|
||||||
|
|
||||||
|
if(s==null || s.equals("")){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
log.info("将字符串中的空格去除");
|
||||||
|
s = s.replace(" ", "");
|
||||||
|
byte[] bytes = new byte[s.length() / 2];
|
||||||
|
for (int i = 0; i < bytes.length; i++) {
|
||||||
|
bytes[i] = (byte) (0xff & Integer.parseInt(s.substring(i*2,i*2+2), 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
s=new String(bytes, StandardCharsets.UTF_8);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,19 +1,14 @@
|
||||||
package com.template.util;
|
package com.template.util;
|
||||||
|
|
||||||
import com.template.domain.MessageTemplateType;
|
import com.template.domain.MessageTemplateType;
|
||||||
import com.template.domain.Template;
|
import com.template.domain.Template;
|
||||||
import com.template.service.TemplateService;
|
import com.template.service.TemplateService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.redis.core.ListOperations;
|
import org.springframework.data.redis.core.ListOperations;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:liuxinyue
|
* @Author:liuxinyue
|
||||||
* @Package:com.template.util
|
* @Package:com.template.util
|
||||||
|
@ -30,7 +25,6 @@ public class SynchronizingTemplate {
|
||||||
@Resource
|
@Resource
|
||||||
private TemplateService templateService;
|
private TemplateService templateService;
|
||||||
|
|
||||||
|
|
||||||
//redis
|
//redis
|
||||||
@Resource
|
@Resource
|
||||||
private RedisTemplate redisTemplate;
|
private RedisTemplate redisTemplate;
|
||||||
|
@ -56,7 +50,5 @@ public class SynchronizingTemplate {
|
||||||
log.info("数据为:"+o);
|
log.info("数据为:"+o);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package com.template.util;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
/**
|
|
||||||
* @Author:liuxinyue
|
|
||||||
* @Package:com.template.util
|
|
||||||
* @Project:cloud-server
|
|
||||||
* @name:ToIoTDB 连接IoTDB数据库
|
|
||||||
* @Date:2024/9/20 19:40
|
|
||||||
*/
|
|
||||||
@Log4j2
|
|
||||||
@Configuration
|
|
||||||
public class ToIoTDB {
|
|
||||||
|
|
||||||
private final String IOTDB_DRIVER="org.apache.iotdb.jdbc.IoTDBDriver";
|
|
||||||
private static final String url="jdbc:iotdb://47.116.173.119:6667/";
|
|
||||||
private static final String userName="root";
|
|
||||||
private static final String passWord="root";
|
|
||||||
|
|
||||||
public Connection getConnection() throws ClassNotFoundException, SQLException {
|
|
||||||
Connection connection=null;
|
|
||||||
try{
|
|
||||||
Class.forName(IOTDB_DRIVER);
|
|
||||||
connection = DriverManager.getConnection(url, userName, passWord);
|
|
||||||
}catch(SQLException e){
|
|
||||||
log.error("SQLException: " + e.getMessage());
|
|
||||||
log.error("SQLState: " + e.getSQLState());
|
|
||||||
log.error("VendorError: " + e.getErrorCode());
|
|
||||||
}
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
package com.template.util;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author:liuxinyue
|
|
||||||
* @Package:com.template.util
|
|
||||||
* @Project:cloud-server
|
|
||||||
* @name:ToIoTDBTest
|
|
||||||
* @Date:2024/9/24 10:12
|
|
||||||
*/
|
|
||||||
public class ToIoTDBTest {
|
|
||||||
|
|
||||||
private static final String host = "47.116.173.119";
|
|
||||||
private static final String url = "jdbc:iotdb://" + host + ":6667/";
|
|
||||||
private static final String username = "root";
|
|
||||||
private static final String password = "root";
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws SQLException, ClassNotFoundException {
|
|
||||||
|
|
||||||
ToIoTDB toIoTDB = new ToIoTDB();
|
|
||||||
Connection connection = toIoTDB.getConnection();
|
|
||||||
// Connection connection = (Connection) new IOTdbJDBCUtils(url, username, password).getConnection();
|
|
||||||
System.out.println(connection!=null?"打开连接成功!":"打开连接失败!");
|
|
||||||
|
|
||||||
ResultSet rs=null;
|
|
||||||
String storgeGroup="root.test";
|
|
||||||
Statement statement = connection.createStatement();
|
|
||||||
String sql=String.format("set storage group to %s",storgeGroup);
|
|
||||||
statement = connection.createStatement();
|
|
||||||
int i = statement.executeUpdate(sql);
|
|
||||||
System.out.println("当前创建组的结果为:"+i);
|
|
||||||
|
|
||||||
//查看创建的组是否存在
|
|
||||||
sql="SHOW STORAGE GROUPS"; //查看所有的存储组
|
|
||||||
rs= statement.executeQuery(sql);
|
|
||||||
outputResult(rs);
|
|
||||||
|
|
||||||
sql=String.format("show storage group %s",storgeGroup);
|
|
||||||
rs=statement.executeQuery(sql);
|
|
||||||
outputResult(rs);
|
|
||||||
//统计存在的数量
|
|
||||||
sql=String.format("count storage group %s",storgeGroup);
|
|
||||||
rs=statement.executeQuery(sql);
|
|
||||||
outputResult(rs);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void outputResult(ResultSet resultSet) throws SQLException {
|
|
||||||
if (resultSet != null) {
|
|
||||||
System.out.println("--------------------------");
|
|
||||||
final ResultSetMetaData metaData = resultSet.getMetaData();
|
|
||||||
final int columnCount = metaData.getColumnCount();
|
|
||||||
for (int i = 0; i < columnCount; i++) {
|
|
||||||
System.out.print(metaData.getColumnLabel(i + 1) + ", ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
while (resultSet.next()) {
|
|
||||||
for (int i = 1;; i++) {
|
|
||||||
System.out.print(resultSet.getString(i));
|
|
||||||
if (i < columnCount) {
|
|
||||||
System.out.print(", ");
|
|
||||||
} else {
|
|
||||||
System.out.println();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println("--------------------------\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue