1、将mybatis-plus升级到3.5以上:
<!-- 支持tdengine,mybatis-plus需要升级到3.5.3 -->
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.17</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3</version>
</dependency>
2、配置yaml文件:
server:
port: 11400 #端口
spring:
datasource:
driver-class-name: com.taosdata.jdbc.TSDBDriver
url: jdbc:TAOS://192.168.50.35:6030/pks_gps_db
username: weizhi
password: 123456
druid:
initial-size: 5
min-idle: 5
max-active: 5
# max wait time for get connection, ms
max-wait: 60000
validation-query: select server_status();
validation-query-timeout: 5000
test-on-borrow: false
test-on-return: false
test-while-idle: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
3、创建数据库和超级表:
--创建数据库:pks_gps_db
DROP DATABASE IF EXISTS pks_gps_db;
CREATE DATABASE IF NOT EXISTS pks_gps_db KEEP 3650 ; --保存10年
--创建超级表:
use pks_gps_db;
--创建gps信息超级表
DROP STABLE IF EXISTS s_gps;
CREATE STABLE IF NOT EXISTS s_gps (ts timestamp ,e_quantity float,longitude double,latitude double,v_speed int,status int,r_mileage float,t_mileage float) TAGS (gps_imei nchar(64)) ;
4、DAO层展示:
package com.perkins.gps.platform.biz.dao;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import com.perkins.gps.platform.common.dto.SaveGpsInfoDTO;
import com.perkins.gps.platform.common.dto.SaveUploadGpsInfoDTO;
/**
*
* @ClassName: GpsInfoDao
* @Description: GPS信息DAO
* @author dingjy
* @date 2024年2月23日 下午2:22:04
*/
@Repository
public interface GpsInfoDao {
public static final String table_prefix="t_";
public static final String s_table_name="s_gps";
/**
*
* @Title: saveGpsInfo
* @Description: 注册终端信息
* @param dto
* @throws
*/
@Update("create table if not exists "+table_prefix+"#{gps_imei} using "+s_table_name+" tags(#{gps_imei})")
void saveGpsInfo(SaveGpsInfoDTO dto);
/**
*
* @Title: saveUploadGpsInfo
* @Description: GPS信息上报
* @param dto
* @throws
*/
@Insert("insert into "+table_prefix+"#{gps_imei} using "+s_table_name+" tags(#{gps_imei}) values (now(),#{e_quantity},#{longitude},#{latitude},#{v_speed},#{status},#{r_mileage},#{t_mileage})")
void saveUploadGpsInfo(SaveUploadGpsInfoDTO dto);
}