<?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.OriginalMapper">
  <resultMap id="BaseResultMap" type="com.sckw.slope.detection.model.dos.tdengine.Original">
    <!--@mbg.generated-->
    <!--@Table original-->
    <id column="ts" jdbcType="TIMESTAMP" property="ts" />
    <result column="raw_str" jdbcType="VARCHAR" property="rawStr" />
    <result column="guid" jdbcType="VARCHAR" property="guid" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    ts, raw_str, guid
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.util.Date" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from devicesv2.original
    where ts = #{ts,jdbcType=TIMESTAMP}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.util.Date">
    <!--@mbg.generated-->
    delete from devicesv2.original
    where ts = #{ts,jdbcType=TIMESTAMP}
  </delete>
  <insert id="insert" parameterType="com.sckw.slope.detection.model.dos.tdengine.Original">
    <!--@mbg.generated-->
    insert into devicesv2.original (ts, raw_str, guid
      )
    values (#{ts,jdbcType=TIMESTAMP}, #{rawStr,jdbcType=VARCHAR}, #{guid,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.tdengine.Original">
    <!--@mbg.generated-->
    insert into original
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="ts != null">
        ts,
      </if>
      <if test="rawStr != null">
        raw_str,
      </if>
      <if test="guid != null">
        guid,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="ts != null">
        #{ts,jdbcType=TIMESTAMP},
      </if>
      <if test="rawStr != null">
        #{rawStr,jdbcType=VARCHAR},
      </if>
      <if test="guid != null">
        #{guid,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.sckw.slope.detection.model.dos.tdengine.Original">
    <!--@mbg.generated-->
    update devicesv2.original
    <set>
      <if test="rawStr != null">
        raw_str = #{rawStr,jdbcType=VARCHAR},
      </if>
      <if test="guid != null">
        guid = #{guid,jdbcType=VARCHAR},
      </if>
    </set>
    where ts = #{ts,jdbcType=TIMESTAMP}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.sckw.slope.detection.model.dos.tdengine.Original">
    <!--@mbg.generated-->
    update devicesv2.original
    set raw_str = #{rawStr,jdbcType=VARCHAR},
      guid = #{guid,jdbcType=VARCHAR}
    where ts = #{ts,jdbcType=TIMESTAMP}
  </update>

  <select id="selectByData" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List">
      </include>
      FROM devicesv2.original_${deviceCode}
      order by ts desc limit 1
    </select>

  <select id="selectListLimit" resultType="com.sckw.slope.detection.model.vo.OriginalDeviceVO">
      SELECT raw_str as jsonText,
             guid,
             ts
      from devicesv2.original_${deviceSn}
      order by ts desc limit #{newPage}, #{pageSize}
  </select>

  <select id="selectDataCount" resultType="java.lang.Integer">
      SELECT count(ts)
      from devicesv2.original_${deviceSn}
    </select>
</mapper>