<?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.emsehistory.mapper.EmsEHistoryMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.emsehistory.model.EmsEHistory">
    <id column="E_ID" jdbcType="DECIMAL" property="eId" />
    <result column="E_LINE" jdbcType="VARCHAR" property="eLine" />
    <result column="E_DATA" jdbcType="VARCHAR" property="eData" />
    <result column="E_DATE" jdbcType="TIMESTAMP" property="eDate" />
    <result column="E_CREATEDATE" jdbcType="TIMESTAMP" property="eCreatedate" />
  </resultMap>
  <sql id="columns">
    E_ID, E_LINE, E_DATA, E_DATE, E_CREATEDATE
  </sql>
  <sql id="columns_alias">
    t.E_ID, t.E_LINE, t.E_DATA, t.E_DATE, t.E_CREATEDATE
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM EMS_E_HISTORY
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM EMS_E_HISTORY t
  </sql>
  <sql id="where">
    <where> 
      <if test="eId != null">
        and E_ID = #{eId}
      </if>
      <if test="eLine != null and eLine != ''">
        and E_LINE = #{eLine}
      </if>
      <if test="eData != null and eData != ''">
        and E_DATA = #{eData}
      </if>
      <if test="eDate != null">
        and TO_CHAR(E_DATE,'yyyy-MM-dd') = #{eDate}
      </if>
      <if test="eCreatedate != null">
        and TO_CHAR(E_CREATEDATE,'yyyy-MM-dd') = #{eCreatedate}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="eId != null">
        and E_ID = #{eId}
      </if>
      <if test="eLine != null and eLine != ''">
        and E_LINE LIKE '%${eLine}%'
      </if>
      <if test="eData != null and eData != ''">
        and E_DATA LIKE '%${eData}%'
      </if>
      <if test="eDate != null">
        and TO_CHAR(E_DATE,'yyyy-MM-dd') = #{eDate}
      </if>
      <if test="eCreatedate != null">
        and TO_CHAR(E_CREATEDATE,'yyyy-MM-dd') = #{eCreatedate}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Short">
    delete from EMS_E_HISTORY
    where E_ID = #{eId,jdbcType=DECIMAL}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from EMS_E_HISTORY
    where 1!=1 
      <if test="eLine != null and eLine != ''">
        or E_LINE = #{eLine}
      </if>
      <if test="eData != null and eData != ''">
        or E_DATA = #{eData}
      </if>
      <if test="eDate != null">
        or TO_CHAR(E_DATE,'yyyy-MM-dd') = '#{eDate}'
      </if>
      <if test="eCreatedate != null">
        or TO_CHAR(E_CREATEDATE,'yyyy-MM-dd') = '#{eCreatedate}'
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.emsehistory.model.EmsEHistory">
    insert into EMS_E_HISTORY (E_ID, E_LINE, E_DATA, 
      E_DATE, E_CREATEDATE)
    values (#{eId,jdbcType=DECIMAL}, #{eLine,jdbcType=VARCHAR}, #{eData,jdbcType=VARCHAR}, 
      #{eDate,jdbcType=TIMESTAMP}, #{eCreatedate,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.emsehistory.model.EmsEHistory">
    insert into EMS_E_HISTORY
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="eId != null">
        E_ID,
      </if>
      <if test="eLine != null">
        E_LINE,
      </if>
      <if test="eData != null">
        E_DATA,
      </if>
      <if test="eDate != null">
        E_DATE,
      </if>
      <if test="eCreatedate != null">
        E_CREATEDATE,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="eId != null">
        #{eId,jdbcType=DECIMAL},
      </if>
      <if test="eLine != null">
        #{eLine,jdbcType=VARCHAR},
      </if>
      <if test="eData != null">
        #{eData,jdbcType=VARCHAR},
      </if>
      <if test="eDate != null">
        #{eDate,jdbcType=TIMESTAMP},
      </if>
      <if test="eCreatedate != null">
        #{eCreatedate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.emsehistory.model.EmsEHistory">
    update EMS_E_HISTORY
    set E_LINE = #{eLine,jdbcType=VARCHAR},
      E_DATA = #{eData,jdbcType=VARCHAR},
      E_DATE = #{eDate,jdbcType=TIMESTAMP},
      E_CREATEDATE = #{eCreatedate,jdbcType=TIMESTAMP}
    where E_ID = #{eId,jdbcType=DECIMAL}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.emsehistory.model.EmsEHistory">
    update EMS_E_HISTORY
    <set>
      <if test="eLine != null">
        E_LINE = #{eLine,jdbcType=VARCHAR},
      </if>
      <if test="eData != null">
        E_DATA = #{eData,jdbcType=VARCHAR},
      </if>
      <if test="eDate != null">
        E_DATE = #{eDate,jdbcType=TIMESTAMP},
      </if>
      <if test="eCreatedate != null">
        E_CREATEDATE = #{eCreatedate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where E_ID = #{eId,jdbcType=DECIMAL}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.Short" resultMap="BaseResultMap">
    <include refid="select"/>
    where E_ID = #{eId,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 EMS_E_HISTORY 
      (E_ID, 
      E_LINE, E_DATA, E_DATE, 
      E_CREATEDATE)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.eId,jdbcType=DECIMAL}, 
      #{item.eLine,jdbcType=VARCHAR}, #{item.eData,jdbcType=VARCHAR}, #{item.eDate,jdbcType=TIMESTAMP}, 
      #{item.eCreatedate,jdbcType=TIMESTAMP} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update EMS_E_HISTORY
     set
       E_ID=
       <foreach collection="list" item="item" index="index" separator=" " open="case E_ID" close="end">
          when #{item.eId,jdbcType=DECIMAL} then #{item.eId,jdbcType=DECIMAL}
       </foreach>
       ,E_LINE=
       <foreach collection="list" item="item" index="index" separator=" " open="case E_ID" close="end">
          when #{item.eId,jdbcType=DECIMAL} then #{item.eLine,jdbcType=VARCHAR}
       </foreach>
       ,E_DATA=
       <foreach collection="list" item="item" index="index" separator=" " open="case E_ID" close="end">
          when #{item.eId,jdbcType=DECIMAL} then #{item.eData,jdbcType=VARCHAR}
       </foreach>
       ,E_DATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case E_ID" close="end">
          when #{item.eId,jdbcType=DECIMAL} then #{item.eDate,jdbcType=TIMESTAMP}
       </foreach>
       ,E_CREATEDATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case E_ID" close="end">
          when #{item.eId,jdbcType=DECIMAL} then #{item.eCreatedate,jdbcType=TIMESTAMP}
       </foreach>
     where E_ID in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.eId,jdbcType=DECIMAL}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from EMS_E_HISTORY
    where E_ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <!-- 查询时间段数据 -->
  <select id="getEmsEHistoryByDate" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <where>
      <if test="clock != null and clock != ''">
          and E_DATE &gt;= TO_DATE(#{clock},'yyyy-MM-dd hh24:mi:ss')
      </if>
      <if test="clocke != null and clocke != ''">
          and E_DATE &lt;= TO_DATE(#{clocke},'yyyy-MM-dd hh24:mi:ss')
      </if>
      and to_char(E_DATE,'mi') &lt; 9
    </where>
    order by E_DATE
  </select>
</mapper>