<?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.tcm0311.mapper.TCm0311Mapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.tcm0311.model.TCm0311">
    <id column="ITEMCODE" jdbcType="VARCHAR" property="itemcode" />
    <result column="RECORDID" jdbcType="VARCHAR" property="recordid" />
    <result column="CHECKSTATE" jdbcType="VARCHAR" property="checkstate" />
    <result column="ITEMNAME" jdbcType="VARCHAR" property="itemname" />
    <result column="UNIT" jdbcType="VARCHAR" property="unit" />
    <result column="BZ" jdbcType="VARCHAR" property="bz" />
    <result column="XH" jdbcType="DECIMAL" property="xh" />
    <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>

  <insert id="insert" parameterType="com.steerinfo.ems.tcm0311.model.TCm0311">
    insert into T_CM_0311 (ITEMCODE, RECORDID, CHECKSTATE, ITEMNAME, UNIT, BZ, XH, CREATEMAN, CREATETIME)
    values (#{itemcode,jdbcType=VARCHAR}, #{recordid,jdbcType=VARCHAR}, #{checkstate,jdbcType=VARCHAR},
      #{itemname,jdbcType=VARCHAR}, #{unit,jdbcType=VARCHAR}, #{bz,jdbcType=VARCHAR},
      #{xh,jdbcType=DECIMAL}, #{createman,jdbcType=VARCHAR}, SYSDATE
      )
  </insert>

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

  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.tcm0311.model.TCm0311">
    update T_CM_0311
    <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="bz != null">
        BZ = #{bz,jdbcType=VARCHAR},
      </if>
      <if test="xh != null">
        XH = #{xh,jdbcType=DECIMAL},
      </if>
      UPDATEMAN = #{updateman, jdbcType=VARCHAR},
      UPDATETIME = SYSDATE
    </set>
    where ITEMCODE = #{itemcode,jdbcType=VARCHAR}
  </update>

  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select ITEMCODE, RECORDID, CHECKSTATE, ITEMNAME, UNIT, BZ, XH, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_CM_0311
    where ITEMCODE = #{itemcode,jdbcType=VARCHAR}
  </select>

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

  <delete id="batchDelete" parameterType="java.util.List">
    delete from T_CM_0311
    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_0311
    where ITEMCODE not in (select SITEM from T_CM_0312
    where SYSTEMNAME = #{systemname}
        and POWERMONITORNAME = #{powermonitorname}
    <if test="datasource != null and datasource != ''">
        and DATASOURCE = #{datasource}
    </if>
  </select>

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

  <select id="getcheckstate" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select t.ITEMCODE, t.RECORDID, t.CHECKSTATE, t.ITEMNAME, t.UNIT, t.BZ, t.XH from T_CM_0311 t
    join T_CM_0312 t2 on t.ITEMCODE = t2.SITEM
    where t.CHECKSTATE = 'Check'
    <if test="itemcode != null and itemcode !=''">
    and t.ITEMCODE = #{itemcode, jdbcType=VARCHAR}
    </if>
  </select>

  <select id="getMaxXh" resultType="java.lang.Long">
    select MAX(XH) from T_CM_0311
  </select>
  <!--
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_CM_0311
    where 1=1
      <if test="recordid != null">
        and RECORDID = #{recordid}
      </if>
      <if test="checkstate != null and checkstate != ''">
        and CHECKSTATE = #{checkstate}
      </if>
      <if test="itemname != null and itemname != ''">
        and ITEMNAME = #{itemname}
      </if>
      <if test="unit != null and unit != ''">
        and UNIT = #{unit}
      </if>
      <if test="bz != null and bz != ''">
        and BZ = #{bz}
      </if>
      <if test="xh != null">
        and XH = #{xh}
      </if>
  </delete>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.tcm0311.model.TCm0311">
    insert into T_CM_0311
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="itemcode != null">
        ITEMCODE,
      </if>
      <if test="recordid != null">
        RECORDID,
      </if>
      <if test="checkstate != null">
        CHECKSTATE,
      </if>
      <if test="itemname != null">
        ITEMNAME,
      </if>
      <if test="unit != null">
        UNIT,
      </if>
      <if test="bz != null">
        BZ,
      </if>
      <if test="xh != null">
        XH,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="itemcode != null">
        #{itemcode,jdbcType=VARCHAR},
      </if>
      <if test="recordid != null">
        #{recordid,jdbcType=VARCHAR},
      </if>
      <if test="checkstate != null">
        #{checkstate,jdbcType=VARCHAR},
      </if>
      <if test="itemname != null">
        #{itemname,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        #{unit,jdbcType=VARCHAR},
      </if>
      <if test="bz != null">
        #{bz,jdbcType=VARCHAR},
      </if>
      <if test="wsystemcode != null">
        #{wsystemcode,jdbcType=VARCHAR},
      </if>
      <if test="xh != null">
        #{xh,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.tcm0311.model.TCm0311">
    update T_CM_0311
    set RECORDID = #{recordid,jdbcType=VARCHAR},
      CHECKSTATE = #{checkstate,jdbcType=VARCHAR},
      ITEMNAME = #{itemname,jdbcType=VARCHAR},
      UNIT = #{unit,jdbcType=VARCHAR},
      BZ = #{bz,jdbcType=VARCHAR},
      XH = #{xh,jdbcType=DECIMAL}
    where ITEMCODE = #{itemcode,jdbcType=VARCHAR}
  </update>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ITEMCODE, RECORDID, CHECKSTATE, ITEMNAME, UNIT, BZ, XH
    from T_CM_0311
    <where>
      <if test="itemcode != null and itemcode != ''">
        and ITEMCODE = #{itemcode}
      </if>
      <if test="recordid != null">
        and RECORDID = #{recordid}
      </if>
      <if test="checkstate != null and checkstate != ''">
        and CHECKSTATE LIKE '%${checkstate}%'
      </if>
      <if test="itemname != null and itemname != ''">
        and ITEMNAME LIKE '%${itemname}%'
      </if>
      <if test="unit != null and unit != ''">
        and UNIT LIKE '%${unit}%'
      </if>
      <if test="bz != null and bz != ''">
        and BZ LIKE '%${bz}%'
      </if>
      <if test="xh != null">
        and XH = #{xh}
      </if>
    </where>
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_CM_0311 
      (ITEMCODE, RECORDID, CHECKSTATE, ITEMNAME, UNIT, BZ, XH)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.itemcode,jdbcType=VARCHAR}, #{item.recordid,jdbcType=VARCHAR}, #{item.checkstate,jdbcType=VARCHAR}, #{item.itemname,jdbcType=VARCHAR},
      #{item.unit,jdbcType=VARCHAR}, #{item.bz,jdbcType=VARCHAR}, #{item.xh,jdbcType=DECIMAL} from dual
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_CM_0311
     set
       ITEMCODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMCODE" close="end">
          when #{item.itemcode,jdbcType=VARCHAR} then #{item.itemcode,jdbcType=VARCHAR}
       </foreach>
       ,RECORDID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMCODE" close="end">
          when #{item.itemcode,jdbcType=VARCHAR} then #{item.recordid,jdbcType=VARCHAR}
       </foreach>
       ,CHECKSTATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMCODE" close="end">
          when #{item.itemcode,jdbcType=VARCHAR} then #{item.checkstate,jdbcType=VARCHAR}
       </foreach>
       ,ITEMNAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMCODE" close="end">
          when #{item.itemcode,jdbcType=VARCHAR} then #{item.itemname,jdbcType=VARCHAR}
       </foreach>
       ,UNIT=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMCODE" close="end">
          when #{item.itemcode,jdbcType=VARCHAR} then #{item.unit,jdbcType=VARCHAR}
       </foreach>
       ,BZ=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMCODE" close="end">
          when #{item.itemcode,jdbcType=VARCHAR} then #{item.bz,jdbcType=VARCHAR}
       </foreach>
       ,XH=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMCODE" close="end">
          when #{item.itemcode,jdbcType=VARCHAR} then #{item.xh,jdbcType=DECIMAL}
       </foreach>
     where ITEMCODE in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.itemcode,jdbcType=VARCHAR}
     </foreach> 
  </update>
  -->
</mapper>