<?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.tcm0310.mapper.TCm0310Mapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.tcm0310.model.TCm0310">
    <id column="WATERCODE" jdbcType="VARCHAR" property="watercode" />
    <result column="RECORDID" jdbcType="VARCHAR" property="recordid" />
    <result column="WATERNAME" jdbcType="VARCHAR" property="watername" />
    <result column="DETECTIONDEPARTMENT" jdbcType="VARCHAR" property="detectiondepartment" />
    <result column="SORT" jdbcType="DECIMAL" property="sort" />
    <result column="USESTATE" jdbcType="VARCHAR" property="usestate" />
    <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>

  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select WATERCODE, RECORDID, WATERNAME, DETECTIONDEPARTMENT, SORT, USESTATE, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_CM_0310
    <where>
      <if test="watercode != null and watercode != ''">
        and WATERCODE like '%${watercode}%'
      </if>
      <if test="watername != null and watername != ''">
        and WATERNAME like '%${watername}%'
      </if>
      <if test="detectiondepartment != null and detectiondepartment != ''">
        and DETECTIONDEPARTMENT = #{detectiondepartment}
      </if>
      <if test="sort != null">
        and SORT = #{sort}
      </if>
      <if test="usestate != null and usestate != ''">
        and USESTATE = #{usestate}
      </if>
    </where>
    order by SORT
  </select>

  <insert id="insert" parameterType="com.steerinfo.ems.tcm0310.model.TCm0310">
    insert into T_CM_0310 (WATERCODE, RECORDID, WATERNAME, DETECTIONDEPARTMENT, SORT, USESTATE, CREATEMAN, CREATETIME)
   values (#{watercode,jdbcType=VARCHAR}, #{recordid,jdbcType=VARCHAR}, #{watername,jdbcType=VARCHAR},
      #{detectiondepartment,jdbcType=VARCHAR}, #{sort,jdbcType=DECIMAL}, #{usestate,jdbcType=VARCHAR},
      #{createman,jdbcType=VARCHAR}, SYSDATE)
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.tcm0310.model.TCm0310">
    update T_CM_0310
    <set>
      <if test="detectiondepartment != null">
        DETECTIONDEPARTMENT = #{detectiondepartment,jdbcType=VARCHAR},
      </if>
      <if test="recordid != null">
        RECORDID = #{recordid,jdbcType=VARCHAR},
      </if>
      <if test="watername != null">
        WATERNAME = #{watername,jdbcType=VARCHAR},
      </if>
      <if test="usestate != null">
        USESTATE = #{usestate,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        SORT = #{sort,jdbcType=DECIMAL},
      </if>
      UPDATEMAN = #{updateman, jdbcType=VARCHAR},
      UPDATETIME = SYSDATE
    </set>
    where WATERCODE = #{watercode,jdbcType=VARCHAR}
  </update>

  <select id="selectByPrimaryKey" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select WATERCODE, RECORDID, WATERNAME, DETECTIONDEPARTMENT, SORT, USESTATE, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
     from T_CM_0310
     where WATERCODE = #{watercode,jdbcType=VARCHAR}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_CM_0310
    where WATERCODE = #{watercode,jdbcType=VARCHAR}
  </delete>


  <select id="getNameAndId" resultMap="BaseResultMap">
    select WATERCODE, WATERNAME from T_CM_0310
    order by WATERNAME
  </select>

  <select id="getUseState" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select * from T_CM_0310 t join T_CM_0312 t2 on t.WATERCODE = t2.SYSTEMNAME
    where t.USESTATE = 'Use'
    <if test="watercode != null and watercode !=''">
      and t.WATERCODE = #{watercode, jdbcType=VARCHAR}
    </if>
  </select>

  <select id="getMaxSort" resultType="java.lang.Long">
    SELECT nvl(MAX(SORT),0) from T_CM_0310
  </select>

  <select id="getMaxId" resultType="java.lang.String">
    SELECT MAX(SUBSTR(WATERCODE, LENGTH(WATERCODE) - 4)) from T_CM_0310
  </select>
  <!--
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_CM_0310
    where WATERCODE = #{watercode,jdbcType=VARCHAR}
    <if test="newdetectiondepartment != null">
      and DETECTIONDEPARTMENT = #{detectiondepartment,jdbcType=VARCHAR}
    </if>
  </delete>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_CM_0310
    where WATERCODE = #{watercode,jdbcType=VARCHAR}
  </delete>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.tcm0310.model.TCm0310">
    insert into T_CM_0310
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="watercode != null">
        WATERCODE,
      </if>
      <if test="recordid != null">
        RECORDID,
      </if>
      <if test="watername != null">
        WATERNAME,
      </if>
      <if test="detectiondepartment != null">
        DETECTIONDEPARTMENT,
      </if>
      <if test="sort != null">
        SORT,
      </if>
      <if test="usestate != null">
        USESTATE,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="watercode != null">
        #{watercode,jdbcType=VARCHAR},
      </if>
      <if test="recordid != null">
        #{recordid,jdbcType=VARCHAR},
      </if>
      <if test="watername != null">
        #{watername,jdbcType=VARCHAR},
      </if>
      <if test="detectiondepartment != null">
        #{detectiondepartment,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        #{sort,jdbcType=DECIMAL},
      </if>
      <if test="usestate != null">
        #{usestate,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.tcm0310.model.TCm0310">
    update T_CM_0310
    set RECORDID = #{recordid,jdbcType=VARCHAR},
      WATERNAME = #{watername,jdbcType=VARCHAR},
      DETECTIONDEPARTMENT = #{detectiondepartment,jdbcType=VARCHAR},
      SORT = #{sort,jdbcType=DECIMAL},
      USESTATE = #{usestate,jdbcType=VARCHAR}
    where WATERCODE = #{watercode,jdbcType=VARCHAR}
  </update>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select WATERCODE, RECORDID, WATERNAME, DETECTIONDEPARTMENT, SORT, USESTATE
    from T_CM_0310
    <where>
      <if test="watercode != null and watercode != ''">
        and WATERCODE = #{watercode}
      </if>
      <if test="recordid != null">
        and RECORDID = #{recordid}
      </if>
      <if test="watername != null and watername != ''">
        and WATERNAME LIKE '%${watername}%'
      </if>
      <if test="detectiondepartment != null and detectiondepartment != ''">
        and DETECTIONDEPARTMENT LIKE '%${detectiondepartment}%'
      </if>
      <if test="sort != null">
        and SORT = #{sort}
      </if>
      <if test="usestate != null and usestate != ''">
        and USESTATE LIKE '%${usestate}%'
      </if>
    </where>
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_CM_0310 
      (WATERCODE, 
      RECORDID, WATERNAME, DETECTIONDEPARTMENT, 
      SORT, USESTATE)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.watercode,jdbcType=VARCHAR}, 
      #{item.recordid,jdbcType=VARCHAR}, #{item.watername,jdbcType=VARCHAR}, #{item.detectiondepartment,jdbcType=VARCHAR},
      #{item.sort,jdbcType=DECIMAL}, #{item.usestate,jdbcType=VARCHAR} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_CM_0310
     set
       WATERCODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case WATERCODE" close="end">
          when #{item.watercode,jdbcType=VARCHAR} then #{item.watercode,jdbcType=VARCHAR}
       </foreach>
       ,RECORDID=
       <foreach collection="list" item="item" index="index" separator=" " open="case WATERCODE" close="end">
          when #{item.watercode,jdbcType=VARCHAR} then #{item.recordid,jdbcType=VARCHAR}
       </foreach>
       ,WATERNAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case WATERCODE" close="end">
          when #{item.watercode,jdbcType=VARCHAR} then #{item.watername,jdbcType=VARCHAR}
       </foreach>
       ,DETECTIONDEPARTMENT=
       <foreach collection="list" item="item" index="index" separator=" " open="case WATERCODE" close="end">
          when #{item.watercode,jdbcType=VARCHAR} then #{item.detectiondepartment,jdbcType=VARCHAR}
       </foreach>
       ,SORT=
       <foreach collection="list" item="item" index="index" separator=" " open="case WATERCODE" close="end">
          when #{item.watercode,jdbcType=VARCHAR} then #{item.sort,jdbcType=DECIMAL}
       </foreach>
       ,USESTATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case WATERCODE" close="end">
          when #{item.watercode,jdbcType=VARCHAR} then #{item.usestate,jdbcType=VARCHAR}
       </foreach>
     where WATERCODE in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.watercode,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from T_CM_0310
    where WATERCODE in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  -->
</mapper>