<?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.steerinfo.ems.rttable.mapper.RttableMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.rttable.model.Rttable">
    <id column="ID" jdbcType="DECIMAL" property="id" />
    <result column="ALTID" jdbcType="VARCHAR" property="altid" />
    <result column="RTVALUE" jdbcType="DECIMAL" property="rtvalue" />
    <result column="ALARMSTATUS" jdbcType="DECIMAL" property="alarmstatus" />
    <result column="COMMSTATUS" jdbcType="DECIMAL" property="commstatus" />
    <result column="UPDATETIME" jdbcType="TIMESTAMP" property="updatetime" />
    <result column="NOTE" jdbcType="VARCHAR" property="note" />
  </resultMap>
  <sql id="columns">
    ID, ALTID, RTVALUE, ALARMSTATUS, COMMSTATUS, UPDATETIME, NOTE
  </sql>
  <sql id="columns_alias">
    t.ID, t.ALTID, t.RTVALUE, t.ALARMSTATUS, t.COMMSTATUS, t.UPDATETIME, t.NOTE
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM RTTABLE
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM RTTABLE t
  </sql>
  <sql id="where">
    <where> 
      <if test="id != null">
        and ID = #{id}
      </if>
      <if test="altid != null and altid != ''">
        and ALTID = #{altid}
      </if>
      <if test="rtvalue != null">
        and RTVALUE = #{rtvalue}
      </if>
      <if test="alarmstatus != null">
        and ALARMSTATUS = #{alarmstatus}
      </if>
      <if test="commstatus != null">
        and COMMSTATUS = #{commstatus}
      </if>
      <if test="updatetime != null">
        and TO_CHAR(UPDATETIME,'yyyy-MM-dd') = #{updatetime}
      </if>
      <if test="note != null and note != ''">
        and NOTE = #{note}
      </if>
    </where>
    order by ALTID
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="id != null">
        and ID = #{id}
      </if>
      <if test="altid != null and altid != ''">
        and ALTID LIKE '%${altid}%'
      </if>
      <if test="rtvalue != null">
        and RTVALUE = #{rtvalue}
      </if>
      <if test="alarmstatus != null">
        and ALARMSTATUS = #{alarmstatus}
      </if>
      <if test="commstatus != null">
        and COMMSTATUS = #{commstatus}
      </if>
      <if test="updatetime != null">
        and TO_CHAR(UPDATETIME,'yyyy-MM-dd') = #{updatetime}
      </if>
      <if test="note != null and note != ''">
        and NOTE LIKE '%${note}%'
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.math.BigDecimal">
    delete from RTTABLE
    where ID = #{id,jdbcType=DECIMAL}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from RTTABLE
    where 1!=1 
      <if test="altid != null and altid != ''">
        or ALTID = #{altid}
      </if>
      <if test="rtvalue != null">
        or RTVALUE = #{rtvalue}
      </if>
      <if test="alarmstatus != null">
        or ALARMSTATUS = #{alarmstatus}
      </if>
      <if test="commstatus != null">
        or COMMSTATUS = #{commstatus}
      </if>
      <if test="updatetime != null">
        or TO_CHAR(UPDATETIME,'yyyy-MM-dd') = '#{updatetime}'
      </if>
      <if test="note != null and note != ''">
        or NOTE = #{note}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.rttable.model.Rttable">
    insert into RTTABLE (ID, ALTID, RTVALUE, 
      ALARMSTATUS, COMMSTATUS, UPDATETIME, 
      NOTE)
    values (#{id,jdbcType=DECIMAL}, #{altid,jdbcType=VARCHAR}, #{rtvalue,jdbcType=DECIMAL}, 
      #{alarmstatus,jdbcType=DECIMAL}, #{commstatus,jdbcType=DECIMAL}, #{updatetime,jdbcType=TIMESTAMP}, 
      #{note,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.rttable.model.Rttable">
    insert into RTTABLE
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="altid != null">
        ALTID,
      </if>
      <if test="rtvalue != null">
        RTVALUE,
      </if>
      <if test="alarmstatus != null">
        ALARMSTATUS,
      </if>
      <if test="commstatus != null">
        COMMSTATUS,
      </if>
      <if test="updatetime != null">
        UPDATETIME,
      </if>
      <if test="note != null">
        NOTE,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=DECIMAL},
      </if>
      <if test="altid != null">
        #{altid,jdbcType=VARCHAR},
      </if>
      <if test="rtvalue != null">
        #{rtvalue,jdbcType=DECIMAL},
      </if>
      <if test="alarmstatus != null">
        #{alarmstatus,jdbcType=DECIMAL},
      </if>
      <if test="commstatus != null">
        #{commstatus,jdbcType=DECIMAL},
      </if>
      <if test="updatetime != null">
        #{updatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="note != null">
        #{note,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.rttable.model.Rttable">
    update RTTABLE
    set ALTID = #{altid,jdbcType=VARCHAR},
      RTVALUE = #{rtvalue,jdbcType=DECIMAL},
      ALARMSTATUS = #{alarmstatus,jdbcType=DECIMAL},
      COMMSTATUS = #{commstatus,jdbcType=DECIMAL},
      UPDATETIME = #{updatetime,jdbcType=TIMESTAMP},
      NOTE = #{note,jdbcType=VARCHAR}
    where ID = #{id,jdbcType=DECIMAL}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.rttable.model.Rttable">
    update RTTABLE
    <set>
      <if test="altid != null">
        ALTID = #{altid,jdbcType=VARCHAR},
      </if>
      <if test="rtvalue != null">
        RTVALUE = #{rtvalue,jdbcType=DECIMAL},
      </if>
      <if test="alarmstatus != null">
        ALARMSTATUS = #{alarmstatus,jdbcType=DECIMAL},
      </if>
      <if test="commstatus != null">
        COMMSTATUS = #{commstatus,jdbcType=DECIMAL},
      </if>
      <if test="updatetime != null">
        UPDATETIME = #{updatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="note != null">
        NOTE = #{note,jdbcType=VARCHAR},
      </if>
    </set>
    where ID = #{id,jdbcType=DECIMAL}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.math.BigDecimal" resultMap="BaseResultMap">
    <include refid="select"/>
    where ID = #{id,jdbcType=DECIMAL}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="where"/>
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into RTTABLE 
      (ID, 
      ALTID, RTVALUE, ALARMSTATUS, 
      COMMSTATUS, UPDATETIME, NOTE
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.id,jdbcType=DECIMAL}, 
      #{item.altid,jdbcType=VARCHAR}, #{item.rtvalue,jdbcType=DECIMAL}, #{item.alarmstatus,jdbcType=DECIMAL}, 
      #{item.commstatus,jdbcType=DECIMAL}, #{item.updatetime,jdbcType=TIMESTAMP}, #{item.note,jdbcType=VARCHAR}
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update RTTABLE
     set
       ID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.id,jdbcType=DECIMAL}
       </foreach>
       ,ALTID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.altid,jdbcType=VARCHAR}
       </foreach>
       ,RTVALUE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.rtvalue,jdbcType=DECIMAL}
       </foreach>
       ,ALARMSTATUS=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.alarmstatus,jdbcType=DECIMAL}
       </foreach>
       ,COMMSTATUS=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.commstatus,jdbcType=DECIMAL}
       </foreach>
       ,UPDATETIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.updatetime,jdbcType=TIMESTAMP}
       </foreach>
       ,NOTE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.note,jdbcType=VARCHAR}
       </foreach>
     where ID in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.id,jdbcType=DECIMAL}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from RTTABLE
    where ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <insert id="insertPowerTenMinutes" parameterType="java.util.HashMap">
    INSERT INTO EMS_POWER_TIMING(TMSTMP) VALUES
    (to_date (#{clock1,jdbcType=TIME}, 'YYYY-MM-DD HH24:MI:SS' )
    )
  </insert>
  <update id="updatePowerTenMinutes" parameterType="java.util.HashMap">
    update EMS_POWER_TIMING
    <set>
      ${sql}
    </set>
    where TMSTMP =to_date (#{clock1,jdbcType=TIME}, 'YYYY-MM-DD HH24:MI:SS' )
  </update>
  <update id="updatePowerMinutes" parameterType="java.util.HashMap">
    update ${table}
    <set>
      <if test="clock != null and clock != ''">
        TMSTMP = to_date (#{clock,jdbcType=TIME}, 'YYYY-MM-DD HH24:MI:SS' )
      </if>
      ${sql}
    </set>
  </update>
  <select id="selectPowerAltId" resultMap="BaseResultMap">
    SELECT p.ALTID,p.RTVALUE,BTYPE2 AS NOTE
    FROM T_RM_CALPOINT c
    INNER JOIN RTTABLE p ON c.TAGID = p.ALTID
    AND c.ENERGYTYPEID  IN ('P','X') AND c.ITEMTYPE='AUTO'  AND c.USEFLAG = '1' AND RTVALUE IS NOT NULL
  </select>
  <select id="selectElectricAltId" resultMap="BaseResultMap">
    SELECT p.ALTID,p.RTVALUE,BTYPE2 AS NOTE
    FROM T_RM_CALPOINT c
                 INNER JOIN RTTABLE p ON c.TAGID = p.ALTID
            AND c.ENERGYTYPEID = 'E' AND c.ITEMTYPE='AUTO'  AND c.USEFLAG = '1' AND RTVALUE IS NOT NULL
  </select>
</mapper>