<?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.tcm0312.mapper.TCm0312Mapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.tcm0312.model.TCm0312">
    <id column="RECORDID" jdbcType="VARCHAR" property="recordid" />
    <result column="CREATYEAR" jdbcType="VARCHAR" property="creatyear" />
    <result column="DETECTIONDEPARTMENT" jdbcType="VARCHAR" property="detectiondepartment" />
    <result column="DETECTIONF" jdbcType="VARCHAR" property="detectionf" />
    <result column="NOTE" jdbcType="VARCHAR" property="note" />
    <result column="POWERMONITORNAME" jdbcType="VARCHAR" property="powermonitorname" />
    <result column="SITEM" jdbcType="VARCHAR" property="sitem" />
    <result column="SYSTEMNAME" jdbcType="VARCHAR" property="systemname" />
    <result column="UNIT" jdbcType="VARCHAR" property="unit" />
    <result column="TIMEGRANID" jdbcType="VARCHAR" property="timegranid" />
    <result column="LOWERLIMIT" jdbcType="DECIMAL" property="lowerlimit" />
    <result column="UPPERLIMIT" jdbcType="DECIMAL" property="upperlimit" />
    <result column="DATASOURCE" jdbcType="VARCHAR" property="datasource" />
    <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>

  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.tcm0312.model.TCm0312">
    update T_CM_0312
    <set>
      <if test="creatyear != null">
        CREATYEAR = #{creatyear,jdbcType=VARCHAR},
      </if>
      <if test="detectiondepartment != null">
        DETECTIONDEPARTMENT = #{detectiondepartment,jdbcType=VARCHAR},
      </if>
      <if test="detectionf != null">
        DETECTIONF = #{detectionf,jdbcType=VARCHAR},
      </if>
      <if test="powermonitorname != null">
        POWERMONITORNAME = #{powermonitorname,jdbcType=VARCHAR},
      </if>
      <if test="sitem != null">
        SITEM = #{sitem,jdbcType=VARCHAR},
      </if>
      <if test="systemname != null">
        SYSTEMNAME = #{systemname,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        UNIT = #{unit,jdbcType=VARCHAR},
      </if>
      <if test="timegranid != null">
        TIMEGRANID = #{timegranid,jdbcType=VARCHAR},
      </if>
      <if test="datasource != null">
        DATASOURCE = #{datasource,jdbcType=VARCHAR},
      </if>
      UPDATEMAN = #{updateman, jdbcType=VARCHAR},
      UPDATETIME = SYSDATE
    </set>
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </update>

  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select RECORDID, CREATYEAR, DETECTIONDEPARTMENT, DETECTIONF, LOWERLIMIT, NOTE, POWERMONITORNAME,
    SITEM, SYSTEMNAME, UNIT, UPPERLIMIT, TIMEGRANID, DATASOURCE, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_CM_0312
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </select>

  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, CREATYEAR, DETECTIONDEPARTMENT, DETECTIONF, POWERMONITORNAME, SITEM, SYSTEMNAME,
    UNIT, TIMEGRANID, NOTE, DATASOURCE, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_CM_0312
    <where>
      <if test="creatyear != null and creatyear != ''">
        and CREATYEAR like '%${creatyear,jdbcType=VARCHAR}%'
      </if>
      <if test="detectiondepartment != null and detectiondepartment != ''">
        and DETECTIONDEPARTMENT = #{detectiondepartment,jdbcType=VARCHAR}
      </if>
      <if test="detectionf != null and detectionf != ''">
        and DETECTIONF = #{detectionf,jdbcType=VARCHAR}
      </if>
      <if test="powermonitorname != null and powermonitorname != ''">
        and POWERMONITORNAME = #{powermonitorname,jdbcType=VARCHAR}
      </if>
      <if test="systemname != null and systemname != ''">
        and SYSTEMNAME = #{systemname,jdbcType=VARCHAR}
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
      </if>
      <if test="sitem != null and sitem != ''">
        and SITEM = #{sitem,jdbcType=VARCHAR}
      </if>
      <if test="note != null and note != ''">
        and NOTE = #{note, jdbcType=VARCHAR}
      </if>
      <if test="datasource != null and datasource != ''">
        and DATASOURCE = #{datasource,jdbcType=VARCHAR}
      </if>
    </where>
  </select>

  <insert id="insert" parameterType="com.steerinfo.ems.tcm0312.model.TCm0312">
    insert into T_CM_0312 (RECORDID, CREATYEAR, DETECTIONDEPARTMENT, DETECTIONF, POWERMONITORNAME,
    SITEM, SYSTEMNAME, TIMEGRANID, DATASOURCE, CREATEMAN, CREATETIME)
    values (#{recordid,jdbcType=DECIMAL}, #{creatyear,jdbcType=VARCHAR}, #{detectiondepartment,jdbcType=VARCHAR}, #{detectionf,jdbcType=VARCHAR},
        #{powermonitorname,jdbcType=VARCHAR}, #{sitem,jdbcType=VARCHAR}, #{systemname,jdbcType=VARCHAR}, #{timegranid,jdbcType=VARCHAR},
        #{datasource,jdbcType=VARCHAR}, #{createman,jdbcType=VARCHAR}, SYSDATE)
  </insert>

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

  <select id="getPlanNameAndId" resultType="com.steerinfo.ems.tcm0312.model.VWaterPlanId">
    select ITEMCODE, ITEMNAME from V_WATER_PLANID order by ITEMNAME
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_CM_0312
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </delete>

  <select id="getmanualdata" parameterType="java.util.HashMap">
    select RECORDID, CREATYEAR, DETECTIONDEPARTMENT, DETECTIONF, POWERMONITORNAME, SITEM, SYSTEMNAME,
    UNIT, TIMEGRANID, NOTE, DATASOURCE, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_CM_0312
    where DATASOURCE = #{datasource}
    and TIMEGRANID = #{timegranid}
    and CREATYEAR &lt;= #{creatyear}
  </select>

  <select id="getMaxId" resultType="java.lang.String">
    SELECT MAX(to_number(RECORDID)) from T_CM_0312
  </select>
  <!--
  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_CM_0312
    (RECORDID, CREATYEAR, DETECTIONDEPARTMENT, DETECTIONF, NOTE, POWERMONITORNAME, SITEM, SYSTEMNAME, UNIT, TIMEGRANID)
    ( <foreach collection="list" item="item" separator="union all">
    select
    #{item.recordid,jdbcType=DECIMAL}, #{item.creatyear,jdbcType=VARCHAR}, #{item.detectiondepartment,jdbcType=VARCHAR},
    #{item.detectionf,jdbcType=VARCHAR}, #{item.lowerlimit,jdbcType=DECIMAL}, #{item.note,jdbcType=VARCHAR}, #{item.powermonitorname,jdbcType=VARCHAR},
    #{item.sitem,jdbcType=VARCHAR}, #{item.systemname,jdbcType=VARCHAR}, #{item.unit,jdbcType=VARCHAR}, #{item.upperlimit,jdbcType=DECIMAL}, #{item.timegranid,jdbcType=VARCHAR}
    from dual
  </foreach> )
  </insert>

  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_CM_0312
    where 1=1
      <if test="creatyear != null and creatyear != ''">
        and CREATYEAR = #{creatyear}
      </if>
      <if test="detectiondepartment != null and detectiondepartment != ''">
        and DETECTIONDEPARTMENT = #{detectiondepartment}
      </if>
      <if test="detectionf != null and detectionf != ''">
        and DETECTIONF = #{detectionf}
      </if>
      <if test="lowerlimit != null">
        and LOWERLIMIT = #{lowerlimit}
      </if>
      <if test="note != null and note != ''">
        and NOTE = #{note}
      </if>
      <if test="powermonitorname != null and powermonitorname != ''">
        and POWERMONITORNAME = #{powermonitorname}
      </if>
      <if test="sitem != null and sitem != ''">
        and SITEM = #{sitem}
      </if>
      <if test="systemname != null and systemname != ''">
        and SYSTEMNAME = #{systemname}
      </if>
      <if test="unit != null and unit != ''">
        and UNIT = #{unit}
      </if>
      <if test="upperlimit != null">
        and UPPERLIMIT = #{upperlimit}
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID = #{timegranid}
      </if>
  </delete>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.tcm0312.model.TCm0312">
    insert into T_CM_0312
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="recordid != null">
        RECORDID,
      </if>
      <if test="creatyear != null">
        CREATYEAR,
      </if>
      <if test="detectiondepartment != null">
        DETECTIONDEPARTMENT,
      </if>
      <if test="detectionf != null">
        DETECTIONF,
      </if>
      <if test="lowerlimit != null">
        LOWERLIMIT,
      </if>
      <if test="note != null">
        NOTE,
      </if>
      <if test="powermonitorname != null">
        POWERMONITORNAME,
      </if>
      <if test="sitem != null">
        SITEM,
      </if>
      <if test="systemname != null">
        SYSTEMNAME,
      </if>
      <if test="unit != null">
        UNIT,
      </if>
      <if test="upperlimit != null">
        UPPERLIMIT,
      </if>
      <if test="timegranid != null">
        TIMEGRANID,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="recordid != null">
        #{recordid,jdbcType=DECIMAL},
      </if>
      <if test="creatyear != null">
        #{creatyear,jdbcType=VARCHAR},
      </if>
      <if test="detectiondepartment != null">
        #{detectiondepartment,jdbcType=VARCHAR},
      </if>
      <if test="detectionf != null">
        #{detectionf,jdbcType=VARCHAR},
      </if>
      <if test="lowerlimit != null">
        #{lowerlimit,jdbcType=DECIMAL},
      </if>
      <if test="note != null">
        #{note,jdbcType=VARCHAR},
      </if>
      <if test="powermonitorname != null">
        #{powermonitorname,jdbcType=VARCHAR},
      </if>
      <if test="sitem != null">
        #{sitem,jdbcType=VARCHAR},
      </if>
      <if test="systemname != null">
        #{systemname,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        #{unit,jdbcType=VARCHAR},
      </if>
      <if test="upperlimit != null">
        #{upperlimit,jdbcType=DECIMAL},
      </if>
      <if test="timegranid != null">
        #{timegranid,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.tcm0312.model.TCm0312">
    update T_CM_0312
    set
      CREATYEAR = #{creatyear,jdbcType=VARCHAR},
      DETECTIONDEPARTMENT = #{detectiondepartment,jdbcType=VARCHAR},
      DETECTIONF = #{detectionf,jdbcType=VARCHAR},
      LOWERLIMIT = #{lowerlimit,jdbcType=DECIMAL},
      NOTE = #{note,jdbcType=VARCHAR},
      POWERMONITORNAME = #{powermonitorname,jdbcType=VARCHAR},
      SITEM = #{sitem,jdbcType=VARCHAR},
      SYSTEMNAME = #{systemname,jdbcType=VARCHAR},
      UNIT = #{unit,jdbcType=VARCHAR},
      UPPERLIMIT = #{upperlimit,jdbcType=DECIMAL},
      TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </update>

  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, CREATYEAR, DETECTIONDEPARTMENT, DETECTIONF, LOWERLIMIT, NOTE, POWERMONITORNAME, SITEM, SYSTEMNAME, UNIT, UPPERLIMIT, TIMEGRANID
    from T_CM_0312
    <where>
      <if test="creatyear != null and creatyear != ''">
        and CREATYEAR LIKE '%${creatyear}%'
      </if>
      <if test="detectiondepartment != null and detectiondepartment != ''">
        and DETECTIONDEPARTMENT LIKE '%${detectiondepartment}%'
      </if>
      <if test="detectionf != null and detectionf != ''">
        and DETECTIONF LIKE '%${detectionf}%'
      </if>
      <if test="lowerlimit != null">
        and LOWERLIMIT = #{lowerlimit}
      </if>
      <if test="note != null and note != ''">
        and NOTE LIKE '%${note}%'
      </if>
      <if test="powermonitorname != null and powermonitorname != ''">
        and POWERMONITORNAME LIKE '%${powermonitorname}%'
      </if>
      <if test="sitem != null and sitem != ''">
        and SITEM LIKE '%${sitem}%'
      </if>
      <if test="systemname != null and systemname != ''">
        and SYSTEMNAME LIKE '%${systemname}%'
      </if>
      <if test="unit != null and unit != ''">
        and UNIT LIKE '%${unit}%'
      </if>
      <if test="upperlimit != null">
        and UPPERLIMIT = #{upperlimit}
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID LIKE '%${timegranid}%'
      </if>
    </where>
  </select>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_CM_0312
     set
       RECORDID=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.recordid,jdbcType=DECIMAL}
       </foreach>
       ,CREATYEAR=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.creatyear,jdbcType=VARCHAR}
       </foreach>
       ,DETECTIONDEPARTMENT=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.detectiondepartment,jdbcType=VARCHAR}
       </foreach>
       ,DETECTIONF=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.detectionf,jdbcType=VARCHAR}
       </foreach>
       ,LOWERLIMIT=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.lowerlimit,jdbcType=DECIMAL}
       </foreach>
       ,NOTE=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.note,jdbcType=VARCHAR}
       </foreach>
       ,POWERMONITORNAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.powermonitorname,jdbcType=VARCHAR}
       </foreach>
       ,SITEM=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.sitem,jdbcType=VARCHAR}
       </foreach>
       ,SYSTEMNAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.systemname,jdbcType=VARCHAR}
       </foreach>
       ,UNIT=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.unit,jdbcType=VARCHAR}
       </foreach>
       ,UPPERLIMIT=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.upperlimit,jdbcType=DECIMAL}
       </foreach>
       ,TIMEGRANID=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.timegranid,jdbcType=VARCHAR}
       </foreach>
     where RECORDID in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.recordid,jdbcType=DECIMAL}
     </foreach> 
  </update>
  -->
</mapper>