ADD: datasource test
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package com.xapg.energystoragesafety;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.xapg.energystoragesafety.mapper")
|
||||
public class EnergyStorageSafetyApplication {
|
||||
|
||||
public static void main(String[] 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;
|
||||
|
||||
import com.xapg.energystoragesafety.mapper.AccountMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class EnergyStorageSafetyApplicationTests {
|
||||
@Autowired
|
||||
private AccountMapper accountMapper;
|
||||
|
||||
@Test
|
||||
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