<?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.chemicalconstituents.mapper.ChemicalConstituentsMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.chemicalconstituents.model.ChemicalConstituents">
    <id column="GMID" jdbcType="VARCHAR" property="gmid" />
    <id column="CHEM_CODE" jdbcType="VARCHAR" property="chemCode" />
    <result column="NK_STD_MIN" jdbcType="DECIMAL" property="nkStdMin" />
    <result column="NK_STD_MAX" jdbcType="DECIMAL" property="nkStdMax" />
  </resultMap>
  <sql id="columns">
    GMID, CHEM_CODE, NK_STD_MIN, NK_STD_MAX
  </sql>
  <sql id="columns_alias">
    t.GMID, t.CHEM_CODE, t.NK_STD_MIN, t.NK_STD_MAX
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM CHEMICAL_CONSTITUENTS
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM CHEMICAL_CONSTITUENTS t
  </sql>
  <sql id="where">
    <where> 
      <if test="gmid != null and gmid != ''">
        and GMID = #{gmid}
      </if>
      <if test="chemCode != null and chemCode != ''">
        and CHEM_CODE = #{chemCode}
      </if>
      <if test="nkStdMin != null">
        and NK_STD_MIN = #{nkStdMin}
      </if>
      <if test="nkStdMax != null">
        and NK_STD_MAX = #{nkStdMax}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="gmid != null and gmid != ''">
        and GMID LIKE '%${gmid}%'
      </if>
      <if test="chemCode != null and chemCode != ''">
        and CHEM_CODE LIKE '%${chemCode}%'
      </if>
      <if test="nkStdMin != null">
        and NK_STD_MIN = #{nkStdMin}
      </if>
      <if test="nkStdMax != null">
        and NK_STD_MAX = #{nkStdMax}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="map">
    delete from CHEMICAL_CONSTITUENTS
    where GMID = #{gmid,jdbcType=VARCHAR}
      and CHEM_CODE = #{chemCode,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from CHEMICAL_CONSTITUENTS
    where 1!=1 
      <if test="chemCode != null and chemCode != ''">
        or CHEM_CODE = #{chemCode}
      </if>
      <if test="nkStdMin != null">
        or NK_STD_MIN = #{nkStdMin}
      </if>
      <if test="nkStdMax != null">
        or NK_STD_MAX = #{nkStdMax}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.chemicalconstituents.model.ChemicalConstituents">
    insert into CHEMICAL_CONSTITUENTS (GMID, CHEM_CODE,
      NK_STD_MIN, NK_STD_MAX)
    values (#{gmid,jdbcType=VARCHAR}, #{chemCode,jdbcType=VARCHAR},
      #{nkStdMin,jdbcType=DECIMAL}, #{nkStdMax,jdbcType=DECIMAL})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.chemicalconstituents.model.ChemicalConstituents">
    insert into CHEMICAL_CONSTITUENTS
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="gmid != null">
        GMID,
      </if>
      <if test="chemCode != null">
        CHEM_CODE,
      </if>
      <if test="nkStdMin != null">
        NK_STD_MIN,
      </if>
      <if test="nkStdMax != null">
        NK_STD_MAX,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="gmid != null">
        #{gmid,jdbcType=VARCHAR},
      </if>
      <if test="chemCode != null">
        #{chemCode,jdbcType=VARCHAR},
      </if>
      <if test="nkStdMin != null">
        #{nkStdMin,jdbcType=DECIMAL},
      </if>
      <if test="nkStdMax != null">
        #{nkStdMax,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.chemicalconstituents.model.ChemicalConstituents">
    update CHEMICAL_CONSTITUENTS
    set NK_STD_MIN = #{nkStdMin,jdbcType=DECIMAL},
      NK_STD_MAX = #{nkStdMax,jdbcType=DECIMAL}
    where GMID = #{gmid,jdbcType=VARCHAR}
      and CHEM_CODE = #{chemCode,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.chemicalconstituents.model.ChemicalConstituents">
    update CHEMICAL_CONSTITUENTS
    <set>
      <if test="nkStdMin != null">
        NK_STD_MIN = #{nkStdMin,jdbcType=DECIMAL},
      </if>
      <if test="nkStdMax != null">
        NK_STD_MAX = #{nkStdMax,jdbcType=DECIMAL},
      </if>
    </set>
    where GMID = #{gmid,jdbcType=VARCHAR}
      and CHEM_CODE = #{chemCode,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="map" resultMap="BaseResultMap">
    <include refid="select"/>
    where GMID = #{gmid,jdbcType=VARCHAR}
      and CHEM_CODE = #{chemCode,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 CHEMICAL_CONSTITUENTS 
      (GMID, 
      CHEM_CODE, NK_STD_MIN,
      NK_STD_MAX)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.gmid,jdbcType=VARCHAR}, 
      #{item.chemCode,jdbcType=VARCHAR}, #{item.nkStdMin,jdbcType=DECIMAL},
      #{item.nkStdMax,jdbcType=DECIMAL} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update CHEMICAL_CONSTITUENTS
     set
       GMID=
       <foreach collection="list" item="item" index="index" separator=" " open="case GMID" close="end">
          when #{item.gmid,jdbcType=VARCHAR} then #{item.gmid,jdbcType=VARCHAR}
       </foreach>
       ,CHEM_CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case GMID" close="end">
          when #{item.gmid,jdbcType=VARCHAR} then #{item.chemCode,jdbcType=VARCHAR}
       </foreach>
       ,NK_STD_MIN=
       <foreach collection="list" item="item" index="index" separator=" " open="case GMID" close="end">
          when #{item.gmid,jdbcType=VARCHAR} then #{item.nkStdMin,jdbcType=DECIMAL}
       </foreach>
       ,NK_STD_MAX=
       <foreach collection="list" item="item" index="index" separator=" " open="case GMID" close="end">
          when #{item.gmid,jdbcType=VARCHAR} then #{item.nkStdMax,jdbcType=DECIMAL}
       </foreach>
    where (GMID,CHEM_CODE) in
    <foreach collection="list" item="item" open="(" close=")" separator=",">
     (#{item.gmid, jdbcType=VARCHAR},#{item.chemCode, jdbcType=VARCHAR})
    </foreach>
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from CHEMICAL_CONSTITUENTS
    where (GMID,CHEM_CODE) in
    <foreach collection="list" item="item" open="(" close=")" separator=",">
     ( #{item.gmid, jdbcType=VARCHAR}, #{item.chemCode, jdbcType=VARCHAR})
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="getDataByGmid" parameterType="java.lang.String" resultMap="BaseResultMap">
    SELECT GMID, CHEM_CODE, NK_STD_MIN, NK_STD_MAX FROM CHEMICAL_CONSTITUENTS
    WHERE
    GMID = #{gmid}
  </select>
</mapper>