<?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.coredasabnormalinfo.mapper.CoredasAbnormalInfoMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.coredasabnormalinfo.model.CoredasAbnormalInfo">
    <id column="NO" jdbcType="VARCHAR" property="no" />
    <result column="TAB_COL" jdbcType="VARCHAR" property="tabCol" />
    <result column="COL_NAME" jdbcType="VARCHAR" property="colName" />
    <result column="DATA_S" jdbcType="FLOAT" property="dataS" />
    <result column="DATA_UP" jdbcType="FLOAT" property="dataUp" />
    <result column="DATA_DOWN" jdbcType="FLOAT" property="dataDown" />
    <result column="OVER_STANDARD" jdbcType="VARCHAR" property="overStandard" />
    <result column="DATE_S" jdbcType="TIMESTAMP" property="dateS" />
  </resultMap>
  <sql id="columns">
    NO, TAB_COL, COL_NAME, DATA_S, DATA_UP, DATA_DOWN, OVER_STANDARD, DATE_S
  </sql>
  <sql id="columns_alias">
    t.NO, t.TAB_COL, t.COL_NAME, t.DATA_S, t.DATA_UP, t.DATA_DOWN, t.OVER_STANDARD, t.DATE_S
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM COREDAS_ABNORMAL_INFO
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM COREDAS_ABNORMAL_INFO t
  </sql>
  <sql id="where">
    <where> 
      <if test="no != null and no != ''">
        and NO = #{no}
      </if>
      <if test="tabCol != null and tabCol != ''">
        and TAB_COL = #{tabCol}
      </if>
      <if test="colName != null and colName != ''">
        and COL_NAME = #{colName}
      </if>
      <if test="dataS != null">
        and DATA_S = #{dataS}
      </if>
      <if test="dataUp != null">
        and DATA_UP = #{dataUp}
      </if>
      <if test="dataDown != null">
        and DATA_DOWN = #{dataDown}
      </if>
      <if test="overStandard != null and overStandard != ''">
        and OVER_STANDARD = #{overStandard}
      </if>
      <if test="dateS != null">
        and TO_CHAR(DATE_S,'yyyy-MM-dd') = #{dateS}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="no != null and no != ''">
        and NO LIKE '%${no}%'
      </if>
      <if test="tabCol != null and tabCol != ''">
        and TAB_COL LIKE '%${tabCol}%'
      </if>
      <if test="colName != null and colName != ''">
        and COL_NAME LIKE '%${colName}%'
      </if>
      <if test="dataS != null">
        and DATA_S = #{dataS}
      </if>
      <if test="dataUp != null">
        and DATA_UP = #{dataUp}
      </if>
      <if test="dataDown != null">
        and DATA_DOWN = #{dataDown}
      </if>
      <if test="overStandard != null and overStandard != ''">
        and OVER_STANDARD LIKE '%${overStandard}%'
      </if>
      <if test="dateS != null">
        and TO_CHAR(DATE_S,'yyyy-MM-dd') = #{dateS}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from COREDAS_ABNORMAL_INFO
    where NO = #{no,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from COREDAS_ABNORMAL_INFO
    where 1!=1 
      <if test="tabCol != null and tabCol != ''">
        or TAB_COL = #{tabCol}
      </if>
      <if test="colName != null and colName != ''">
        or COL_NAME = #{colName}
      </if>
      <if test="dataS != null">
        or DATA_S = #{dataS}
      </if>
      <if test="dataUp != null">
        or DATA_UP = #{dataUp}
      </if>
      <if test="dataDown != null">
        or DATA_DOWN = #{dataDown}
      </if>
      <if test="overStandard != null and overStandard != ''">
        or OVER_STANDARD = #{overStandard}
      </if>
      <if test="dateS != null">
        or TO_CHAR(DATE_S,'yyyy-MM-dd') = '#{dateS}'
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.coredasabnormalinfo.model.CoredasAbnormalInfo">
    insert into COREDAS_ABNORMAL_INFO (NO, TAB_COL, COL_NAME, 
      DATA_S, DATA_UP, DATA_DOWN, 
      OVER_STANDARD, DATE_S)
    values (#{no,jdbcType=VARCHAR}, #{tabCol,jdbcType=VARCHAR}, #{colName,jdbcType=VARCHAR}, 
      #{dataS,jdbcType=FLOAT}, #{dataUp,jdbcType=FLOAT}, #{dataDown,jdbcType=FLOAT}, 
      #{overStandard,jdbcType=VARCHAR}, #{dateS,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.coredasabnormalinfo.model.CoredasAbnormalInfo">
    insert into COREDAS_ABNORMAL_INFO
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="no != null">
        NO,
      </if>
      <if test="tabCol != null">
        TAB_COL,
      </if>
      <if test="colName != null">
        COL_NAME,
      </if>
      <if test="dataS != null">
        DATA_S,
      </if>
      <if test="dataUp != null">
        DATA_UP,
      </if>
      <if test="dataDown != null">
        DATA_DOWN,
      </if>
      <if test="overStandard != null">
        OVER_STANDARD,
      </if>
      <if test="dateS != null">
        DATE_S,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="no != null">
        #{no,jdbcType=VARCHAR},
      </if>
      <if test="tabCol != null">
        #{tabCol,jdbcType=VARCHAR},
      </if>
      <if test="colName != null">
        #{colName,jdbcType=VARCHAR},
      </if>
      <if test="dataS != null">
        #{dataS,jdbcType=FLOAT},
      </if>
      <if test="dataUp != null">
        #{dataUp,jdbcType=FLOAT},
      </if>
      <if test="dataDown != null">
        #{dataDown,jdbcType=FLOAT},
      </if>
      <if test="overStandard != null">
        #{overStandard,jdbcType=VARCHAR},
      </if>
      <if test="dateS != null">
        #{dateS,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.coredasabnormalinfo.model.CoredasAbnormalInfo">
    update COREDAS_ABNORMAL_INFO
    set TAB_COL = #{tabCol,jdbcType=VARCHAR},
      COL_NAME = #{colName,jdbcType=VARCHAR},
      DATA_S = #{dataS,jdbcType=FLOAT},
      DATA_UP = #{dataUp,jdbcType=FLOAT},
      DATA_DOWN = #{dataDown,jdbcType=FLOAT},
      OVER_STANDARD = #{overStandard,jdbcType=VARCHAR},
      DATE_S = #{dateS,jdbcType=TIMESTAMP}
    where NO = #{no,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.coredasabnormalinfo.model.CoredasAbnormalInfo">
    update COREDAS_ABNORMAL_INFO
    <set>
      <if test="tabCol != null">
        TAB_COL = #{tabCol,jdbcType=VARCHAR},
      </if>
      <if test="colName != null">
        COL_NAME = #{colName,jdbcType=VARCHAR},
      </if>
      <if test="dataS != null">
        DATA_S = #{dataS,jdbcType=FLOAT},
      </if>
      <if test="dataUp != null">
        DATA_UP = #{dataUp,jdbcType=FLOAT},
      </if>
      <if test="dataDown != null">
        DATA_DOWN = #{dataDown,jdbcType=FLOAT},
      </if>
      <if test="overStandard != null">
        OVER_STANDARD = #{overStandard,jdbcType=VARCHAR},
      </if>
      <if test="dateS != null">
        DATE_S = #{dateS,jdbcType=TIMESTAMP},
      </if>
    </set>
    where NO = #{no,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where NO = #{no,jdbcType=VARCHAR}
  </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 COREDAS_ABNORMAL_INFO 
      (NO, 
      TAB_COL, COL_NAME, DATA_S, 
      DATA_UP, DATA_DOWN, OVER_STANDARD, 
      DATE_S)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.no,jdbcType=VARCHAR}, 
      #{item.tabCol,jdbcType=VARCHAR}, #{item.colName,jdbcType=VARCHAR}, #{item.dataS,jdbcType=FLOAT}, 
      #{item.dataUp,jdbcType=FLOAT}, #{item.dataDown,jdbcType=FLOAT}, #{item.overStandard,jdbcType=VARCHAR}, 
      #{item.dateS,jdbcType=TIMESTAMP} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update COREDAS_ABNORMAL_INFO
     set
       NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.no,jdbcType=VARCHAR}
       </foreach>
       ,TAB_COL=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.tabCol,jdbcType=VARCHAR}
       </foreach>
       ,COL_NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.colName,jdbcType=VARCHAR}
       </foreach>
       ,DATA_S=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.dataS,jdbcType=FLOAT}
       </foreach>
       ,DATA_UP=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.dataUp,jdbcType=FLOAT}
       </foreach>
       ,DATA_DOWN=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.dataDown,jdbcType=FLOAT}
       </foreach>
       ,OVER_STANDARD=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.overStandard,jdbcType=VARCHAR}
       </foreach>
       ,DATE_S=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.dateS,jdbcType=TIMESTAMP}
       </foreach>
     where NO in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.no,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from COREDAS_ABNORMAL_INFO
    where NO in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <!-- 查询能源瞬时数据 -->
  <select id="getCoredasData" parameterType="java.util.HashMap" resultType="Map">
	select * from
    (select * from COREDAS_AR where tmstmp > sysdate-6/86400) a full join
    (select * from COREDAS_BFG where tmstmp > sysdate-6/86400) b on 1=1 full join
    (select * from COREDAS_CLD where tmstmp > sysdate-6/86400) c on 1=1 full join
    (select * from COREDAS_COG where tmstmp > sysdate-6/86400) cog on 1=1 full join
    (select * from COREDAS_N2 where tmstmp > sysdate-6/86400) n on 1=1 full join
    (select * from COREDAS_O2 where tmstmp > sysdate-6/86400) o on 1=1
    <!--
    select * from COREDAS_AR a
    full join COREDAS_BFG b on 1=1
    full join COREDAS_CLD c on 1=1
    full join COREDAS_COG cog on 1=1
    full join COREDAS_N2 n on 1=1
    full join COREDAS_O2 o on 1=1
    -->
  </select>
  
  <!-- 查询能源标准数据 -->
  <select id="getCoredasStdData" parameterType="java.util.HashMap" resultType="Map">
    select * from COREDAS_AR_STANDARD
	full join COREDAS_BFG_STANDARD on 1=1
	full join COREDAS_CLD_STANDARD on 1=1
	full join COREDAS_COG_STANDARD on 1=1
	full join COREDAS_N2_STANDARD on 1=1
	full join COREDAS_O2_STANDARD on 1=1
  </select>
  
  <!-- 查询监控的能源名称、字段 -->
  <select id="getEmsCoredas" parameterType="java.util.HashMap" resultType="Map">
    select t.table_name,t.COLUMN_NAME,c.COMMENTS from user_tab_cols t inner join user_col_comments c
    on t.table_name=c.table_name and t.COLUMN_NAME=c.COLUMN_NAME
    where regexp_like(t.table_name, '^COREDAS_[A-Z0-9]+$') and t.DATA_TYPE='FLOAT'
    <if test="comments != null and comments != ''">
        and c.COMMENTS like '%${comments}%'
    </if>
    order by t.TABLE_NAME,t.COLUMN_NAME
  </select>
  
  <!-- 查询历史报警数据 -->
  <select id="getEmsCoredasWarnHis" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <where>
      <if test="clock != null and clock != ''">
          and TO_CHAR(DATE_S,'yyyy-MM-dd hh24:mi:ss') &gt;= #{clock}
      </if>
      <if test="clocke != null and clocke != ''">
          and TO_CHAR(DATE_S,'yyyy-MM-dd hh24:mi:ss') &lt;= #{clocke}
      </if>
    </where>
    order by DATE_S desc
  </select>
</mapper>