<?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.qcmbasechem.mapper.QcmBaseChemMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.qcmbasechem.model.QcmBaseChem">
    <id column="CHEM_CODE" jdbcType="VARCHAR" property="chemCode" />
    <result column="CHEM_NAME" jdbcType="VARCHAR" property="chemName" />
    <result column="CHEM_TYPE" jdbcType="CHAR" property="chemType" />
    <result column="CHEM_FORMULA" jdbcType="VARCHAR" property="chemFormula" />
    <result column="VALID_FLAG" jdbcType="CHAR" property="validFlag" />
    <result column="CHEM_SOURCE" jdbcType="VARCHAR" property="chemSource" />
    <result column="L3_CODE_NO" jdbcType="VARCHAR" property="l3CodeNo" />
    <result column="L3_CHEM_CODE" jdbcType="VARCHAR" property="l3ChemCode" />
    <result column="DISPLAY_ORDER" jdbcType="DECIMAL" property="displayOrder" />
    <result column="MEMO" jdbcType="VARCHAR" property="memo" />
    <result column="CREATE_OPR" jdbcType="VARCHAR" property="createOpr" />
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    <result column="UPDATE_OPR" jdbcType="VARCHAR" property="updateOpr" />
    <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="columns">
    CHEM_CODE, CHEM_NAME, CHEM_TYPE, CHEM_FORMULA, VALID_FLAG, CHEM_SOURCE, L3_CODE_NO, 
    L3_CHEM_CODE, DISPLAY_ORDER, MEMO, CREATE_OPR, CREATE_TIME, UPDATE_OPR, UPDATE_TIME
  </sql>
  <sql id="columns_alias">
    t.CHEM_CODE, t.CHEM_NAME, t.CHEM_TYPE, t.CHEM_FORMULA, t.VALID_FLAG, t.CHEM_SOURCE, 
    t.L3_CODE_NO, t.L3_CHEM_CODE, t.DISPLAY_ORDER, t.MEMO, t.CREATE_OPR, t.CREATE_TIME, 
    t.UPDATE_OPR, t.UPDATE_TIME
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM QCM_BASE_CHEM
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM QCM_BASE_CHEM t
  </sql>
  <sql id="where">
    <where> 
      <if test="chemCode != null and chemCode != ''">
        and CHEM_CODE = #{chemCode}
      </if>
      <if test="chemName != null and chemName != ''">
        and CHEM_NAME = #{chemName}
      </if>
      <if test="chemType != null">
        and CHEM_TYPE = #{chemType}
      </if>
      <if test="chemFormula != null and chemFormula != ''">
        and CHEM_FORMULA = #{chemFormula}
      </if>
      <if test="validFlag != null">
        and VALID_FLAG = #{validFlag}
      </if>
      <if test="chemSource != null and chemSource != ''">
        and CHEM_SOURCE = #{chemSource}
      </if>
      <if test="l3CodeNo != null and l3CodeNo != ''">
        and L3_CODE_NO = #{l3CodeNo}
      </if>
      <if test="l3ChemCode != null and l3ChemCode != ''">
        and L3_CHEM_CODE = #{l3ChemCode}
      </if>
      <if test="displayOrder != null">
        and DISPLAY_ORDER = #{displayOrder}
      </if>
      <if test="memo != null and memo != ''">
        and MEMO = #{memo}
      </if>
      <if test="createOpr != null and createOpr != ''">
        and CREATE_OPR = #{createOpr}
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="updateOpr != null and updateOpr != ''">
        and UPDATE_OPR = #{updateOpr}
      </if>
      <if test="updateTime != null">
        and TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = #{updateTime}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="chemCode != null and chemCode != ''">
        and CHEM_CODE LIKE '%${chemCode}%'
      </if>
      <if test="chemName != null and chemName != ''">
        and CHEM_NAME LIKE '%${chemName}%'
      </if>
      <if test="chemType != null">
        and CHEM_TYPE = #{chemType}
      </if>
      <if test="chemFormula != null and chemFormula != ''">
        and CHEM_FORMULA LIKE '%${chemFormula}%'
      </if>
      <if test="validFlag != null">
        and VALID_FLAG = #{validFlag}
      </if>
      <if test="chemSource != null and chemSource != ''">
        and CHEM_SOURCE LIKE '%${chemSource}%'
      </if>
      <if test="l3CodeNo != null and l3CodeNo != ''">
        and L3_CODE_NO LIKE '%${l3CodeNo}%'
      </if>
      <if test="l3ChemCode != null and l3ChemCode != ''">
        and L3_CHEM_CODE LIKE '%${l3ChemCode}%'
      </if>
      <if test="displayOrder != null">
        and DISPLAY_ORDER = #{displayOrder}
      </if>
      <if test="memo != null and memo != ''">
        and MEMO LIKE '%${memo}%'
      </if>
      <if test="createOpr != null and createOpr != ''">
        and CREATE_OPR LIKE '%${createOpr}%'
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="updateOpr != null and updateOpr != ''">
        and UPDATE_OPR LIKE '%${updateOpr}%'
      </if>
      <if test="updateTime != null">
        and TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = #{updateTime}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from QCM_BASE_CHEM
    where CHEM_CODE = #{chemCode,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from QCM_BASE_CHEM
    where 1!=1 
      <if test="chemName != null and chemName != ''">
        or CHEM_NAME = #{chemName}
      </if>
      <if test="chemType != null">
        or CHEM_TYPE = #{chemType}
      </if>
      <if test="chemFormula != null and chemFormula != ''">
        or CHEM_FORMULA = #{chemFormula}
      </if>
      <if test="validFlag != null">
        or VALID_FLAG = #{validFlag}
      </if>
      <if test="chemSource != null and chemSource != ''">
        or CHEM_SOURCE = #{chemSource}
      </if>
      <if test="l3CodeNo != null and l3CodeNo != ''">
        or L3_CODE_NO = #{l3CodeNo}
      </if>
      <if test="l3ChemCode != null and l3ChemCode != ''">
        or L3_CHEM_CODE = #{l3ChemCode}
      </if>
      <if test="displayOrder != null">
        or DISPLAY_ORDER = #{displayOrder}
      </if>
      <if test="memo != null and memo != ''">
        or MEMO = #{memo}
      </if>
      <if test="createOpr != null and createOpr != ''">
        or CREATE_OPR = #{createOpr}
      </if>
      <if test="createTime != null">
        or TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = '#{createTime}'
      </if>
      <if test="updateOpr != null and updateOpr != ''">
        or UPDATE_OPR = #{updateOpr}
      </if>
      <if test="updateTime != null">
        or TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = '#{updateTime}'
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.qcmbasechem.model.QcmBaseChem">
    insert into QCM_BASE_CHEM (CHEM_CODE, CHEM_NAME, CHEM_TYPE, 
      CHEM_FORMULA, VALID_FLAG, CHEM_SOURCE, 
      L3_CODE_NO, L3_CHEM_CODE, DISPLAY_ORDER, 
      MEMO, CREATE_OPR, CREATE_TIME, 
      UPDATE_OPR, UPDATE_TIME)
    values (#{chemCode,jdbcType=VARCHAR}, #{chemName,jdbcType=VARCHAR}, #{chemType,jdbcType=CHAR}, 
      #{chemFormula,jdbcType=VARCHAR}, #{validFlag,jdbcType=CHAR}, #{chemSource,jdbcType=VARCHAR}, 
      #{l3CodeNo,jdbcType=VARCHAR}, #{l3ChemCode,jdbcType=VARCHAR}, #{displayOrder,jdbcType=DECIMAL}, 
      #{memo,jdbcType=VARCHAR}, #{createOpr,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateOpr,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.qcmbasechem.model.QcmBaseChem">
    insert into QCM_BASE_CHEM
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="chemCode != null">
        CHEM_CODE,
      </if>
      <if test="chemName != null">
        CHEM_NAME,
      </if>
      <if test="chemType != null">
        CHEM_TYPE,
      </if>
      <if test="chemFormula != null">
        CHEM_FORMULA,
      </if>
      <if test="validFlag != null">
        VALID_FLAG,
      </if>
      <if test="chemSource != null">
        CHEM_SOURCE,
      </if>
      <if test="l3CodeNo != null">
        L3_CODE_NO,
      </if>
      <if test="l3ChemCode != null">
        L3_CHEM_CODE,
      </if>
      <if test="displayOrder != null">
        DISPLAY_ORDER,
      </if>
      <if test="memo != null">
        MEMO,
      </if>
      <if test="createOpr != null">
        CREATE_OPR,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
      <if test="updateOpr != null">
        UPDATE_OPR,
      </if>
      <if test="updateTime != null">
        UPDATE_TIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="chemCode != null">
        #{chemCode,jdbcType=VARCHAR},
      </if>
      <if test="chemName != null">
        #{chemName,jdbcType=VARCHAR},
      </if>
      <if test="chemType != null">
        #{chemType,jdbcType=CHAR},
      </if>
      <if test="chemFormula != null">
        #{chemFormula,jdbcType=VARCHAR},
      </if>
      <if test="validFlag != null">
        #{validFlag,jdbcType=CHAR},
      </if>
      <if test="chemSource != null">
        #{chemSource,jdbcType=VARCHAR},
      </if>
      <if test="l3CodeNo != null">
        #{l3CodeNo,jdbcType=VARCHAR},
      </if>
      <if test="l3ChemCode != null">
        #{l3ChemCode,jdbcType=VARCHAR},
      </if>
      <if test="displayOrder != null">
        #{displayOrder,jdbcType=DECIMAL},
      </if>
      <if test="memo != null">
        #{memo,jdbcType=VARCHAR},
      </if>
      <if test="createOpr != null">
        #{createOpr,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateOpr != null">
        #{updateOpr,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.qcmbasechem.model.QcmBaseChem">
    update QCM_BASE_CHEM
    set CHEM_NAME = #{chemName,jdbcType=VARCHAR},
      CHEM_TYPE = #{chemType,jdbcType=CHAR},
      CHEM_FORMULA = #{chemFormula,jdbcType=VARCHAR},
      VALID_FLAG = #{validFlag,jdbcType=CHAR},
      CHEM_SOURCE = #{chemSource,jdbcType=VARCHAR},
      L3_CODE_NO = #{l3CodeNo,jdbcType=VARCHAR},
      L3_CHEM_CODE = #{l3ChemCode,jdbcType=VARCHAR},
      DISPLAY_ORDER = #{displayOrder,jdbcType=DECIMAL},
      MEMO = #{memo,jdbcType=VARCHAR},
      CREATE_OPR = #{createOpr,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      UPDATE_OPR = #{updateOpr,jdbcType=VARCHAR},
      UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}
    where CHEM_CODE = #{chemCode,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.qcmbasechem.model.QcmBaseChem">
    update QCM_BASE_CHEM
    <set>
      <if test="chemName != null">
        CHEM_NAME = #{chemName,jdbcType=VARCHAR},
      </if>
      <if test="chemType != null">
        CHEM_TYPE = #{chemType,jdbcType=CHAR},
      </if>
      <if test="chemFormula != null">
        CHEM_FORMULA = #{chemFormula,jdbcType=VARCHAR},
      </if>
      <if test="validFlag != null">
        VALID_FLAG = #{validFlag,jdbcType=CHAR},
      </if>
      <if test="chemSource != null">
        CHEM_SOURCE = #{chemSource,jdbcType=VARCHAR},
      </if>
      <if test="l3CodeNo != null">
        L3_CODE_NO = #{l3CodeNo,jdbcType=VARCHAR},
      </if>
      <if test="l3ChemCode != null">
        L3_CHEM_CODE = #{l3ChemCode,jdbcType=VARCHAR},
      </if>
      <if test="displayOrder != null">
        DISPLAY_ORDER = #{displayOrder,jdbcType=DECIMAL},
      </if>
      <if test="memo != null">
        MEMO = #{memo,jdbcType=VARCHAR},
      </if>
      <if test="createOpr != null">
        CREATE_OPR = #{createOpr,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateOpr != null">
        UPDATE_OPR = #{updateOpr,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where CHEM_CODE = #{chemCode,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where 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 QCM_BASE_CHEM 
      (CHEM_CODE, 
      CHEM_NAME, CHEM_TYPE, CHEM_FORMULA, 
      VALID_FLAG, CHEM_SOURCE, L3_CODE_NO, 
      L3_CHEM_CODE, DISPLAY_ORDER, MEMO, 
      CREATE_OPR, CREATE_TIME, UPDATE_OPR, 
      UPDATE_TIME)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.chemCode,jdbcType=VARCHAR}, 
      #{item.chemName,jdbcType=VARCHAR}, #{item.chemType,jdbcType=CHAR}, #{item.chemFormula,jdbcType=VARCHAR}, 
      #{item.validFlag,jdbcType=CHAR}, #{item.chemSource,jdbcType=VARCHAR}, #{item.l3CodeNo,jdbcType=VARCHAR}, 
      #{item.l3ChemCode,jdbcType=VARCHAR}, #{item.displayOrder,jdbcType=DECIMAL}, #{item.memo,jdbcType=VARCHAR}, 
      #{item.createOpr,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateOpr,jdbcType=VARCHAR}, 
      #{item.updateTime,jdbcType=TIMESTAMP} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update QCM_BASE_CHEM
     set
       CHEM_CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.chemCode,jdbcType=VARCHAR}
       </foreach>
       ,CHEM_NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.chemName,jdbcType=VARCHAR}
       </foreach>
       ,CHEM_TYPE=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.chemType,jdbcType=CHAR}
       </foreach>
       ,CHEM_FORMULA=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.chemFormula,jdbcType=VARCHAR}
       </foreach>
       ,VALID_FLAG=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.validFlag,jdbcType=CHAR}
       </foreach>
       ,CHEM_SOURCE=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.chemSource,jdbcType=VARCHAR}
       </foreach>
       ,L3_CODE_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.l3CodeNo,jdbcType=VARCHAR}
       </foreach>
       ,L3_CHEM_CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.l3ChemCode,jdbcType=VARCHAR}
       </foreach>
       ,DISPLAY_ORDER=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.displayOrder,jdbcType=DECIMAL}
       </foreach>
       ,MEMO=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.memo,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_OPR=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.createOpr,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
       </foreach>
       ,UPDATE_OPR=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.updateOpr,jdbcType=VARCHAR}
       </foreach>
       ,UPDATE_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case CHEM_CODE" close="end">
          when #{item.chemCode,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
       </foreach>
     where CHEM_CODE in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.chemCode,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from QCM_BASE_CHEM
    where CHEM_CODE in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="getIdAndName" resultMap="BaseResultMap">
    select  t.chem_code,t.chem_name from QCM_BASE_CHEM t where 1=1
  </select>
</mapper>