<?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.usagedataconfig.mapper.UsageDataConfigMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.usagedataconfig.model.UsageDataConfig">
    <id column="ID" jdbcType="DECIMAL" property="id" />
    <result column="ENERGY_CODE" jdbcType="VARCHAR" property="energyCode" />
    <result column="DATA_CODE" jdbcType="VARCHAR" property="dataCode" />
    <result column="NOTE" jdbcType="VARCHAR" property="note" />
    <result column="CT" jdbcType="TIMESTAMP" property="ct" />
    <result column="PRODLINE" jdbcType="VARCHAR" property="prodline" />
    <result column="MATERIALCODE" jdbcType="VARCHAR" property="materialcode" />
    <result column="ISAUTO" jdbcType="VARCHAR" property="isauto" />
    <result column="UNIT" jdbcType="VARCHAR" property="unit" />
    <result column="ISUPLOAD" jdbcType="VARCHAR" property="isupload" />
    <result column="START_DATE" jdbcType="VARCHAR" property="startDate" />
  </resultMap>
  <sql id="columns">
    ID, ENERGY_CODE, DATA_CODE, NOTE, CT, PRODLINE, MATERIALCODE, ISAUTO, UNIT, ISUPLOAD, 
    START_DATE
  </sql>
  <sql id="columns_alias">
    t.ID, t.ENERGY_CODE, t.DATA_CODE, t.NOTE, t.CT, t.PRODLINE, t.MATERIALCODE, t.ISAUTO, 
    t.UNIT, t.ISUPLOAD, t.START_DATE
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM USAGE_DATA_CONFIG
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM USAGE_DATA_CONFIG t
  </sql>
  <sql id="where">
    <where> 
      <if test="id != null">
        and ID = #{id}
      </if>
      <if test="energyCode != null and energyCode != ''">
        and ENERGY_CODE = #{energyCode}
      </if>
      <if test="dataCode != null and dataCode != ''">
        and DATA_CODE = #{dataCode}
      </if>
      <if test="note != null and note != ''">
        and NOTE = #{note}
      </if>
      <if test="ct != null">
        and TO_CHAR(CT,'yyyy-MM-dd') = #{ct}
      </if>
      <if test="prodline != null and prodline != ''">
        and PRODLINE = #{prodline}
      </if>
      <if test="materialcode != null and materialcode != ''">
        and MATERIALCODE = #{materialcode}
      </if>
      <if test="isauto != null and isauto != ''">
        and ISAUTO = #{isauto}
      </if>
      <if test="unit != null and unit != ''">
        and UNIT = #{unit}
      </if>
      <if test="isupload != null and isupload != ''">
        and ISUPLOAD = #{isupload}
      </if>
      <if test="startDate != null and startDate != ''">
        and START_DATE = #{startDate}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="id != null and id != ''">
        and ID = #{id}
      </if>
      <if test="energyCode != null and energyCode != ''">
        and ENERGY_CODE LIKE '%${energyCode}%'
      </if>
      <if test="dataCode != null and dataCode != ''">
        and DATA_CODE LIKE '%${dataCode}%'
      </if>
      <if test="note != null and note != ''">
        and NOTE LIKE '%${note}%'
      </if>
      <if test="ct != null">
        and TO_CHAR(CT,'yyyy-MM-dd') = #{ct}
      </if>
      <if test="prodline != null and prodline != ''">
        and PRODLINE LIKE '%${prodline}%'
      </if>
      <if test="materialcode != null and materialcode != ''">
        and MATERIALCODE LIKE '%${materialcode}%'
      </if>
      <if test="isauto != null and isauto != ''">
        and ISAUTO LIKE '%${isauto}%'
      </if>
      <if test="unit != null and unit != ''">
        and UNIT LIKE '%${unit}%'
      </if>
      <if test="isupload != null and isupload != ''">
        and ISUPLOAD LIKE '%${isupload}%'
      </if>
      <if test="startDate != null and startDate != ''">
        and START_DATE LIKE '%${startDate}%'
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Short">
    delete from USAGE_DATA_CONFIG
    where ID = #{id,jdbcType=DECIMAL}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from USAGE_DATA_CONFIG
    where 1!=1 
      <if test="energyCode != null and energyCode != ''">
        or ENERGY_CODE = #{energyCode}
      </if>
      <if test="dataCode != null and dataCode != ''">
        or DATA_CODE = #{dataCode}
      </if>
      <if test="note != null and note != ''">
        or NOTE = #{note}
      </if>
      <if test="ct != null">
        or TO_CHAR(CT,'yyyy-MM-dd') = '#{ct}'
      </if>
      <if test="prodline != null and prodline != ''">
        or PRODLINE = #{prodline}
      </if>
      <if test="materialcode != null and materialcode != ''">
        or MATERIALCODE = #{materialcode}
      </if>
      <if test="isauto != null and isauto != ''">
        or ISAUTO = #{isauto}
      </if>
      <if test="unit != null and unit != ''">
        or UNIT = #{unit}
      </if>
      <if test="isupload != null and isupload != ''">
        or ISUPLOAD = #{isupload}
      </if>
      <if test="startDate != null and startDate != ''">
        or START_DATE = #{startDate}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.usagedataconfig.model.UsageDataConfig">
    insert into USAGE_DATA_CONFIG (ID, ENERGY_CODE, DATA_CODE, 
      NOTE, CT, PRODLINE, 
      MATERIALCODE, ISAUTO, UNIT, 
      ISUPLOAD, START_DATE)
    values (#{id,jdbcType=DECIMAL}, #{energyCode,jdbcType=VARCHAR}, #{dataCode,jdbcType=VARCHAR}, 
      #{note,jdbcType=VARCHAR}, #{ct,jdbcType=TIMESTAMP}, #{prodline,jdbcType=VARCHAR}, 
      #{materialcode,jdbcType=VARCHAR}, #{isauto,jdbcType=VARCHAR}, #{unit,jdbcType=VARCHAR}, 
      #{isupload,jdbcType=VARCHAR}, #{startDate,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.usagedataconfig.model.UsageDataConfig">
    insert into USAGE_DATA_CONFIG
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="energyCode != null">
        ENERGY_CODE,
      </if>
      <if test="dataCode != null">
        DATA_CODE,
      </if>
      <if test="note != null">
        NOTE,
      </if>
      <if test="ct != null">
        CT,
      </if>
      <if test="prodline != null">
        PRODLINE,
      </if>
      <if test="materialcode != null">
        MATERIALCODE,
      </if>
      <if test="isauto != null">
        ISAUTO,
      </if>
      <if test="unit != null">
        UNIT,
      </if>
      <if test="isupload != null">
        ISUPLOAD,
      </if>
      <if test="startDate != null">
        START_DATE,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=DECIMAL},
      </if>
      <if test="energyCode != null">
        #{energyCode,jdbcType=VARCHAR},
      </if>
      <if test="dataCode != null">
        #{dataCode,jdbcType=VARCHAR},
      </if>
      <if test="note != null">
        #{note,jdbcType=VARCHAR},
      </if>
      <if test="ct != null">
        #{ct,jdbcType=TIMESTAMP},
      </if>
      <if test="prodline != null">
        #{prodline,jdbcType=VARCHAR},
      </if>
      <if test="materialcode != null">
        #{materialcode,jdbcType=VARCHAR},
      </if>
      <if test="isauto != null">
        #{isauto,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        #{unit,jdbcType=VARCHAR},
      </if>
      <if test="isupload != null">
        #{isupload,jdbcType=VARCHAR},
      </if>
      <if test="startDate != null">
        #{startDate,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.usagedataconfig.model.UsageDataConfig">
    update USAGE_DATA_CONFIG
    set ENERGY_CODE = #{energyCode,jdbcType=VARCHAR},
      DATA_CODE = #{dataCode,jdbcType=VARCHAR},
      NOTE = #{note,jdbcType=VARCHAR},
      CT = #{ct,jdbcType=TIMESTAMP},
      PRODLINE = #{prodline,jdbcType=VARCHAR},
      MATERIALCODE = #{materialcode,jdbcType=VARCHAR},
      ISAUTO = #{isauto,jdbcType=VARCHAR},
      UNIT = #{unit,jdbcType=VARCHAR},
      ISUPLOAD = #{isupload,jdbcType=VARCHAR},
      START_DATE = #{startDate,jdbcType=VARCHAR}
    where ID = #{id,jdbcType=DECIMAL}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.usagedataconfig.model.UsageDataConfig">
    update USAGE_DATA_CONFIG
    <set>
      <if test="energyCode != null">
        ENERGY_CODE = #{energyCode,jdbcType=VARCHAR},
      </if>
      <if test="dataCode != null">
        DATA_CODE = #{dataCode,jdbcType=VARCHAR},
      </if>
      <if test="note != null">
        NOTE = #{note,jdbcType=VARCHAR},
      </if>
      <if test="ct != null">
        CT = #{ct,jdbcType=TIMESTAMP},
      </if>
      <if test="prodline != null">
        PRODLINE = #{prodline,jdbcType=VARCHAR},
      </if>
      <if test="materialcode != null">
        MATERIALCODE = #{materialcode,jdbcType=VARCHAR},
      </if>
      <if test="isauto != null">
        ISAUTO = #{isauto,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        UNIT = #{unit,jdbcType=VARCHAR},
      </if>
      <if test="isupload != null">
        ISUPLOAD = #{isupload,jdbcType=VARCHAR},
      </if>
      <if test="startDate != null">
        START_DATE = #{startDate,jdbcType=VARCHAR},
      </if>
    </set>
    where ID = #{id,jdbcType=DECIMAL}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.Short" 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 USAGE_DATA_CONFIG 
      (ID, 
      ENERGY_CODE, DATA_CODE, NOTE, 
      CT, PRODLINE, MATERIALCODE, 
      ISAUTO, UNIT, ISUPLOAD, 
      START_DATE)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.id,jdbcType=DECIMAL}, 
      #{item.energyCode,jdbcType=VARCHAR}, #{item.dataCode,jdbcType=VARCHAR}, #{item.note,jdbcType=VARCHAR}, 
      #{item.ct,jdbcType=TIMESTAMP}, #{item.prodline,jdbcType=VARCHAR}, #{item.materialcode,jdbcType=VARCHAR}, 
      #{item.isauto,jdbcType=VARCHAR}, #{item.unit,jdbcType=VARCHAR}, #{item.isupload,jdbcType=VARCHAR}, 
      #{item.startDate,jdbcType=VARCHAR} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update USAGE_DATA_CONFIG
     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>
       ,ENERGY_CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.energyCode,jdbcType=VARCHAR}
       </foreach>
       ,DATA_CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.dataCode,jdbcType=VARCHAR}
       </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>
       ,CT=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.ct,jdbcType=TIMESTAMP}
       </foreach>
       ,PRODLINE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.prodline,jdbcType=VARCHAR}
       </foreach>
       ,MATERIALCODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.materialcode,jdbcType=VARCHAR}
       </foreach>
       ,ISAUTO=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.isauto,jdbcType=VARCHAR}
       </foreach>
       ,UNIT=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.unit,jdbcType=VARCHAR}
       </foreach>
       ,ISUPLOAD=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.isupload,jdbcType=VARCHAR}
       </foreach>
       ,START_DATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=DECIMAL} then #{item.startDate,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 USAGE_DATA_CONFIG
    where ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="getIdAndNote" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ID, ENERGY_CODE, NOTE, PRODLINE, MATERIALCODE, UNIT
    from USAGE_DATA_CONFIG
    where NOTE is not null
    and ENERGY_CODE is not null
  </select>
  <select id="getAutoData" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ID, ENERGY_CODE, NOTE, PRODLINE, MATERIALCODE, UNIT
    from USAGE_DATA_CONFIG
    where ISAUTO = '1'
  </select>
</mapper>