<?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.trmenergyprice.mapper.TRmEnergyPriceMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.trmenergyprice.model.TRmEnergyPrice">
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="ENERGYID" jdbcType="VARCHAR" property="energyid" />
    <result column="PRICE" jdbcType="DECIMAL" property="price" />
    <result column="BZ" jdbcType="VARCHAR" property="bz" />
    <result column="CREATEMAN" jdbcType="VARCHAR" property="createman" />
    <result column="CREATETIME" jdbcType="TIMESTAMP" property="createtime" />
    <result column="UPDATEMAN" jdbcType="VARCHAR" property="updateman" />
    <result column="UPDATETIME" jdbcType="TIMESTAMP" property="updatetime" />
  </resultMap>
  <sql id="columns">
    ID, ENERGYID, PRICE, BZ, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
  </sql>
  <sql id="columns_alias">
    t.ID, t.ENERGYID, t.PRICE, t.BZ, t.CREATEMAN, t.CREATETIME, t.UPDATEMAN, t.UPDATETIME
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM T_RM_ENERGY_PRICE
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM T_RM_ENERGY_PRICE t
  </sql>
  <sql id="where">
    <where> 
      <if test="energyid != null and energyid != ''">
        and ENERGYID = #{energyid}
      </if>
      <if test="price != null">
        and PRICE = #{price}
      </if>
      <if test="bz != null and bz != ''">
        and BZ = #{bz}
      </if>
      <if test="createman != null and createman != ''">
        and CREATEMAN = #{createman}
      </if>
      <if test="createtime != null">
        and TO_CHAR(CREATETIME,'yyyy-MM-dd') = #{createtime}
      </if>
      <if test="updateman != null and updateman != ''">
        and UPDATEMAN = #{updateman}
      </if>
      <if test="updatetime != null">
        and TO_CHAR(UPDATETIME,'yyyy-MM-dd') = #{updatetime}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="energyid != null and energyid != ''">
        and ENERGYID LIKE '%${energyid}%'
      </if>
      <if test="price != null">
        and PRICE = #{price}
      </if>
      <if test="bz != null and bz != ''">
        and BZ LIKE '%${bz}%'
      </if>
      <if test="createman != null and createman != ''">
        and CREATEMAN LIKE '%${createman}%'
      </if>
      <if test="createtime != null">
        and TO_CHAR(CREATETIME,'yyyy-MM-dd') = #{createtime}
      </if>
      <if test="updateman != null and updateman != ''">
        and UPDATEMAN LIKE '%${updateman}%'
      </if>
      <if test="updatetime != null">
        and TO_CHAR(UPDATETIME,'yyyy-MM-dd') = #{updatetime}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_RM_ENERGY_PRICE
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_RM_ENERGY_PRICE
    where 1!=1 
      <if test="energyid != null and energyid != ''">
        or ENERGYID = #{energyid}
      </if>
      <if test="price != null">
        or PRICE = #{price}
      </if>
      <if test="bz != null and bz != ''">
        or BZ = #{bz}
      </if>
      <if test="createman != null and createman != ''">
        or CREATEMAN = #{createman}
      </if>
      <if test="createtime != null">
        or TO_CHAR(CREATETIME,'yyyy-MM-dd') = '#{createtime}'
      </if>
      <if test="updateman != null and updateman != ''">
        or UPDATEMAN = #{updateman}
      </if>
      <if test="updatetime != null">
        or TO_CHAR(UPDATETIME,'yyyy-MM-dd') = '#{updatetime}'
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.trmenergyprice.model.TRmEnergyPrice">
    insert into T_RM_ENERGY_PRICE (ID, ENERGYID, PRICE, 
      BZ, CREATEMAN, CREATETIME, 
      UPDATEMAN, UPDATETIME)
    values (#{id,jdbcType=VARCHAR}, #{energyid,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, 
      #{bz,jdbcType=VARCHAR}, #{createman,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, 
      #{updateman,jdbcType=VARCHAR}, #{updatetime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.trmenergyprice.model.TRmEnergyPrice">
    insert into T_RM_ENERGY_PRICE
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="energyid != null">
        ENERGYID,
      </if>
      <if test="price != null">
        PRICE,
      </if>
      <if test="bz != null">
        BZ,
      </if>
      <if test="createman != null">
        CREATEMAN,
      </if>
      <if test="createtime != null">
        CREATETIME,
      </if>
      <if test="updateman != null">
        UPDATEMAN,
      </if>
      <if test="updatetime != null">
        UPDATETIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="energyid != null">
        #{energyid,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        #{price,jdbcType=DECIMAL},
      </if>
      <if test="bz != null">
        #{bz,jdbcType=VARCHAR},
      </if>
      <if test="createman != null">
        #{createman,jdbcType=VARCHAR},
      </if>
      <if test="createtime != null">
        #{createtime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateman != null">
        #{updateman,jdbcType=VARCHAR},
      </if>
      <if test="updatetime != null">
        #{updatetime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.trmenergyprice.model.TRmEnergyPrice">
    update T_RM_ENERGY_PRICE
    set ENERGYID = #{energyid,jdbcType=VARCHAR},
      PRICE = #{price,jdbcType=DECIMAL},
      BZ = #{bz,jdbcType=VARCHAR},
      CREATEMAN = #{createman,jdbcType=VARCHAR},
      CREATETIME = #{createtime,jdbcType=TIMESTAMP},
      UPDATEMAN = #{updateman,jdbcType=VARCHAR},
      UPDATETIME = #{updatetime,jdbcType=TIMESTAMP}
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.trmenergyprice.model.TRmEnergyPrice">
    update T_RM_ENERGY_PRICE
    <set>
      <if test="energyid != null">
        ENERGYID = #{energyid,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        PRICE = #{price,jdbcType=DECIMAL},
      </if>
      <if test="bz != null">
        BZ = #{bz,jdbcType=VARCHAR},
      </if>
      <if test="createman != null">
        CREATEMAN = #{createman,jdbcType=VARCHAR},
      </if>
      <if test="createtime != null">
        CREATETIME = #{createtime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateman != null">
        UPDATEMAN = #{updateman,jdbcType=VARCHAR},
      </if>
      <if test="updatetime != null">
        UPDATETIME = #{updatetime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </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"/>
  </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 T_RM_ENERGY_PRICE 
      (ID, 
      ENERGYID, PRICE, BZ, 
      CREATEMAN, CREATETIME, UPDATEMAN, 
      UPDATETIME)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.id,jdbcType=VARCHAR}, 
      #{item.energyid,jdbcType=VARCHAR}, #{item.price,jdbcType=DECIMAL}, #{item.bz,jdbcType=VARCHAR}, 
      #{item.createman,jdbcType=VARCHAR}, #{item.createtime,jdbcType=TIMESTAMP}, #{item.updateman,jdbcType=VARCHAR}, 
      #{item.updatetime,jdbcType=TIMESTAMP} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_RM_ENERGY_PRICE
     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>
       ,ENERGYID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.energyid,jdbcType=VARCHAR}
       </foreach>
       ,PRICE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.price,jdbcType=DECIMAL}
       </foreach>
       ,BZ=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.bz,jdbcType=VARCHAR}
       </foreach>
       ,CREATEMAN=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.createman,jdbcType=VARCHAR}
       </foreach>
       ,CREATETIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.createtime,jdbcType=TIMESTAMP}
       </foreach>
       ,UPDATEMAN=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.updateman,jdbcType=VARCHAR}
       </foreach>
       ,UPDATETIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.updatetime,jdbcType=TIMESTAMP}
       </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 T_RM_ENERGY_PRICE
    where ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  
  <!-- 根据过滤条件查询能介价格-->
  <select id="getData" parameterType="java.util.HashMap" resultType="Map">
    select t.id,e.id as energyid,t.price,t.bz,t.createman,t.createtime,
    t.updateman,t.updatetime,e.name,e.energytypeid,e.unitid
    from T_RM_ENERGY e left join T_RM_ENERGY_PRICE t on t.energyid = e.id 
    where e.id not in ('X015','X016','X020')
    <if test="energytypeid != null and energytypeid != '' ">
        and energytypeid = #{energytypeid}
    </if>
    <if test="energyid != null and energyid != ''">
        and e.id like '%${energyid}%'
    </if>
    <if test="name != null and name != ''">
        and name like '%${name}%'
    </if>
    order by e.id
  </select>
</mapper>