<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sckw.slope.detection.dao.tdengine.InsTablesMapper">
    <resultMap id="BaseResultMap" type="com.sckw.slope.detection.model.dos.tdengine.InsTables">
        <!--@mbg.generated-->
        <!--@Table ins_tables-->
        <id column="table_name" jdbcType="VARCHAR" property="tableName"/>
        <result column="db_name" jdbcType="VARCHAR" property="dbName"/>
        <result column="createTime" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="columns" jdbcType="INTEGER" property="columns"/>
        <result column="stable_name" jdbcType="VARCHAR" property="stableName"/>
        <result column="uid" jdbcType="INTEGER" property="uid"/>
        <result column="vgroup_id" jdbcType="INTEGER" property="vgroupId"/>
        <!--        <result column="ttl" jdbcType="TINYINT" property="ttl"/>-->
        <result column="table_comment" jdbcType="TINYINT" property="tableComment"/>
        <result column="type" jdbcType="VARCHAR" property="type"/>
    </resultMap>

    <sql id="Base_List">
        table_name    as tableName,
        db_name       as dbName,
        create_time as createTime,
        columns,
        stable_name   as stableName,
        uid,
        vgroup_id     as vgroupId,
        table_comment as tableComment,
        type
    </sql>

    <select id="selectTableIsExit" resultType="com.sckw.slope.detection.model.dos.tdengine.InsTables">
        select
        <include refid="Base_List">
        </include>
        from information_schema.ins_tables a
        where a.db_name = 'devicesv2'
          and a.table_name = #{tableName}
    </select>

    <insert id="createTable">
        CREATE TABLE #{tableName}
        (
            ts          TIMESTAMP,
            tslver_id   INT,
            line        VARCHAR(64),
            val         VARCHAR(64),
            msg_id      VARCHAR(64),
            guid        VARCHAR(64),
            raw_ts      TIMESTAMP
        )
    </insert>
</mapper>