ADD: datasource test
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -31,3 +31,7 @@ build/
|
|||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
/.mvn/
|
||||||
|
mvnw
|
||||||
|
mvnw.cmd
|
||||||
|
|||||||
3
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
3
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
wrapperVersion=3.3.4
|
||||||
|
distributionType=only-script
|
||||||
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip
|
||||||
28
docker/docker-compose.yaml
Normal file
28
docker/docker-compose.yaml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
services:
|
||||||
|
tsdb:
|
||||||
|
image: tdengine/tsdb:3.3.8.8
|
||||||
|
hostname: tsdb
|
||||||
|
ports:
|
||||||
|
- "6030:6030"
|
||||||
|
- "6041:6041"
|
||||||
|
- "6043:6043"
|
||||||
|
- "6060:6060"
|
||||||
|
- "6044-6049:6044-6049"
|
||||||
|
- "6044-6045:6044-6045/udp"
|
||||||
|
- "6050:6050"
|
||||||
|
- "6055:6055"
|
||||||
|
- "6030-6060:6030-6060/udp"
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:15.15
|
||||||
|
hostname: postgres
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
environment:
|
||||||
|
- TZ=Asia/Shanghai
|
||||||
|
- POSTGRES_USER=energy
|
||||||
|
- POSTGRES_PASSWORD=energy
|
||||||
|
- POSTGRES_DB=energy
|
||||||
|
restart: always
|
||||||
|
|
||||||
40
pom.xml
40
pom.xml
@@ -35,6 +35,41 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Sa-Token 权限认证,在线文档:https://sa-token.cc -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-spring-boot3-starter</artifactId>
|
||||||
|
<version>1.44.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 数据库 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||||
|
<version>1.2.27</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||||
|
<version>1.11.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.11.4</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
|
<version>3.7.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<version>42.7.8</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@@ -58,6 +93,11 @@
|
|||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</path>
|
</path>
|
||||||
|
<path>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.11.4</version>
|
||||||
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package com.xapg.energystoragesafety;
|
package com.xapg.energystoragesafety;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@MapperScan("com.xapg.energystoragesafety.mapper")
|
||||||
public class EnergyStorageSafetyApplication {
|
public class EnergyStorageSafetyApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(EnergyStorageSafetyApplication.class, args);
|
SpringApplication.run(EnergyStorageSafetyApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.xapg.energystoragesafety.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Table("account")
|
||||||
|
public class Account {
|
||||||
|
@Id(keyType = KeyType.Auto)
|
||||||
|
private Long id;
|
||||||
|
private String userName;
|
||||||
|
private Integer age;
|
||||||
|
private Date birthday;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.xapg.energystoragesafety.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Table(value = "meters", dataSource = "tsdb")
|
||||||
|
public class Meters {
|
||||||
|
@Id
|
||||||
|
private Timestamp ts;
|
||||||
|
private Double current;
|
||||||
|
private Integer voltage;
|
||||||
|
private Double phase;
|
||||||
|
private Integer groupid;
|
||||||
|
private String location;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.xapg.energystoragesafety.mapper;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import com.xapg.energystoragesafety.entity.Account;
|
||||||
|
|
||||||
|
public interface AccountMapper extends BaseMapper<Account> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.xapg.energystoragesafety.mapper;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import com.xapg.energystoragesafety.entity.Meters;
|
||||||
|
|
||||||
|
public interface MetersMapper extends BaseMapper<Meters> {
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
spring.application.name=energy-storage-safety
|
|
||||||
38
src/main/resources/application.yaml
Normal file
38
src/main/resources/application.yaml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: energy-storage-safety
|
||||||
|
|
||||||
|
############## Sa-Token 配置 (文档: https://sa-token.cc) ##############
|
||||||
|
sa-token:
|
||||||
|
# token 名称(同时也是 cookie 名称)
|
||||||
|
token-name: energy-storage-safety
|
||||||
|
# token 有效期(单位:秒) 默认30天,-1 代表永久有效
|
||||||
|
timeout: 2592000
|
||||||
|
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
|
||||||
|
active-timeout: -1
|
||||||
|
# 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
|
||||||
|
is-concurrent: true
|
||||||
|
# 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
|
||||||
|
is-share: false
|
||||||
|
# token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
||||||
|
token-style: uuid
|
||||||
|
# 是否输出操作日志
|
||||||
|
is-log: true
|
||||||
|
|
||||||
|
mybatis-flex:
|
||||||
|
configuration:
|
||||||
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
datasource:
|
||||||
|
# 主数据源 - PostgreSQL
|
||||||
|
db:
|
||||||
|
url: jdbc:postgresql://localhost:5432/energy
|
||||||
|
username: energy
|
||||||
|
password: energy
|
||||||
|
driver-class-name: org.postgresql.Driver
|
||||||
|
|
||||||
|
# 从数据源 - TDengine
|
||||||
|
tsdb:
|
||||||
|
url: jdbc:TAOS-RS://localhost:6041/test?useSSL=false
|
||||||
|
username: root
|
||||||
|
password: taosdata
|
||||||
|
driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
package com.xapg.energystoragesafety;
|
package com.xapg.energystoragesafety;
|
||||||
|
|
||||||
|
import com.xapg.energystoragesafety.mapper.AccountMapper;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class EnergyStorageSafetyApplicationTests {
|
class EnergyStorageSafetyApplicationTests {
|
||||||
|
@Autowired
|
||||||
|
private AccountMapper accountMapper;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
||||||
|
System.out.println(accountMapper.selectAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/test/java/com/xapg/energystoragesafety/TDengineTest.java
Normal file
26
src/test/java/com/xapg/energystoragesafety/TDengineTest.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package com.xapg.energystoragesafety;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.xapg.energystoragesafety.mapper.MetersMapper;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import static com.xapg.energystoragesafety.Tables.METERS;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class TDengineTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MetersMapper metersMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertAndQuery() {
|
||||||
|
QueryWrapper qw = QueryWrapper.create()
|
||||||
|
.select() // 可选:指定字段,如 .select(YOUR_ENTITY.ID, YOUR_ENTITY.NAME)
|
||||||
|
.from(METERS) // 替换为你的表常量
|
||||||
|
.limit(200); // 限制最多 200 条
|
||||||
|
// 创建测试数据
|
||||||
|
metersMapper.selectListByQuery(qw).forEach(System.out::println);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user