<?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.usagedata.mapper.UsageDataMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.usagedata.model.UsageData">
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="DATA_CODE" jdbcType="VARCHAR" property="dataCode" />
    <result column="DATA_NAME" jdbcType="VARCHAR" property="dataName" />
    <result column="DT" jdbcType="VARCHAR" property="dt" />
    <result column="USAGE" jdbcType="DECIMAL" property="usage" />
    <result column="CT" jdbcType="TIMESTAMP" property="ct" />
    <result column="STATUS" jdbcType="VARCHAR" property="status" />
    <result column="UNIT" jdbcType="VARCHAR" property="unit" />
    <result column="GRANULARITY" jdbcType="VARCHAR" property="granularity" />
    <result column="CZR" jdbcType="VARCHAR" property="czr" />
    <result column="MEMO" jdbcType="VARCHAR" property="memo" />
    <result column="UPMAN" jdbcType="VARCHAR" property="upman" />
    <result column="UPTIME" jdbcType="TIMESTAMP" property="uptime" />
    <result column="OPERATOR_MAN" jdbcType="VARCHAR" property="operatorMan" />
    <result column="OPERATOR_DATE" jdbcType="TIMESTAMP" property="operatorDate" />
    <result column="SUMVAL" jdbcType="DECIMAL" property="sumval" />
  </resultMap>
  <sql id="columns">
    ID, DATA_CODE, DATA_NAME, DT, USAGE, CT, STATUS, UNIT, GRANULARITY, CZR, MEMO, UPMAN, 
    UPTIME, OPERATOR_MAN, OPERATOR_DATE, SUMVAL
  </sql>
  <sql id="columns_alias">
    t.ID, t.DATA_CODE, t.DATA_NAME, t.DT, t.USAGE, t.CT, t.STATUS, t.UNIT, t.GRANULARITY, 
    t.CZR, t.MEMO, t.UPMAN, t.UPTIME, t.OPERATOR_MAN, t.OPERATOR_DATE, t.SUMVAL
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM USAGE_DATA
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM USAGE_DATA t
  </sql>
  <sql id="where">
    <where> 
      <if test="id != null and id != ''">
        and ID = #{id}
      </if>
      <if test="dataCode != null and dataCode != ''">
        and DATA_CODE = #{dataCode}
      </if>
      <if test="dataName != null and dataName != ''">
        and DATA_NAME = #{dataName}
      </if>
      <if test="dt != null and dt != ''">
        and DT = #{dt}
      </if>
      <if test="usage != null">
        and USAGE = #{usage}
      </if>
      <if test="ct != null">
        and TO_CHAR(CT,'yyyy-MM-dd') = #{ct}
      </if>
      <if test="status != null and status != ''">
        and STATUS = #{status}
      </if>
      <if test="unit != null and unit != ''">
        and UNIT = #{unit}
      </if>
      <if test="granularity != null and granularity != ''">
        and GRANULARITY = #{granularity}
      </if>
      <if test="czr != null and czr != ''">
        and CZR = #{czr}
      </if>
      <if test="memo != null and memo != ''">
        and MEMO = #{memo}
      </if>
      <if test="upman != null and upman != ''">
        and UPMAN = #{upman}
      </if>
      <if test="uptime != null">
        and TO_CHAR(UPTIME,'yyyy-MM-dd') = #{uptime}
      </if>
      <if test="operatorMan != null and operatorMan != ''">
        and OPERATOR_MAN = #{operatorMan}
      </if>
      <if test="operatorDate != null">
        and TO_CHAR(OPERATOR_DATE,'yyyy-MM-dd') = #{operatorDate}
      </if>
      <if test="sumval != null">
        and SUMVAL = #{sumval}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="id != null and id != ''">
        and ID LIKE '%${id}%'
      </if>
      <if test="dataCode != null and dataCode != ''">
        and DATA_CODE LIKE '%${dataCode}%'
      </if>
      <if test="dataName != null and dataName != ''">
        and DATA_NAME LIKE '%${dataName}%'
      </if>
      <if test="dt != null and dt != ''">
        and DT LIKE '%${dt}%'
      </if>
      <if test="usage != null">
        and USAGE = #{usage}
      </if>
      <if test="ct != null">
        and TO_CHAR(CT,'yyyy-MM-dd') = #{ct}
      </if>
      <if test="status != null and status != ''">
        and STATUS LIKE '%${status}%'
      </if>
      <if test="unit != null and unit != ''">
        and UNIT LIKE '%${unit}%'
      </if>
      <if test="granularity != null and granularity != ''">
        and GRANULARITY LIKE '%${granularity}%'
      </if>
      <if test="czr != null and czr != ''">
        and CZR LIKE '%${czr}%'
      </if>
      <if test="memo != null and memo != ''">
        and MEMO LIKE '%${memo}%'
      </if>
      <if test="upman != null and upman != ''">
        and UPMAN LIKE '%${upman}%'
      </if>
      <if test="uptime != null">
        and TO_CHAR(UPTIME,'yyyy-MM-dd') = #{uptime}
      </if>
      <if test="operatorMan != null and operatorMan != ''">
        and OPERATOR_MAN LIKE '%${operatorMan}%'
      </if>
      <if test="operatorDate != null">
        and TO_CHAR(OPERATOR_DATE,'yyyy-MM-dd') = #{operatorDate}
      </if>
      <if test="sumval != null">
        and SUMVAL = #{sumval}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from USAGE_DATA
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from USAGE_DATA
    where 1!=1 
      <if test="dataCode != null and dataCode != ''">
        or DATA_CODE = #{dataCode}
      </if>
      <if test="dataName != null and dataName != ''">
        or DATA_NAME = #{dataName}
      </if>
      <if test="dt != null and dt != ''">
        or DT = #{dt}
      </if>
      <if test="usage != null">
        or USAGE = #{usage}
      </if>
      <if test="ct != null">
        or TO_CHAR(CT,'yyyy-MM-dd') = '#{ct}'
      </if>
      <if test="status != null and status != ''">
        or STATUS = #{status}
      </if>
      <if test="unit != null and unit != ''">
        or UNIT = #{unit}
      </if>
      <if test="granularity != null and granularity != ''">
        or GRANULARITY = #{granularity}
      </if>
      <if test="czr != null and czr != ''">
        or CZR = #{czr}
      </if>
      <if test="memo != null and memo != ''">
        or MEMO = #{memo}
      </if>
      <if test="upman != null and upman != ''">
        or UPMAN = #{upman}
      </if>
      <if test="uptime != null">
        or TO_CHAR(UPTIME,'yyyy-MM-dd') = '#{uptime}'
      </if>
      <if test="operatorMan != null and operatorMan != ''">
        or OPERATOR_MAN = #{operatorMan}
      </if>
      <if test="operatorDate != null">
        or TO_CHAR(OPERATOR_DATE,'yyyy-MM-dd') = '#{operatorDate}'
      </if>
      <if test="sumval != null">
        or SUMVAL = #{sumval}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.usagedata.model.UsageData">
    insert into USAGE_DATA (ID, DATA_CODE, DATA_NAME, 
      DT, USAGE, CT, STATUS, 
      UNIT, GRANULARITY, CZR, 
      MEMO, UPMAN, UPTIME, 
      OPERATOR_MAN, OPERATOR_DATE, SUMVAL
      )
    values (SEQ_USAGE_DATA_ID.NEXTVAL, #{dataCode,jdbcType=VARCHAR}, #{dataName,jdbcType=VARCHAR}, 
      #{dt,jdbcType=VARCHAR}, #{usage,jdbcType=DECIMAL}, #{ct,jdbcType=TIMESTAMP}, #{status,jdbcType=VARCHAR}, 
      #{unit,jdbcType=VARCHAR}, #{granularity,jdbcType=VARCHAR}, #{czr,jdbcType=VARCHAR}, 
      #{memo,jdbcType=VARCHAR}, #{upman,jdbcType=VARCHAR}, #{uptime,jdbcType=TIMESTAMP}, 
      #{operatorMan,jdbcType=VARCHAR}, #{operatorDate,jdbcType=TIMESTAMP}, #{sumval,jdbcType=DECIMAL}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.usagedata.model.UsageData">
    insert into USAGE_DATA
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="dataCode != null">
        DATA_CODE,
      </if>
      <if test="dataName != null">
        DATA_NAME,
      </if>
      <if test="dt != null">
        DT,
      </if>
      <if test="usage != null">
        USAGE,
      </if>
      <if test="ct != null">
        CT,
      </if>
      <if test="status != null">
        STATUS,
      </if>
      <if test="unit != null">
        UNIT,
      </if>
      <if test="granularity != null">
        GRANULARITY,
      </if>
      <if test="czr != null">
        CZR,
      </if>
      <if test="memo != null">
        MEMO,
      </if>
      <if test="upman != null">
        UPMAN,
      </if>
      <if test="uptime != null">
        UPTIME,
      </if>
      <if test="operatorMan != null">
        OPERATOR_MAN,
      </if>
      <if test="operatorDate != null">
        OPERATOR_DATE,
      </if>
      <if test="sumval != null">
        SUMVAL,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="dataCode != null">
        #{dataCode,jdbcType=VARCHAR},
      </if>
      <if test="dataName != null">
        #{dataName,jdbcType=VARCHAR},
      </if>
      <if test="dt != null">
        #{dt,jdbcType=VARCHAR},
      </if>
      <if test="usage != null">
        #{usage,jdbcType=DECIMAL},
      </if>
      <if test="ct != null">
        #{ct,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null">
        #{status,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        #{unit,jdbcType=VARCHAR},
      </if>
      <if test="granularity != null">
        #{granularity,jdbcType=VARCHAR},
      </if>
      <if test="czr != null">
        #{czr,jdbcType=VARCHAR},
      </if>
      <if test="memo != null">
        #{memo,jdbcType=VARCHAR},
      </if>
      <if test="upman != null">
        #{upman,jdbcType=VARCHAR},
      </if>
      <if test="uptime != null">
        #{uptime,jdbcType=TIMESTAMP},
      </if>
      <if test="operatorMan != null">
        #{operatorMan,jdbcType=VARCHAR},
      </if>
      <if test="operatorDate != null">
        #{operatorDate,jdbcType=TIMESTAMP},
      </if>
      <if test="sumval != null">
        #{sumval,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.usagedata.model.UsageData">
    update USAGE_DATA
    set DATA_CODE = #{dataCode,jdbcType=VARCHAR},
      DATA_NAME = #{dataName,jdbcType=VARCHAR},
      DT = #{dt,jdbcType=VARCHAR},
      USAGE = #{usage,jdbcType=DECIMAL},
      CT = #{ct,jdbcType=TIMESTAMP},
      STATUS = #{status,jdbcType=VARCHAR},
      UNIT = #{unit,jdbcType=VARCHAR},
      GRANULARITY = #{granularity,jdbcType=VARCHAR},
      CZR = #{czr,jdbcType=VARCHAR},
      MEMO = #{memo,jdbcType=VARCHAR},
      UPMAN = #{upman,jdbcType=VARCHAR},
      UPTIME = #{uptime,jdbcType=TIMESTAMP},
      OPERATOR_MAN = #{operatorMan,jdbcType=VARCHAR},
      OPERATOR_DATE = #{operatorDate,jdbcType=TIMESTAMP},
      SUMVAL = #{sumval,jdbcType=DECIMAL}
    where ID = #{id,jdbcType=VARCHAR}
    and STATUS = 0
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.usagedata.model.UsageData">
    update USAGE_DATA
    <set>
      <if test="dataCode != null">
        DATA_CODE = #{dataCode,jdbcType=VARCHAR},
      </if>
      <if test="dataName != null">
        DATA_NAME = #{dataName,jdbcType=VARCHAR},
      </if>
      <if test="dt != null">
        DT = #{dt,jdbcType=VARCHAR},
      </if>
      <if test="usage != null">
        USAGE = #{usage,jdbcType=DECIMAL},
      </if>
      <if test="ct != null">
        CT = #{ct,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null">
        STATUS = #{status,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        UNIT = #{unit,jdbcType=VARCHAR},
      </if>
      <if test="granularity != null">
        GRANULARITY = #{granularity,jdbcType=VARCHAR},
      </if>
      <if test="czr != null">
        CZR = #{czr,jdbcType=VARCHAR},
      </if>
      <if test="memo != null">
        MEMO = #{memo,jdbcType=VARCHAR},
      </if>
      <if test="upman != null">
        UPMAN = #{upman,jdbcType=VARCHAR},
      </if>
      <if test="uptime != null">
        UPTIME = #{uptime,jdbcType=TIMESTAMP},
      </if>
      <if test="operatorMan != null">
        OPERATOR_MAN = #{operatorMan,jdbcType=VARCHAR},
      </if>
      <if test="operatorDate != null">
        OPERATOR_DATE = #{operatorDate,jdbcType=TIMESTAMP},
      </if>
      <if test="sumval != null">
        SUMVAL = #{sumval,jdbcType=DECIMAL},
      </if>
    </set>
    where ID = #{id,jdbcType=VARCHAR}
    and STATUS = 0
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="where"/>
    ORDER BY DT DESC, DATA_CODE
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
    ORDER BY DT DESC, DATA_CODE
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into USAGE_DATA 
      (ID, 
      DATA_CODE, DATA_NAME, DT, 
      USAGE, CT, STATUS, 
      UNIT, GRANULARITY, CZR, 
      MEMO, UPMAN, UPTIME, 
      OPERATOR_MAN, OPERATOR_DATE, 
      SUMVAL)
    ( <foreach collection="list" item="item" separator="union all">
        select SEQ_USAGE_DATA_ID.NEXTVAL, 
      #{item.dataCode,jdbcType=VARCHAR}, #{item.dataName,jdbcType=VARCHAR}, #{item.dt,jdbcType=VARCHAR}, 
      #{item.usage,jdbcType=DECIMAL}, #{item.ct,jdbcType=TIMESTAMP}, #{item.status,jdbcType=VARCHAR}, 
      #{item.unit,jdbcType=VARCHAR}, #{item.granularity,jdbcType=VARCHAR}, #{item.czr,jdbcType=VARCHAR}, 
      #{item.memo,jdbcType=VARCHAR}, #{item.upman,jdbcType=VARCHAR}, #{item.uptime,jdbcType=TIMESTAMP}, 
      #{item.operatorMan,jdbcType=VARCHAR}, #{item.operatorDate,jdbcType=TIMESTAMP}, 
      #{item.sumval,jdbcType=DECIMAL} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update USAGE_DATA
     set
       ID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.id,jdbcType=VARCHAR}
       </foreach>
       ,DATA_CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.dataCode,jdbcType=VARCHAR}
       </foreach>
       ,DATA_NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.dataName,jdbcType=VARCHAR}
       </foreach>
       ,DT=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.dt,jdbcType=VARCHAR}
       </foreach>
       ,USAGE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.usage,jdbcType=DECIMAL}
       </foreach>
       ,CT=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.ct,jdbcType=TIMESTAMP}
       </foreach>
       ,STATUS=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.status,jdbcType=VARCHAR}
       </foreach>
       ,UNIT=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.unit,jdbcType=VARCHAR}
       </foreach>
       ,GRANULARITY=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.granularity,jdbcType=VARCHAR}
       </foreach>
       ,CZR=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.czr,jdbcType=VARCHAR}
       </foreach>
       ,MEMO=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.memo,jdbcType=VARCHAR}
       </foreach>
       ,UPMAN=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.upman,jdbcType=VARCHAR}
       </foreach>
       ,UPTIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.uptime,jdbcType=TIMESTAMP}
       </foreach>
       ,OPERATOR_MAN=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.operatorMan,jdbcType=VARCHAR}
       </foreach>
       ,OPERATOR_DATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.operatorDate,jdbcType=TIMESTAMP}
       </foreach>
       ,SUMVAL=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.sumval,jdbcType=DECIMAL}
       </foreach>
     where ID in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.id,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from USAGE_DATA
    where ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="selectDataCodeAndDt" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ID, DATA_CODE, DT
    from USAGE_DATA
    where DATA_CODE = #{dataCode}
    and DT = #{dt}
  </select>

  <select id="getEmsData" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where STATUS = '0'
  </select>

  <update id="updateState" parameterType="com.steerinfo.ems.usagedata.model.UsageData">
    update USAGE_DATA
    <set>
      <if test="status != null">
        STATUS = #{status,jdbcType=VARCHAR},
      </if>
      <if test="operatorMan != null">
        OPERATOR_MAN = #{operatorMan,jdbcType=VARCHAR},
      </if>
      <if test="operatorDate != null">
        OPERATOR_DATE = #{operatorDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <!-- 获取累计值 -->
  <select id="getSumval" parameterType="java.util.HashMap" resultType="double">
    select nvl(sum(USAGE), 0) from USAGE_DATA
    <where>
        <if test="startDate !=null and startDate != '' ">
            AND  dt &gt;= #{startDate}
        </if>
        <if test="dt !=null and dt !='' ">
            AND  dt &lt;= #{dt}
        </if>
        <if test="dataCode !=null and dataCode !='' ">
            AND DATA_CODE = #{dataCode}
        </if>
    </where>
  </select>
  
  <!-- 获取累计值 2-用于修改数据 -->
  <select id="getSumval2" parameterType="java.util.HashMap" resultType="double">
    select nvl(sum(USAGE), 0) from USAGE_DATA
    <where>
        <if test="startDate !=null and startDate != '' ">
            AND  dt &gt;= #{startDate}
        </if>
        <if test="dt !=null and dt !='' ">
            AND  dt &lt; #{dt}
        </if>
        <if test="dataCode !=null and dataCode !='' ">
            AND DATA_CODE = #{dataCode}
        </if>
    </where>
  </select>
  
  <!-- 通过物料信息-获取钢种牌号 -->
  <select id="searchList" parameterType="java.util.HashMap" resultType="Map">
    SELECT t.ID as "id", t.DATA_CODE as "dataCode", t.DATA_NAME as "dataName", t.DT as "dt", t.USAGE as "usage", 
    TO_CHAR(t.CT,'yyyy-MM-dd hh24:mi:ss') as "ct", t.STATUS as "status", t.UNIT as "unit", t.GRANULARITY as "granularity", 
    t.CZR as "czr", t.MEMO as "memo", t.UPMAN as "upman", 
    TO_CHAR(t.UPTIME,'yyyy-MM-dd hh24:mi:ss') as "uptime", t.OPERATOR_MAN as "operatorMan", 
    TO_CHAR(t.OPERATOR_DATE,'yyyy-MM-dd hh24:mi:ss') as "operatorDate", t.SUMVAL as "sumval",
    u.isupload as "isupload",u.start_date as "startDate"
    FROM USAGE_DATA t
    inner join USAGE_DATA_CONFIG u on t.DATA_CODE = u.ENERGY_CODE
    <where> 
      <if test="clock != null and clock != ''">
        and t.DT &gt;= #{clock}
      </if>
      <if test="clocke != null and clocke != ''">
        and t.DT &lt;= #{clocke}
      </if>
      <if test="dataCode != null and dataCode != ''">
        and t.DATA_CODE = #{dataCode}
      </if>
      <if test="status != null and status != ''">
        and STATUS = #{status}
      </if>
    </where>
    ORDER BY t.DT DESC, t.DATA_CODE
  </select>
</mapper>