<?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.mesemsdieseloil.mapper.MesEmsDieseloilMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.mesemsdieseloil.model.MesEmsDieseloil">
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="STATE" jdbcType="VARCHAR" property="state" />
    <result column="BUSINESS_DATE" jdbcType="VARCHAR" property="businessDate" />
    <result column="MATERIALCODE" jdbcType="VARCHAR" property="materialcode" />
    <result column="MATERIALNAME" jdbcType="VARCHAR" property="materialname" />
    <result column="VOLUME" jdbcType="DECIMAL" property="volume" />
    <result column="FACTORY_CODE" jdbcType="VARCHAR" property="factoryCode" />
    <result column="FACTORY_NAME" jdbcType="VARCHAR" property="factoryName" />
    <result column="UNIT" jdbcType="VARCHAR" property="unit" />
    <result column="MATERIALSPEC" jdbcType="VARCHAR" property="materialspec" />
    <result column="SENDTIME" jdbcType="TIMESTAMP" property="sendtime" />
    <result column="WEIGHT" jdbcType="DECIMAL" property="weight" />
  </resultMap>
  <sql id="columns">
    ID, STATE, BUSINESS_DATE, MATERIALCODE, MATERIALNAME, VOLUME, FACTORY_CODE, FACTORY_NAME, 
    UNIT, MATERIALSPEC, SENDTIME, WEIGHT
  </sql>
  <sql id="columns_alias">
    t.ID, t.STATE, t.BUSINESS_DATE, t.MATERIALCODE, t.MATERIALNAME, t.VOLUME, t.FACTORY_CODE, 
    t.FACTORY_NAME, t.UNIT, t.MATERIALSPEC, t.SENDTIME, t.WEIGHT
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM MES_EMS_DIESELOIL
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM MES_EMS_DIESELOIL t
  </sql>
  <sql id="where">
    <where> 
      <if test="state != null and state != ''">
        and STATE = #{state}
      </if>
      <if test="businessDate != null and businessDate != ''">
        and BUSINESS_DATE = #{businessDate}
      </if>
      <if test="materialcode != null and materialcode != ''">
        and MATERIALCODE = #{materialcode}
      </if>
      <if test="materialname != null and materialname != ''">
        and MATERIALNAME = #{materialname}
      </if>
      <if test="volume != null">
        and VOLUME = #{volume}
      </if>
      <if test="factoryCode != null and factoryCode != ''">
        and FACTORY_CODE = #{factoryCode}
      </if>
      <if test="factoryName != null and factoryName != ''">
        and FACTORY_NAME = #{factoryName}
      </if>
      <if test="unit != null and unit != ''">
        and UNIT = #{unit}
      </if>
      <if test="materialspec != null and materialspec != ''">
        and MATERIALSPEC = #{materialspec}
      </if>
      <if test="sendtime != null">
        and TO_CHAR(SENDTIME,'yyyy-MM-dd') = #{sendtime}
      </if>
      <if test="weight != null">
        and WEIGHT = #{weight}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="state != null and state != ''">
        and STATE LIKE '%${state}%'
      </if>
      <if test="businessDate != null and businessDate != ''">
        and BUSINESS_DATE = #{businessDate}
      </if>
      <if test="materialcode != null and materialcode != ''">
        and MATERIALCODE LIKE '%${materialcode}%'
      </if>
      <if test="materialname != null and materialname != ''">
        and MATERIALNAME LIKE '%${materialname}%'
      </if>
      <if test="volume != null">
        and VOLUME = #{volume}
      </if>
      <if test="factoryCode != null and factoryCode != ''">
        and FACTORY_CODE LIKE '%${factoryCode}%'
      </if>
      <if test="factoryName != null and factoryName != ''">
        and FACTORY_NAME LIKE '%${factoryName}%'
      </if>
      <if test="unit != null and unit != ''">
        and UNIT LIKE '%${unit}%'
      </if>
      <if test="materialspec != null and materialspec != ''">
        and MATERIALSPEC LIKE '%${materialspec}%'
      </if>
      <if test="sendtime != null">
        and TO_CHAR(SENDTIME,'yyyy-MM-dd') = #{sendtime}
      </if>
      <if test="weight != null">
        and WEIGHT = #{weight}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from MES_EMS_DIESELOIL
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from MES_EMS_DIESELOIL
    where 1!=1 
      <if test="state != null and state != ''">
        or STATE = #{state}
      </if>
      <if test="businessDate != null and businessDate != ''">
        or BUSINESS_DATE = '#{businessDate}'
      </if>
      <if test="materialcode != null and materialcode != ''">
        or MATERIALCODE = #{materialcode}
      </if>
      <if test="materialname != null and materialname != ''">
        or MATERIALNAME = #{materialname}
      </if>
      <if test="volume != null">
        or VOLUME = #{volume}
      </if>
      <if test="factoryCode != null and factoryCode != ''">
        or FACTORY_CODE = #{factoryCode}
      </if>
      <if test="factoryName != null and factoryName != ''">
        or FACTORY_NAME = #{factoryName}
      </if>
      <if test="unit != null and unit != ''">
        or UNIT = #{unit}
      </if>
      <if test="materialspec != null and materialspec != ''">
        or MATERIALSPEC = #{materialspec}
      </if>
      <if test="sendtime != null">
        or TO_CHAR(SENDTIME,'yyyy-MM-dd') = '#{sendtime}'
      </if>
      <if test="weight != null">
        or WEIGHT = #{weight}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.mesemsdieseloil.model.MesEmsDieseloil">
    insert into MES_EMS_DIESELOIL (ID, STATE, BUSINESS_DATE, 
      MATERIALCODE, MATERIALNAME, VOLUME, 
      FACTORY_CODE, FACTORY_NAME, UNIT, 
      MATERIALSPEC, SENDTIME, WEIGHT)
    values (#{id,jdbcType=VARCHAR}, #{state,jdbcType=VARCHAR}, #{businessDate,jdbcType=VARCHAR}, 
      #{materialcode,jdbcType=VARCHAR}, #{materialname,jdbcType=VARCHAR}, #{volume,jdbcType=DECIMAL}, 
      #{factoryCode,jdbcType=VARCHAR}, #{factoryName,jdbcType=VARCHAR}, #{unit,jdbcType=VARCHAR}, 
      #{materialspec,jdbcType=VARCHAR}, #{sendtime,jdbcType=TIMESTAMP}, #{weight,jdbcType=DECIMAL})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.mesemsdieseloil.model.MesEmsDieseloil">
    insert into MES_EMS_DIESELOIL
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="state != null">
        STATE,
      </if>
      <if test="businessDate != null">
        BUSINESS_DATE,
      </if>
      <if test="materialcode != null">
        MATERIALCODE,
      </if>
      <if test="materialname != null">
        MATERIALNAME,
      </if>
      <if test="volume != null">
        VOLUME,
      </if>
      <if test="factoryCode != null">
        FACTORY_CODE,
      </if>
      <if test="factoryName != null">
        FACTORY_NAME,
      </if>
      <if test="unit != null">
        UNIT,
      </if>
      <if test="materialspec != null">
        MATERIALSPEC,
      </if>
      <if test="sendtime != null">
        SENDTIME,
      </if>
      <if test="weight != null">
        WEIGHT,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="state != null">
        #{state,jdbcType=VARCHAR},
      </if>
      <if test="businessDate != null">
        #{businessDate,jdbcType=VARCHAR},
      </if>
      <if test="materialcode != null">
        #{materialcode,jdbcType=VARCHAR},
      </if>
      <if test="materialname != null">
        #{materialname,jdbcType=VARCHAR},
      </if>
      <if test="volume != null">
        #{volume,jdbcType=DECIMAL},
      </if>
      <if test="factoryCode != null">
        #{factoryCode,jdbcType=VARCHAR},
      </if>
      <if test="factoryName != null">
        #{factoryName,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        #{unit,jdbcType=VARCHAR},
      </if>
      <if test="materialspec != null">
        #{materialspec,jdbcType=VARCHAR},
      </if>
      <if test="sendtime != null">
        #{sendtime,jdbcType=TIMESTAMP},
      </if>
      <if test="weight != null">
        #{weight,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.mesemsdieseloil.model.MesEmsDieseloil">
    update MES_EMS_DIESELOIL
    set STATE = #{state,jdbcType=VARCHAR},
      BUSINESS_DATE = #{businessDate,jdbcType=VARCHAR},
      MATERIALCODE = #{materialcode,jdbcType=VARCHAR},
      MATERIALNAME = #{materialname,jdbcType=VARCHAR},
      VOLUME = #{volume,jdbcType=DECIMAL},
      FACTORY_CODE = #{factoryCode,jdbcType=VARCHAR},
      FACTORY_NAME = #{factoryName,jdbcType=VARCHAR},
      UNIT = #{unit,jdbcType=VARCHAR},
      MATERIALSPEC = #{materialspec,jdbcType=VARCHAR},
      SENDTIME = #{sendtime,jdbcType=TIMESTAMP},
      WEIGHT = #{weight,jdbcType=DECIMAL}
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.mesemsdieseloil.model.MesEmsDieseloil">
    update MES_EMS_DIESELOIL
    <set>
      <if test="state != null">
        STATE = #{state,jdbcType=VARCHAR},
      </if>
      <if test="businessDate != null">
        BUSINESS_DATE = #{businessDate,jdbcType=VARCHAR},
      </if>
      <if test="materialcode != null">
        MATERIALCODE = #{materialcode,jdbcType=VARCHAR},
      </if>
      <if test="materialname != null">
        MATERIALNAME = #{materialname,jdbcType=VARCHAR},
      </if>
      <if test="volume != null">
        VOLUME = #{volume,jdbcType=DECIMAL},
      </if>
      <if test="factoryCode != null">
        FACTORY_CODE = #{factoryCode,jdbcType=VARCHAR},
      </if>
      <if test="factoryName != null">
        FACTORY_NAME = #{factoryName,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        UNIT = #{unit,jdbcType=VARCHAR},
      </if>
      <if test="materialspec != null">
        MATERIALSPEC = #{materialspec,jdbcType=VARCHAR},
      </if>
      <if test="sendtime != null">
        SENDTIME = #{sendtime,jdbcType=TIMESTAMP},
      </if>
      <if test="weight != null">
        WEIGHT = #{weight,jdbcType=DECIMAL},
      </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 MES_EMS_DIESELOIL 
      (ID, 
      STATE, BUSINESS_DATE, MATERIALCODE, 
      MATERIALNAME, VOLUME, FACTORY_CODE, 
      FACTORY_NAME, UNIT, MATERIALSPEC, 
      SENDTIME, WEIGHT)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.id,jdbcType=VARCHAR}, 
      #{item.state,jdbcType=VARCHAR}, #{item.businessDate,jdbcType=VARCHAR}, #{item.materialcode,jdbcType=VARCHAR}, 
      #{item.materialname,jdbcType=VARCHAR}, #{item.volume,jdbcType=DECIMAL}, #{item.factoryCode,jdbcType=VARCHAR}, 
      #{item.factoryName,jdbcType=VARCHAR}, #{item.unit,jdbcType=VARCHAR}, #{item.materialspec,jdbcType=VARCHAR}, 
      #{item.sendtime,jdbcType=TIMESTAMP}, #{item.weight,jdbcType=DECIMAL} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update MES_EMS_DIESELOIL
     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>
       ,STATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.state,jdbcType=VARCHAR}
       </foreach>
       ,BUSINESS_DATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.businessDate,jdbcType=VARCHAR}
       </foreach>
       ,MATERIALCODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.materialcode,jdbcType=VARCHAR}
       </foreach>
       ,MATERIALNAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.materialname,jdbcType=VARCHAR}
       </foreach>
       ,VOLUME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.volume,jdbcType=DECIMAL}
       </foreach>
       ,WEIGHT=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.weight,jdbcType=DECIMAL}
       </foreach>
       ,FACTORY_CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.factoryCode,jdbcType=VARCHAR}
       </foreach>
       ,FACTORY_NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.factoryName,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>
       ,MATERIALSPEC=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.materialspec,jdbcType=VARCHAR}
       </foreach>
       ,SENDTIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.sendtime,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 MES_EMS_DIESELOIL
    where ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  
  <!-- 分组统计柴油重量（不区分柴油型号） -->
  <select id="getMesEmsDieseloils" parameterType="java.lang.String" resultType = "Map">
    select business_date,factory_code,nvl(sum(weight),0) weight from MES_EMS_DIESELOIL 
    where business_date = #{businessDate} group by business_date,factory_code
  </select>
</mapper>