<?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.trmmaterial.mapper.TRmMaterialMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.trmmaterial.model.TRmMaterial">
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="NAME" jdbcType="VARCHAR" property="name" />
    <result column="REMARK" jdbcType="VARCHAR" property="remark" />
    <result column="TYPE" jdbcType="VARCHAR" property="type" />
    <result column="SEQNO" jdbcType="VARCHAR" property="seqno" />
    <result column="BCODE" jdbcType="VARCHAR" property="bcode" />
    <result column="BDESC1" jdbcType="VARCHAR" property="bdesc1" />
    <result column="BDESC2" jdbcType="VARCHAR" property="bdesc2" />
    <result column="STATE" jdbcType="VARCHAR" property="state" />
    <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_MATERIAL
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_RM_MATERIAL
    where 1!=1 
      <if test="name != null and name != ''">
        and NAME = #{name}
      </if>
      <if test="remark != null and remark != ''">
        and REMARK = #{remark}
      </if>
      <if test="type != null and type != ''">
        and TYPE = #{type}
      </if>
      <if test="seqno != null and seqno != ''">
        and SEQNO = #{seqno}
      </if>
      <if test="bcode != null and bcode != ''">
        and BCODE = #{bcode}
      </if>
      <if test="bdesc1 != null and bdesc1 != ''">
        and BDESC1 = #{bdesc1}
      </if>
      <if test="bdesc2 != null and bdesc2 != ''">
        and BDESC2 = #{bdesc2}
      </if>
      <if test="state != null and state != ''">
        and STATE = #{state}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.trmmaterial.model.TRmMaterial">
    insert into T_RM_MATERIAL (ID, NAME, REMARK, 
      TYPE, SEQNO, BCODE, 
      BDESC1, BDESC2, STATE, CREATEMAN, CREATETIME
      )
    values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, 
      #{type,jdbcType=VARCHAR}, #{seqno,jdbcType=VARCHAR}, #{bcode,jdbcType=VARCHAR}, 
      #{bdesc1,jdbcType=VARCHAR}, #{bdesc2,jdbcType=VARCHAR}, #{state,jdbcType=VARCHAR},
      #{createman,jdbcType=VARCHAR}, SYSDATE
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.trmmaterial.model.TRmMaterial">
    insert into T_RM_MATERIAL
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="name != null">
        NAME,
      </if>
      <if test="remark != null">
        REMARK,
      </if>
      <if test="type != null">
        TYPE,
      </if>
      <if test="seqno != null">
        SEQNO,
      </if>
      <if test="bcode != null">
        BCODE,
      </if>
      <if test="bdesc1 != null">
        BDESC1,
      </if>
      <if test="bdesc2 != null">
        BDESC2,
      </if>
      <if test="state != null">
        STATE,
      </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="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=VARCHAR},
      </if>
      <if test="seqno != null">
        #{seqno,jdbcType=VARCHAR},
      </if>
      <if test="bcode != null">
        #{bcode,jdbcType=VARCHAR},
      </if>
      <if test="bdesc1 != null">
        #{bdesc1,jdbcType=VARCHAR},
      </if>
      <if test="bdesc2 != null">
        #{bdesc2,jdbcType=VARCHAR},
      </if>
      <if test="state != null">
        #{state,jdbcType=VARCHAR},
      </if>
      #{createman,jdbcType=VARCHAR},
      SYSDATE
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.trmmaterial.model.TRmMaterial">
    update T_RM_MATERIAL
    set NAME = #{name,jdbcType=VARCHAR},
      REMARK = #{remark,jdbcType=VARCHAR},
      TYPE = #{type,jdbcType=VARCHAR},
      SEQNO = #{seqno,jdbcType=VARCHAR},
      BCODE = #{bcode,jdbcType=VARCHAR},
      BDESC1 = #{bdesc1,jdbcType=VARCHAR},
      BDESC2 = #{bdesc2,jdbcType=VARCHAR},
      STATE = #{state,jdbcType=VARCHAR},
      UPDATEMAN = #{updateman, jdbcType=VARCHAR},
      UPDATETIME = SYSDATE
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.trmmaterial.model.TRmMaterial">
    update T_RM_MATERIAL
    <set>
      <if test="name != null">
        NAME = #{name,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        REMARK = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        TYPE = #{type,jdbcType=VARCHAR},
      </if>
      <if test="seqno != null">
        SEQNO = #{seqno,jdbcType=VARCHAR},
      </if>
      <if test="bcode != null">
        BCODE = #{bcode,jdbcType=VARCHAR},
      </if>
      <if test="bdesc1 != null">
        BDESC1 = #{bdesc1,jdbcType=VARCHAR},
      </if>
      <if test="bdesc2 != null">
        BDESC2 = #{bdesc2,jdbcType=VARCHAR},
      </if>
      <if test="state != null">
        STATE = #{state,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, REMARK, TYPE, SEQNO, BCODE, BDESC1, BDESC2, STATE, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_RM_MATERIAL
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ID, NAME, REMARK, TYPE, SEQNO, BCODE, BDESC1, BDESC2, STATE, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_RM_MATERIAL
    <where> 
      <if test="name != null and name != ''">
        and NAME = #{name}
      </if>
      <if test="remark != null and remark != ''">
        and REMARK = #{remark}
      </if>
      <if test="type != null and type != ''">
        and TYPE = #{type}
      </if>
      <if test="seqno != null and seqno != ''">
        and SEQNO = #{seqno}
      </if>
      <if test="bcode != null and bcode != ''">
        and BCODE = #{bcode}
      </if>
      <if test="bdesc1 != null and bdesc1 != ''">
        and BDESC1 = #{bdesc1}
      </if>
      <if test="bdesc2 != null and bdesc2 != ''">
        and BDESC2 = #{bdesc2}
      </if>
      <if test="state != null and state != ''">
        and STATE = #{state}
      </if>
    </where>
    order by id
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ID, NAME, REMARK, TYPE, SEQNO, BCODE, BDESC1, BDESC2, STATE, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_RM_MATERIAL
    <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="remark != null and remark != ''">
        and REMARK LIKE '%${remark}%'
      </if>
      <if test="type != null and type != ''">
        and TYPE LIKE '%${type}%'
      </if>
      <if test="seqno != null and seqno != ''">
        and SEQNO LIKE '%${seqno}%'
      </if>
      <if test="bcode != null and bcode != ''">
        and BCODE LIKE '%${bcode}%'
      </if>
      <if test="bdesc1 != null and bdesc1 != ''">
        and BDESC1 LIKE '%${bdesc1}%'
      </if>
      <if test="bdesc2 != null and bdesc2 != ''">
        and BDESC2 LIKE '%${bdesc2}%'
      </if>
      <if test="state != null and state != ''">
        and STATE LIKE '%${state}%'
      </if>
    </where>
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_RM_MATERIAL 
      (ID, 
      NAME, REMARK, TYPE, 
      SEQNO, BCODE, BDESC1, 
      BDESC2, STATE, CREATEMAN, CREATETIME)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.id,jdbcType=VARCHAR}, 
      #{item.name,jdbcType=VARCHAR}, #{item.remark,jdbcType=VARCHAR}, #{item.type,jdbcType=VARCHAR}, 
      #{item.seqno,jdbcType=VARCHAR}, #{item.bcode,jdbcType=VARCHAR}, #{item.bdesc1,jdbcType=VARCHAR}, 
      #{item.bdesc2,jdbcType=VARCHAR}, #{item.state,jdbcType=VARCHAR},
    #{item.createman,jdbcType=VARCHAR}, SYSDATE from dual
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_RM_MATERIAL
     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>
       ,REMARK=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.remark,jdbcType=VARCHAR}
       </foreach>
       ,TYPE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.type,jdbcType=VARCHAR}
       </foreach>
       ,SEQNO=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.seqno,jdbcType=VARCHAR}
       </foreach>
       ,BCODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.bcode,jdbcType=VARCHAR}
       </foreach>
       ,BDESC1=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.bdesc1,jdbcType=VARCHAR}
       </foreach>
       ,BDESC2=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.bdesc2,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>
        ,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_MATERIAL
    where ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>

    <!--查询下拉框-->
    <select id="getIdAndName" resultType="com.steerinfo.ems.trmmaterial.model.TRmMaterial">
        SELECT ID , NAME FROM T_RM_MATERIAL ORDER BY NAME
    </select>

   <!--获取ems物料编码-->
    <select id="getBcode" parameterType="string" resultType="string">
        select t1.bcode from t_rm_material t1 where t1.id=#{materialid}
    </select>

    <!--获取最大值-->
    <select id="getMaxId" resultType="string">
        select nvl(max(to_number(SUBSTR(ID,2))),'000') from T_RM_MATERIAL
    </select>

    <!--获取最大序列-->
    <select id="getMaxNo" resultType="string">
         select max(to_number(SEQNO)) from T_RM_MATERIAL
    </select>

  <select id="getDataForPk" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    SELECT ID,NAME FROM T_RM_MATERIAL
    <where>
      <if test="materialid != null and  materialid != ''">
        and ID in  (${materialid})
      </if>
    </where>
  </select>
</mapper>