<?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.njformula.mapper.NjFormulaMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.njformula.model.NjFormula">
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="MATERIALNO" jdbcType="VARCHAR" property="materialno" />
    <result column="CODE" jdbcType="VARCHAR" property="code" />
    <result column="MEMO" jdbcType="VARCHAR" property="memo" />
  </resultMap>
  <sql id="columns">
    ID, MATERIALNO, CODE, MEMO
  </sql>
  <sql id="columns_alias">
    t.ID, t.MATERIALNO, t.CODE, t.MEMO
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM NJ_FORMULA
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM NJ_FORMULA t
  </sql>
  <sql id="where">
    <where> 
      <if test="id != null and id != ''">
        and ID = #{id}
      </if>
      <if test="materialno != null and materialno != ''">
        and MATERIALNO = #{materialno}
      </if>
      <if test="code != null and code != ''">
        and CODE = #{code}
      </if>
      <if test="memo != null and memo != ''">
        and MEMO = #{memo}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="id != null and id != ''">
        and ID LIKE '%${id}%'
      </if>
      <if test="materialno != null and materialno != ''">
        and MATERIALNO LIKE '%${materialno}%'
      </if>
      <if test="code != null and code != ''">
        and CODE LIKE '%${code}%'
      </if>
      <if test="memo != null and memo != ''">
        and MEMO LIKE '%${memo}%'
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from NJ_FORMULA
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from NJ_FORMULA
    where 1!=1 
      <if test="materialno != null and materialno != ''">
        or MATERIALNO = #{materialno}
      </if>
      <if test="code != null and code != ''">
        or CODE = #{code}
      </if>
      <if test="memo != null and memo != ''">
        or MEMO = #{memo}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.njformula.model.NjFormula">
    insert into NJ_FORMULA (ID, MATERIALNO, CODE, 
      MEMO)
    values (#{id,jdbcType=VARCHAR}, #{materialno,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, 
      #{memo,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.njformula.model.NjFormula">
    insert into NJ_FORMULA
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="materialno != null">
        MATERIALNO,
      </if>
      <if test="code != null">
        CODE,
      </if>
      <if test="memo != null">
        MEMO,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="materialno != null">
        #{materialno,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        #{code,jdbcType=VARCHAR},
      </if>
      <if test="memo != null">
        #{memo,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.njformula.model.NjFormula">
    update NJ_FORMULA
    set MATERIALNO = #{materialno,jdbcType=VARCHAR},
      CODE = #{code,jdbcType=VARCHAR},
      MEMO = #{memo,jdbcType=VARCHAR}
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.njformula.model.NjFormula">
    update NJ_FORMULA
    <set>
      <if test="materialno != null">
        MATERIALNO = #{materialno,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        CODE = #{code,jdbcType=VARCHAR},
      </if>
      <if test="memo != null">
        MEMO = #{memo,jdbcType=VARCHAR},
      </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 NJ_FORMULA 
      (ID, 
      MATERIALNO, CODE, MEMO
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.id,jdbcType=VARCHAR}, 
      #{item.materialno,jdbcType=VARCHAR}, #{item.code,jdbcType=VARCHAR}, #{item.memo,jdbcType=VARCHAR}
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update NJ_FORMULA
     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>
       ,MATERIALNO=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.materialno,jdbcType=VARCHAR}
       </foreach>
       ,CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.code,jdbcType=VARCHAR}
       </foreach>
       ,MEMO=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.memo,jdbcType=VARCHAR}
       </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 NJ_FORMULA
    where ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
<!--  根据物料编码获取公式-->
  <select id="getByMateralNo" parameterType="java.lang.String" resultMap="BaseResultMap">
    select t.code from NJ_FORMULA t where
    t.MATERIALNO =#{MateralNo}
  </select>
</mapper>