<?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.tcm0323.mapper.TCm0323Mapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.tcm0323.model.TCm0323">
    <id column="ITEMCODE" jdbcType="VARCHAR" property="itemcode" />
    <result column="RECORDID" jdbcType="VARCHAR" property="recordid" />
    <result column="ITEMNAME" jdbcType="VARCHAR" property="itemname" />
    <result column="UNIT" jdbcType="VARCHAR" property="unit" />
    <result column="NOTE" jdbcType="VARCHAR" property="note" />
    <result column="CHECKSTATE" jdbcType="VARCHAR" property="checkstate" />
  </resultMap>

  <insert id="insert" parameterType="com.steerinfo.ems.tcm0323.model.TCm0323">
    insert into T_CM_0323 (ITEMCODE, RECORDID, ITEMNAME, UNIT, NOTE, CHECKSTATE)
    values (#{itemcode,jdbcType=VARCHAR}, #{recordid,jdbcType=VARCHAR}, #{itemname,jdbcType=VARCHAR}, 
    #{unit,jdbcType=VARCHAR}, #{note,jdbcType=VARCHAR}, #{checkstate,jdbcType=VARCHAR})
  </insert>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_CM_0323
    where ITEMCODE = #{itemcode,jdbcType=VARCHAR}
  </delete>

  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.tcm0323.model.TCm0323">
    update T_CM_0323
    <set>
      <if test="recordid != null">
        RECORDID = #{recordid,jdbcType=VARCHAR},
      </if>
      <if test="checkstate != null">
        CHECKSTATE = #{checkstate,jdbcType=VARCHAR},
      </if>
      <if test="itemname != null">
        ITEMNAME = #{itemname,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        UNIT = #{unit,jdbcType=VARCHAR},
      </if>
      <if test="note != null">
        NOTE = #{note,jdbcType=VARCHAR},
      </if>
    </set>
    where ITEMCODE = #{itemcode,jdbcType=VARCHAR}
  </update>

  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select ITEMCODE, RECORDID, ITEMNAME, UNIT, NOTE, CHECKSTATE
    from T_CM_0323
    where ITEMCODE = #{itemcode,jdbcType=VARCHAR}
  </select>

  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ITEMCODE, RECORDID, ITEMNAME, UNIT, NOTE, CHECKSTATE
    from T_CM_0323
    <where>
      <if test="itemcode != null and itemcode != ''">
        and ITEMCODE like '%${itemcode}%'
      </if>
      <if test="checkstate != null and checkstate != ''">
        and CHECKSTATE = #{checkstate}
      </if>
      <if test="itemname != null and itemname != ''">
        and ITEMNAME like '%${itemname}%'
      </if>
      <if test="unit != null and unit != ''">
        and UNIT like '%${unit}%'
      </if>
    </where>
    order by ITEMNAME
  </select>

  <delete id="batchDelete" parameterType="java.util.List">
    delete from T_CM_0323
    where ITEMCODE in
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>

  <select id="getUnsitemNameAndId" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ITEMCODE, ITEMNAME from T_CM_0323
    where CHECKSTATE = "NoCheck"
    order by ITEMNAME
  </select>

  <select id="getNameAndId" resultMap="BaseResultMap">
    select ITEMCODE, ITEMNAME from T_CM_0323
    order by ITEMNAME
  </select>

  <select id="getcheckstate" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select * from T_CM_0323 t join T_CM_0315 t2 on t.ITEMCODE = t2.SITEM
    where t.CHECKSTATE = 'Check'
    <if test="itemcode != null and itemcode !=''">
      and t.ITEMCODE = #{itemcode, jdbcType=VARCHAR}
    </if>
  </select>
</mapper>