<?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.trmstation.mapper.TRmStationMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.trmstation.model.TRmStation">
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="NAME" jdbcType="VARCHAR" property="name" />
    <result column="SORTSEQ" jdbcType="DECIMAL" property="sortseq" />
    <result column="ADRESS" jdbcType="VARCHAR" property="adress" />
    <result column="DEMO" jdbcType="VARCHAR" property="demo" />
    <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>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_RM_STATION
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_RM_STATION
    where 1=1
      <if test="name != null and name != ''">
        and NAME = #{name}
      </if>
      <if test="sortseq != null">
        and SORTSEQ = #{sortseq}
      </if>
      <if test="adress != null and adress != ''">
        and ADRESS = #{adress}
      </if>
      <if test="demo != null and demo != ''">
        and DEMO = #{demo}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.trmstation.model.TRmStation">
    insert into T_RM_STATION (ID, NAME, SORTSEQ, 
      ADRESS, DEMO, CREATEMAN, CREATETIME)
    values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{sortseq,jdbcType=DECIMAL}, 
      #{adress,jdbcType=VARCHAR}, #{demo,jdbcType=VARCHAR}, #{createman,jdbcType=VARCHAR}, SYSDATE)
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.trmstation.model.TRmStation">
    insert into T_RM_STATION
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="name != null">
        NAME,
      </if>
      <if test="sortseq != null">
        SORTSEQ,
      </if>
      <if test="adress != null">
        ADRESS,
      </if>
      <if test="demo != null">
        DEMO,
      </if>
        CREATEMAN,
        CREATETIME
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="sortseq != null">
        #{sortseq,jdbcType=DECIMAL},
      </if>
      <if test="adress != null">
        #{adress,jdbcType=VARCHAR},
      </if>
      <if test="demo != null">
        #{demo,jdbcType=VARCHAR},
      </if>
        #{createman,jdbcType=VARCHAR},
        SYSDATE
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.trmstation.model.TRmStation">
    update T_RM_STATION
    set NAME = #{name,jdbcType=VARCHAR},
      SORTSEQ = #{sortseq,jdbcType=DECIMAL},
      ADRESS = #{adress,jdbcType=VARCHAR},
      DEMO = #{demo,jdbcType=VARCHAR},
      UPDATEMAN = #{updateman, jdbcType=VARCHAR},
      UPDATETIME = SYSDATE
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.trmstation.model.TRmStation">
    update T_RM_STATION
    <set>
      <if test="name != null">
        NAME = #{name,jdbcType=VARCHAR},
      </if>
      <if test="sortseq != null">
        SORTSEQ = #{sortseq,jdbcType=DECIMAL},
      </if>
      <if test="adress != null">
        ADRESS = #{adress,jdbcType=VARCHAR},
      </if>
      <if test="demo != null">
        DEMO = #{demo,jdbcType=VARCHAR},
      </if>
        UPDATEMAN = #{updateman, jdbcType=VARCHAR},
        UPDATETIME = SYSDATE
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select ID, NAME, SORTSEQ, ADRESS, DEMO
    from T_RM_STATION
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ID, NAME, SORTSEQ, ADRESS, DEMO, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_RM_STATION
    <where>
      <if test="id != null and id != ''">
        and ID = #{id}
      </if>
      <if test="name != null and name != ''">
        and NAME = #{name}
      </if>
      <if test="sortseq != null">
        and SORTSEQ = #{sortseq}
      </if>
      <if test="adress != null and adress != ''">
        and ADRESS = #{adress}
      </if>
      <if test="demo != null and demo != ''">
        and DEMO = #{demo}
      </if>
    </where>
    order by SORTSEQ
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ID, NAME, SORTSEQ, ADRESS, DEMO, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_RM_STATION
    <where>
      <if test="id != null and id != ''">
        and ID LIKE '%${id}%'
      </if>
      <if test="name != null and name != ''">
        and NAME LIKE '%${name}%'
      </if>
      <if test="sortseq != null">
        and SORTSEQ = #{sortseq}
      </if>
      <if test="adress != null and adress != ''">
        and ADRESS LIKE '%${adress}%'
      </if>
      <if test="demo != null and demo != ''">
        and DEMO LIKE '%${demo}%'
      </if>
    </where>
    order by SORTSEQ
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_RM_STATION 
      (ID, 
      NAME, SORTSEQ, ADRESS, 
      DEMO, CREATEMAN, CREATETIME)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.id,jdbcType=VARCHAR}, 
      #{item.name,jdbcType=VARCHAR}, #{item.sortseq,jdbcType=DECIMAL}, #{item.adress,jdbcType=VARCHAR}, 
      #{item.demo,jdbcType=VARCHAR}, #{item.createman,jdbcType=VARCHAR}, SYSDATE from dual
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_RM_STATION
     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>
       ,NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.name,jdbcType=VARCHAR}
       </foreach>
       ,SORTSEQ=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.sortseq,jdbcType=DECIMAL}
       </foreach>
       ,ADRESS=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.adress,jdbcType=VARCHAR}
       </foreach>
       ,DEMO=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.demo,jdbcType=VARCHAR}
       </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 SYSDATE
        </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_STATION
    where ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <select id="getNameAndId" resultMap="BaseResultMap">
    select ID, NAME from T_RM_STATION order by NAME
  </select>
  <select id="getMaxSortSeq" resultType="java.lang.Long">
    SELECT MAX(SORTSEQ) from T_RM_STATION
  </select>
</mapper>